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'; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 TestContextManagerCallbacks callbacks; | 57 TestContextManagerCallbacks callbacks; |
58 | 58 |
59 MemoryResourceProvider resourceProvider; | 59 MemoryResourceProvider resourceProvider; |
60 | 60 |
61 MockPackageMapProvider packageMapProvider; | 61 MockPackageMapProvider packageMapProvider; |
62 | 62 |
63 UriResolver packageResolver = null; | 63 UriResolver packageResolver = null; |
64 | 64 |
65 String projPath = '/my/proj'; | 65 String projPath = '/my/proj'; |
66 | 66 |
67 void fail_test_setRoots_addPackageRoot() { | |
68 // TODO(paulberry): failing due to dartbug.com/23909. | |
69 String packagePathFoo = '/package1/foo'; | |
70 String packageRootPath = '/package2/foo'; | |
71 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); | |
72 packageMapProvider.packageMap = {'foo': [packageFolder]}; | |
73 List<String> includedPaths = <String>[projPath]; | |
74 List<String> excludedPaths = <String>[]; | |
75 manager.setRoots(includedPaths, excludedPaths, <String, String>{}); | |
76 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); | |
77 manager.setRoots(includedPaths, excludedPaths, <String, String>{ | |
78 projPath: packageRootPath | |
79 }); | |
80 _checkPackageRoot(projPath, equals(packageRootPath)); | |
81 } | |
82 | |
83 void fail_test_setRoots_changePackageRoot() { | |
84 // TODO(paulberry): failing due to dartbug.com/23909. | |
85 String packageRootPath1 = '/package1'; | |
86 String packageRootPath2 = '/package2'; | |
87 List<String> includedPaths = <String>[projPath]; | |
88 List<String> excludedPaths = <String>[]; | |
89 manager.setRoots(includedPaths, excludedPaths, <String, String>{ | |
90 projPath: packageRootPath1 | |
91 }); | |
92 _checkPackageRoot(projPath, equals(packageRootPath1)); | |
93 manager.setRoots(includedPaths, excludedPaths, <String, String>{ | |
94 projPath: packageRootPath2 | |
95 }); | |
96 _checkPackageRoot(projPath, equals(packageRootPath2)); | |
97 } | |
98 | |
99 void fail_test_setRoots_newFolderWithPackageRoot() { | |
100 // TODO(paulberry): failing due to dartbug.com/23909. | |
101 String packageRootPath = '/package'; | |
102 manager.setRoots(<String>[projPath], <String>[], <String, String>{ | |
103 projPath: packageRootPath | |
104 }); | |
105 _checkPackageRoot(projPath, equals(packageRootPath)); | |
106 } | |
107 | |
108 void fail_test_setRoots_removePackageRoot() { | |
109 // TODO(paulberry): failing due to dartbug.com/23909. | |
110 String packagePathFoo = '/package1/foo'; | |
111 String packageRootPath = '/package2/foo'; | |
112 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); | |
113 packageMapProvider.packageMap = {'foo': [packageFolder]}; | |
114 List<String> includedPaths = <String>[projPath]; | |
115 List<String> excludedPaths = <String>[]; | |
116 manager.setRoots(includedPaths, excludedPaths, <String, String>{ | |
117 projPath: packageRootPath | |
118 }); | |
119 _checkPackageRoot(projPath, equals(packageRootPath)); | |
120 manager.setRoots(includedPaths, excludedPaths, <String, String>{}); | |
121 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); | |
122 } | |
123 | |
124 String newFile(List<String> pathComponents, [String content = '']) { | 67 String newFile(List<String> pathComponents, [String content = '']) { |
125 String filePath = posix.joinAll(pathComponents); | 68 String filePath = posix.joinAll(pathComponents); |
126 resourceProvider.newFile(filePath, content); | 69 resourceProvider.newFile(filePath, content); |
127 return filePath; | 70 return filePath; |
128 } | 71 } |
129 | 72 |
130 String newFolder(List<String> pathComponents) { | 73 String newFolder(List<String> pathComponents) { |
131 String folderPath = posix.joinAll(pathComponents); | 74 String folderPath = posix.joinAll(pathComponents); |
132 resourceProvider.newFolder(folderPath); | 75 resourceProvider.newFolder(folderPath); |
133 return folderPath; | 76 return folderPath; |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); | 568 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); |
626 callbacks.assertContextFiles(subProjectB, [subProjectB_file]); | 569 callbacks.assertContextFiles(subProjectB, [subProjectB_file]); |
627 // verify package maps | 570 // verify package maps |
628 _checkPackageMap(root, isNull); | 571 _checkPackageMap(root, isNull); |
629 _checkPackageMap( | 572 _checkPackageMap( |
630 subProjectA, equals(packageMapProvider.packageMaps[subProjectA])); | 573 subProjectA, equals(packageMapProvider.packageMaps[subProjectA])); |
631 _checkPackageMap( | 574 _checkPackageMap( |
632 subProjectB, equals(packageMapProvider.packageMaps[subProjectB])); | 575 subProjectB, equals(packageMapProvider.packageMaps[subProjectB])); |
633 } | 576 } |
634 | 577 |
| 578 void test_setRoots_addPackageRoot() { |
| 579 String packagePathFoo = '/package1/foo'; |
| 580 String packageRootPath = '/package2/foo'; |
| 581 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); |
| 582 packageMapProvider.packageMap = {'foo': [packageFolder]}; |
| 583 List<String> includedPaths = <String>[projPath]; |
| 584 List<String> excludedPaths = <String>[]; |
| 585 manager.setRoots(includedPaths, excludedPaths, <String, String>{}); |
| 586 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); |
| 587 manager.setRoots(includedPaths, excludedPaths, <String, String>{ |
| 588 projPath: packageRootPath |
| 589 }); |
| 590 _checkPackageRoot(projPath, equals(packageRootPath)); |
| 591 } |
| 592 |
| 593 void test_setRoots_changePackageRoot() { |
| 594 String packageRootPath1 = '/package1'; |
| 595 String packageRootPath2 = '/package2'; |
| 596 List<String> includedPaths = <String>[projPath]; |
| 597 List<String> excludedPaths = <String>[]; |
| 598 manager.setRoots(includedPaths, excludedPaths, <String, String>{ |
| 599 projPath: packageRootPath1 |
| 600 }); |
| 601 _checkPackageRoot(projPath, equals(packageRootPath1)); |
| 602 manager.setRoots(includedPaths, excludedPaths, <String, String>{ |
| 603 projPath: packageRootPath2 |
| 604 }); |
| 605 _checkPackageRoot(projPath, equals(packageRootPath2)); |
| 606 } |
| 607 |
635 void test_setRoots_exclude_newRoot_withExcludedFile() { | 608 void test_setRoots_exclude_newRoot_withExcludedFile() { |
636 // prepare paths | 609 // prepare paths |
637 String project = '/project'; | 610 String project = '/project'; |
638 String file1 = '$project/file1.dart'; | 611 String file1 = '$project/file1.dart'; |
639 String file2 = '$project/file2.dart'; | 612 String file2 = '$project/file2.dart'; |
640 // create files | 613 // create files |
641 resourceProvider.newFile(file1, '// 1'); | 614 resourceProvider.newFile(file1, '// 1'); |
642 resourceProvider.newFile(file2, '// 2'); | 615 resourceProvider.newFile(file2, '// 2'); |
643 // set roots | 616 // set roots |
644 manager.setRoots(<String>[project], <String>[file1], <String, String>{}); | 617 manager.setRoots(<String>[project], <String>[file1], <String, String>{}); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 // exclude "bbb/" | 722 // exclude "bbb/" |
750 manager.setRoots(<String>[project], <String>[folderB], <String, String>{}); | 723 manager.setRoots(<String>[project], <String>[folderB], <String, String>{}); |
751 callbacks.assertContextPaths([project]); | 724 callbacks.assertContextPaths([project]); |
752 callbacks.assertContextFiles(project, [fileA]); | 725 callbacks.assertContextFiles(project, [fileA]); |
753 // stop excluding "bbb/" | 726 // stop excluding "bbb/" |
754 manager.setRoots(<String>[project], <String>[], <String, String>{}); | 727 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
755 callbacks.assertContextPaths([project]); | 728 callbacks.assertContextPaths([project]); |
756 callbacks.assertContextFiles(project, [fileA, fileB]); | 729 callbacks.assertContextFiles(project, [fileA, fileB]); |
757 } | 730 } |
758 | 731 |
| 732 void test_setRoots_newFolderWithPackageRoot() { |
| 733 String packageRootPath = '/package'; |
| 734 manager.setRoots(<String>[projPath], <String>[], <String, String>{ |
| 735 projPath: packageRootPath |
| 736 }); |
| 737 _checkPackageRoot(projPath, equals(packageRootPath)); |
| 738 } |
| 739 |
759 void test_setRoots_newlyAddedFoldersGetProperPackageMap() { | 740 void test_setRoots_newlyAddedFoldersGetProperPackageMap() { |
760 String packagePath = '/package/foo'; | 741 String packagePath = '/package/foo'; |
761 Folder packageFolder = resourceProvider.newFolder(packagePath); | 742 Folder packageFolder = resourceProvider.newFolder(packagePath); |
762 packageMapProvider.packageMap = {'foo': [packageFolder]}; | 743 packageMapProvider.packageMap = {'foo': [packageFolder]}; |
763 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 744 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
764 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); | 745 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); |
765 } | 746 } |
766 | 747 |
767 void test_setRoots_packageResolver() { | 748 void test_setRoots_packageResolver() { |
768 Uri uri = Uri.parse('package:foo/foo.dart'); | 749 Uri uri = Uri.parse('package:foo/foo.dart'); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 callbacks.assertContextFiles(projectB, [projectB_file]); | 862 callbacks.assertContextFiles(projectB, [projectB_file]); |
882 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); | 863 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); |
883 callbacks.assertContextFiles(subProjectB, [subProjectB_file]); | 864 callbacks.assertContextFiles(subProjectB, [subProjectB_file]); |
884 // remove "projectB" | 865 // remove "projectB" |
885 manager.setRoots(<String>[projectA], <String>[], <String, String>{}); | 866 manager.setRoots(<String>[projectA], <String>[], <String, String>{}); |
886 callbacks.assertContextPaths([projectA, subProjectA]); | 867 callbacks.assertContextPaths([projectA, subProjectA]); |
887 callbacks.assertContextFiles(projectA, [projectA_file]); | 868 callbacks.assertContextFiles(projectA, [projectA_file]); |
888 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); | 869 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); |
889 } | 870 } |
890 | 871 |
| 872 void test_setRoots_removePackageRoot() { |
| 873 String packagePathFoo = '/package1/foo'; |
| 874 String packageRootPath = '/package2/foo'; |
| 875 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); |
| 876 packageMapProvider.packageMap = {'foo': [packageFolder]}; |
| 877 List<String> includedPaths = <String>[projPath]; |
| 878 List<String> excludedPaths = <String>[]; |
| 879 manager.setRoots(includedPaths, excludedPaths, <String, String>{ |
| 880 projPath: packageRootPath |
| 881 }); |
| 882 _checkPackageRoot(projPath, equals(packageRootPath)); |
| 883 manager.setRoots(includedPaths, excludedPaths, <String, String>{}); |
| 884 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); |
| 885 } |
| 886 |
891 test_watch_addDummyLink() { | 887 test_watch_addDummyLink() { |
892 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 888 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
893 // empty folder initially | 889 // empty folder initially |
894 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; | 890 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; |
895 expect(filePaths, isEmpty); | 891 expect(filePaths, isEmpty); |
896 // add link | 892 // add link |
897 String filePath = posix.join(projPath, 'foo.dart'); | 893 String filePath = posix.join(projPath, 'foo.dart'); |
898 resourceProvider.newDummyLink(filePath); | 894 resourceProvider.newDummyLink(filePath); |
899 // the link was ignored | 895 // the link was ignored |
900 return pumpEventQueue().then((_) { | 896 return pumpEventQueue().then((_) { |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1413 Map<String, List<Folder>> packageMap = | 1409 Map<String, List<Folder>> packageMap = |
1414 disposition is PackageMapDisposition ? disposition.packageMap : null; | 1410 disposition is PackageMapDisposition ? disposition.packageMap : null; |
1415 expect(packageMap, expectation); | 1411 expect(packageMap, expectation); |
1416 } | 1412 } |
1417 | 1413 |
1418 /** | 1414 /** |
1419 * Verify that package URI's for source files in [path] will be resolved | 1415 * Verify that package URI's for source files in [path] will be resolved |
1420 * using a package root maching [expectation]. | 1416 * using a package root maching [expectation]. |
1421 */ | 1417 */ |
1422 void _checkPackageRoot(String path, expectation) { | 1418 void _checkPackageRoot(String path, expectation) { |
1423 // TODO(paulberry): this code needs to be reworked, since the context | 1419 FolderDisposition disposition = callbacks.currentContextDispositions[path]; |
1424 // manager inspects the contents of the package root directory and converts | 1420 expect(disposition.packageRoot, expectation); |
1425 // it to a package map. The only reason this code used to work was due to | 1421 // TODO(paulberry): we should also verify that the package map itself is |
1426 // dartbug.com/23909. | 1422 // correct. See dartbug.com/23909. |
1427 fail('Cannot verify package root'); | |
1428 } | 1423 } |
1429 } | 1424 } |
1430 | 1425 |
1431 class TestContextManagerCallbacks extends ContextManagerCallbacks { | 1426 class TestContextManagerCallbacks extends ContextManagerCallbacks { |
1432 /** | 1427 /** |
1433 * Source of timestamps stored in [currentContextFilePaths]. | 1428 * Source of timestamps stored in [currentContextFilePaths]. |
1434 */ | 1429 */ |
1435 int now = 0; | 1430 int now = 0; |
1436 | 1431 |
1437 /** | 1432 /** |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1567 class TestUriResolver extends UriResolver { | 1562 class TestUriResolver extends UriResolver { |
1568 Map<Uri, Source> uriMap; | 1563 Map<Uri, Source> uriMap; |
1569 | 1564 |
1570 TestUriResolver(this.uriMap); | 1565 TestUriResolver(this.uriMap); |
1571 | 1566 |
1572 @override | 1567 @override |
1573 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 1568 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
1574 return uriMap[uri]; | 1569 return uriMap[uri]; |
1575 } | 1570 } |
1576 } | 1571 } |
OLD | NEW |