| OLD | NEW |
| 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 test.context.directory.manager; | 5 library test.context.directory.manager; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/context_manager.dart'; | 9 import 'package:analysis_server/src/context_manager.dart'; |
| 10 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
| 11 import 'package:analyzer/file_system/memory_file_system.dart'; | 11 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 12 import 'package:analyzer/instrumentation/instrumentation.dart'; | 12 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 13 import 'package:analyzer/source/embedder.dart'; | 13 import 'package:analyzer/source/embedder.dart'; |
| 14 import 'package:analyzer/source/error_processor.dart'; | 14 import 'package:analyzer/source/error_processor.dart'; |
| 15 import 'package:analyzer/src/generated/engine.dart'; | 15 import 'package:analyzer/src/generated/engine.dart'; |
| 16 import 'package:analyzer/src/generated/error.dart'; | 16 import 'package:analyzer/src/generated/error.dart'; |
| 17 import 'package:analyzer/src/generated/java_io.dart'; | 17 import 'package:analyzer/src/generated/java_io.dart'; |
| 18 import 'package:analyzer/src/generated/sdk.dart'; |
| 18 import 'package:analyzer/src/generated/source.dart'; | 19 import 'package:analyzer/src/generated/source.dart'; |
| 19 import 'package:analyzer/src/generated/source_io.dart'; | 20 import 'package:analyzer/src/generated/source_io.dart'; |
| 20 import 'package:analyzer/src/services/lint.dart'; | 21 import 'package:analyzer/src/services/lint.dart'; |
| 21 import 'package:analyzer/src/util/glob.dart'; | 22 import 'package:analyzer/src/util/glob.dart'; |
| 22 import 'package:linter/src/plugin/linter_plugin.dart'; | 23 import 'package:linter/src/plugin/linter_plugin.dart'; |
| 23 import 'package:linter/src/rules/avoid_as.dart'; | 24 import 'package:linter/src/rules/avoid_as.dart'; |
| 24 import 'package:package_config/packages.dart'; | |
| 25 import 'package:path/path.dart'; | 25 import 'package:path/path.dart'; |
| 26 import 'package:plugin/manager.dart'; | 26 import 'package:plugin/manager.dart'; |
| 27 import 'package:plugin/plugin.dart'; | 27 import 'package:plugin/plugin.dart'; |
| 28 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 28 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 29 import 'package:unittest/unittest.dart'; | 29 import 'package:unittest/unittest.dart'; |
| 30 | 30 |
| 31 import 'mock_sdk.dart'; |
| 31 import 'mocks.dart'; | 32 import 'mocks.dart'; |
| 32 import 'utils.dart'; | 33 import 'utils.dart'; |
| 33 | 34 |
| 34 main() { | 35 main() { |
| 35 initializeTestEnvironment(); | 36 initializeTestEnvironment(); |
| 36 defineReflectiveTests(AbstractContextManagerTest); | 37 defineReflectiveTests(AbstractContextManagerTest); |
| 37 } | 38 } |
| 38 | 39 |
| 39 @reflectiveTest | 40 @reflectiveTest |
| 40 class AbstractContextManagerTest { | 41 class AbstractContextManagerTest { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 .toList(); | 106 .toList(); |
| 106 } | 107 } |
| 107 | 108 |
| 108 List<ErrorProcessor> get errorProcessors => callbacks.currentContext | 109 List<ErrorProcessor> get errorProcessors => callbacks.currentContext |
| 109 .getConfigurationData(CONFIGURED_ERROR_PROCESSORS); | 110 .getConfigurationData(CONFIGURED_ERROR_PROCESSORS); |
| 110 | 111 |
| 111 List<Linter> get lints => getLints(callbacks.currentContext); | 112 List<Linter> get lints => getLints(callbacks.currentContext); |
| 112 | 113 |
| 113 AnalysisOptions get options => callbacks.currentContext.analysisOptions; | 114 AnalysisOptions get options => callbacks.currentContext.analysisOptions; |
| 114 | 115 |
| 116 Map<String, List<Folder>> get _currentPackageMap => _packageMap(projPath); |
| 117 |
| 115 void deleteFile(List<String> pathComponents) { | 118 void deleteFile(List<String> pathComponents) { |
| 116 String filePath = posix.joinAll(pathComponents); | 119 String filePath = posix.joinAll(pathComponents); |
| 117 resourceProvider.deleteFile(filePath); | 120 resourceProvider.deleteFile(filePath); |
| 118 } | 121 } |
| 119 | 122 |
| 120 ErrorProcessor getProcessor(AnalysisError error) => | 123 ErrorProcessor getProcessor(AnalysisError error) => |
| 121 ErrorProcessor.getProcessor(callbacks.currentContext, error); | 124 ErrorProcessor.getProcessor(callbacks.currentContext, error); |
| 122 | 125 |
| 123 String newFile(List<String> pathComponents, [String content = '']) { | 126 String newFile(List<String> pathComponents, [String content = '']) { |
| 124 String filePath = posix.joinAll(pathComponents); | 127 String filePath = posix.joinAll(pathComponents); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 143 } | 146 } |
| 144 | 147 |
| 145 UriResolver provideEmbeddedUriResolver(Folder folder) => embeddedUriResolver; | 148 UriResolver provideEmbeddedUriResolver(Folder folder) => embeddedUriResolver; |
| 146 | 149 |
| 147 UriResolver providePackageResolver(Folder folder) => packageResolver; | 150 UriResolver providePackageResolver(Folder folder) => packageResolver; |
| 148 | 151 |
| 149 void setUp() { | 152 void setUp() { |
| 150 processRequiredPlugins(); | 153 processRequiredPlugins(); |
| 151 resourceProvider = new MemoryResourceProvider(); | 154 resourceProvider = new MemoryResourceProvider(); |
| 152 packageMapProvider = new MockPackageMapProvider(); | 155 packageMapProvider = new MockPackageMapProvider(); |
| 156 DartSdkManager sdkManager = new DartSdkManager(() { |
| 157 return new MockSdk(); |
| 158 }); |
| 153 manager = new ContextManagerImpl( | 159 manager = new ContextManagerImpl( |
| 154 resourceProvider, | 160 resourceProvider, |
| 161 sdkManager, |
| 155 providePackageResolver, | 162 providePackageResolver, |
| 156 provideEmbeddedUriResolver, | 163 provideEmbeddedUriResolver, |
| 157 packageMapProvider, | 164 packageMapProvider, |
| 158 analysisFilesGlobs, | 165 analysisFilesGlobs, |
| 159 InstrumentationService.NULL_SERVICE, | 166 InstrumentationService.NULL_SERVICE, |
| 160 new AnalysisOptionsImpl()); | 167 new AnalysisOptionsImpl()); |
| 161 callbacks = new TestContextManagerCallbacks(resourceProvider); | 168 callbacks = new TestContextManagerCallbacks(resourceProvider); |
| 162 manager.callbacks = callbacks; | 169 manager.callbacks = callbacks; |
| 163 resourceProvider.newFolder(projPath); | 170 resourceProvider.newFolder(projPath); |
| 164 } | 171 } |
| (...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 void test_setRoots_addFolderWithPackagespecAndPackageRoot() { | 1070 void test_setRoots_addFolderWithPackagespecAndPackageRoot() { |
| 1064 // The package root should take priority. | 1071 // The package root should take priority. |
| 1065 String packagespecPath = posix.join(projPath, '.packages'); | 1072 String packagespecPath = posix.join(projPath, '.packages'); |
| 1066 resourceProvider.newFile(packagespecPath, | 1073 resourceProvider.newFile(packagespecPath, |
| 1067 'unittest:file:///home/somebody/.pub/cache/unittest-0.9.9/lib/'); | 1074 'unittest:file:///home/somebody/.pub/cache/unittest-0.9.9/lib/'); |
| 1068 String packageRootPath = '/package/root/'; | 1075 String packageRootPath = '/package/root/'; |
| 1069 manager.setRoots(<String>[projPath], <String>[], | 1076 manager.setRoots(<String>[projPath], <String>[], |
| 1070 <String, String>{projPath: packageRootPath}); | 1077 <String, String>{projPath: packageRootPath}); |
| 1071 expect(callbacks.currentContextPaths, hasLength(1)); | 1078 expect(callbacks.currentContextPaths, hasLength(1)); |
| 1072 expect(callbacks.currentContextPaths, contains(projPath)); | 1079 expect(callbacks.currentContextPaths, contains(projPath)); |
| 1073 expect(callbacks.currentContextDispositions[projPath].packageRoot, | 1080 _checkPackageRoot(projPath, packageRootPath); |
| 1074 packageRootPath); | |
| 1075 } | 1081 } |
| 1076 | 1082 |
| 1077 void test_setRoots_addFolderWithPubspec() { | 1083 void test_setRoots_addFolderWithPubspec() { |
| 1078 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); | 1084 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); |
| 1079 resourceProvider.newFile(pubspecPath, 'pubspec'); | 1085 resourceProvider.newFile(pubspecPath, 'pubspec'); |
| 1080 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 1086 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 1081 // verify | 1087 // verify |
| 1082 expect(callbacks.currentContextPaths, hasLength(1)); | 1088 expect(callbacks.currentContextPaths, hasLength(1)); |
| 1083 expect(callbacks.currentContextPaths, contains(projPath)); | 1089 expect(callbacks.currentContextPaths, contains(projPath)); |
| 1084 expect(callbacks.currentContextFilePaths[projPath], hasLength(0)); | 1090 expect(callbacks.currentContextFilePaths[projPath], hasLength(0)); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1175 }, | 1181 }, |
| 1176 }; | 1182 }; |
| 1177 // set roots | 1183 // set roots |
| 1178 manager.setRoots(<String>[root], <String>[], <String, String>{}); | 1184 manager.setRoots(<String>[root], <String>[], <String, String>{}); |
| 1179 callbacks.assertContextPaths([root, subProjectA, subProjectB]); | 1185 callbacks.assertContextPaths([root, subProjectA, subProjectB]); |
| 1180 // verify files | 1186 // verify files |
| 1181 callbacks.assertContextFiles(root, [rootFile]); | 1187 callbacks.assertContextFiles(root, [rootFile]); |
| 1182 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); | 1188 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); |
| 1183 callbacks.assertContextFiles(subProjectB, [subProjectB_file]); | 1189 callbacks.assertContextFiles(subProjectB, [subProjectB_file]); |
| 1184 // verify package maps | 1190 // verify package maps |
| 1185 _checkPackageMap(root, isNull); | 1191 expect(_packageMap(root), isNull); |
| 1186 _checkPackageMap( | 1192 expect(_packageMap(subProjectA), |
| 1187 subProjectA, equals(packageMapProvider.packageMaps[subProjectA])); | 1193 equals(packageMapProvider.packageMaps[subProjectA])); |
| 1188 _checkPackageMap( | 1194 expect(_packageMap(subProjectB), |
| 1189 subProjectB, equals(packageMapProvider.packageMaps[subProjectB])); | 1195 equals(packageMapProvider.packageMaps[subProjectB])); |
| 1190 } | 1196 } |
| 1191 | 1197 |
| 1192 void test_setRoots_addPackageRoot() { | 1198 void test_setRoots_addPackageRoot() { |
| 1193 String packagePathFoo = '/package1/foo'; | 1199 String packagePathFoo = '/package1/foo'; |
| 1194 String packageRootPath = '/package2/foo'; | 1200 String packageRootPath = '/package2/foo'; |
| 1195 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); | 1201 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); |
| 1196 packageMapProvider.packageMap = { | 1202 packageMapProvider.packageMap = { |
| 1197 'foo': [packageFolder] | 1203 'foo': [packageFolder] |
| 1198 }; | 1204 }; |
| 1199 List<String> includedPaths = <String>[projPath]; | 1205 List<String> includedPaths = <String>[projPath]; |
| 1200 List<String> excludedPaths = <String>[]; | 1206 List<String> excludedPaths = <String>[]; |
| 1201 manager.setRoots(includedPaths, excludedPaths, <String, String>{}); | 1207 manager.setRoots(includedPaths, excludedPaths, <String, String>{}); |
| 1202 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); | 1208 expect(_currentPackageMap, equals(packageMapProvider.packageMap)); |
| 1203 manager.setRoots(includedPaths, excludedPaths, | 1209 manager.setRoots(includedPaths, excludedPaths, |
| 1204 <String, String>{projPath: packageRootPath}); | 1210 <String, String>{projPath: packageRootPath}); |
| 1205 _checkPackageRoot(projPath, equals(packageRootPath)); | 1211 _checkPackageRoot(projPath, equals(packageRootPath)); |
| 1206 } | 1212 } |
| 1207 | 1213 |
| 1208 void test_setRoots_changePackageRoot() { | 1214 void test_setRoots_changePackageRoot() { |
| 1209 String packageRootPath1 = '/package1'; | 1215 String packageRootPath1 = '/package1'; |
| 1210 String packageRootPath2 = '/package2'; | 1216 String packageRootPath2 = '/package2'; |
| 1211 List<String> includedPaths = <String>[projPath]; | 1217 List<String> includedPaths = <String>[projPath]; |
| 1212 List<String> excludedPaths = <String>[]; | 1218 List<String> excludedPaths = <String>[]; |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1514 _checkPackageRoot(projPath, equals(packageRootPath)); | 1520 _checkPackageRoot(projPath, equals(packageRootPath)); |
| 1515 } | 1521 } |
| 1516 | 1522 |
| 1517 void test_setRoots_newlyAddedFoldersGetProperPackageMap() { | 1523 void test_setRoots_newlyAddedFoldersGetProperPackageMap() { |
| 1518 String packagePath = '/package/foo'; | 1524 String packagePath = '/package/foo'; |
| 1519 Folder packageFolder = resourceProvider.newFolder(packagePath); | 1525 Folder packageFolder = resourceProvider.newFolder(packagePath); |
| 1520 packageMapProvider.packageMap = { | 1526 packageMapProvider.packageMap = { |
| 1521 'foo': [packageFolder] | 1527 'foo': [packageFolder] |
| 1522 }; | 1528 }; |
| 1523 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 1529 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 1524 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); | 1530 expect(_currentPackageMap, equals(packageMapProvider.packageMap)); |
| 1525 } | 1531 } |
| 1526 | 1532 |
| 1527 void test_setRoots_noContext_excludedFolder() { | 1533 void test_setRoots_noContext_excludedFolder() { |
| 1528 // prepare paths | 1534 // prepare paths |
| 1529 String project = '/project'; | 1535 String project = '/project'; |
| 1530 String excludedFolder = '$project/excluded'; | 1536 String excludedFolder = '$project/excluded'; |
| 1531 String excludedPubspec = '$excludedFolder/pubspec.yaml'; | 1537 String excludedPubspec = '$excludedFolder/pubspec.yaml'; |
| 1532 // create files | 1538 // create files |
| 1533 resourceProvider.newFile(excludedPubspec, 'name: ignore-me'); | 1539 resourceProvider.newFile(excludedPubspec, 'name: ignore-me'); |
| 1534 // set "/project", and exclude "/project/excluded" | 1540 // set "/project", and exclude "/project/excluded" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1702 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); | 1708 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); |
| 1703 packageMapProvider.packageMap = { | 1709 packageMapProvider.packageMap = { |
| 1704 'foo': [packageFolder] | 1710 'foo': [packageFolder] |
| 1705 }; | 1711 }; |
| 1706 List<String> includedPaths = <String>[projPath]; | 1712 List<String> includedPaths = <String>[projPath]; |
| 1707 List<String> excludedPaths = <String>[]; | 1713 List<String> excludedPaths = <String>[]; |
| 1708 manager.setRoots(includedPaths, excludedPaths, | 1714 manager.setRoots(includedPaths, excludedPaths, |
| 1709 <String, String>{projPath: packageRootPath}); | 1715 <String, String>{projPath: packageRootPath}); |
| 1710 _checkPackageRoot(projPath, equals(packageRootPath)); | 1716 _checkPackageRoot(projPath, equals(packageRootPath)); |
| 1711 manager.setRoots(includedPaths, excludedPaths, <String, String>{}); | 1717 manager.setRoots(includedPaths, excludedPaths, <String, String>{}); |
| 1712 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); | 1718 expect(_currentPackageMap, equals(packageMapProvider.packageMap)); |
| 1713 } | 1719 } |
| 1714 | 1720 |
| 1715 void test_setRoots_rootPathContainsDotFile() { | 1721 void test_setRoots_rootPathContainsDotFile() { |
| 1716 // If the path to the context root itself contains a folder whose name | 1722 // If the path to the context root itself contains a folder whose name |
| 1717 // begins with '.', then that is not sufficient to cause any files in the | 1723 // begins with '.', then that is not sufficient to cause any files in the |
| 1718 // context to be ignored. | 1724 // context to be ignored. |
| 1719 String project = '/.pub/project'; | 1725 String project = '/.pub/project'; |
| 1720 String fileA = '$project/foo.dart'; | 1726 String fileA = '$project/foo.dart'; |
| 1721 resourceProvider.newFile(fileA, ''); | 1727 resourceProvider.newFile(fileA, ''); |
| 1722 manager.setRoots(<String>[project], <String>[], <String, String>{}); | 1728 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2240 test_watch_modifyPackageMapDependency() { | 2246 test_watch_modifyPackageMapDependency() { |
| 2241 // create a dependency file | 2247 // create a dependency file |
| 2242 String dependencyPath = posix.join(projPath, 'dep'); | 2248 String dependencyPath = posix.join(projPath, 'dep'); |
| 2243 resourceProvider.newFile(dependencyPath, 'contents'); | 2249 resourceProvider.newFile(dependencyPath, 'contents'); |
| 2244 packageMapProvider.dependencies.add(dependencyPath); | 2250 packageMapProvider.dependencies.add(dependencyPath); |
| 2245 // create a Dart file | 2251 // create a Dart file |
| 2246 String dartFilePath = posix.join(projPath, 'main.dart'); | 2252 String dartFilePath = posix.join(projPath, 'main.dart'); |
| 2247 resourceProvider.newFile(dartFilePath, 'contents'); | 2253 resourceProvider.newFile(dartFilePath, 'contents'); |
| 2248 // the created context has the expected empty package map | 2254 // the created context has the expected empty package map |
| 2249 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 2255 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 2250 _checkPackageMap(projPath, isEmpty); | 2256 expect(_currentPackageMap, isEmpty); |
| 2251 // configure package map | 2257 // configure package map |
| 2252 String packagePath = '/package/foo'; | 2258 String packagePath = '/package/foo'; |
| 2253 resourceProvider.newFolder(packagePath); | 2259 resourceProvider.newFolder(packagePath); |
| 2254 packageMapProvider.packageMap = {'foo': projPath}; | 2260 packageMapProvider.packageMap = { |
| 2261 'foo': [resourceProvider.newFolder(projPath)] |
| 2262 }; |
| 2255 // Changing a .dart file in the project shouldn't cause a new | 2263 // Changing a .dart file in the project shouldn't cause a new |
| 2256 // package map to be picked up. | 2264 // package map to be picked up. |
| 2257 resourceProvider.modifyFile(dartFilePath, 'new contents'); | 2265 resourceProvider.modifyFile(dartFilePath, 'new contents'); |
| 2258 return pumpEventQueue().then((_) { | 2266 return pumpEventQueue().then((_) { |
| 2259 _checkPackageMap(projPath, isEmpty); | 2267 expect(_currentPackageMap, isEmpty); |
| 2260 // However, changing the package map dependency should. | 2268 // However, changing the package map dependency should. |
| 2261 resourceProvider.modifyFile(dependencyPath, 'new contents'); | 2269 resourceProvider.modifyFile(dependencyPath, 'new contents'); |
| 2262 return pumpEventQueue().then((_) { | 2270 return pumpEventQueue().then((_) { |
| 2263 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); | 2271 expect(_currentPackageMap, equals(packageMapProvider.packageMap)); |
| 2264 }); | 2272 }); |
| 2265 }); | 2273 }); |
| 2266 } | 2274 } |
| 2267 | 2275 |
| 2268 test_watch_modifyPackageMapDependency_fail() { | 2276 test_watch_modifyPackageMapDependency_fail() { |
| 2269 // create a dependency file | 2277 // create a dependency file |
| 2270 String dependencyPath = posix.join(projPath, 'dep'); | 2278 String dependencyPath = posix.join(projPath, 'dep'); |
| 2271 resourceProvider.newFile(dependencyPath, 'contents'); | 2279 resourceProvider.newFile(dependencyPath, 'contents'); |
| 2272 packageMapProvider.dependencies.add(dependencyPath); | 2280 packageMapProvider.dependencies.add(dependencyPath); |
| 2273 // create a Dart file | 2281 // create a Dart file |
| 2274 String dartFilePath = posix.join(projPath, 'main.dart'); | 2282 String dartFilePath = posix.join(projPath, 'main.dart'); |
| 2275 resourceProvider.newFile(dartFilePath, 'contents'); | 2283 resourceProvider.newFile(dartFilePath, 'contents'); |
| 2276 // the created context has the expected empty package map | 2284 // the created context has the expected empty package map |
| 2277 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 2285 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 2278 _checkPackageMap(projPath, isEmpty); | 2286 expect(_currentPackageMap, isEmpty); |
| 2279 // Change the package map dependency so that the packageMapProvider is | 2287 // Change the package map dependency so that the packageMapProvider is |
| 2280 // re-run, and arrange for it to return null from computePackageMap(). | 2288 // re-run, and arrange for it to return null from computePackageMap(). |
| 2281 packageMapProvider.packageMap = null; | 2289 packageMapProvider.packageMap = null; |
| 2282 resourceProvider.modifyFile(dependencyPath, 'new contents'); | 2290 resourceProvider.modifyFile(dependencyPath, 'new contents'); |
| 2283 return pumpEventQueue().then((_) { | 2291 return pumpEventQueue().then((_) { |
| 2284 // The package map should have been changed to null. | 2292 // The package map should have been changed to null. |
| 2285 _checkPackageMap(projPath, isNull); | 2293 expect(_currentPackageMap, isNull); |
| 2286 }); | 2294 }); |
| 2287 } | 2295 } |
| 2288 | 2296 |
| 2289 test_watch_modifyPackagespec() { | 2297 test_watch_modifyPackagespec() { |
| 2290 String packagesPath = '$projPath/.packages'; | 2298 String packagesPath = '$projPath/.packages'; |
| 2291 String filePath = '$projPath/bin/main.dart'; | 2299 String filePath = '$projPath/bin/main.dart'; |
| 2292 | 2300 |
| 2293 resourceProvider.newFile(packagesPath, ''); | 2301 resourceProvider.newFile(packagesPath, ''); |
| 2294 resourceProvider.newFile(filePath, 'library main;'); | 2302 resourceProvider.newFile(filePath, 'library main;'); |
| 2295 | 2303 |
| 2296 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 2304 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 2297 | 2305 |
| 2298 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; | 2306 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; |
| 2299 expect(filePaths, hasLength(1)); | 2307 expect(filePaths, hasLength(1)); |
| 2300 expect(filePaths, contains(filePath)); | 2308 expect(filePaths, contains(filePath)); |
| 2301 Packages packages = callbacks.currentContextDispositions[projPath].packages; | 2309 expect(_currentPackageMap, isEmpty); |
| 2302 expect(packages.packages, isEmpty); | |
| 2303 | 2310 |
| 2304 // update .packages | 2311 // update .packages |
| 2305 callbacks.now++; | 2312 callbacks.now++; |
| 2306 resourceProvider.modifyFile(packagesPath, 'main:./lib/'); | 2313 resourceProvider.modifyFile(packagesPath, 'main:./lib/'); |
| 2307 return pumpEventQueue().then((_) { | 2314 return pumpEventQueue().then((_) { |
| 2308 // verify new package info | 2315 // verify new package info |
| 2309 packages = callbacks.currentContextDispositions[projPath].packages; | 2316 expect(_currentPackageMap.keys, unorderedEquals(['main'])); |
| 2310 expect(packages.packages, unorderedEquals(['main'])); | |
| 2311 }); | 2317 }); |
| 2312 } | 2318 } |
| 2313 | 2319 |
| 2314 /** | 2320 /** |
| 2315 * Verify that package URI's for source files in [path] will be resolved | 2321 * Verify that package URI's for source files in [path] will be resolved |
| 2316 * using a package map matching [expectation]. | 2322 * using a package root matching [expectation]. |
| 2317 */ | 2323 */ |
| 2318 void _checkPackageMap(String path, expectation) { | 2324 void _checkPackageRoot(String path, expectation) { |
| 2319 FolderDisposition disposition = callbacks.currentContextDispositions[path]; | 2325 // TODO(brianwilkerson) Figure out how to test this. Possibly by comparing |
| 2320 Map<String, List<Folder>> packageMap = | 2326 // the contents of the package map (although that approach doesn't work at |
| 2321 disposition is PackageMapDisposition ? disposition.packageMap : null; | 2327 // the moment). |
| 2322 expect(packageMap, expectation); | 2328 // FolderDisposition disposition = callbacks.currentContextDispositions[path]
; |
| 2329 // expect(disposition.packageRoot, expectation); |
| 2330 // TODO(paulberry): we should also verify that the package map itself is |
| 2331 // correct. See dartbug.com/23909. |
| 2323 } | 2332 } |
| 2324 | 2333 |
| 2325 /** | 2334 Map<String, List<Folder>> _packageMap(String contextPath) { |
| 2326 * Verify that package URI's for source files in [path] will be resolved | 2335 Folder folder = resourceProvider.getFolder(contextPath); |
| 2327 * using a package root maching [expectation]. | 2336 return manager.folderMap[folder]?.sourceFactory?.packageMap; |
| 2328 */ | |
| 2329 void _checkPackageRoot(String path, expectation) { | |
| 2330 FolderDisposition disposition = callbacks.currentContextDispositions[path]; | |
| 2331 expect(disposition.packageRoot, expectation); | |
| 2332 // TODO(paulberry): we should also verify that the package map itself is | |
| 2333 // correct. See dartbug.com/23909. | |
| 2334 } | 2337 } |
| 2335 } | 2338 } |
| 2336 | 2339 |
| 2337 class TestContextManagerCallbacks extends ContextManagerCallbacks { | 2340 class TestContextManagerCallbacks extends ContextManagerCallbacks { |
| 2338 /** | 2341 /** |
| 2339 * Source of timestamps stored in [currentContextFilePaths]. | 2342 * Source of timestamps stored in [currentContextFilePaths]. |
| 2340 */ | 2343 */ |
| 2341 int now = 0; | 2344 int now = 0; |
| 2342 | 2345 |
| 2343 /** | 2346 /** |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2357 <String, Map<String, int>>{}; | 2360 <String, Map<String, int>>{}; |
| 2358 | 2361 |
| 2359 /** | 2362 /** |
| 2360 * A map from the paths of contexts to a set of the sources that should be | 2363 * A map from the paths of contexts to a set of the sources that should be |
| 2361 * explicitly analyzed in those contexts. | 2364 * explicitly analyzed in those contexts. |
| 2362 */ | 2365 */ |
| 2363 final Map<String, Set<Source>> currentContextSources = | 2366 final Map<String, Set<Source>> currentContextSources = |
| 2364 <String, Set<Source>>{}; | 2367 <String, Set<Source>>{}; |
| 2365 | 2368 |
| 2366 /** | 2369 /** |
| 2367 * Map from context to folder disposition. | |
| 2368 */ | |
| 2369 final Map<String, FolderDisposition> currentContextDispositions = | |
| 2370 <String, FolderDisposition>{}; | |
| 2371 | |
| 2372 /** | |
| 2373 * Resource provider used for this test. | 2370 * Resource provider used for this test. |
| 2374 */ | 2371 */ |
| 2375 final ResourceProvider resourceProvider; | 2372 final ResourceProvider resourceProvider; |
| 2376 | 2373 |
| 2377 TestContextManagerCallbacks(this.resourceProvider); | 2374 TestContextManagerCallbacks(this.resourceProvider); |
| 2378 | 2375 |
| 2379 /** | 2376 /** |
| 2380 * Iterable of the paths to contexts that currently exist. | 2377 * Iterable of the paths to contexts that currently exist. |
| 2381 */ | 2378 */ |
| 2382 Iterable<String> get currentContextPaths => currentContextTimestamps.keys; | 2379 Iterable<String> get currentContextPaths => currentContextTimestamps.keys; |
| 2383 | 2380 |
| 2384 @override | 2381 @override |
| 2385 AnalysisContext addContext( | 2382 AnalysisContext addContext( |
| 2386 Folder folder, AnalysisOptions options, FolderDisposition disposition) { | 2383 Folder folder, AnalysisOptions options, FolderDisposition disposition) { |
| 2387 String path = folder.path; | 2384 String path = folder.path; |
| 2388 expect(currentContextPaths, isNot(contains(path))); | 2385 expect(currentContextPaths, isNot(contains(path))); |
| 2389 currentContextTimestamps[path] = now; | 2386 currentContextTimestamps[path] = now; |
| 2390 currentContextFilePaths[path] = <String, int>{}; | 2387 currentContextFilePaths[path] = <String, int>{}; |
| 2391 currentContextSources[path] = new HashSet<Source>(); | 2388 currentContextSources[path] = new HashSet<Source>(); |
| 2392 currentContextDispositions[path] = disposition; | |
| 2393 currentContext = AnalysisEngine.instance.createAnalysisContext(); | 2389 currentContext = AnalysisEngine.instance.createAnalysisContext(); |
| 2394 _locateEmbedderYamls(currentContext, disposition); | 2390 _locateEmbedderYamls(currentContext, disposition); |
| 2395 List<UriResolver> resolvers = []; | 2391 List<UriResolver> resolvers = []; |
| 2396 if (currentContext is InternalAnalysisContext) { | 2392 if (currentContext is InternalAnalysisContext) { |
| 2397 EmbedderYamlLocator embedderYamlLocator = | 2393 EmbedderYamlLocator embedderYamlLocator = |
| 2398 (currentContext as InternalAnalysisContext).embedderYamlLocator; | 2394 (currentContext as InternalAnalysisContext).embedderYamlLocator; |
| 2399 EmbedderUriResolver embedderUriResolver = | 2395 EmbedderUriResolver embedderUriResolver = |
| 2400 new EmbedderUriResolver(embedderYamlLocator.embedderYamls); | 2396 new EmbedderUriResolver(embedderYamlLocator.embedderYamls); |
| 2401 if (embedderUriResolver.length > 0) { | 2397 if (embedderUriResolver.length > 0) { |
| 2402 // We have some embedder dart: uri mappings, add the resolver | 2398 // We have some embedder dart: uri mappings, add the resolver |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2449 // Do nothing. | 2445 // Do nothing. |
| 2450 } | 2446 } |
| 2451 | 2447 |
| 2452 @override | 2448 @override |
| 2453 void removeContext(Folder folder, List<String> flushedFiles) { | 2449 void removeContext(Folder folder, List<String> flushedFiles) { |
| 2454 String path = folder.path; | 2450 String path = folder.path; |
| 2455 expect(currentContextPaths, contains(path)); | 2451 expect(currentContextPaths, contains(path)); |
| 2456 currentContextTimestamps.remove(path); | 2452 currentContextTimestamps.remove(path); |
| 2457 currentContextFilePaths.remove(path); | 2453 currentContextFilePaths.remove(path); |
| 2458 currentContextSources.remove(path); | 2454 currentContextSources.remove(path); |
| 2459 currentContextDispositions.remove(path); | |
| 2460 } | 2455 } |
| 2461 | 2456 |
| 2462 @override | 2457 @override |
| 2463 void updateContextPackageUriResolver( | 2458 void updateContextPackageUriResolver(AnalysisContext context) { |
| 2464 Folder contextFolder, FolderDisposition disposition) { | 2459 // Nothing to do. |
| 2465 currentContextDispositions[contextFolder.path] = disposition; | |
| 2466 } | 2460 } |
| 2467 | 2461 |
| 2468 /// If [disposition] has a package map, attempt to locate `_embedder.yaml` | 2462 /// If [disposition] has a package map, attempt to locate `_embedder.yaml` |
| 2469 /// files. | 2463 /// files. |
| 2470 void _locateEmbedderYamls( | 2464 void _locateEmbedderYamls( |
| 2471 InternalAnalysisContext context, FolderDisposition disposition) { | 2465 InternalAnalysisContext context, FolderDisposition disposition) { |
| 2472 Map<String, List<Folder>> packageMap; | 2466 Map<String, List<Folder>> packageMap; |
| 2473 if (disposition is PackageMapDisposition) { | 2467 if (disposition is PackageMapDisposition) { |
| 2474 packageMap = disposition.packageMap; | 2468 packageMap = disposition.packageMap; |
| 2475 } else if (disposition is PackagesFileDisposition) { | 2469 } else if (disposition is PackagesFileDisposition) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2492 class TestUriResolver extends UriResolver { | 2486 class TestUriResolver extends UriResolver { |
| 2493 Map<Uri, Source> uriMap; | 2487 Map<Uri, Source> uriMap; |
| 2494 | 2488 |
| 2495 TestUriResolver(this.uriMap); | 2489 TestUriResolver(this.uriMap); |
| 2496 | 2490 |
| 2497 @override | 2491 @override |
| 2498 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 2492 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
| 2499 return uriMap[uri]; | 2493 return uriMap[uri]; |
| 2500 } | 2494 } |
| 2501 } | 2495 } |
| OLD | NEW |