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:analysis_server/src/source/optimizing_pub_package_map_provider.d art'; | 10 import 'package:analysis_server/src/source/optimizing_pub_package_map_provider.d art'; |
11 import 'package:analysis_server/uri/resolver_provider.dart'; | 11 import 'package:analysis_server/uri/resolver_provider.dart'; |
12 import 'package:analyzer/file_system/file_system.dart'; | 12 import 'package:analyzer/file_system/file_system.dart'; |
13 import 'package:analyzer/file_system/memory_file_system.dart'; | 13 import 'package:analyzer/file_system/memory_file_system.dart'; |
14 import 'package:analyzer/instrumentation/instrumentation.dart'; | 14 import 'package:analyzer/instrumentation/instrumentation.dart'; |
15 import 'package:analyzer/source/package_map_resolver.dart'; | 15 import 'package:analyzer/source/package_map_resolver.dart'; |
16 import 'package:analyzer/src/generated/engine.dart'; | 16 import 'package:analyzer/src/generated/engine.dart'; |
17 import 'package:analyzer/src/generated/source.dart'; | 17 import 'package:analyzer/src/generated/source.dart'; |
18 import 'package:analyzer/src/generated/source_io.dart'; | 18 import 'package:analyzer/src/generated/source_io.dart'; |
19 import 'package:package_config/packages.dart'; | |
19 import 'package:path/path.dart'; | 20 import 'package:path/path.dart'; |
20 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 21 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
21 import 'package:unittest/unittest.dart'; | 22 import 'package:unittest/unittest.dart'; |
22 | 23 |
23 import 'mocks.dart'; | 24 import 'mocks.dart'; |
24 | 25 |
25 main() { | 26 main() { |
26 groupSep = ' | '; | 27 groupSep = ' | '; |
27 defineReflectiveTests(AbstractContextManagerTest); | 28 defineReflectiveTests(AbstractContextManagerTest); |
28 } | 29 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 void test_isInAnalysisRoot_inRoot() { | 123 void test_isInAnalysisRoot_inRoot() { |
123 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 124 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
124 expect(manager.isInAnalysisRoot('$projPath/test.dart'), isTrue); | 125 expect(manager.isInAnalysisRoot('$projPath/test.dart'), isTrue); |
125 } | 126 } |
126 | 127 |
127 void test_isInAnalysisRoot_notInRoot() { | 128 void test_isInAnalysisRoot_notInRoot() { |
128 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 129 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
129 expect(manager.isInAnalysisRoot('/test.dart'), isFalse); | 130 expect(manager.isInAnalysisRoot('/test.dart'), isFalse); |
130 } | 131 } |
131 | 132 |
133 test_refresh_folder_with_packagespec() { | |
134 // create a context with a .packages file | |
135 String packagespecFile = posix.join(projPath, '.packages'); | |
136 resourceProvider.newFile(packagespecFile, ''); | |
137 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | |
138 return pumpEventQueue().then((_) { | |
Brian Wilkerson
2015/07/17 18:02:58
You can also make this an async method and return
pquitslund
2015/07/17 19:30:02
Acknowledged.
| |
139 expect(manager.currentContextPaths.toList(), [projPath]); | |
140 manager.now++; | |
141 manager.refresh(null); | |
142 return pumpEventQueue().then((_) { | |
143 expect(manager.currentContextPaths.toList(), [projPath]); | |
144 expect(manager.currentContextTimestamps[projPath], manager.now); | |
145 }); | |
146 }); | |
147 } | |
148 | |
149 test_refresh_folder_with_packagespec_subfolders() { | |
150 // Create a folder with no .packages file, containing two subfolders with | |
151 // .packages files. | |
152 String subdir1Path = posix.join(projPath, 'subdir1'); | |
153 String subdir2Path = posix.join(projPath, 'subdir2'); | |
154 String packagespec1Path = posix.join(subdir1Path, '.packages'); | |
155 String packagespec2Path = posix.join(subdir2Path, '.packages'); | |
156 resourceProvider.newFile(packagespec1Path, ''); | |
157 resourceProvider.newFile(packagespec2Path, ''); | |
158 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | |
159 return pumpEventQueue().then((_) { | |
160 expect(manager.currentContextPaths.toSet(), | |
161 [subdir1Path, subdir2Path, projPath].toSet()); | |
162 manager.now++; | |
163 manager.refresh(null); | |
164 return pumpEventQueue().then((_) { | |
165 expect(manager.currentContextPaths.toSet(), | |
166 [subdir1Path, subdir2Path, projPath].toSet()); | |
167 expect(manager.currentContextTimestamps[projPath], manager.now); | |
168 expect(manager.currentContextTimestamps[subdir1Path], manager.now); | |
169 expect(manager.currentContextTimestamps[subdir2Path], manager.now); | |
170 }); | |
171 }); | |
172 } | |
173 | |
132 test_refresh_folder_with_pubspec() { | 174 test_refresh_folder_with_pubspec() { |
133 // create a context with a pubspec.yaml file | 175 // create a context with a pubspec.yaml file |
134 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); | 176 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); |
135 resourceProvider.newFile(pubspecPath, 'pubspec'); | 177 resourceProvider.newFile(pubspecPath, 'pubspec'); |
136 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 178 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
137 return pumpEventQueue().then((_) { | 179 return pumpEventQueue().then((_) { |
138 expect(manager.currentContextPaths.toList(), [projPath]); | 180 expect(manager.currentContextPaths.toList(), [projPath]); |
139 manager.now++; | 181 manager.now++; |
140 manager.refresh(null); | 182 manager.refresh(null); |
141 return pumpEventQueue().then((_) { | 183 return pumpEventQueue().then((_) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 | 267 |
226 void test_setRoots_addFolderWithDummyLink() { | 268 void test_setRoots_addFolderWithDummyLink() { |
227 String filePath = posix.join(projPath, 'foo.dart'); | 269 String filePath = posix.join(projPath, 'foo.dart'); |
228 resourceProvider.newDummyLink(filePath); | 270 resourceProvider.newDummyLink(filePath); |
229 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 271 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
230 // verify | 272 // verify |
231 var filePaths = manager.currentContextFilePaths[projPath]; | 273 var filePaths = manager.currentContextFilePaths[projPath]; |
232 expect(filePaths, isEmpty); | 274 expect(filePaths, isEmpty); |
233 } | 275 } |
234 | 276 |
277 void test_setRoots_addFolderWithNestedPackageSpec() { | |
278 String examplePath = newFolder([projPath, EXAMPLE_NAME]); | |
279 String libPath = newFolder([projPath, LIB_NAME]); | |
280 | |
281 newFile([projPath, AbstractContextManager.PACKAGE_SPEC_NAME]); | |
282 newFile([libPath, 'main.dart']); | |
283 newFile([examplePath, AbstractContextManager.PACKAGE_SPEC_NAME]); | |
284 newFile([examplePath, 'example.dart']); | |
285 | |
286 packageMapProvider.packageMap['proj'] = | |
287 [resourceProvider.getResource(libPath)]; | |
288 | |
289 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | |
290 | |
291 expect(manager.currentContextPaths, hasLength(2)); | |
292 | |
293 expect(manager.currentContextPaths, contains(projPath)); | |
294 Set<Source> projSources = manager.currentContextSources[projPath]; | |
295 expect(projSources, hasLength(1)); | |
296 expect(projSources.first.uri.toString(), 'file:///my/proj/lib/main.dart'); | |
297 | |
298 expect(manager.currentContextPaths, contains(examplePath)); | |
299 Set<Source> exampleSources = manager.currentContextSources[examplePath]; | |
300 expect(exampleSources, hasLength(1)); | |
301 expect(exampleSources.first.uri.toString(), | |
302 'file:///my/proj/example/example.dart'); | |
303 } | |
304 | |
235 void test_setRoots_addFolderWithNestedPubspec() { | 305 void test_setRoots_addFolderWithNestedPubspec() { |
236 String examplePath = newFolder([projPath, EXAMPLE_NAME]); | 306 String examplePath = newFolder([projPath, EXAMPLE_NAME]); |
237 String libPath = newFolder([projPath, LIB_NAME]); | 307 String libPath = newFolder([projPath, LIB_NAME]); |
238 | 308 |
239 newFile([projPath, AbstractContextManager.PUBSPEC_NAME]); | 309 newFile([projPath, AbstractContextManager.PUBSPEC_NAME]); |
240 newFile([libPath, 'main.dart']); | 310 newFile([libPath, 'main.dart']); |
241 newFile([examplePath, AbstractContextManager.PUBSPEC_NAME]); | 311 newFile([examplePath, AbstractContextManager.PUBSPEC_NAME]); |
242 newFile([examplePath, 'example.dart']); | 312 newFile([examplePath, 'example.dart']); |
243 | 313 |
244 packageMapProvider.packageMap['proj'] = | 314 packageMapProvider.packageMap['proj'] = |
(...skipping 17 matching lines...) Expand all Loading... | |
262 | 332 |
263 void test_setRoots_addFolderWithoutPubspec() { | 333 void test_setRoots_addFolderWithoutPubspec() { |
264 packageMapProvider.packageMap = null; | 334 packageMapProvider.packageMap = null; |
265 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 335 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
266 // verify | 336 // verify |
267 expect(manager.currentContextPaths, hasLength(1)); | 337 expect(manager.currentContextPaths, hasLength(1)); |
268 expect(manager.currentContextPaths, contains(projPath)); | 338 expect(manager.currentContextPaths, contains(projPath)); |
269 expect(manager.currentContextFilePaths[projPath], hasLength(0)); | 339 expect(manager.currentContextFilePaths[projPath], hasLength(0)); |
270 } | 340 } |
271 | 341 |
342 void test_setRoots_addFolderWithPackagespec() { | |
343 String packagespecPath = posix.join(projPath, '.packages'); | |
344 resourceProvider.newFile(packagespecPath, | |
345 'unittest:file:///home/somebody/.pub/cache/unittest-0.9.9/lib/'); | |
346 String libPath = newFolder([projPath, LIB_NAME]); | |
347 File mainFile = | |
348 resourceProvider.newFile(posix.join(libPath, 'main.dart'), ''); | |
349 Source source = mainFile.createSource(); | |
350 | |
351 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | |
352 | |
353 // verify | |
354 expect(manager.currentContextPaths, hasLength(1)); | |
355 expect(manager.currentContextPaths, contains(projPath)); | |
356 expect(manager.currentContextFilePaths[projPath], hasLength(1)); | |
357 | |
358 // smoketest resolution | |
359 SourceFactory sourceFactory = manager.currentContext.sourceFactory; | |
360 Source resolvedSource = | |
361 sourceFactory.resolveUri(source, 'package:unittest/unittest.dart'); | |
362 expect(resolvedSource, isNotNull); | |
363 expect(resolvedSource.fullName, | |
364 equals('/home/somebody/.pub/cache/unittest-0.9.9/lib/unittest.dart')); | |
365 } | |
366 | |
272 void test_setRoots_addFolderWithPubspec() { | 367 void test_setRoots_addFolderWithPubspec() { |
273 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); | 368 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); |
274 resourceProvider.newFile(pubspecPath, 'pubspec'); | 369 resourceProvider.newFile(pubspecPath, 'pubspec'); |
275 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 370 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
276 // verify | 371 // verify |
277 expect(manager.currentContextPaths, hasLength(1)); | 372 expect(manager.currentContextPaths, hasLength(1)); |
278 expect(manager.currentContextPaths, contains(projPath)); | 373 expect(manager.currentContextPaths, contains(projPath)); |
279 expect(manager.currentContextFilePaths[projPath], hasLength(0)); | 374 expect(manager.currentContextFilePaths[projPath], hasLength(0)); |
280 } | 375 } |
281 | 376 |
377 void test_setRoots_addFolderWithPubspec_andPackagespec() { | |
378 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); | |
379 String packagespecPath = posix.join(projPath, '.packages'); | |
380 resourceProvider.newFile(pubspecPath, 'pubspec'); | |
381 resourceProvider.newFile(packagespecPath, ''); | |
382 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | |
383 // verify | |
384 manager.assertContextPaths([projPath]); | |
385 } | |
386 | |
282 void test_setRoots_addFolderWithPubspecAndLib() { | 387 void test_setRoots_addFolderWithPubspecAndLib() { |
283 String binPath = newFolder([projPath, BIN_NAME]); | 388 String binPath = newFolder([projPath, BIN_NAME]); |
284 String libPath = newFolder([projPath, LIB_NAME]); | 389 String libPath = newFolder([projPath, LIB_NAME]); |
285 String srcPath = newFolder([libPath, SRC_NAME]); | 390 String srcPath = newFolder([libPath, SRC_NAME]); |
286 String testPath = newFolder([projPath, TEST_NAME]); | 391 String testPath = newFolder([projPath, TEST_NAME]); |
287 | 392 |
288 newFile([projPath, AbstractContextManager.PUBSPEC_NAME]); | 393 newFile([projPath, AbstractContextManager.PUBSPEC_NAME]); |
289 String appPath = newFile([binPath, 'app.dart']); | 394 String appPath = newFile([binPath, 'app.dart']); |
290 newFile([libPath, 'main.dart']); | 395 newFile([libPath, 'main.dart']); |
291 newFile([srcPath, 'internal.dart']); | 396 newFile([srcPath, 'internal.dart']); |
292 String testFilePath = newFile([testPath, 'main_test.dart']); | 397 String testFilePath = newFile([testPath, 'main_test.dart']); |
293 | 398 |
294 packageMapProvider.packageMap['proj'] = | 399 packageMapProvider.packageMap['proj'] = |
295 [resourceProvider.getResource(libPath)]; | 400 [resourceProvider.getResource(libPath)]; |
296 | 401 |
297 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 402 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
298 Set<Source> sources = manager.currentContextSources[projPath]; | 403 Set<Source> sources = manager.currentContextSources[projPath]; |
299 | 404 |
300 expect(manager.currentContextPaths, hasLength(1)); | 405 expect(manager.currentContextPaths, hasLength(1)); |
301 expect(manager.currentContextPaths, contains(projPath)); | 406 expect(manager.currentContextPaths, contains(projPath)); |
302 expect(sources, hasLength(4)); | 407 expect(sources, hasLength(4)); |
303 List<String> uris = | 408 List<String> uris = |
304 sources.map((Source source) => source.uri.toString()).toList(); | 409 sources.map((Source source) => source.uri.toString()).toList(); |
305 expect(uris, contains('file://$appPath')); | 410 expect(uris, contains('file://$appPath')); |
306 expect(uris, contains('package:proj/main.dart')); | 411 expect(uris, contains('package:proj/main.dart')); |
307 expect(uris, contains('package:proj/src/internal.dart')); | 412 expect(uris, contains('package:proj/src/internal.dart')); |
308 expect(uris, contains('file://$testFilePath')); | 413 expect(uris, contains('file://$testFilePath')); |
309 } | 414 } |
310 | 415 |
416 void test_setRoots_addFolderWithPubspecAndPackagespecFolders() { | |
417 // prepare paths | |
418 String root = '/root'; | |
419 String rootFile = '$root/root.dart'; | |
420 String subProjectA = '$root/sub/aaa'; | |
421 String subProjectB = '$root/sub/sub2/bbb'; | |
422 String subProjectA_file = '$subProjectA/bin/a.dart'; | |
423 String subProjectB_file = '$subProjectB/bin/b.dart'; | |
424 // create files | |
425 resourceProvider.newFile('$subProjectA/pubspec.yaml', 'pubspec'); | |
426 resourceProvider.newFile('$subProjectB/pubspec.yaml', 'pubspec'); | |
427 resourceProvider.newFile('$subProjectA/.packages', ''); | |
428 resourceProvider.newFile('$subProjectB/.packages', ''); | |
429 | |
430 resourceProvider.newFile(rootFile, 'library root;'); | |
431 resourceProvider.newFile(subProjectA_file, 'library a;'); | |
432 resourceProvider.newFile(subProjectB_file, 'library b;'); | |
433 | |
434 // set roots | |
435 manager.setRoots(<String>[root], <String>[], <String, String>{}); | |
436 manager.assertContextPaths([root, subProjectA, subProjectB]); | |
437 // verify files | |
438 manager.assertContextFiles(root, [rootFile]); | |
439 manager.assertContextFiles(subProjectA, [subProjectA_file]); | |
440 manager.assertContextFiles(subProjectB, [subProjectB_file]); | |
441 } | |
442 | |
311 void test_setRoots_addFolderWithPubspecFolders() { | 443 void test_setRoots_addFolderWithPubspecFolders() { |
312 // prepare paths | 444 // prepare paths |
313 String root = '/root'; | 445 String root = '/root'; |
314 String rootFile = '$root/root.dart'; | 446 String rootFile = '$root/root.dart'; |
315 String subProjectA = '$root/sub/aaa'; | 447 String subProjectA = '$root/sub/aaa'; |
316 String subProjectB = '$root/sub/sub2/bbb'; | 448 String subProjectB = '$root/sub/sub2/bbb'; |
317 String subProjectA_file = '$subProjectA/bin/a.dart'; | 449 String subProjectA_file = '$subProjectA/bin/a.dart'; |
318 String subProjectB_file = '$subProjectB/bin/b.dart'; | 450 String subProjectB_file = '$subProjectB/bin/b.dart'; |
319 // create files | 451 // create files |
320 resourceProvider.newFile('$subProjectA/pubspec.yaml', 'pubspec'); | 452 resourceProvider.newFile('$subProjectA/pubspec.yaml', 'pubspec'); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 packageMapProvider.packageMap = null; | 665 packageMapProvider.packageMap = null; |
534 // add one root - there is a context | 666 // add one root - there is a context |
535 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 667 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
536 expect(manager.currentContextPaths, hasLength(1)); | 668 expect(manager.currentContextPaths, hasLength(1)); |
537 // set empty roots - no contexts | 669 // set empty roots - no contexts |
538 manager.setRoots(<String>[], <String>[], <String, String>{}); | 670 manager.setRoots(<String>[], <String>[], <String, String>{}); |
539 expect(manager.currentContextPaths, hasLength(0)); | 671 expect(manager.currentContextPaths, hasLength(0)); |
540 expect(manager.currentContextFilePaths, hasLength(0)); | 672 expect(manager.currentContextFilePaths, hasLength(0)); |
541 } | 673 } |
542 | 674 |
675 void test_setRoots_removeFolderWithPackagespec() { | |
676 // create a pubspec | |
677 String pubspecPath = posix.join(projPath, '.packages'); | |
678 resourceProvider.newFile(pubspecPath, ''); | |
679 // add one root - there is a context | |
680 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | |
681 expect(manager.currentContextPaths, hasLength(1)); | |
682 // set empty roots - no contexts | |
683 manager.setRoots(<String>[], <String>[], <String, String>{}); | |
684 expect(manager.currentContextPaths, hasLength(0)); | |
685 expect(manager.currentContextFilePaths, hasLength(0)); | |
686 } | |
687 | |
688 void test_setRoots_removeFolderWithPackagespecFolder() { | |
689 // prepare paths | |
690 String projectA = '/projectA'; | |
691 String projectB = '/projectB'; | |
692 String subProjectA = '$projectA/sub'; | |
693 String subProjectB = '$projectB/sub'; | |
694 String projectA_file = '$projectA/a.dart'; | |
695 String projectB_file = '$projectB/a.dart'; | |
696 String subProjectA_pubspec = '$subProjectA/.packages'; | |
697 String subProjectB_pubspec = '$subProjectB/.packages'; | |
698 String subProjectA_file = '$subProjectA/bin/sub_a.dart'; | |
699 String subProjectB_file = '$subProjectB/bin/sub_b.dart'; | |
700 // create files | |
701 resourceProvider.newFile(projectA_file, '// a'); | |
702 resourceProvider.newFile(projectB_file, '// b'); | |
703 resourceProvider.newFile(subProjectA_pubspec, ''); | |
704 resourceProvider.newFile(subProjectB_pubspec, ''); | |
705 resourceProvider.newFile(subProjectA_file, '// sub-a'); | |
706 resourceProvider.newFile(subProjectB_file, '// sub-b'); | |
707 // set roots | |
708 manager.setRoots( | |
709 <String>[projectA, projectB], <String>[], <String, String>{}); | |
710 manager.assertContextPaths([projectA, subProjectA, projectB, subProjectB]); | |
711 manager.assertContextFiles(projectA, [projectA_file]); | |
712 manager.assertContextFiles(projectB, [projectB_file]); | |
713 manager.assertContextFiles(subProjectA, [subProjectA_file]); | |
714 manager.assertContextFiles(subProjectB, [subProjectB_file]); | |
715 // remove "projectB" | |
716 manager.setRoots(<String>[projectA], <String>[], <String, String>{}); | |
717 manager.assertContextPaths([projectA, subProjectA]); | |
718 manager.assertContextFiles(projectA, [projectA_file]); | |
719 manager.assertContextFiles(subProjectA, [subProjectA_file]); | |
720 } | |
721 | |
543 void test_setRoots_removeFolderWithPubspec() { | 722 void test_setRoots_removeFolderWithPubspec() { |
544 // create a pubspec | 723 // create a pubspec |
545 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); | 724 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); |
546 resourceProvider.newFile(pubspecPath, 'pubspec'); | 725 resourceProvider.newFile(pubspecPath, 'pubspec'); |
547 // add one root - there is a context | 726 // add one root - there is a context |
548 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 727 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
549 expect(manager.currentContextPaths, hasLength(1)); | 728 expect(manager.currentContextPaths, hasLength(1)); |
550 // set empty roots - no contexts | 729 // set empty roots - no contexts |
551 manager.setRoots(<String>[], <String>[], <String, String>{}); | 730 manager.setRoots(<String>[], <String>[], <String, String>{}); |
552 expect(manager.currentContextPaths, hasLength(0)); | 731 expect(manager.currentContextPaths, hasLength(0)); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
660 // add file in subfolder | 839 // add file in subfolder |
661 String filePath = posix.join(projPath, 'foo', 'bar.dart'); | 840 String filePath = posix.join(projPath, 'foo', 'bar.dart'); |
662 resourceProvider.newFile(filePath, 'contents'); | 841 resourceProvider.newFile(filePath, 'contents'); |
663 // the file was added | 842 // the file was added |
664 return pumpEventQueue().then((_) { | 843 return pumpEventQueue().then((_) { |
665 expect(filePaths, hasLength(1)); | 844 expect(filePaths, hasLength(1)); |
666 expect(filePaths, contains(filePath)); | 845 expect(filePaths, contains(filePath)); |
667 }); | 846 }); |
668 } | 847 } |
669 | 848 |
849 test_watch_addPackagespec_toRoot() { | |
850 // prepare paths | |
851 String root = '/root'; | |
852 String rootFile = '$root/root.dart'; | |
853 String rootPubspec = '$root/.packages'; | |
Brian Wilkerson
2015/07/17 18:02:58
nit: rootPubspec --> rootPackagespec?
pquitslund
2015/07/17 19:30:02
Done.
| |
854 // create files | |
855 resourceProvider.newFile(rootFile, 'library root;'); | |
856 // set roots | |
857 manager.setRoots(<String>[root], <String>[], <String, String>{}); | |
858 manager.assertContextPaths([root]); | |
859 // verify files | |
860 manager.assertContextFiles(root, [rootFile]); | |
861 // add packagespec - still just one root | |
862 resourceProvider.newFile(rootPubspec, ''); | |
863 return pumpEventQueue().then((_) { | |
864 manager.assertContextPaths([root]); | |
865 manager.assertContextFiles(root, [rootFile]); | |
Brian Wilkerson
2015/07/17 18:02:58
This doesn't actually guarantee that the changes t
pquitslund
2015/07/17 19:30:02
Good call!
This may be tricky to test since the s
| |
866 }); | |
867 } | |
868 | |
869 test_watch_addPackagespec_toSubFolder() { | |
870 // prepare paths | |
871 String root = '/root'; | |
872 String rootFile = '$root/root.dart'; | |
873 String subProject = '$root/sub/aaa'; | |
874 String subPubspec = '$subProject/.packages'; | |
875 String subFile = '$subProject/bin/a.dart'; | |
876 // create files | |
877 resourceProvider.newFile(rootFile, 'library root;'); | |
878 resourceProvider.newFile(subFile, 'library a;'); | |
879 // set roots | |
880 manager.setRoots(<String>[root], <String>[], <String, String>{}); | |
881 manager.assertContextPaths([root]); | |
882 // verify files | |
883 manager.assertContextFiles(root, [rootFile, subFile]); | |
884 // add .packages | |
885 resourceProvider.newFile(subPubspec, ''); | |
886 return pumpEventQueue().then((_) { | |
887 manager.assertContextPaths([root, subProject]); | |
888 manager.assertContextFiles(root, [rootFile]); | |
889 manager.assertContextFiles(subProject, [subFile]); | |
890 }); | |
891 } | |
892 | |
893 test_watch_addPackagespec_toSubFolder_ofSubFolder() { | |
894 // prepare paths | |
895 String root = '/root'; | |
896 String rootFile = '$root/root.dart'; | |
897 String subProject = '$root/sub'; | |
898 String subPubspec = '$subProject/.packages'; | |
899 String subFile = '$subProject/bin/sub.dart'; | |
900 String subSubPubspec = '$subProject/subsub/.packages'; | |
901 // create files | |
902 resourceProvider.newFile(rootFile, 'library root;'); | |
903 resourceProvider.newFile(subPubspec, ''); | |
904 resourceProvider.newFile(subFile, 'library sub;'); | |
905 // set roots | |
906 manager.setRoots(<String>[root], <String>[], <String, String>{}); | |
907 manager.assertContextPaths([root, subProject]); | |
908 manager.assertContextFiles(root, [rootFile]); | |
909 manager.assertContextFiles(subProject, [subFile]); | |
910 // add pubspec - ignore, because is already in a pubspec-based context | |
Brian Wilkerson
2015/07/17 18:02:58
Was "pubspec-based" suppose to be ".packages-based
pquitslund
2015/07/17 19:30:02
Yes!
| |
911 resourceProvider.newFile(subSubPubspec, ''); | |
912 return pumpEventQueue().then((_) { | |
913 manager.assertContextPaths([root, subProject]); | |
914 manager.assertContextFiles(root, [rootFile]); | |
915 manager.assertContextFiles(subProject, [subFile]); | |
916 }); | |
917 } | |
918 | |
919 test_watch_addPackagespec_toSubFolder_withPubspec() { | |
920 // prepare paths | |
921 String root = '/root'; | |
922 String rootFile = '$root/root.dart'; | |
923 String subProject = '$root/sub/aaa'; | |
924 String subPackagespec = '$subProject/.packages'; | |
925 String subPubspec = '$subProject/pubspec.yaml'; | |
926 String subFile = '$subProject/bin/a.dart'; | |
927 // create files | |
928 resourceProvider.newFile(subPubspec, 'pubspec'); | |
929 resourceProvider.newFile(rootFile, 'library root;'); | |
930 resourceProvider.newFile(subFile, 'library a;'); | |
931 // set roots | |
932 manager.setRoots(<String>[root], <String>[], <String, String>{}); | |
933 manager.assertContextPaths([root, subProject]); | |
934 // verify files | |
935 manager.assertContextFiles(root, [rootFile]); | |
936 manager.assertContextFiles(subProject, [subFile]); | |
937 | |
938 // add .packages | |
939 resourceProvider.newFile(subPackagespec, ''); | |
940 return pumpEventQueue().then((_) { | |
941 // Should NOT create another context. | |
942 manager.assertContextPaths([root, subProject]); | |
943 manager.assertContextFiles(root, [rootFile]); | |
944 manager.assertContextFiles(subProject, [subFile]); | |
945 }); | |
946 } | |
947 | |
670 test_watch_addPubspec_toRoot() { | 948 test_watch_addPubspec_toRoot() { |
671 // prepare paths | 949 // prepare paths |
672 String root = '/root'; | 950 String root = '/root'; |
673 String rootFile = '$root/root.dart'; | 951 String rootFile = '$root/root.dart'; |
674 String rootPubspec = '$root/pubspec.yaml'; | 952 String rootPubspec = '$root/pubspec.yaml'; |
675 // create files | 953 // create files |
676 resourceProvider.newFile(rootFile, 'library root;'); | 954 resourceProvider.newFile(rootFile, 'library root;'); |
677 // set roots | 955 // set roots |
678 manager.setRoots(<String>[root], <String>[], <String, String>{}); | 956 manager.setRoots(<String>[root], <String>[], <String, String>{}); |
679 manager.assertContextPaths([root]); | 957 manager.assertContextPaths([root]); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
772 expect(projFolder.exists, isTrue); | 1050 expect(projFolder.exists, isTrue); |
773 // delete the folder | 1051 // delete the folder |
774 resourceProvider.deleteFolder(projPath); | 1052 resourceProvider.deleteFolder(projPath); |
775 return pumpEventQueue().then((_) { | 1053 return pumpEventQueue().then((_) { |
776 expect(file.exists, isFalse); | 1054 expect(file.exists, isFalse); |
777 expect(projFolder.exists, isFalse); | 1055 expect(projFolder.exists, isFalse); |
778 return expect(filePaths, hasLength(0)); | 1056 return expect(filePaths, hasLength(0)); |
779 }); | 1057 }); |
780 } | 1058 } |
781 | 1059 |
1060 test_watch_deletePackagespec_fromRoot() { | |
1061 // prepare paths | |
1062 String root = '/root'; | |
1063 String rootPubspec = '$root/.packages'; | |
1064 String rootFile = '$root/root.dart'; | |
1065 // create files | |
1066 resourceProvider.newFile(rootPubspec, ''); | |
1067 resourceProvider.newFile(rootFile, 'library root;'); | |
1068 // set roots | |
1069 manager.setRoots(<String>[root], <String>[], <String, String>{}); | |
1070 manager.assertContextPaths([root]); | |
1071 manager.assertContextFiles(root, [rootFile]); | |
1072 // delete the pubspec | |
1073 resourceProvider.deleteFile(rootPubspec); | |
1074 return pumpEventQueue().then((_) { | |
1075 manager.assertContextPaths([root]); | |
1076 manager.assertContextFiles(root, [rootFile]); | |
1077 }); | |
1078 } | |
1079 | |
1080 test_watch_deletePackagespec_fromSubFolder() { | |
1081 // prepare paths | |
1082 String root = '/root'; | |
1083 String rootFile = '$root/root.dart'; | |
1084 String subProject = '$root/sub/aaa'; | |
1085 String subPubspec = '$subProject/.packages'; | |
1086 String subFile = '$subProject/bin/a.dart'; | |
1087 // create files | |
1088 resourceProvider.newFile(subPubspec, ''); | |
1089 resourceProvider.newFile(rootFile, 'library root;'); | |
1090 resourceProvider.newFile(subFile, 'library a;'); | |
1091 // set roots | |
1092 manager.setRoots(<String>[root], <String>[], <String, String>{}); | |
1093 manager.assertContextPaths([root, subProject]); | |
1094 // verify files | |
1095 manager.assertContextFiles(root, [rootFile]); | |
1096 manager.assertContextFiles(subProject, [subFile]); | |
1097 // delete the pubspec | |
1098 resourceProvider.deleteFile(subPubspec); | |
1099 return pumpEventQueue().then((_) { | |
1100 manager.assertContextPaths([root]); | |
1101 manager.assertContextFiles(root, [rootFile, subFile]); | |
1102 }); | |
1103 } | |
1104 | |
1105 test_watch_deletePackagespec_fromSubFolder_withPubspec() { | |
1106 // prepare paths | |
1107 String root = '/root'; | |
1108 String rootFile = '$root/root.dart'; | |
1109 String subProject = '$root/sub/aaa'; | |
1110 String subPackagespec = '$subProject/.packages'; | |
1111 String subPubspec = '$subProject/pubspec.yaml'; | |
1112 String subFile = '$subProject/bin/a.dart'; | |
1113 // create files | |
1114 resourceProvider.newFile(subPackagespec, ''); | |
1115 resourceProvider.newFile(subPubspec, 'pubspec'); | |
1116 resourceProvider.newFile(rootFile, 'library root;'); | |
1117 resourceProvider.newFile(subFile, 'library a;'); | |
1118 // set roots | |
1119 manager.setRoots(<String>[root], <String>[], <String, String>{}); | |
1120 manager.assertContextPaths([root, subProject]); | |
1121 // verify files | |
1122 manager.assertContextFiles(root, [rootFile]); | |
1123 manager.assertContextFiles(subProject, [subFile]); | |
1124 // delete the packagespec | |
1125 resourceProvider.deleteFile(subPackagespec); | |
1126 return pumpEventQueue().then((_) { | |
1127 // Should NOT merge | |
1128 manager.assertContextPaths([root, subProject]); | |
1129 manager.assertContextFiles(subProject, [subFile]); | |
1130 }); | |
1131 } | |
1132 | |
782 test_watch_deletePubspec_fromRoot() { | 1133 test_watch_deletePubspec_fromRoot() { |
783 // prepare paths | 1134 // prepare paths |
784 String root = '/root'; | 1135 String root = '/root'; |
785 String rootPubspec = '$root/pubspec.yaml'; | 1136 String rootPubspec = '$root/pubspec.yaml'; |
786 String rootFile = '$root/root.dart'; | 1137 String rootFile = '$root/root.dart'; |
787 // create files | 1138 // create files |
788 resourceProvider.newFile(rootPubspec, 'pubspec'); | 1139 resourceProvider.newFile(rootPubspec, 'pubspec'); |
789 resourceProvider.newFile(rootFile, 'library root;'); | 1140 resourceProvider.newFile(rootFile, 'library root;'); |
790 // set roots | 1141 // set roots |
791 manager.setRoots(<String>[root], <String>[], <String, String>{}); | 1142 manager.setRoots(<String>[root], <String>[], <String, String>{}); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
835 expect(filePaths, contains(filePath)); | 1186 expect(filePaths, contains(filePath)); |
836 expect(filePaths[filePath], equals(manager.now)); | 1187 expect(filePaths[filePath], equals(manager.now)); |
837 // update the file | 1188 // update the file |
838 manager.now++; | 1189 manager.now++; |
839 resourceProvider.modifyFile(filePath, 'new contents'); | 1190 resourceProvider.modifyFile(filePath, 'new contents'); |
840 return pumpEventQueue().then((_) { | 1191 return pumpEventQueue().then((_) { |
841 return expect(filePaths[filePath], equals(manager.now)); | 1192 return expect(filePaths[filePath], equals(manager.now)); |
842 }); | 1193 }); |
843 } | 1194 } |
844 | 1195 |
1196 test_watch_modifyPackagespec() { | |
1197 String packagesPath = '$projPath/.packages'; | |
1198 String filePath = '$projPath/bin/main.dart'; | |
1199 | |
1200 resourceProvider.newFile(packagesPath, ''); | |
1201 resourceProvider.newFile(filePath, 'library main;'); | |
1202 | |
1203 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | |
1204 | |
1205 Map<String, int> filePaths = manager.currentContextFilePaths[projPath]; | |
1206 expect(filePaths, hasLength(1)); | |
1207 expect(filePaths, contains(filePath)); | |
1208 Packages packages = | |
1209 manager.currentContextPackagespecs[projPath]; | |
1210 expect(packages.packages, isEmpty); | |
1211 | |
1212 // update .packages | |
1213 manager.now++; | |
1214 resourceProvider.modifyFile(packagesPath, 'main:./lib/'); | |
1215 return pumpEventQueue().then((_) { | |
1216 // verify new package info | |
1217 packages = manager.currentContextPackagespecs[projPath]; | |
1218 expect(packages.packages, unorderedEquals(['main'])); | |
1219 }); | |
1220 } | |
1221 | |
845 test_watch_modifyPackageMapDependency() { | 1222 test_watch_modifyPackageMapDependency() { |
846 // create a dependency file | 1223 // create a dependency file |
847 String dependencyPath = posix.join(projPath, 'dep'); | 1224 String dependencyPath = posix.join(projPath, 'dep'); |
848 resourceProvider.newFile(dependencyPath, 'contents'); | 1225 resourceProvider.newFile(dependencyPath, 'contents'); |
849 packageMapProvider.dependencies.add(dependencyPath); | 1226 packageMapProvider.dependencies.add(dependencyPath); |
850 // create a Dart file | 1227 // create a Dart file |
851 String dartFilePath = posix.join(projPath, 'main.dart'); | 1228 String dartFilePath = posix.join(projPath, 'main.dart'); |
852 resourceProvider.newFile(dartFilePath, 'contents'); | 1229 resourceProvider.newFile(dartFilePath, 'contents'); |
853 // the created context has the expected empty package map | 1230 // the created context has the expected empty package map |
854 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 1231 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1006 */ | 1383 */ |
1007 final Map<String, Set<Source>> currentContextSources = <String, Set<Source>>{ | 1384 final Map<String, Set<Source>> currentContextSources = <String, Set<Source>>{ |
1008 }; | 1385 }; |
1009 | 1386 |
1010 /** | 1387 /** |
1011 * Map from context to package URI resolver. | 1388 * Map from context to package URI resolver. |
1012 */ | 1389 */ |
1013 final Map<String, UriResolver> currentContextPackageUriResolvers = | 1390 final Map<String, UriResolver> currentContextPackageUriResolvers = |
1014 <String, UriResolver>{}; | 1391 <String, UriResolver>{}; |
1015 | 1392 |
1393 /** | |
1394 * Map from context to packages object. | |
1395 */ | |
1396 final Map<String, Packages> currentContextPackagespecs = <String, Packages>{}; | |
1397 | |
1016 TestContextManager(MemoryResourceProvider resourceProvider, | 1398 TestContextManager(MemoryResourceProvider resourceProvider, |
1017 ResolverProvider packageResolverProvider, | 1399 ResolverProvider packageResolverProvider, |
1018 OptimizingPubPackageMapProvider packageMapProvider) | 1400 OptimizingPubPackageMapProvider packageMapProvider) |
1019 : super(resourceProvider, packageResolverProvider, packageMapProvider, | 1401 : super(resourceProvider, packageResolverProvider, packageMapProvider, |
1020 InstrumentationService.NULL_SERVICE); | 1402 InstrumentationService.NULL_SERVICE); |
1021 | 1403 |
1022 /** | 1404 /** |
1023 * Iterable of the paths to contexts that currently exist. | 1405 * Iterable of the paths to contexts that currently exist. |
1024 */ | 1406 */ |
1025 Iterable<String> get currentContextPaths => currentContextTimestamps.keys; | 1407 Iterable<String> get currentContextPaths => currentContextTimestamps.keys; |
1026 | 1408 |
1027 @override | 1409 @override |
1028 AnalysisContext addContext(Folder folder, UriResolver packageUriResolver) { | 1410 AnalysisContext addContext( |
1411 Folder folder, UriResolver packageUriResolver, Packages packages) { | |
1029 String path = folder.path; | 1412 String path = folder.path; |
1030 expect(currentContextPaths, isNot(contains(path))); | 1413 expect(currentContextPaths, isNot(contains(path))); |
1031 currentContextTimestamps[path] = now; | 1414 currentContextTimestamps[path] = now; |
1032 currentContextFilePaths[path] = <String, int>{}; | 1415 currentContextFilePaths[path] = <String, int>{}; |
1033 currentContextSources[path] = new HashSet<Source>(); | 1416 currentContextSources[path] = new HashSet<Source>(); |
1034 currentContextPackageUriResolvers[path] = packageUriResolver; | 1417 currentContextPackageUriResolvers[path] = packageUriResolver; |
1418 currentContextPackagespecs[path] = packages; | |
1035 currentContext = AnalysisEngine.instance.createAnalysisContext(); | 1419 currentContext = AnalysisEngine.instance.createAnalysisContext(); |
1036 currentContext.sourceFactory = new SourceFactory( | 1420 List<UriResolver> resolvers = [new FileUriResolver()]; |
1037 packageUriResolver == null ? [] : [packageUriResolver]); | 1421 if (packageUriResolver != null) { |
1422 resolvers.add(packageUriResolver); | |
1423 } | |
1424 currentContext.sourceFactory = new SourceFactory(resolvers, packages); | |
1038 return currentContext; | 1425 return currentContext; |
1039 } | 1426 } |
1040 | 1427 |
1041 @override | 1428 @override |
1042 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { | 1429 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { |
1043 Map<String, int> filePaths = currentContextFilePaths[contextFolder.path]; | 1430 Map<String, int> filePaths = currentContextFilePaths[contextFolder.path]; |
1044 Set<Source> sources = currentContextSources[contextFolder.path]; | 1431 Set<Source> sources = currentContextSources[contextFolder.path]; |
1045 | 1432 |
1046 for (Source source in changeSet.addedSources) { | 1433 for (Source source in changeSet.addedSources) { |
1047 expect(filePaths, isNot(contains(source.fullName))); | 1434 expect(filePaths, isNot(contains(source.fullName))); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1089 // Emacs creates dummy links to track the fact that a file is open for | 1476 // Emacs creates dummy links to track the fact that a file is open for |
1090 // editing and has unsaved changes (e.g. having unsaved changes to | 1477 // editing and has unsaved changes (e.g. having unsaved changes to |
1091 // 'foo.dart' causes a link '.#foo.dart' to be created, which points to the | 1478 // 'foo.dart' causes a link '.#foo.dart' to be created, which points to the |
1092 // non-existent file 'username@hostname.pid'. To avoid these dummy links | 1479 // non-existent file 'username@hostname.pid'. To avoid these dummy links |
1093 // causing the analyzer to thrash, just ignore links to non-existent files. | 1480 // causing the analyzer to thrash, just ignore links to non-existent files. |
1094 return file.exists; | 1481 return file.exists; |
1095 } | 1482 } |
1096 | 1483 |
1097 @override | 1484 @override |
1098 void updateContextPackageUriResolver( | 1485 void updateContextPackageUriResolver( |
1099 Folder contextFolder, UriResolver packageUriResolver) { | 1486 Folder contextFolder, UriResolver packageUriResolver, Packages packages) { |
1100 currentContextPackageUriResolvers[contextFolder.path] = packageUriResolver; | 1487 currentContextPackageUriResolvers[contextFolder.path] = packageUriResolver; |
1488 currentContextPackagespecs[contextFolder.path] = packages; | |
1101 } | 1489 } |
1102 } | 1490 } |
1103 | 1491 |
1104 /** | 1492 /** |
1105 * A [Source] that knows it's [fullName]. | 1493 * A [Source] that knows it's [fullName]. |
1106 */ | 1494 */ |
1107 class TestSource implements Source { | 1495 class TestSource implements Source { |
1108 TestSource(); | 1496 TestSource(); |
1109 | 1497 |
1110 @override | 1498 @override |
1111 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 1499 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
1112 } | 1500 } |
1113 | 1501 |
1114 class TestUriResolver extends UriResolver { | 1502 class TestUriResolver extends UriResolver { |
1115 Map<Uri, Source> uriMap; | 1503 Map<Uri, Source> uriMap; |
1116 | 1504 |
1117 TestUriResolver(this.uriMap); | 1505 TestUriResolver(this.uriMap); |
1118 | 1506 |
1119 @override | 1507 @override |
1120 Source resolveAbsolute(Uri uri) { | 1508 Source resolveAbsolute(Uri uri) { |
1121 return uriMap[uri]; | 1509 return uriMap[uri]; |
1122 } | 1510 } |
1123 } | 1511 } |
OLD | NEW |