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:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 | 9 |
10 import 'package:analysis_server/src/context_manager.dart'; | 10 import 'package:analysis_server/src/context_manager.dart'; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 main() { | 43 main() { |
44 defineReflectiveSuite(() { | 44 defineReflectiveSuite(() { |
45 defineReflectiveTests(AbstractContextManagerTest); | 45 defineReflectiveTests(AbstractContextManagerTest); |
46 defineReflectiveTests(ContextManagerWithNewOptionsTest); | 46 defineReflectiveTests(ContextManagerWithNewOptionsTest); |
47 defineReflectiveTests(ContextManagerWithOldOptionsTest); | 47 defineReflectiveTests(ContextManagerWithOldOptionsTest); |
48 }); | 48 }); |
49 } | 49 } |
50 | 50 |
51 @reflectiveTest | 51 @reflectiveTest |
52 class AbstractContextManagerTest extends ContextManagerTest { | 52 class AbstractContextManagerTest extends ContextManagerTest { |
53 bool get enableAnalysisDriver => true; | |
54 | |
55 void test_contextsInAnalysisRoot_nestedContext() { | 53 void test_contextsInAnalysisRoot_nestedContext() { |
56 String subProjPath = path.posix.join(projPath, 'subproj'); | 54 String subProjPath = path.posix.join(projPath, 'subproj'); |
57 Folder subProjFolder = resourceProvider.newFolder(subProjPath); | 55 Folder subProjFolder = resourceProvider.newFolder(subProjPath); |
58 resourceProvider.newFile( | 56 resourceProvider.newFile( |
59 path.posix.join(subProjPath, 'pubspec.yaml'), 'contents'); | 57 path.posix.join(subProjPath, 'pubspec.yaml'), 'contents'); |
60 String subProjFilePath = path.posix.join(subProjPath, 'file.dart'); | 58 String subProjFilePath = path.posix.join(subProjPath, 'file.dart'); |
61 resourceProvider.newFile(subProjFilePath, 'contents'); | 59 resourceProvider.newFile(subProjFilePath, 'contents'); |
62 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 60 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
63 // Make sure that there really are contexts for both the main project and | 61 // Make sure that there really are contexts for both the main project and |
64 // the subproject. | 62 // the subproject. |
65 Folder projectFolder = resourceProvider.getFolder(projPath); | 63 Folder projectFolder = resourceProvider.getFolder(projPath); |
66 ContextInfo projContextInfo = manager.getContextInfoFor(projectFolder); | 64 ContextInfo projContextInfo = manager.getContextInfoFor(projectFolder); |
67 expect(projContextInfo, isNotNull); | 65 expect(projContextInfo, isNotNull); |
68 expect(projContextInfo.folder, projectFolder); | 66 expect(projContextInfo.folder, projectFolder); |
69 ContextInfo subProjContextInfo = manager.getContextInfoFor(subProjFolder); | 67 ContextInfo subProjContextInfo = manager.getContextInfoFor(subProjFolder); |
70 expect(subProjContextInfo, isNotNull); | 68 expect(subProjContextInfo, isNotNull); |
71 expect(subProjContextInfo.folder, subProjFolder); | 69 expect(subProjContextInfo.folder, subProjFolder); |
72 if (enableAnalysisDriver) { | 70 expect(projContextInfo.analysisDriver, |
73 expect(projContextInfo.analysisDriver, | 71 isNot(equals(subProjContextInfo.analysisDriver))); |
74 isNot(equals(subProjContextInfo.analysisDriver))); | 72 // Check that getDriversInAnalysisRoot() works. |
75 // Check that getDriversInAnalysisRoot() works. | 73 List<AnalysisDriver> drivers = |
76 List<AnalysisDriver> drivers = | 74 manager.getDriversInAnalysisRoot(projectFolder); |
77 manager.getDriversInAnalysisRoot(projectFolder); | 75 expect(drivers, isNotNull); |
78 expect(drivers, isNotNull); | 76 expect(drivers, hasLength(2)); |
79 expect(drivers, hasLength(2)); | 77 expect(drivers, contains(projContextInfo.analysisDriver)); |
80 expect(drivers, contains(projContextInfo.analysisDriver)); | 78 expect(drivers, contains(subProjContextInfo.analysisDriver)); |
81 expect(drivers, contains(subProjContextInfo.analysisDriver)); | |
82 } else { | |
83 expect(projContextInfo.context != subProjContextInfo.context, isTrue); | |
84 // Check that contextsInAnalysisRoot() works. | |
85 List<AnalysisContext> contexts = | |
86 manager.contextsInAnalysisRoot(projectFolder); | |
87 expect(contexts, hasLength(2)); | |
88 expect(contexts, contains(projContextInfo.context)); | |
89 expect(contexts, contains(subProjContextInfo.context)); | |
90 } | |
91 } | 79 } |
92 | 80 |
93 @failingTest | 81 @failingTest |
94 test_embedder_added() async { | 82 test_embedder_added() async { |
95 // NoSuchMethodError: The getter 'apiSignature' was called on null. | 83 // NoSuchMethodError: The getter 'apiSignature' was called on null. |
96 // Receiver: null | 84 // Receiver: null |
97 // Tried calling: apiSignature | 85 // Tried calling: apiSignature |
98 // dart:core Object
.noSuchMethod | 86 // dart:core Object
.noSuchMethod |
99 // package:analyzer/src/dart/analysis/driver.dart 460:20 Analys
isDriver.configure | 87 // package:analyzer/src/dart/analysis/driver.dart 460:20 Analys
isDriver.configure |
100 // package:analysis_server/src/context_manager.dart 1043:16 Contex
tManagerImpl._checkForPackagespecUpdate | 88 // package:analysis_server/src/context_manager.dart 1043:16 Contex
tManagerImpl._checkForPackagespecUpdate |
(...skipping 19 matching lines...) Expand all Loading... |
120 '''); | 108 '''); |
121 | 109 |
122 Folder projectFolder = resourceProvider.newFolder(projPath); | 110 Folder projectFolder = resourceProvider.newFolder(projPath); |
123 | 111 |
124 // NOTE that this is Not in our package path yet. | 112 // NOTE that this is Not in our package path yet. |
125 | 113 |
126 // Setup context. | 114 // Setup context. |
127 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 115 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
128 await pumpEventQueue(); | 116 await pumpEventQueue(); |
129 // Confirm that one driver / context was created. | 117 // Confirm that one driver / context was created. |
130 if (enableAnalysisDriver) { | 118 List<AnalysisDriver> drivers = |
131 List<AnalysisDriver> drivers = | 119 manager.getDriversInAnalysisRoot(projectFolder); |
132 manager.getDriversInAnalysisRoot(projectFolder); | 120 expect(drivers, isNotNull); |
133 expect(drivers, isNotNull); | 121 expect(drivers, hasLength(1)); |
134 expect(drivers, hasLength(1)); | |
135 } else { | |
136 List<AnalysisContext> contexts = | |
137 manager.contextsInAnalysisRoot(projectFolder); | |
138 expect(contexts, isNotNull); | |
139 expect(contexts, hasLength(1)); | |
140 } | |
141 | 122 |
142 // No embedded libs yet. | 123 // No embedded libs yet. |
143 expect(sourceFactory.forUri('dart:typed_data'), isNull); | 124 expect(sourceFactory.forUri('dart:typed_data'), isNull); |
144 | 125 |
145 // Add .packages file that introduces a dependency with embedded libs. | 126 // Add .packages file that introduces a dependency with embedded libs. |
146 newFile( | 127 newFile( |
147 [projPath, '.packages'], | 128 [projPath, '.packages'], |
148 r''' | 129 r''' |
149 test_pack:lib/'''); | 130 test_pack:lib/'''); |
150 | 131 |
151 await pumpEventQueue(); | 132 await pumpEventQueue(); |
152 | 133 |
153 // Confirm that we still have just one driver / context. | 134 // Confirm that we still have just one driver / context. |
154 if (enableAnalysisDriver) { | 135 drivers = manager.getDriversInAnalysisRoot(projectFolder); |
155 List<AnalysisDriver> drivers = | 136 expect(drivers, isNotNull); |
156 manager.getDriversInAnalysisRoot(projectFolder); | 137 expect(drivers, hasLength(1)); |
157 expect(drivers, isNotNull); | |
158 expect(drivers, hasLength(1)); | |
159 } else { | |
160 List<AnalysisContext> contexts = | |
161 manager.contextsInAnalysisRoot(projectFolder); | |
162 | |
163 expect(contexts, isNotNull); | |
164 expect(contexts, hasLength(1)); | |
165 } | |
166 | 138 |
167 // Embedded lib should be defined now. | 139 // Embedded lib should be defined now. |
168 expect(sourceFactory.forUri('dart:typed_data'), isNotNull); | 140 expect(sourceFactory.forUri('dart:typed_data'), isNotNull); |
169 } | 141 } |
170 | 142 |
171 test_embedder_packagespec() async { | 143 test_embedder_packagespec() async { |
172 // Create files. | 144 // Create files. |
173 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); | 145 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); |
174 newFile([libPath, 'main.dart']); | 146 newFile([libPath, 'main.dart']); |
175 newFile([libPath, 'nope.dart']); | 147 newFile([libPath, 'nope.dart']); |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 } | 409 } |
438 | 410 |
439 void test_setRoots_addFolderWithDartFile() { | 411 void test_setRoots_addFolderWithDartFile() { |
440 String filePath = path.posix.join(projPath, 'foo.dart'); | 412 String filePath = path.posix.join(projPath, 'foo.dart'); |
441 resourceProvider.newFile(filePath, 'contents'); | 413 resourceProvider.newFile(filePath, 'contents'); |
442 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 414 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
443 // verify | 415 // verify |
444 Iterable<String> filePaths = callbacks.currentFilePaths; | 416 Iterable<String> filePaths = callbacks.currentFilePaths; |
445 expect(filePaths, hasLength(1)); | 417 expect(filePaths, hasLength(1)); |
446 expect(filePaths, contains(filePath)); | 418 expect(filePaths, contains(filePath)); |
447 if (enableAnalysisDriver) { | 419 List<AnalysisDriver> drivers = |
448 List<AnalysisDriver> drivers = manager | 420 manager.getDriversInAnalysisRoot(resourceProvider.newFolder(projPath)); |
449 .getDriversInAnalysisRoot(resourceProvider.newFolder(projPath)); | 421 expect(drivers, hasLength(1)); |
450 expect(drivers, hasLength(1)); | 422 expect(drivers[0], isNotNull); |
451 expect(drivers[0], isNotNull); | |
452 } else { | |
453 List<AnalysisContext> contextsInAnalysisRoot = | |
454 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); | |
455 expect(contextsInAnalysisRoot, hasLength(1)); | |
456 expect(contextsInAnalysisRoot[0], isNotNull); | |
457 } | |
458 Source result = sourceFactory.forUri('dart:async'); | 423 Source result = sourceFactory.forUri('dart:async'); |
459 expect(result, isNotNull); | 424 expect(result, isNotNull); |
460 } | 425 } |
461 | 426 |
462 void test_setRoots_addFolderWithDartFileInSubfolder() { | 427 void test_setRoots_addFolderWithDartFileInSubfolder() { |
463 String filePath = path.posix.join(projPath, 'foo', 'bar.dart'); | 428 String filePath = path.posix.join(projPath, 'foo', 'bar.dart'); |
464 resourceProvider.newFile(filePath, 'contents'); | 429 resourceProvider.newFile(filePath, 'contents'); |
465 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 430 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
466 // verify | 431 // verify |
467 Iterable<String> filePaths = callbacks.currentFilePaths; | 432 Iterable<String> filePaths = callbacks.currentFilePaths; |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 expect(callbacks.currentContextRoots, contains(projPath)); | 950 expect(callbacks.currentContextRoots, contains(projPath)); |
986 expect(callbacks.currentFilePaths, hasLength(0)); | 951 expect(callbacks.currentFilePaths, hasLength(0)); |
987 } | 952 } |
988 | 953 |
989 void test_setRoots_packageResolver() { | 954 void test_setRoots_packageResolver() { |
990 String filePath = path.posix.join(projPath, 'lib', 'foo.dart'); | 955 String filePath = path.posix.join(projPath, 'lib', 'foo.dart'); |
991 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME], 'foo:lib/'); | 956 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME], 'foo:lib/'); |
992 resourceProvider.newFile(filePath, 'contents'); | 957 resourceProvider.newFile(filePath, 'contents'); |
993 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 958 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
994 | 959 |
995 if (enableAnalysisDriver) { | 960 var drivers = |
996 var drivers = manager | 961 manager.getDriversInAnalysisRoot(resourceProvider.newFolder(projPath)); |
997 .getDriversInAnalysisRoot(resourceProvider.newFolder(projPath)); | 962 expect(drivers, hasLength(1)); |
998 expect(drivers, hasLength(1)); | 963 expect(drivers[0], isNotNull); |
999 expect(drivers[0], isNotNull); | |
1000 } else { | |
1001 List<AnalysisContext> contextsInAnalysisRoot = | |
1002 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); | |
1003 expect(contextsInAnalysisRoot, hasLength(1)); | |
1004 expect(contextsInAnalysisRoot[0], isNotNull); | |
1005 } | |
1006 Source result = sourceFactory.forUri('package:foo/foo.dart'); | 964 Source result = sourceFactory.forUri('package:foo/foo.dart'); |
1007 expect(result.fullName, filePath); | 965 expect(result.fullName, filePath); |
1008 } | 966 } |
1009 | 967 |
1010 void test_setRoots_pathContainsDotFile() { | 968 void test_setRoots_pathContainsDotFile() { |
1011 // If the path to a file (relative to the context root) contains a folder | 969 // If the path to a file (relative to the context root) contains a folder |
1012 // whose name begins with '.', then the file is ignored. | 970 // whose name begins with '.', then the file is ignored. |
1013 String project = '/project'; | 971 String project = '/project'; |
1014 String fileA = '$project/foo.dart'; | 972 String fileA = '$project/foo.dart'; |
1015 String fileB = '$project/.pub/bar.dart'; | 973 String fileB = '$project/.pub/bar.dart'; |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1634 callbacks.assertContextFiles(root, [rootFile, subFile]); | 1592 callbacks.assertContextFiles(root, [rootFile, subFile]); |
1635 }); | 1593 }); |
1636 } | 1594 } |
1637 | 1595 |
1638 test_watch_modifyFile() { | 1596 test_watch_modifyFile() { |
1639 String filePath = path.posix.join(projPath, 'foo.dart'); | 1597 String filePath = path.posix.join(projPath, 'foo.dart'); |
1640 // add root with a file | 1598 // add root with a file |
1641 resourceProvider.newFile(filePath, 'contents'); | 1599 resourceProvider.newFile(filePath, 'contents'); |
1642 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 1600 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
1643 // the file was added | 1601 // the file was added |
1644 if (enableAnalysisDriver) { | 1602 Iterable<String> filePaths = callbacks.currentFilePaths; |
1645 Iterable<String> filePaths = callbacks.currentFilePaths; | 1603 expect(filePaths, hasLength(1)); |
1646 expect(filePaths, hasLength(1)); | 1604 expect(filePaths, contains(filePath)); |
1647 expect(filePaths, contains(filePath)); | 1605 // TODO(brianwilkerson) Test when the file was modified |
1648 // TODO(brianwilkerson) Test when the file was modified | |
1649 } else { | |
1650 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; | |
1651 expect(filePaths, hasLength(1)); | |
1652 expect(filePaths, contains(filePath)); | |
1653 expect(filePaths[filePath], equals(callbacks.now)); | |
1654 } | |
1655 // update the file | 1606 // update the file |
1656 callbacks.now++; | 1607 callbacks.now++; |
1657 resourceProvider.modifyFile(filePath, 'new contents'); | 1608 resourceProvider.modifyFile(filePath, 'new contents'); |
1658 return pumpEventQueue().then((_) { | 1609 return pumpEventQueue().then((_) { |
1659 if (enableAnalysisDriver) { | 1610 // TODO(brianwilkerson) Test when the file was modified |
1660 // TODO(brianwilkerson) Test when the file was modified | |
1661 return null; | |
1662 } | |
1663 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; | |
1664 return expect(filePaths[filePath], equals(callbacks.now)); | |
1665 }); | 1611 }); |
1666 } | 1612 } |
1667 | 1613 |
1668 test_watch_modifyPackageMapDependency_fail() async { | 1614 test_watch_modifyPackageMapDependency_fail() async { |
1669 // create a dependency file | 1615 // create a dependency file |
1670 String dependencyPath = path.posix.join(projPath, 'dep'); | 1616 String dependencyPath = path.posix.join(projPath, 'dep'); |
1671 resourceProvider.newFile(dependencyPath, 'contents'); | 1617 resourceProvider.newFile(dependencyPath, 'contents'); |
1672 packageMapProvider.dependencies.add(dependencyPath); | 1618 packageMapProvider.dependencies.add(dependencyPath); |
1673 // create a Dart file | 1619 // create a Dart file |
1674 String dartFilePath = path.posix.join(projPath, 'main.dart'); | 1620 String dartFilePath = path.posix.join(projPath, 'main.dart'); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1790 '**/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}', | 1736 '**/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}', |
1791 '**/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}' | 1737 '**/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}' |
1792 ]; | 1738 ]; |
1793 return patterns | 1739 return patterns |
1794 .map((pattern) => new Glob(path.posix.separator, pattern)) | 1740 .map((pattern) => new Glob(path.posix.separator, pattern)) |
1795 .toList(); | 1741 .toList(); |
1796 } | 1742 } |
1797 | 1743 |
1798 AnalysisOptions get analysisOptions => callbacks.analysisOptions; | 1744 AnalysisOptions get analysisOptions => callbacks.analysisOptions; |
1799 | 1745 |
1800 bool get enableAnalysisDriver => false; | |
1801 | |
1802 List<ErrorProcessor> get errorProcessors => analysisOptions.errorProcessors; | 1746 List<ErrorProcessor> get errorProcessors => analysisOptions.errorProcessors; |
1803 | 1747 |
1804 List<Linter> get lints => analysisOptions.lintRules; | 1748 List<Linter> get lints => analysisOptions.lintRules; |
1805 | 1749 |
1806 SourceFactory get sourceFactory => callbacks.sourceFactory; | 1750 SourceFactory get sourceFactory => callbacks.sourceFactory; |
1807 | 1751 |
1808 Map<String, List<Folder>> get _currentPackageMap => _packageMap(projPath); | 1752 Map<String, List<Folder>> get _currentPackageMap => _packageMap(projPath); |
1809 | 1753 |
1810 void deleteFile(List<String> pathComponents) { | 1754 void deleteFile(List<String> pathComponents) { |
1811 String filePath = path.posix.joinAll(pathComponents); | 1755 String filePath = path.posix.joinAll(pathComponents); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1860 // Create an SDK in the mock file system. | 1804 // Create an SDK in the mock file system. |
1861 new MockSdk(generateSummaryFiles: true, resourceProvider: resourceProvider); | 1805 new MockSdk(generateSummaryFiles: true, resourceProvider: resourceProvider); |
1862 DartSdkManager sdkManager = new DartSdkManager('/', true); | 1806 DartSdkManager sdkManager = new DartSdkManager('/', true); |
1863 manager = new ContextManagerImpl( | 1807 manager = new ContextManagerImpl( |
1864 resourceProvider, | 1808 resourceProvider, |
1865 sdkManager, | 1809 sdkManager, |
1866 providePackageResolver, | 1810 providePackageResolver, |
1867 packageMapProvider, | 1811 packageMapProvider, |
1868 analysisFilesGlobs, | 1812 analysisFilesGlobs, |
1869 InstrumentationService.NULL_SERVICE, | 1813 InstrumentationService.NULL_SERVICE, |
1870 new AnalysisOptionsImpl(), | 1814 new AnalysisOptionsImpl()); |
1871 enableAnalysisDriver); | |
1872 PerformanceLog logger = new PerformanceLog(new NullStringSink()); | 1815 PerformanceLog logger = new PerformanceLog(new NullStringSink()); |
1873 AnalysisDriverScheduler scheduler = new AnalysisDriverScheduler(logger); | 1816 AnalysisDriverScheduler scheduler = new AnalysisDriverScheduler(logger); |
1874 callbacks = new TestContextManagerCallbacks( | 1817 callbacks = new TestContextManagerCallbacks( |
1875 resourceProvider, sdkManager, logger, scheduler); | 1818 resourceProvider, sdkManager, logger, scheduler); |
1876 manager.callbacks = callbacks; | 1819 manager.callbacks = callbacks; |
1877 } | 1820 } |
1878 | 1821 |
1879 /** | 1822 /** |
1880 * Verify that package URI's for source files in [path] will be resolved | 1823 * Verify that package URI's for source files in [path] will be resolved |
1881 * using a package root matching [expectation]. | 1824 * using a package root matching [expectation]. |
1882 */ | 1825 */ |
1883 void _checkPackageRoot(String path, expectation) { | 1826 void _checkPackageRoot(String path, expectation) { |
1884 // TODO(brianwilkerson) Figure out how to test this. Possibly by comparing | 1827 // TODO(brianwilkerson) Figure out how to test this. Possibly by comparing |
1885 // the contents of the package map (although that approach doesn't work at | 1828 // the contents of the package map (although that approach doesn't work at |
1886 // the moment). | 1829 // the moment). |
1887 // FolderDisposition disposition = callbacks.currentContextDispositions[path]
; | 1830 // FolderDisposition disposition = callbacks.currentContextDispositions[path]
; |
1888 // expect(disposition.packageRoot, expectation); | 1831 // expect(disposition.packageRoot, expectation); |
1889 // TODO(paulberry): we should also verify that the package map itself is | 1832 // TODO(paulberry): we should also verify that the package map itself is |
1890 // correct. See dartbug.com/23909. | 1833 // correct. See dartbug.com/23909. |
1891 } | 1834 } |
1892 | 1835 |
1893 Map<String, List<Folder>> _packageMap(String contextPath) { | 1836 Map<String, List<Folder>> _packageMap(String contextPath) { |
1894 Folder folder = resourceProvider.getFolder(contextPath); | 1837 Folder folder = resourceProvider.getFolder(contextPath); |
1895 if (enableAnalysisDriver) { | 1838 ContextInfo info = manager.getContextInfoFor(folder); |
1896 ContextInfo info = manager.getContextInfoFor(folder); | 1839 return info.analysisDriver.sourceFactory?.packageMap; |
1897 return info.analysisDriver.sourceFactory?.packageMap; | |
1898 } else { | |
1899 return manager.folderMap[folder]?.sourceFactory?.packageMap; | |
1900 } | |
1901 } | 1840 } |
1902 } | 1841 } |
1903 | 1842 |
1904 @reflectiveTest | 1843 @reflectiveTest |
1905 class ContextManagerWithNewOptionsTest extends ContextManagerWithOptionsTest { | 1844 class ContextManagerWithNewOptionsTest extends ContextManagerWithOptionsTest { |
1906 bool get enableAnalysisDriver => true; | |
1907 | |
1908 String get optionsFileName => AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE; | 1845 String get optionsFileName => AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE; |
1909 } | 1846 } |
1910 | 1847 |
1911 @reflectiveTest | 1848 @reflectiveTest |
1912 class ContextManagerWithOldOptionsTest extends ContextManagerWithOptionsTest { | 1849 class ContextManagerWithOldOptionsTest extends ContextManagerWithOptionsTest { |
1913 bool get enableAnalysisDriver => true; | |
1914 | |
1915 String get optionsFileName => AnalysisEngine.ANALYSIS_OPTIONS_FILE; | 1850 String get optionsFileName => AnalysisEngine.ANALYSIS_OPTIONS_FILE; |
1916 } | 1851 } |
1917 | 1852 |
1918 abstract class ContextManagerWithOptionsTest extends ContextManagerTest { | 1853 abstract class ContextManagerWithOptionsTest extends ContextManagerTest { |
1919 String get optionsFileName; | 1854 String get optionsFileName; |
1920 | 1855 |
1921 test_analysis_options_file_delete() async { | 1856 test_analysis_options_file_delete() async { |
1922 // Setup analysis options | 1857 // Setup analysis options |
1923 newFile( | 1858 newFile( |
1924 [projPath, optionsFileName], | 1859 [projPath, optionsFileName], |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2309 resourceProvider.newFile( | 2244 resourceProvider.newFile( |
2310 '$projPath/$optionsFileName', | 2245 '$projPath/$optionsFileName', |
2311 r''' | 2246 r''' |
2312 analyzer: | 2247 analyzer: |
2313 strong-mode: false | 2248 strong-mode: false |
2314 '''); | 2249 '''); |
2315 // Create the context. | 2250 // Create the context. |
2316 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 2251 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
2317 await pumpEventQueue(); | 2252 await pumpEventQueue(); |
2318 | 2253 |
2319 if (enableAnalysisDriver) { | 2254 AnalysisResult result = await callbacks.currentDriver.getResult(file.path); |
2320 AnalysisResult result = | |
2321 await callbacks.currentDriver.getResult(file.path); | |
2322 | 2255 |
2323 // Not strong mode - both in the context and the SDK context. | 2256 // Not strong mode - both in the context and the SDK context. |
2324 AnalysisContext sdkContext = sourceFactory.dartSdk.context; | 2257 AnalysisContext sdkContext = sourceFactory.dartSdk.context; |
2325 expect(analysisOptions.strongMode, isFalse); | 2258 expect(analysisOptions.strongMode, isFalse); |
2326 expect(sdkContext.analysisOptions.strongMode, isFalse); | 2259 expect(sdkContext.analysisOptions.strongMode, isFalse); |
2327 expect(result.errors, isEmpty); | 2260 expect(result.errors, isEmpty); |
2328 } else { | |
2329 AnalysisContext context = manager.getContextFor(projPath); | |
2330 Source testSource = context.getSourcesWithFullName(file.path).single; | |
2331 | |
2332 // Not strong mode - both in the context and the SDK context. | |
2333 AnalysisContext sdkContext = sourceFactory.dartSdk.context; | |
2334 expect(analysisOptions.strongMode, isFalse); | |
2335 expect(sdkContext.analysisOptions.strongMode, isFalse); | |
2336 expect(context.computeErrors(testSource), isEmpty); | |
2337 } | |
2338 | 2261 |
2339 // Update the options file - turn on 'strong-mode'. | 2262 // Update the options file - turn on 'strong-mode'. |
2340 resourceProvider.updateFile( | 2263 resourceProvider.updateFile( |
2341 '$projPath/$optionsFileName', | 2264 '$projPath/$optionsFileName', |
2342 r''' | 2265 r''' |
2343 analyzer: | 2266 analyzer: |
2344 strong-mode: true | 2267 strong-mode: true |
2345 '''); | 2268 '''); |
2346 await pumpEventQueue(); | 2269 await pumpEventQueue(); |
2347 | 2270 |
2348 // Strong mode - both in the context and the SDK context. | 2271 // Strong mode - both in the context and the SDK context. |
2349 if (enableAnalysisDriver) { | 2272 result = await callbacks.currentDriver.getResult(file.path); |
2350 AnalysisResult result = | |
2351 await callbacks.currentDriver.getResult(file.path); | |
2352 | 2273 |
2353 // Not strong mode - both in the context and the SDK context. | 2274 // Not strong mode - both in the context and the SDK context. |
2354 AnalysisContext sdkContext = sourceFactory.dartSdk.context; | 2275 sdkContext = sourceFactory.dartSdk.context; |
2355 expect(analysisOptions.strongMode, isTrue); | 2276 expect(analysisOptions.strongMode, isTrue); |
2356 expect(sdkContext.analysisOptions.strongMode, isTrue); | 2277 expect(sdkContext.analysisOptions.strongMode, isTrue); |
2357 // The code is strong-mode clean. | 2278 // The code is strong-mode clean. |
2358 // Verify that TypeSystem was reset. | 2279 // Verify that TypeSystem was reset. |
2359 expect(result.errors, isEmpty); | 2280 expect(result.errors, isEmpty); |
2360 } else { | |
2361 AnalysisContext context = manager.getContextFor(projPath); | |
2362 Source testSource = context.getSourcesWithFullName(file.path).single; | |
2363 AnalysisContext sdkContext = sourceFactory.dartSdk.context; | |
2364 expect(analysisOptions.strongMode, isTrue); | |
2365 expect(sdkContext.analysisOptions.strongMode, isTrue); | |
2366 // The code is strong-mode clean. | |
2367 // Verify that TypeSystem was reset. | |
2368 expect(context.computeErrors(testSource), isEmpty); | |
2369 } | |
2370 } | 2281 } |
2371 | 2282 |
2372 @failingTest | 2283 @failingTest |
2373 test_path_filter_analysis_option() async { | 2284 test_path_filter_analysis_option() async { |
2374 // This fails because we're not analyzing the analysis options file. | 2285 // This fails because we're not analyzing the analysis options file. |
2375 // Create files. | 2286 // Create files. |
2376 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); | 2287 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); |
2377 newFile([libPath, 'main.dart']); | 2288 newFile([libPath, 'main.dart']); |
2378 newFile([libPath, 'nope.dart']); | 2289 newFile([libPath, 'nope.dart']); |
2379 String sdkExtPath = newFolder([projPath, 'sdk_ext']); | 2290 String sdkExtPath = newFolder([projPath, 'sdk_ext']); |
2380 newFile([sdkExtPath, 'entry.dart']); | 2291 newFile([sdkExtPath, 'entry.dart']); |
2381 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']); | 2292 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']); |
2382 newFile([sdkExtSrcPath, 'part.dart']); | 2293 newFile([sdkExtSrcPath, 'part.dart']); |
2383 // Setup analysis options file with ignore list. | 2294 // Setup analysis options file with ignore list. |
2384 newFile( | 2295 newFile( |
2385 [projPath, optionsFileName], | 2296 [projPath, optionsFileName], |
2386 r''' | 2297 r''' |
2387 analyzer: | 2298 analyzer: |
2388 exclude: | 2299 exclude: |
2389 - lib/nope.dart | 2300 - lib/nope.dart |
2390 - 'sdk_ext/**' | 2301 - 'sdk_ext/**' |
2391 '''); | 2302 '''); |
2392 // Setup context. | 2303 // Setup context. |
2393 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 2304 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
2394 | 2305 |
2395 // Verify that analysis options was parsed and the ignore patterns applied. | 2306 // Verify that analysis options was parsed and the ignore patterns applied. |
2396 Folder projectFolder = resourceProvider.newFolder(projPath); | 2307 Folder projectFolder = resourceProvider.newFolder(projPath); |
2397 if (enableAnalysisDriver) { | 2308 var drivers = manager.getDriversInAnalysisRoot(projectFolder); |
2398 var drivers = manager.getDriversInAnalysisRoot(projectFolder); | 2309 expect(drivers, hasLength(1)); |
2399 expect(drivers, hasLength(1)); | 2310 AnalysisDriver driver = drivers[0]; |
2400 AnalysisDriver driver = drivers[0]; | 2311 expect( |
2401 expect( | 2312 driver.addedFiles, |
2402 driver.addedFiles, | 2313 unorderedEquals( |
2403 unorderedEquals( | 2314 ['/my/proj/lib/main.dart', '/my/proj/$optionsFileName'])); |
2404 ['/my/proj/lib/main.dart', '/my/proj/$optionsFileName'])); | |
2405 } else { | |
2406 Map<String, int> fileTimestamps = | |
2407 callbacks.currentContextFilePaths[projPath]; | |
2408 expect(fileTimestamps, isNotEmpty); | |
2409 List<String> files = fileTimestamps.keys.toList(); | |
2410 expect( | |
2411 files, | |
2412 unorderedEquals( | |
2413 ['/my/proj/lib/main.dart', '/my/proj/$optionsFileName'])); | |
2414 } | |
2415 } | 2315 } |
2416 | 2316 |
2417 test_path_filter_child_contexts_option() async { | 2317 test_path_filter_child_contexts_option() async { |
2418 // Create files. | 2318 // Create files. |
2419 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); | 2319 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); |
2420 newFile([libPath, 'main.dart']); | 2320 newFile([libPath, 'main.dart']); |
2421 newFile( | 2321 newFile( |
2422 [libPath, 'pubspec.yaml'], | 2322 [libPath, 'pubspec.yaml'], |
2423 r''' | 2323 r''' |
2424 name: foobar | 2324 name: foobar |
(...skipping 12 matching lines...) Expand all Loading... |
2437 r''' | 2337 r''' |
2438 analyzer: | 2338 analyzer: |
2439 exclude: | 2339 exclude: |
2440 - 'other_lib' | 2340 - 'other_lib' |
2441 '''); | 2341 '''); |
2442 // Setup context. | 2342 // Setup context. |
2443 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 2343 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
2444 // Verify that the context in other_lib wasn't created and that the | 2344 // Verify that the context in other_lib wasn't created and that the |
2445 // context in lib was created. | 2345 // context in lib was created. |
2446 Folder projectFolder = resourceProvider.newFolder(projPath); | 2346 Folder projectFolder = resourceProvider.newFolder(projPath); |
2447 if (enableAnalysisDriver) { | 2347 var drivers = manager.getDriversInAnalysisRoot(projectFolder); |
2448 var drivers = manager.getDriversInAnalysisRoot(projectFolder); | 2348 expect(drivers, hasLength(2)); |
2449 expect(drivers, hasLength(2)); | 2349 expect(drivers[0].name, equals('/my/proj')); |
2450 expect(drivers[0].name, equals('/my/proj')); | 2350 expect(drivers[1].name, equals('/my/proj/lib')); |
2451 expect(drivers[1].name, equals('/my/proj/lib')); | |
2452 } else { | |
2453 var contexts = | |
2454 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); | |
2455 expect(contexts.length, 2); | |
2456 expect(contexts[0].name, equals('/my/proj')); | |
2457 expect(contexts[1].name, equals('/my/proj/lib')); | |
2458 } | |
2459 } | 2351 } |
2460 | 2352 |
2461 test_path_filter_recursive_wildcard_child_contexts_option() async { | 2353 test_path_filter_recursive_wildcard_child_contexts_option() async { |
2462 // Create files. | 2354 // Create files. |
2463 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); | 2355 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); |
2464 newFile([libPath, 'main.dart']); | 2356 newFile([libPath, 'main.dart']); |
2465 newFile( | 2357 newFile( |
2466 [libPath, 'pubspec.yaml'], | 2358 [libPath, 'pubspec.yaml'], |
2467 r''' | 2359 r''' |
2468 name: foobar | 2360 name: foobar |
(...skipping 13 matching lines...) Expand all Loading... |
2482 analyzer: | 2374 analyzer: |
2483 exclude: | 2375 exclude: |
2484 - 'other_lib/**' | 2376 - 'other_lib/**' |
2485 '''); | 2377 '''); |
2486 // Setup context. | 2378 // Setup context. |
2487 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 2379 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
2488 | 2380 |
2489 // Verify that the context in other_lib wasn't created and that the | 2381 // Verify that the context in other_lib wasn't created and that the |
2490 // context in lib was created. | 2382 // context in lib was created. |
2491 Folder projectFolder = resourceProvider.newFolder(projPath); | 2383 Folder projectFolder = resourceProvider.newFolder(projPath); |
2492 if (enableAnalysisDriver) { | 2384 var drivers = manager.getDriversInAnalysisRoot(projectFolder); |
2493 var drivers = manager.getDriversInAnalysisRoot(projectFolder); | 2385 expect(drivers, hasLength(2)); |
2494 expect(drivers, hasLength(2)); | 2386 expect(drivers[0].name, equals('/my/proj')); |
2495 expect(drivers[0].name, equals('/my/proj')); | 2387 expect(drivers[1].name, equals('/my/proj/lib')); |
2496 expect(drivers[1].name, equals('/my/proj/lib')); | |
2497 } else { | |
2498 var contexts = manager.contextsInAnalysisRoot(projectFolder); | |
2499 expect(contexts.length, 2); | |
2500 expect(contexts[0].name, equals('/my/proj')); | |
2501 expect(contexts[1].name, equals('/my/proj/lib')); | |
2502 } | |
2503 } | 2388 } |
2504 | 2389 |
2505 test_path_filter_wildcard_child_contexts_option() async { | 2390 test_path_filter_wildcard_child_contexts_option() async { |
2506 // Create files. | 2391 // Create files. |
2507 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); | 2392 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); |
2508 newFile([libPath, 'main.dart']); | 2393 newFile([libPath, 'main.dart']); |
2509 newFile( | 2394 newFile( |
2510 [libPath, 'pubspec.yaml'], | 2395 [libPath, 'pubspec.yaml'], |
2511 r''' | 2396 r''' |
2512 name: foobar | 2397 name: foobar |
(...skipping 11 matching lines...) Expand all Loading... |
2524 [projPath, optionsFileName], | 2409 [projPath, optionsFileName], |
2525 r''' | 2410 r''' |
2526 analyzer: | 2411 analyzer: |
2527 exclude: | 2412 exclude: |
2528 - 'other_lib/*' | 2413 - 'other_lib/*' |
2529 '''); | 2414 '''); |
2530 // Setup context / driver. | 2415 // Setup context / driver. |
2531 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 2416 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
2532 | 2417 |
2533 Folder projectFolder = resourceProvider.newFolder(projPath); | 2418 Folder projectFolder = resourceProvider.newFolder(projPath); |
2534 if (enableAnalysisDriver) { | 2419 var drivers = manager.getDriversInAnalysisRoot(projectFolder); |
2535 var drivers = manager.getDriversInAnalysisRoot(projectFolder); | 2420 expect(drivers, hasLength(2)); |
2536 expect(drivers, hasLength(2)); | 2421 expect(drivers[0].name, equals('/my/proj')); |
2537 expect(drivers[0].name, equals('/my/proj')); | 2422 expect(drivers[1].name, equals('/my/proj/lib')); |
2538 expect(drivers[1].name, equals('/my/proj/lib')); | |
2539 } else { | |
2540 // Verify that the context in other_lib wasn't created and that the | |
2541 // context in lib was created. | |
2542 var contexts = manager.contextsInAnalysisRoot(projectFolder); | |
2543 expect(contexts, hasLength(2)); | |
2544 expect(contexts[0].name, equals('/my/proj')); | |
2545 expect(contexts[1].name, equals('/my/proj/lib')); | |
2546 } | |
2547 } | 2423 } |
2548 | 2424 |
2549 void test_setRoots_nested_excludedByOuter() { | 2425 void test_setRoots_nested_excludedByOuter() { |
2550 String project = '/project'; | 2426 String project = '/project'; |
2551 String projectPubspec = '$project/pubspec.yaml'; | 2427 String projectPubspec = '$project/pubspec.yaml'; |
2552 String example = '$project/example'; | 2428 String example = '$project/example'; |
2553 String examplePubspec = '$example/pubspec.yaml'; | 2429 String examplePubspec = '$example/pubspec.yaml'; |
2554 // create files | 2430 // create files |
2555 resourceProvider.newFile(projectPubspec, 'name: project'); | 2431 resourceProvider.newFile(projectPubspec, 'name: project'); |
2556 resourceProvider.newFile(examplePubspec, 'name: example'); | 2432 resourceProvider.newFile(examplePubspec, 'name: example'); |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2951 class TestUriResolver extends UriResolver { | 2827 class TestUriResolver extends UriResolver { |
2952 Map<Uri, Source> uriMap; | 2828 Map<Uri, Source> uriMap; |
2953 | 2829 |
2954 TestUriResolver(this.uriMap); | 2830 TestUriResolver(this.uriMap); |
2955 | 2831 |
2956 @override | 2832 @override |
2957 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 2833 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
2958 return uriMap[uri]; | 2834 return uriMap[uri]; |
2959 } | 2835 } |
2960 } | 2836 } |
OLD | NEW |