Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: pkg/analyzer/test/generated/all_the_rest_test.dart

Issue 2273423002: In URI resolution tests, don't access the local filesystem. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.test.generated.all_the_rest_test; 5 library analyzer.test.generated.all_the_rest_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/token.dart'; 8 import 'package:analyzer/dart/ast/token.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/type.dart'; 10 import 'package:analyzer/dart/element/type.dart';
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 runReflectiveTests(ErrorSeverityTest); 57 runReflectiveTests(ErrorSeverityTest);
58 runReflectiveTests(ExitDetectorTest); 58 runReflectiveTests(ExitDetectorTest);
59 runReflectiveTests(ExitDetectorTest2); 59 runReflectiveTests(ExitDetectorTest2);
60 runReflectiveTests(FileBasedSourceTest); 60 runReflectiveTests(FileBasedSourceTest);
61 runReflectiveTests(ResolveRelativeUriTest); 61 runReflectiveTests(ResolveRelativeUriTest);
62 // ignore: deprecated_member_use 62 // ignore: deprecated_member_use
63 runReflectiveTests(SDKLibrariesReaderTest); 63 runReflectiveTests(SDKLibrariesReaderTest);
64 runReflectiveTests(UriKindTest); 64 runReflectiveTests(UriKindTest);
65 } 65 }
66 66
67 /**
68 * Create a tiny mock SDK for use in URI resolution tests.
69 */
70 DartSdk _createSdk() {
71 MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
72 String sdkFolderName =
73 resourceProvider.pathContext.separator == '/' ? '/sdk' : r'C:\sdk';
74 Folder sdkFolder = resourceProvider.newFolder(sdkFolderName);
75 expect(sdkFolder, isNotNull);
76 resourceProvider.newFile(
77 resourceProvider.pathContext.join(sdkFolderName, 'lib', '_internal',
78 'sdk_library_metadata', 'lib', 'libraries.dart'),
79 '''
80 const Map<String, LibraryInfo> libraries = const {
81 "core": const LibraryInfo("core/core.dart")
82 };
83 ''');
84 resourceProvider.newFile(
85 resourceProvider.pathContext
86 .join(sdkFolderName, 'lib', 'core', 'core.dart'),
87 '''
88 library dart.core;
89 ''');
90 return new FolderBasedDartSdk(resourceProvider, sdkFolder);
91 }
92
67 @reflectiveTest 93 @reflectiveTest
68 class ContentCacheTest { 94 class ContentCacheTest {
69 void test_setContents() { 95 void test_setContents() {
70 Source source = new TestSource(); 96 Source source = new TestSource();
71 ContentCache cache = new ContentCache(); 97 ContentCache cache = new ContentCache();
72 expect(cache.getContents(source), isNull); 98 expect(cache.getContents(source), isNull);
73 expect(cache.getModificationStamp(source), isNull); 99 expect(cache.getModificationStamp(source), isNull);
74 String contents = "library lib;"; 100 String contents = "library lib;";
75 expect(cache.setContents(source, contents), isNull); 101 expect(cache.setContents(source, contents), isNull);
76 expect(cache.getContents(source), contents); 102 expect(cache.getContents(source), contents);
77 expect(cache.getModificationStamp(source), isNotNull); 103 expect(cache.getModificationStamp(source), isNotNull);
78 expect(cache.setContents(source, contents), contents); 104 expect(cache.setContents(source, contents), contents);
79 expect(cache.setContents(source, null), contents); 105 expect(cache.setContents(source, null), contents);
80 expect(cache.getContents(source), isNull); 106 expect(cache.getContents(source), isNull);
81 expect(cache.getModificationStamp(source), isNull); 107 expect(cache.getModificationStamp(source), isNull);
82 expect(cache.setContents(source, null), isNull); 108 expect(cache.setContents(source, null), isNull);
83 } 109 }
84 } 110 }
85 111
86 @reflectiveTest 112 @reflectiveTest
87 class CustomUriResolverTest { 113 class CustomUriResolverTest {
88 void test_creation() { 114 void test_creation() {
89 expect(new CustomUriResolver({}), isNotNull); 115 expect(new CustomUriResolver({}), isNotNull);
90 } 116 }
91 117
92 void test_resolve_unknown_uri() { 118 void test_resolve_unknown_uri() {
93 UriResolver resolver = new CustomUriResolver({ 119 UriResolver resolver =
94 'custom:library': '/path/to/library.dart', 120 new CustomUriResolver({'custom:library': '/path/to/library.dart',});
95 });
96 Source result = 121 Source result =
97 resolver.resolveAbsolute(parseUriWithException("custom:non_library")); 122 resolver.resolveAbsolute(parseUriWithException("custom:non_library"));
98 expect(result, isNull); 123 expect(result, isNull);
99 } 124 }
100 125
101 void test_resolve_uri() { 126 void test_resolve_uri() {
102 String path = 127 String path =
103 FileUtilities2.createFile("/path/to/library.dart").getAbsolutePath(); 128 FileUtilities2.createFile("/path/to/library.dart").getAbsolutePath();
104 UriResolver resolver = new CustomUriResolver({ 129 UriResolver resolver = new CustomUriResolver({'custom:library': path,});
105 'custom:library': path,
106 });
107 Source result = 130 Source result =
108 resolver.resolveAbsolute(parseUriWithException("custom:library")); 131 resolver.resolveAbsolute(parseUriWithException("custom:library"));
109 expect(result, isNotNull); 132 expect(result, isNotNull);
110 expect(result.fullName, path); 133 expect(result.fullName, path);
111 } 134 }
112 } 135 }
113 136
114 @reflectiveTest 137 @reflectiveTest
115 class DartUriResolverTest { 138 class DartUriResolverTest {
116 void test_creation() { 139 void test_creation() {
(...skipping 22 matching lines...) Expand all
139 expect(result, isNull); 162 expect(result, isNull);
140 } 163 }
141 164
142 void test_resolve_nonDart() { 165 void test_resolve_nonDart() {
143 DartSdk sdk = _createSdk(); 166 DartSdk sdk = _createSdk();
144 UriResolver resolver = new DartUriResolver(sdk); 167 UriResolver resolver = new DartUriResolver(sdk);
145 Source result = resolver 168 Source result = resolver
146 .resolveAbsolute(parseUriWithException("package:some/file.dart")); 169 .resolveAbsolute(parseUriWithException("package:some/file.dart"));
147 expect(result, isNull); 170 expect(result, isNull);
148 } 171 }
149
150 DartSdk _createSdk() {
151 ResourceProvider resourceProvider = PhysicalResourceProvider.INSTANCE;
152 Folder sdkFolder = FolderBasedDartSdk.defaultSdkDirectory(resourceProvider);
153 expect(sdkFolder, isNotNull);
154 return new FolderBasedDartSdk(resourceProvider, sdkFolder);
155 }
156 } 172 }
157 173
158 @deprecated 174 @deprecated
159 @reflectiveTest 175 @reflectiveTest
160 class DirectoryBasedDartSdkTest { 176 class DirectoryBasedDartSdkTest {
161 void fail_getDocFileFor() { 177 void fail_getDocFileFor() {
162 DirectoryBasedDartSdk sdk = _createDartSdk(); 178 DirectoryBasedDartSdk sdk = _createDartSdk();
163 JavaFile docFile = sdk.getDocFileFor("html"); 179 JavaFile docFile = sdk.getDocFileFor("html");
164 expect(docFile, isNotNull); 180 expect(docFile, isNotNull);
165 } 181 }
(...skipping 4204 matching lines...) Expand 10 before | Expand all | Expand 10 after
4370 } 4386 }
4371 4387
4372 void test_system() { 4388 void test_system() {
4373 JavaFile file = FileUtilities2.createFile("/does/not/exist.dart"); 4389 JavaFile file = FileUtilities2.createFile("/does/not/exist.dart");
4374 FileBasedSource source = 4390 FileBasedSource source =
4375 new FileBasedSource(file, parseUriWithException("dart:core")); 4391 new FileBasedSource(file, parseUriWithException("dart:core"));
4376 expect(source, isNotNull); 4392 expect(source, isNotNull);
4377 expect(source.fullName, file.getAbsolutePath()); 4393 expect(source.fullName, file.getAbsolutePath());
4378 expect(source.isInSystemLibrary, isTrue); 4394 expect(source.isInSystemLibrary, isTrue);
4379 } 4395 }
4380
4381 DartSdk _createSdk() {
4382 ResourceProvider resourceProvider = PhysicalResourceProvider.INSTANCE;
4383 Folder sdkFolder = FolderBasedDartSdk.defaultSdkDirectory(resourceProvider);
4384 expect(sdkFolder, isNotNull);
4385 return new FolderBasedDartSdk(resourceProvider, sdkFolder);
4386 }
4387 } 4396 }
4388 4397
4389 @reflectiveTest 4398 @reflectiveTest
4390 class ResolveRelativeUriTest { 4399 class ResolveRelativeUriTest {
4391 void test_resolveRelative_dart_dartUri() { 4400 void test_resolveRelative_dart_dartUri() {
4392 _assertResolve('dart:foo', 'dart:bar', 'dart:bar'); 4401 _assertResolve('dart:foo', 'dart:bar', 'dart:bar');
4393 } 4402 }
4394 4403
4395 void test_resolveRelative_dart_fileName() { 4404 void test_resolveRelative_dart_fileName() {
4396 _assertResolve('dart:test', 'lib.dart', 'dart:test/lib.dart'); 4405 _assertResolve('dart:test', 'lib.dart', 'dart:test/lib.dart');
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
4523 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); 4532 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI));
4524 expect(UriKind.fromEncoding(0x58), same(null)); 4533 expect(UriKind.fromEncoding(0x58), same(null));
4525 } 4534 }
4526 4535
4527 void test_getEncoding() { 4536 void test_getEncoding() {
4528 expect(UriKind.DART_URI.encoding, 0x64); 4537 expect(UriKind.DART_URI.encoding, 0x64);
4529 expect(UriKind.FILE_URI.encoding, 0x66); 4538 expect(UriKind.FILE_URI.encoding, 0x66);
4530 expect(UriKind.PACKAGE_URI.encoding, 0x70); 4539 expect(UriKind.PACKAGE_URI.encoding, 0x70);
4531 } 4540 }
4532 } 4541 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698