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

Side by Side Diff: pkg/analysis_server/test/context_manager_test.dart

Issue 2562083002: Get some tests running using the analysis driver (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library 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/utilities/null_string_sink.dart';
10 import 'package:analyzer/error/error.dart'; 11 import 'package:analyzer/error/error.dart';
11 import 'package:analyzer/file_system/file_system.dart'; 12 import 'package:analyzer/file_system/file_system.dart';
12 import 'package:analyzer/file_system/memory_file_system.dart'; 13 import 'package:analyzer/file_system/memory_file_system.dart';
13 import 'package:analyzer/instrumentation/instrumentation.dart'; 14 import 'package:analyzer/instrumentation/instrumentation.dart';
14 import 'package:analyzer/source/error_processor.dart'; 15 import 'package:analyzer/source/error_processor.dart';
15 import 'package:analyzer/src/context/builder.dart'; 16 import 'package:analyzer/src/context/builder.dart';
17 import 'package:analyzer/src/dart/analysis/byte_store.dart';
16 import 'package:analyzer/src/dart/analysis/driver.dart'; 18 import 'package:analyzer/src/dart/analysis/driver.dart';
19 import 'package:analyzer/src/dart/analysis/file_state.dart';
17 import 'package:analyzer/src/error/codes.dart'; 20 import 'package:analyzer/src/error/codes.dart';
18 import 'package:analyzer/src/generated/engine.dart'; 21 import 'package:analyzer/src/generated/engine.dart' hide AnalysisResult;
19 import 'package:analyzer/src/generated/sdk.dart'; 22 import 'package:analyzer/src/generated/sdk.dart';
20 import 'package:analyzer/src/generated/source.dart'; 23 import 'package:analyzer/src/generated/source.dart';
21 import 'package:analyzer/src/generated/source_io.dart'; 24 import 'package:analyzer/src/generated/source_io.dart';
22 import 'package:analyzer/src/services/lint.dart'; 25 import 'package:analyzer/src/services/lint.dart';
26 import 'package:analyzer/src/summary/summary_file_builder.dart';
23 import 'package:analyzer/src/util/glob.dart'; 27 import 'package:analyzer/src/util/glob.dart';
24 import 'package:linter/src/plugin/linter_plugin.dart'; 28 import 'package:linter/src/plugin/linter_plugin.dart';
25 import 'package:linter/src/rules.dart'; 29 import 'package:linter/src/rules.dart';
26 import 'package:linter/src/rules/avoid_as.dart'; 30 import 'package:linter/src/rules/avoid_as.dart';
27 import 'package:path/path.dart' as path; 31 import 'package:path/path.dart' as path;
28 import 'package:plugin/manager.dart'; 32 import 'package:plugin/manager.dart';
29 import 'package:plugin/plugin.dart'; 33 import 'package:plugin/plugin.dart';
30 import 'package:test/test.dart'; 34 import 'package:test/test.dart';
31 import 'package:test_reflective_loader/test_reflective_loader.dart'; 35 import 'package:test_reflective_loader/test_reflective_loader.dart';
32 36
33 import 'mock_sdk.dart'; 37 import 'mock_sdk.dart';
34 import 'mocks.dart'; 38 import 'mocks.dart';
35 39
36 main() { 40 main() {
37 defineReflectiveSuite(() { 41 defineReflectiveSuite(() {
38 defineReflectiveTests(AbstractContextManagerTest); 42 defineReflectiveTests(AbstractContextManagerTest);
39 defineReflectiveTests(ContextManagerWithNewOptionsTest); 43 defineReflectiveTests(ContextManagerWithNewOptionsTest);
44 defineReflectiveTests(ContextManagerWithNewOptionsTest_Driver);
40 defineReflectiveTests(ContextManagerWithOldOptionsTest); 45 defineReflectiveTests(ContextManagerWithOldOptionsTest);
46 defineReflectiveTests(ContextManagerWithOldOptionsTest_Driver);
41 }); 47 });
42 } 48 }
43 49
44 @reflectiveTest 50 @reflectiveTest
45 class AbstractContextManagerTest extends ContextManagerTest { 51 class AbstractContextManagerTest extends ContextManagerTest {
46 void test_contextsInAnalysisRoot_nestedContext() { 52 void test_contextsInAnalysisRoot_nestedContext() {
47 String subProjPath = path.posix.join(projPath, 'subproj'); 53 String subProjPath = path.posix.join(projPath, 'subproj');
48 Folder subProjFolder = resourceProvider.newFolder(subProjPath); 54 Folder subProjFolder = resourceProvider.newFolder(subProjPath);
49 resourceProvider.newFile( 55 resourceProvider.newFile(
50 path.posix.join(subProjPath, 'pubspec.yaml'), 'contents'); 56 path.posix.join(subProjPath, 'pubspec.yaml'), 'contents');
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 test_pack:lib/'''); 151 test_pack:lib/''');
146 // Setup context. 152 // Setup context.
147 153
148 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 154 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
149 await pumpEventQueue(); 155 await pumpEventQueue();
150 // Confirm that one context was created. 156 // Confirm that one context was created.
151 var contexts = 157 var contexts =
152 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); 158 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
153 expect(contexts, isNotNull); 159 expect(contexts, isNotNull);
154 expect(contexts.length, equals(1)); 160 expect(contexts.length, equals(1));
155 var context = contexts[0]; 161 var source = sourceFactory.forUri('dart:foobar');
156 var source = context.sourceFactory.forUri('dart:foobar');
157 expect(source, isNotNull); 162 expect(source, isNotNull);
158 expect(source.fullName, '/my/proj/sdk_ext/entry.dart'); 163 expect(source.fullName, '/my/proj/sdk_ext/entry.dart');
159 // We can't find dart:core because we didn't list it in our 164 // We can't find dart:core because we didn't list it in our
160 // embedded_libs map. 165 // embedded_libs map.
161 expect(context.sourceFactory.forUri('dart:core'), isNull); 166 expect(sourceFactory.forUri('dart:core'), isNull);
162 // We can find dart:typed_data because we listed it in our 167 // We can find dart:typed_data because we listed it in our
163 // embedded_libs map. 168 // embedded_libs map.
164 expect(context.sourceFactory.forUri('dart:typed_data'), isNotNull); 169 expect(sourceFactory.forUri('dart:typed_data'), isNotNull);
165 } 170 }
166 171
167 test_ignoreFilesInPackagesFolder() { 172 test_ignoreFilesInPackagesFolder() {
168 // create a context with a pubspec.yaml file 173 // create a context with a pubspec.yaml file
169 String pubspecPath = path.posix.join(projPath, 'pubspec.yaml'); 174 String pubspecPath = path.posix.join(projPath, 'pubspec.yaml');
170 resourceProvider.newFile(pubspecPath, 'pubspec'); 175 resourceProvider.newFile(pubspecPath, 'pubspec');
171 // create a file in the "packages" folder 176 // create a file in the "packages" folder
172 String filePath1 = path.posix.join(projPath, 'packages', 'file1.dart'); 177 String filePath1 = path.posix.join(projPath, 'packages', 'file1.dart');
173 resourceProvider.newFile(filePath1, 'contents'); 178 resourceProvider.newFile(filePath1, 'contents');
174 // "packages" files are ignored initially 179 // "packages" files are ignored initially
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 [projPath, '.packages'], 387 [projPath, '.packages'],
383 r''' 388 r'''
384 test_pack:lib/'''); 389 test_pack:lib/''');
385 // Setup context. 390 // Setup context.
386 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 391 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
387 // Confirm that one context was created. 392 // Confirm that one context was created.
388 var contexts = 393 var contexts =
389 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); 394 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
390 expect(contexts, isNotNull); 395 expect(contexts, isNotNull);
391 expect(contexts.length, equals(1)); 396 expect(contexts.length, equals(1));
392 var context = contexts[0]; 397 var source = sourceFactory.forUri('dart:foobar');
393 var source = context.sourceFactory.forUri('dart:foobar');
394 expect(source.fullName, equals('/my/proj/sdk_ext/entry.dart')); 398 expect(source.fullName, equals('/my/proj/sdk_ext/entry.dart'));
395 } 399 }
396 400
397 void test_setRoots_addFolderWithDartFile() { 401 void test_setRoots_addFolderWithDartFile() {
398 String filePath = path.posix.join(projPath, 'foo.dart'); 402 String filePath = path.posix.join(projPath, 'foo.dart');
399 resourceProvider.newFile(filePath, 'contents'); 403 resourceProvider.newFile(filePath, 'contents');
400 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 404 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
401 // verify 405 // verify
402 var filePaths = callbacks.currentContextFilePaths[projPath]; 406 var filePaths = callbacks.currentContextFilePaths[projPath];
403 expect(filePaths, hasLength(1)); 407 expect(filePaths, hasLength(1));
404 expect(filePaths, contains(filePath)); 408 expect(filePaths, contains(filePath));
405 List<AnalysisContext> contextsInAnalysisRoot = 409 List<AnalysisContext> contextsInAnalysisRoot =
406 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); 410 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
407 expect(contextsInAnalysisRoot, hasLength(1)); 411 expect(contextsInAnalysisRoot, hasLength(1));
408 AnalysisContext context = contextsInAnalysisRoot[0]; 412 AnalysisContext context = contextsInAnalysisRoot[0];
409 expect(context, isNotNull); 413 expect(context, isNotNull);
410 Source result = context.sourceFactory.forUri('package:foo/foo.dart'); 414 Source result = sourceFactory.forUri('package:foo/foo.dart');
411 expect(result, isNotNull); 415 expect(result, isNotNull);
412 expect(result.exists(), isFalse); 416 expect(result.exists(), isFalse);
413 } 417 }
414 418
415 void test_setRoots_addFolderWithDartFileInSubfolder() { 419 void test_setRoots_addFolderWithDartFileInSubfolder() {
416 String filePath = path.posix.join(projPath, 'foo', 'bar.dart'); 420 String filePath = path.posix.join(projPath, 'foo', 'bar.dart');
417 resourceProvider.newFile(filePath, 'contents'); 421 resourceProvider.newFile(filePath, 'contents');
418 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 422 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
419 // verify 423 // verify
420 var filePaths = callbacks.currentContextFilePaths[projPath]; 424 var filePaths = callbacks.currentContextFilePaths[projPath];
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 String filePath = path.posix.join(projPath, 'lib', 'foo.dart'); 957 String filePath = path.posix.join(projPath, 'lib', 'foo.dart');
954 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME], 'foo:lib/'); 958 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME], 'foo:lib/');
955 resourceProvider.newFile(filePath, 'contents'); 959 resourceProvider.newFile(filePath, 'contents');
956 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 960 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
957 961
958 List<AnalysisContext> contextsInAnalysisRoot = 962 List<AnalysisContext> contextsInAnalysisRoot =
959 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); 963 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
960 expect(contextsInAnalysisRoot, hasLength(1)); 964 expect(contextsInAnalysisRoot, hasLength(1));
961 AnalysisContext context = contextsInAnalysisRoot[0]; 965 AnalysisContext context = contextsInAnalysisRoot[0];
962 expect(context, isNotNull); 966 expect(context, isNotNull);
963 Source result = context.sourceFactory.forUri('package:foo/foo.dart'); 967 Source result = sourceFactory.forUri('package:foo/foo.dart');
964 expect(result.fullName, filePath); 968 expect(result.fullName, filePath);
965 } 969 }
966 970
967 void test_setRoots_pathContainsDotFile() { 971 void test_setRoots_pathContainsDotFile() {
968 // If the path to a file (relative to the context root) contains a folder 972 // If the path to a file (relative to the context root) contains a folder
969 // whose name begins with '.', then the file is ignored. 973 // whose name begins with '.', then the file is ignored.
970 String project = '/project'; 974 String project = '/project';
971 String fileA = '$project/foo.dart'; 975 String fileA = '$project/foo.dart';
972 String fileB = '$project/.pub/bar.dart'; 976 String fileB = '$project/.pub/bar.dart';
973 resourceProvider.newFile(fileA, ''); 977 resourceProvider.newFile(fileA, '');
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
1739 '**/*.${AnalysisEngine.SUFFIX_HTML}', 1743 '**/*.${AnalysisEngine.SUFFIX_HTML}',
1740 '**/*.${AnalysisEngine.SUFFIX_HTM}', 1744 '**/*.${AnalysisEngine.SUFFIX_HTM}',
1741 '**/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}', 1745 '**/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}',
1742 '**/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}' 1746 '**/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}'
1743 ]; 1747 ];
1744 return patterns 1748 return patterns
1745 .map((pattern) => new Glob(path.posix.separator, pattern)) 1749 .map((pattern) => new Glob(path.posix.separator, pattern))
1746 .toList(); 1750 .toList();
1747 } 1751 }
1748 1752
1749 List<ErrorProcessor> get errorProcessors => 1753 AnalysisOptions get analysisOptions => callbacks.analysisOptions;
1750 callbacks.currentContext.analysisOptions.errorProcessors;
1751 1754
1752 List<Linter> get lints => getLints(callbacks.currentContext); 1755 bool get enableAnalysisDriver => false;
1753 1756
1754 AnalysisOptions get options => callbacks.currentContext.analysisOptions; 1757 List<ErrorProcessor> get errorProcessors => analysisOptions.errorProcessors;
1758
1759 List<Linter> get lints => analysisOptions.lintRules;
1760
1761 SourceFactory get sourceFactory => callbacks.sourceFactory;
1755 1762
1756 Map<String, List<Folder>> get _currentPackageMap => _packageMap(projPath); 1763 Map<String, List<Folder>> get _currentPackageMap => _packageMap(projPath);
1757 1764
1758 void deleteFile(List<String> pathComponents) { 1765 void deleteFile(List<String> pathComponents) {
1759 String filePath = path.posix.joinAll(pathComponents); 1766 String filePath = path.posix.joinAll(pathComponents);
1760 resourceProvider.deleteFile(filePath); 1767 resourceProvider.deleteFile(filePath);
1761 } 1768 }
1762 1769
1770 /**
1771 * TODO(brianwilkerson) This doesn't add the strong mode processor when using
1772 * the new analysis driver.
1773 */
1763 ErrorProcessor getProcessor(AnalysisError error) => 1774 ErrorProcessor getProcessor(AnalysisError error) =>
1764 ErrorProcessor.getProcessor(callbacks.currentContext, error); 1775 callbacks.currentDriver == null
1776 ? ErrorProcessor.getProcessor(callbacks.currentContext, error)
1777 : errorProcessors.firstWhere((ErrorProcessor p) => p.appliesTo(error),
1778 orElse: () => null);
1765 1779
1766 String newFile(List<String> pathComponents, [String content = '']) { 1780 String newFile(List<String> pathComponents, [String content = '']) {
1767 String filePath = path.posix.joinAll(pathComponents); 1781 String filePath = path.posix.joinAll(pathComponents);
1768 resourceProvider.newFile(filePath, content); 1782 resourceProvider.newFile(filePath, content);
1769 return filePath; 1783 return filePath;
1770 } 1784 }
1771 1785
1786 String newFileFromBytes(List<String> pathComponents, List<int> bytes) {
1787 String filePath = path.posix.joinAll(pathComponents);
1788 resourceProvider.newFileWithBytes(filePath, bytes);
1789 return filePath;
1790 }
1791
1772 String newFolder(List<String> pathComponents) { 1792 String newFolder(List<String> pathComponents) {
1773 String folderPath = path.posix.joinAll(pathComponents); 1793 String folderPath = path.posix.joinAll(pathComponents);
1774 resourceProvider.newFolder(folderPath); 1794 resourceProvider.newFolder(folderPath);
1775 return folderPath; 1795 return folderPath;
1776 } 1796 }
1777 1797
1778 void processRequiredPlugins() { 1798 void processRequiredPlugins() {
1779 List<Plugin> plugins = <Plugin>[]; 1799 List<Plugin> plugins = <Plugin>[];
1780 plugins.addAll(AnalysisEngine.instance.requiredPlugins); 1800 plugins.addAll(AnalysisEngine.instance.requiredPlugins);
1781 plugins.add(AnalysisEngine.instance.commandLinePlugin); 1801 plugins.add(AnalysisEngine.instance.commandLinePlugin);
1782 plugins.add(AnalysisEngine.instance.optionsPlugin); 1802 plugins.add(AnalysisEngine.instance.optionsPlugin);
1783 plugins.add(linterPlugin); 1803 plugins.add(linterPlugin);
1784 ExtensionManager manager = new ExtensionManager(); 1804 ExtensionManager manager = new ExtensionManager();
1785 manager.processPlugins(plugins); 1805 manager.processPlugins(plugins);
1786 1806
1787 registerLintRules(); 1807 registerLintRules();
1788 } 1808 }
1789 1809
1790 UriResolver providePackageResolver(Folder folder) => packageResolver; 1810 UriResolver providePackageResolver(Folder folder) => packageResolver;
1791 1811
1792 void setUp() { 1812 void setUp() {
1793 processRequiredPlugins(); 1813 processRequiredPlugins();
1794 resourceProvider = new MemoryResourceProvider(); 1814 resourceProvider = new MemoryResourceProvider();
1815 resourceProvider.newFolder(projPath);
1795 packageMapProvider = new MockPackageMapProvider(); 1816 packageMapProvider = new MockPackageMapProvider();
1796 // Create an SDK in the mock file system. 1817 // Create an SDK in the mock file system.
1797 new MockSdk(resourceProvider: resourceProvider); 1818 new MockSdk(generateSummaryFiles: true, resourceProvider: resourceProvider);
1798 DartSdkManager sdkManager = new DartSdkManager('/', false); 1819 DartSdkManager sdkManager = new DartSdkManager('/', false);
1799 manager = new ContextManagerImpl( 1820 manager = new ContextManagerImpl(
1800 resourceProvider, 1821 resourceProvider,
1801 sdkManager, 1822 sdkManager,
1802 providePackageResolver, 1823 providePackageResolver,
1803 packageMapProvider, 1824 packageMapProvider,
1804 analysisFilesGlobs, 1825 analysisFilesGlobs,
1805 InstrumentationService.NULL_SERVICE, 1826 InstrumentationService.NULL_SERVICE,
1806 new AnalysisOptionsImpl(), 1827 new AnalysisOptionsImpl(),
1807 false); 1828 enableAnalysisDriver);
1808 callbacks = new TestContextManagerCallbacks(resourceProvider); 1829 PerformanceLog logger = new PerformanceLog(new NullStringSink());
1830 AnalysisDriverScheduler scheduler = new AnalysisDriverScheduler(logger);
1831 callbacks =
1832 new TestContextManagerCallbacks(resourceProvider, logger, scheduler);
1809 manager.callbacks = callbacks; 1833 manager.callbacks = callbacks;
1810 resourceProvider.newFolder(projPath);
1811 } 1834 }
1812 1835
1813 /** 1836 /**
1814 * Verify that package URI's for source files in [path] will be resolved 1837 * Verify that package URI's for source files in [path] will be resolved
1815 * using a package root matching [expectation]. 1838 * using a package root matching [expectation].
1816 */ 1839 */
1817 void _checkPackageRoot(String path, expectation) { 1840 void _checkPackageRoot(String path, expectation) {
1818 // TODO(brianwilkerson) Figure out how to test this. Possibly by comparing 1841 // TODO(brianwilkerson) Figure out how to test this. Possibly by comparing
1819 // the contents of the package map (although that approach doesn't work at 1842 // the contents of the package map (although that approach doesn't work at
1820 // the moment). 1843 // the moment).
1821 // FolderDisposition disposition = callbacks.currentContextDispositions[path] ; 1844 // FolderDisposition disposition = callbacks.currentContextDispositions[path] ;
1822 // expect(disposition.packageRoot, expectation); 1845 // expect(disposition.packageRoot, expectation);
1823 // TODO(paulberry): we should also verify that the package map itself is 1846 // TODO(paulberry): we should also verify that the package map itself is
1824 // correct. See dartbug.com/23909. 1847 // correct. See dartbug.com/23909.
1825 } 1848 }
1826 1849
1827 Map<String, List<Folder>> _packageMap(String contextPath) { 1850 Map<String, List<Folder>> _packageMap(String contextPath) {
1828 Folder folder = resourceProvider.getFolder(contextPath); 1851 Folder folder = resourceProvider.getFolder(contextPath);
1829 return manager.folderMap[folder]?.sourceFactory?.packageMap; 1852 return manager.folderMap[folder]?.sourceFactory?.packageMap;
1830 } 1853 }
1831 } 1854 }
1832 1855
1833 @reflectiveTest 1856 @reflectiveTest
1834 class ContextManagerWithNewOptionsTest extends ContextManagerWithOptionsTest { 1857 class ContextManagerWithNewOptionsTest extends ContextManagerWithOptionsTest {
1835 String get optionsFileName => AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE; 1858 String get optionsFileName => AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE;
1836 } 1859 }
1837 1860
1838 @reflectiveTest 1861 @reflectiveTest
1862 class ContextManagerWithNewOptionsTest_Driver
1863 extends ContextManagerWithNewOptionsTest {
1864 bool get enableAnalysisDriver => true;
1865
1866 @failingTest
1867 test_analysis_options_file_delete() async {
1868 // It appears that this fails because we are not correctly updating the
1869 // analysis options in the driver when the file is removed.
1870 return super.test_analysis_options_file_delete();
1871 }
1872
1873 @failingTest
1874 test_analysis_options_file_delete_with_embedder() async {
1875 // This fails because the ContextBuilder doesn't pick up the strongMode
1876 // flag from the embedder.yaml file.
1877 return super.test_analysis_options_file_delete_with_embedder();
1878 }
1879
1880 @failingTest
1881 test_embedder_options() async {
1882 // This fails because the ContextBuilder doesn't pick up the strongMode
1883 // flag from the embedder.yaml file.
1884 return super.test_embedder_options();
1885 }
1886
1887 @failingTest
1888 test_optionsFile_update_strongMode() async {
1889 // It appears that this fails because we are not correctly updating the
1890 // analysis options in the driver when the file is modified.
1891 //return super.test_optionsFile_update_strongMode();
1892 // After a few other changes, the test now times out on my machine, so I'm
1893 // disabling it in order to prevent it from being flaky.
1894 fail('Test times out');
1895 }
1896
1897 @failingTest
1898 test_path_filter_analysis_option() async {
1899 // This fails because we're not analyzing the analyis options file.
1900 return super.test_path_filter_analysis_option();
1901 }
1902 }
1903
1904 @reflectiveTest
1839 class ContextManagerWithOldOptionsTest extends ContextManagerWithOptionsTest { 1905 class ContextManagerWithOldOptionsTest extends ContextManagerWithOptionsTest {
1840 String get optionsFileName => AnalysisEngine.ANALYSIS_OPTIONS_FILE; 1906 String get optionsFileName => AnalysisEngine.ANALYSIS_OPTIONS_FILE;
1841 } 1907 }
1842 1908
1909 @reflectiveTest
1910 class ContextManagerWithOldOptionsTest_Driver
1911 extends ContextManagerWithOldOptionsTest {
1912 bool get enableAnalysisDriver => true;
1913
1914 @failingTest
1915 test_analysis_options_file_delete() async {
1916 // It appears that this fails because we are not correctly updating the
1917 // analysis options in the driver when the file is removed.
1918 return super.test_analysis_options_file_delete();
1919 }
1920
1921 @failingTest
1922 test_analysis_options_file_delete_with_embedder() async {
1923 // This fails because the ContextBuilder doesn't pick up the strongMode
1924 // flag from the embedder.yaml file.
1925 return super.test_analysis_options_file_delete_with_embedder();
1926 }
1927
1928 @failingTest
1929 test_embedder_options() async {
1930 // This fails because the ContextBuilder doesn't pick up the strongMode
1931 // flag from the embedder.yaml file.
1932 return super.test_embedder_options();
1933 }
1934
1935 @failingTest
1936 test_optionsFile_update_strongMode() async {
1937 // It appears that this fails because we are not correctly updating the
1938 // analysis options in the driver when the file is modified.
1939 //return super.test_optionsFile_update_strongMode();
1940 // After a few other changes, the test now times out on my machine, so I'm
1941 // disabling it in order to prevent it from being flaky.
1942 fail('Test times out');
1943 }
1944
1945 @failingTest
1946 test_path_filter_analysis_option() async {
1947 // This fails because we're not analyzing the analyis options file.
1948 return super.test_path_filter_analysis_option();
1949 }
1950 }
1951
1843 abstract class ContextManagerWithOptionsTest extends ContextManagerTest { 1952 abstract class ContextManagerWithOptionsTest extends ContextManagerTest {
1844 String get optionsFileName; 1953 String get optionsFileName;
1845 1954
1846 test_analysis_options_file_delete() async { 1955 test_analysis_options_file_delete() async {
1847 // Setup analysis options 1956 // Setup analysis options
1848 newFile( 1957 newFile(
1849 [projPath, optionsFileName], 1958 [projPath, optionsFileName],
1850 r''' 1959 r'''
1851 embedded_libs: 1960 embedded_libs:
1852 "dart:foobar": "../sdk_ext/entry.dart" 1961 "dart:foobar": "../sdk_ext/entry.dart"
1853 analyzer: 1962 analyzer:
1854 language: 1963 language:
1855 enableStrictCallChecks: true 1964 enableStrictCallChecks: true
1856 errors: 1965 errors:
1857 unused_local_variable: false 1966 unused_local_variable: false
1858 linter: 1967 linter:
1859 rules: 1968 rules:
1860 - camel_case_types 1969 - camel_case_types
1861 '''); 1970 ''');
1862 1971
1863 // Setup context. 1972 // Setup context.
1864 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 1973 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
1865 await pumpEventQueue(); 1974 await pumpEventQueue();
1866 1975
1867 // Verify options were set. 1976 // Verify options were set.
1868 expect(errorProcessors, hasLength(1)); 1977 expect(errorProcessors, hasLength(1));
1869 expect(lints, hasLength(1)); 1978 expect(lints, hasLength(1));
1870 expect(options.enableStrictCallChecks, isTrue); 1979 expect(analysisOptions.enableStrictCallChecks, isTrue);
1871 1980
1872 // Remove options. 1981 // Remove options.
1873 deleteFile([projPath, optionsFileName]); 1982 deleteFile([projPath, optionsFileName]);
1874 await pumpEventQueue(); 1983 await pumpEventQueue();
1875 1984
1876 // Verify defaults restored. 1985 // Verify defaults restored.
1877 expect(errorProcessors, isEmpty); 1986 expect(errorProcessors, isEmpty);
1878 expect(lints, isEmpty); 1987 expect(lints, isEmpty);
1879 expect(options.enableStrictCallChecks, isFalse); 1988 expect(analysisOptions.enableStrictCallChecks, isFalse);
1880 } 1989 }
1881 1990
1882 test_analysis_options_file_delete_with_embedder() async { 1991 test_analysis_options_file_delete_with_embedder() async {
1883 // Setup _embedder.yaml. 1992 // Setup _embedder.yaml.
1884 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); 1993 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
1885 newFile( 1994 newFile(
1886 [libPath, '_embedder.yaml'], 1995 [libPath, '_embedder.yaml'],
1887 r''' 1996 r'''
1888 analyzer: 1997 analyzer:
1889 strong-mode: true 1998 strong-mode: true
(...skipping 22 matching lines...) Expand all
1912 linter: 2021 linter:
1913 rules: 2022 rules:
1914 - camel_case_types 2023 - camel_case_types
1915 '''); 2024 ''');
1916 2025
1917 // Setup context. 2026 // Setup context.
1918 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 2027 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
1919 await pumpEventQueue(); 2028 await pumpEventQueue();
1920 2029
1921 // Verify options were set. 2030 // Verify options were set.
1922 expect(options.enableStrictCallChecks, isTrue); 2031 expect(analysisOptions.enableStrictCallChecks, isTrue);
1923 expect(options.strongMode, isTrue); 2032 expect(analysisOptions.strongMode, isTrue);
1924 expect(errorProcessors, hasLength(2)); 2033 expect(errorProcessors, hasLength(2));
1925 expect(lints, hasLength(2)); 2034 expect(lints, hasLength(2));
1926 2035
1927 // Remove options. 2036 // Remove options.
1928 deleteFile([projPath, optionsFileName]); 2037 deleteFile([projPath, optionsFileName]);
1929 await pumpEventQueue(); 2038 await pumpEventQueue();
1930 2039
1931 // Verify defaults restored. 2040 // Verify defaults restored.
1932 expect(options.enableStrictCallChecks, isFalse); 2041 expect(analysisOptions.enableStrictCallChecks, isFalse);
1933 expect(lints, hasLength(1)); 2042 expect(lints, hasLength(1));
1934 expect(lints.first, new isInstanceOf<AvoidAs>()); 2043 expect(lints.first, new isInstanceOf<AvoidAs>());
1935 expect(errorProcessors, hasLength(1)); 2044 expect(errorProcessors, hasLength(1));
1936 expect(getProcessor(missing_return).severity, isNull); 2045 expect(getProcessor(missing_return).severity, isNull);
1937 } 2046 }
1938 2047
1939 test_analysis_options_include() async { 2048 test_analysis_options_include() async {
1940 // Create files. 2049 // Create files.
1941 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); 2050 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
1942 newFile([libPath, 'main.dart']); 2051 newFile([libPath, 'main.dart']);
(...skipping 16 matching lines...) Expand all
1959 errors: 2068 errors:
1960 unused_local_variable: false 2069 unused_local_variable: false
1961 linter: 2070 linter:
1962 rules: 2071 rules:
1963 - camel_case_types 2072 - camel_case_types
1964 '''); 2073 ''');
1965 // Setup context. 2074 // Setup context.
1966 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 2075 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
1967 await pumpEventQueue(); 2076 await pumpEventQueue();
1968 // Verify options were set. 2077 // Verify options were set.
1969 expect(options.enableStrictCallChecks, isTrue); 2078 expect(analysisOptions.enableStrictCallChecks, isTrue);
1970 expect(errorProcessors, hasLength(1)); 2079 expect(errorProcessors, hasLength(1));
1971 expect(lints, hasLength(1)); 2080 expect(lints, hasLength(1));
1972 expect(lints[0].name, 'camel_case_types'); 2081 expect(lints[0].name, 'camel_case_types');
1973 } 2082 }
1974 2083
1975 test_analysis_options_parse_failure() async { 2084 test_analysis_options_parse_failure() async {
1976 // Create files. 2085 // Create files.
1977 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); 2086 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
1978 newFile([libPath, 'main.dart']); 2087 newFile([libPath, 'main.dart']);
1979 String sdkExtPath = newFolder([projPath, 'sdk_ext']); 2088 String sdkExtPath = newFolder([projPath, 'sdk_ext']);
(...skipping 11 matching lines...) Expand all
1991 2100
1992 // No error means success. 2101 // No error means success.
1993 } 2102 }
1994 2103
1995 test_embedder_options() async { 2104 test_embedder_options() async {
1996 // Create files. 2105 // Create files.
1997 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); 2106 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
1998 String sdkExtPath = newFolder([projPath, 'sdk_ext']); 2107 String sdkExtPath = newFolder([projPath, 'sdk_ext']);
1999 newFile([projPath, 'test', 'test.dart']); 2108 newFile([projPath, 'test', 'test.dart']);
2000 newFile([sdkExtPath, 'entry.dart']); 2109 newFile([sdkExtPath, 'entry.dart']);
2110 List<int> bytes = new SummaryBuilder([], null, true).build();
2111 newFileFromBytes([projPath, 'sdk.ds'], bytes);
2001 // Setup _embedder.yaml. 2112 // Setup _embedder.yaml.
2002 newFile( 2113 newFile(
2003 [libPath, '_embedder.yaml'], 2114 [libPath, '_embedder.yaml'],
2004 r''' 2115 r'''
2005 embedded_libs: 2116 embedded_libs:
2006 "dart:foobar": "../sdk_ext/entry.dart" 2117 "dart:foobar": "../sdk_ext/entry.dart"
2007 analyzer: 2118 analyzer:
2008 strong-mode: true 2119 strong-mode: true
2009 language: 2120 language:
2010 enableSuperMixins: true 2121 enableSuperMixins: true
(...skipping 27 matching lines...) Expand all
2038 2149
2039 // Setup context. 2150 // Setup context.
2040 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 2151 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
2041 await pumpEventQueue(); 2152 await pumpEventQueue();
2042 2153
2043 // Confirm that one context was created. 2154 // Confirm that one context was created.
2044 var contexts = 2155 var contexts =
2045 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); 2156 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
2046 expect(contexts, isNotNull); 2157 expect(contexts, isNotNull);
2047 expect(contexts, hasLength(1)); 2158 expect(contexts, hasLength(1));
2048 var context = contexts[0];
2049 2159
2050 // Verify options. 2160 // Verify options.
2051 // * from `_embedder.yaml`: 2161 // * from `_embedder.yaml`:
2052 expect(context.analysisOptions.strongMode, isTrue); 2162 expect(analysisOptions.strongMode, isTrue);
2053 expect(context.analysisOptions.enableSuperMixins, isTrue); 2163 expect(analysisOptions.enableSuperMixins, isTrue);
2054 // * from analysis options: 2164 // * from analysis options:
2055 expect(context.analysisOptions.enableStrictCallChecks, isTrue); 2165 expect(analysisOptions.enableStrictCallChecks, isTrue);
2056 2166
2057 // * verify tests are excluded 2167 // * verify tests are excluded
2058 expect( 2168 expect(
2059 callbacks.currentContextFilePaths[projPath].keys, 2169 callbacks.currentContextFilePaths[projPath].keys,
2060 unorderedEquals( 2170 unorderedEquals(
2061 ['/my/proj/sdk_ext/entry.dart', '/my/proj/$optionsFileName'])); 2171 ['/my/proj/sdk_ext/entry.dart', '/my/proj/$optionsFileName']));
2062 2172
2063 // Verify filter setup. 2173 // Verify filter setup.
2064 expect(errorProcessors, hasLength(2)); 2174 expect(errorProcessors, hasLength(2));
2065 2175
2066 // * (embedder.) 2176 // * (embedder.)
2067 expect(getProcessor(missing_return).severity, isNull); 2177 expect(getProcessor(missing_return).severity, isNull);
2068 2178
2069 // * (options.) 2179 // * (options.)
2070 expect(getProcessor(unused_local_variable).severity, isNull); 2180 expect(getProcessor(unused_local_variable).severity, isNull);
2071 2181
2072 // Verify lints. 2182 // Verify lints.
2073 var lintNames = lints.map((lint) => lint.name); 2183 var lintNames = lints.map((lint) => lint.name);
2074 2184
2075 expect( 2185 expect(
2076 lintNames, 2186 lintNames,
2077 unorderedEquals( 2187 unorderedEquals(
2078 ['avoid_as' /* embedder */, 'camel_case_types' /* options */])); 2188 ['avoid_as' /* embedder */, 'camel_case_types' /* options */]));
2079 2189
2080 // Sanity check embedder libs. 2190 // Sanity check embedder libs.
2081 var source = context.sourceFactory.forUri('dart:foobar'); 2191 var source = sourceFactory.forUri('dart:foobar');
2082 expect(source, isNotNull); 2192 expect(source, isNotNull);
2083 expect(source.fullName, '/my/proj/sdk_ext/entry.dart'); 2193 expect(source.fullName, '/my/proj/sdk_ext/entry.dart');
2084 } 2194 }
2085 2195
2086 test_error_filter_analysis_option() async { 2196 test_error_filter_analysis_option() async {
2087 // Create files. 2197 // Create files.
2088 newFile( 2198 newFile(
2089 [projPath, optionsFileName], 2199 [projPath, optionsFileName],
2090 r''' 2200 r'''
2091 analyzer: 2201 analyzer:
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
2167 resourceProvider.newFile( 2277 resourceProvider.newFile(
2168 '$projPath/$optionsFileName', 2278 '$projPath/$optionsFileName',
2169 r''' 2279 r'''
2170 analyzer: 2280 analyzer:
2171 strong-mode: false 2281 strong-mode: false
2172 '''); 2282 ''');
2173 // Create the context. 2283 // Create the context.
2174 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 2284 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
2175 await pumpEventQueue(); 2285 await pumpEventQueue();
2176 2286
2177 AnalysisContext context = manager.getContextFor(projPath); 2287 if (enableAnalysisDriver) {
2178 Source testSource = context.getSourcesWithFullName(file.path).single; 2288 AnalysisResult result =
2289 await callbacks.currentDriver.getResult(file.path);
2179 2290
2180 // Not strong mode - both in the context and the SDK context. 2291 // Not strong mode - both in the context and the SDK context.
2181 { 2292 AnalysisContext sdkContext = sourceFactory.dartSdk.context;
2182 AnalysisContext sdkContext = context.sourceFactory.dartSdk.context; 2293 expect(analysisOptions.strongMode, isFalse);
2183 expect(context.analysisOptions.strongMode, isFalse); 2294 expect(sdkContext.analysisOptions.strongMode, isFalse);
2295 expect(result.errors, isEmpty);
2296 } else {
2297 AnalysisContext context = manager.getContextFor(projPath);
2298 Source testSource = context.getSourcesWithFullName(file.path).single;
2299
2300 // Not strong mode - both in the context and the SDK context.
2301 AnalysisContext sdkContext = sourceFactory.dartSdk.context;
2302 expect(analysisOptions.strongMode, isFalse);
2184 expect(sdkContext.analysisOptions.strongMode, isFalse); 2303 expect(sdkContext.analysisOptions.strongMode, isFalse);
2185 expect(context.computeErrors(testSource), isEmpty); 2304 expect(context.computeErrors(testSource), isEmpty);
2186 } 2305 }
2187 2306
2188 // Update the options file - turn on 'strong-mode'. 2307 // Update the options file - turn on 'strong-mode'.
2189 resourceProvider.updateFile( 2308 resourceProvider.updateFile(
2190 '$projPath/$optionsFileName', 2309 '$projPath/$optionsFileName',
2191 r''' 2310 r'''
2192 analyzer: 2311 analyzer:
2193 strong-mode: true 2312 strong-mode: true
2194 '''); 2313 ''');
2195 await pumpEventQueue(); 2314 await pumpEventQueue();
2196 2315
2197 // Strong mode - both in the context and the SDK context. 2316 // Strong mode - both in the context and the SDK context.
2198 { 2317 if (enableAnalysisDriver) {
2199 AnalysisContext context = manager.getContextFor(projPath); 2318 AnalysisResult result =
2200 AnalysisContext sdkContext = context.sourceFactory.dartSdk.context; 2319 await callbacks.currentDriver.getResult(file.path);
2201 expect(context.analysisOptions.strongMode, isTrue); 2320
2321 // Not strong mode - both in the context and the SDK context.
2322 AnalysisContext sdkContext = sourceFactory.dartSdk.context;
2323 expect(analysisOptions.strongMode, isTrue);
2202 expect(sdkContext.analysisOptions.strongMode, isTrue); 2324 expect(sdkContext.analysisOptions.strongMode, isTrue);
2203 // The code is strong-mode clean. 2325 // The code is strong-mode clean.
2204 // Verify that TypeSystem was reset. 2326 // Verify that TypeSystem was reset.
2327 expect(result.errors, isEmpty);
2328 } else {
2329 AnalysisContext context = manager.getContextFor(projPath);
2330 Source testSource = context.getSourcesWithFullName(file.path).single;
2331 AnalysisContext sdkContext = sourceFactory.dartSdk.context;
2332 expect(analysisOptions.strongMode, isTrue);
2333 expect(sdkContext.analysisOptions.strongMode, isTrue);
2334 // The code is strong-mode clean.
2335 // Verify that TypeSystem was reset.
2205 expect(context.computeErrors(testSource), isEmpty); 2336 expect(context.computeErrors(testSource), isEmpty);
2206 } 2337 }
2207 } 2338 }
2208 2339
2209 test_path_filter_analysis_option() async { 2340 test_path_filter_analysis_option() async {
2210 // Create files. 2341 // Create files.
2211 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); 2342 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
2212 newFile([libPath, 'main.dart']); 2343 newFile([libPath, 'main.dart']);
2213 newFile([libPath, 'nope.dart']); 2344 newFile([libPath, 'nope.dart']);
2214 String sdkExtPath = newFolder([projPath, 'sdk_ext']); 2345 String sdkExtPath = newFolder([projPath, 'sdk_ext']);
2215 newFile([sdkExtPath, 'entry.dart']); 2346 newFile([sdkExtPath, 'entry.dart']);
2216 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']); 2347 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']);
2217 newFile([sdkExtSrcPath, 'part.dart']); 2348 newFile([sdkExtSrcPath, 'part.dart']);
2218 // Setup analysis options file with ignore list. 2349 // Setup analysis options file with ignore list.
2219 newFile( 2350 newFile(
2220 [projPath, optionsFileName], 2351 [projPath, optionsFileName],
2221 r''' 2352 r'''
2222 analyzer: 2353 analyzer:
2223 exclude: 2354 exclude:
2224 - lib/nope.dart 2355 - lib/nope.dart
2225 - 'sdk_ext/**' 2356 - 'sdk_ext/**'
2226 '''); 2357 ''');
2227 // Setup context. 2358 // Setup context.
2228 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 2359 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
2360
2229 // Verify that analysis options was parsed and the ignore patterns applied. 2361 // Verify that analysis options was parsed and the ignore patterns applied.
2230 Map<String, int> fileTimestamps = 2362 Folder projectFolder = resourceProvider.newFolder(projPath);
2231 callbacks.currentContextFilePaths[projPath]; 2363 if (enableAnalysisDriver) {
2232 expect(fileTimestamps, isNotEmpty); 2364 var drivers = manager.getDriversInAnalysisRoot(projectFolder);
2233 List<String> files = fileTimestamps.keys.toList(); 2365 expect(drivers, hasLength(1));
2234 expect( 2366 AnalysisDriver driver = drivers[0];
2235 files, 2367 expect(
2236 unorderedEquals( 2368 driver.addedFiles,
2237 ['/my/proj/lib/main.dart', '/my/proj/$optionsFileName'])); 2369 unorderedEquals(
2370 ['/my/proj/lib/main.dart', '/my/proj/$optionsFileName']));
2371 } else {
2372 Map<String, int> fileTimestamps =
2373 callbacks.currentContextFilePaths[projPath];
2374 expect(fileTimestamps, isNotEmpty);
2375 List<String> files = fileTimestamps.keys.toList();
2376 expect(
2377 files,
2378 unorderedEquals(
2379 ['/my/proj/lib/main.dart', '/my/proj/$optionsFileName']));
2380 }
2238 } 2381 }
2239 2382
2240 test_path_filter_child_contexts_option() async { 2383 test_path_filter_child_contexts_option() async {
2241 // Create files. 2384 // Create files.
2242 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); 2385 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
2243 newFile([libPath, 'main.dart']); 2386 newFile([libPath, 'main.dart']);
2244 newFile( 2387 newFile(
2245 [libPath, 'pubspec.yaml'], 2388 [libPath, 'pubspec.yaml'],
2246 r''' 2389 r'''
2247 name: foobar 2390 name: foobar
(...skipping 11 matching lines...) Expand all
2259 [projPath, optionsFileName], 2402 [projPath, optionsFileName],
2260 r''' 2403 r'''
2261 analyzer: 2404 analyzer:
2262 exclude: 2405 exclude:
2263 - 'other_lib' 2406 - 'other_lib'
2264 '''); 2407 ''');
2265 // Setup context. 2408 // Setup context.
2266 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 2409 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
2267 // Verify that the context in other_lib wasn't created and that the 2410 // Verify that the context in other_lib wasn't created and that the
2268 // context in lib was created. 2411 // context in lib was created.
2269 var contexts = 2412 Folder projectFolder = resourceProvider.newFolder(projPath);
2270 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); 2413 if (enableAnalysisDriver) {
2271 expect(contexts.length, 2); 2414 var drivers = manager.getDriversInAnalysisRoot(projectFolder);
2272 expect(contexts[0].name, equals('/my/proj')); 2415 expect(drivers, hasLength(2));
2273 expect(contexts[1].name, equals('/my/proj/lib')); 2416 expect(drivers[0].name, equals('proj'));
2417 expect(drivers[1].name, equals('lib'));
2418 } else {
2419 var contexts =
2420 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath));
2421 expect(contexts.length, 2);
2422 expect(contexts[0].name, equals('/my/proj'));
2423 expect(contexts[1].name, equals('/my/proj/lib'));
2424 }
2274 } 2425 }
2275 2426
2276 test_path_filter_recursive_wildcard_child_contexts_option() async { 2427 test_path_filter_recursive_wildcard_child_contexts_option() async {
2277 // Create files. 2428 // Create files.
2278 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); 2429 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
2279 newFile([libPath, 'main.dart']); 2430 newFile([libPath, 'main.dart']);
2280 newFile( 2431 newFile(
2281 [libPath, 'pubspec.yaml'], 2432 [libPath, 'pubspec.yaml'],
2282 r''' 2433 r'''
2283 name: foobar 2434 name: foobar
2284 '''); 2435 ''');
2285 String otherLibPath = newFolder([projPath, 'other_lib']); 2436 String otherLibPath = newFolder([projPath, 'other_lib']);
2286 newFile([otherLibPath, 'entry.dart']); 2437 newFile([otherLibPath, 'entry.dart']);
2287 newFile( 2438 newFile(
2288 [otherLibPath, 'pubspec.yaml'], 2439 [otherLibPath, 'pubspec.yaml'],
2289 r''' 2440 r'''
2290 name: other_lib 2441 name: other_lib
2291 '''); 2442 ''');
2292 // Setup analysis options file with ignore list that ignores 'other_lib' 2443 // Setup analysis options file with ignore list that ignores 'other_lib'
2293 // and all descendants. 2444 // and all descendants.
2294 newFile( 2445 newFile(
2295 [projPath, optionsFileName], 2446 [projPath, optionsFileName],
2296 r''' 2447 r'''
2297 analyzer: 2448 analyzer:
2298 exclude: 2449 exclude:
2299 - 'other_lib/**' 2450 - 'other_lib/**'
2300 '''); 2451 ''');
2301 // Setup context. 2452 // Setup context.
2302 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 2453 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
2454
2303 // Verify that the context in other_lib wasn't created and that the 2455 // Verify that the context in other_lib wasn't created and that the
2304 // context in lib was created. 2456 // context in lib was created.
2305 var contexts = 2457 Folder projectFolder = resourceProvider.newFolder(projPath);
2306 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); 2458 if (enableAnalysisDriver) {
2307 expect(contexts.length, 2); 2459 var drivers = manager.getDriversInAnalysisRoot(projectFolder);
2308 expect(contexts[0].name, equals('/my/proj')); 2460 expect(drivers, hasLength(2));
2309 expect(contexts[1].name, equals('/my/proj/lib')); 2461 expect(drivers[0].name, equals('proj'));
2462 expect(drivers[1].name, equals('lib'));
2463 } else {
2464 var contexts = manager.contextsInAnalysisRoot(projectFolder);
2465 expect(contexts.length, 2);
2466 expect(contexts[0].name, equals('/my/proj'));
2467 expect(contexts[1].name, equals('/my/proj/lib'));
2468 }
2310 } 2469 }
2311 2470
2312 test_path_filter_wildcard_child_contexts_option() async { 2471 test_path_filter_wildcard_child_contexts_option() async {
2313 // Create files. 2472 // Create files.
2314 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); 2473 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
2315 newFile([libPath, 'main.dart']); 2474 newFile([libPath, 'main.dart']);
2316 newFile( 2475 newFile(
2317 [libPath, 'pubspec.yaml'], 2476 [libPath, 'pubspec.yaml'],
2318 r''' 2477 r'''
2319 name: foobar 2478 name: foobar
2320 '''); 2479 ''');
2321 String otherLibPath = newFolder([projPath, 'other_lib']); 2480 String otherLibPath = newFolder([projPath, 'other_lib']);
2322 newFile([otherLibPath, 'entry.dart']); 2481 newFile([otherLibPath, 'entry.dart']);
2323 newFile( 2482 newFile(
2324 [otherLibPath, 'pubspec.yaml'], 2483 [otherLibPath, 'pubspec.yaml'],
2325 r''' 2484 r'''
2326 name: other_lib 2485 name: other_lib
2327 '''); 2486 ''');
2328 // Setup analysis options file with ignore list that ignores 'other_lib' 2487 // Setup analysis options file with ignore list that ignores 'other_lib'
2329 // and all immediate children. 2488 // and all immediate children.
2330 newFile( 2489 newFile(
2331 [projPath, optionsFileName], 2490 [projPath, optionsFileName],
2332 r''' 2491 r'''
2333 analyzer: 2492 analyzer:
2334 exclude: 2493 exclude:
2335 - 'other_lib/*' 2494 - 'other_lib/*'
2336 '''); 2495 ''');
2337 // Setup context. 2496 // Setup context / driver.
2338 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 2497 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
2339 // Verify that the context in other_lib wasn't created and that the 2498
2340 // context in lib was created. 2499 Folder projectFolder = resourceProvider.newFolder(projPath);
2341 var contexts = 2500 if (enableAnalysisDriver) {
2342 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); 2501 var drivers = manager.getDriversInAnalysisRoot(projectFolder);
2343 expect(contexts.length, 2); 2502 expect(drivers, hasLength(2));
2344 expect(contexts[0].name, equals('/my/proj')); 2503 expect(drivers[0].name, equals('proj'));
2345 expect(contexts[1].name, equals('/my/proj/lib')); 2504 expect(drivers[1].name, equals('lib'));
2505 } else {
2506 // Verify that the context in other_lib wasn't created and that the
2507 // context in lib was created.
2508 var contexts = manager.contextsInAnalysisRoot(projectFolder);
2509 expect(contexts, hasLength(2));
2510 expect(contexts[0].name, equals('/my/proj'));
2511 expect(contexts[1].name, equals('/my/proj/lib'));
2512 }
2346 } 2513 }
2347 2514
2348 void test_setRoots_nested_excludedByOuter() { 2515 void test_setRoots_nested_excludedByOuter() {
2349 String project = '/project'; 2516 String project = '/project';
2350 String projectPubspec = '$project/pubspec.yaml'; 2517 String projectPubspec = '$project/pubspec.yaml';
2351 String example = '$project/example'; 2518 String example = '$project/example';
2352 String examplePubspec = '$example/pubspec.yaml'; 2519 String examplePubspec = '$example/pubspec.yaml';
2353 // create files 2520 // create files
2354 resourceProvider.newFile(projectPubspec, 'name: project'); 2521 resourceProvider.newFile(projectPubspec, 'name: project');
2355 resourceProvider.newFile(examplePubspec, 'name: example'); 2522 resourceProvider.newFile(examplePubspec, 'name: example');
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
2422 [projPath, optionsFileName], 2589 [projPath, optionsFileName],
2423 r''' 2590 r'''
2424 analyzer: 2591 analyzer:
2425 strong-mode: true 2592 strong-mode: true
2426 '''); 2593 ''');
2427 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); 2594 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]);
2428 newFile([libPath, 'main.dart']); 2595 newFile([libPath, 'main.dart']);
2429 // Setup context. 2596 // Setup context.
2430 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); 2597 manager.setRoots(<String>[projPath], <String>[], <String, String>{});
2431 // Verify that analysis options was parsed and strong-mode set. 2598 // Verify that analysis options was parsed and strong-mode set.
2432 Map<String, int> fileTimestamps = 2599 expect(analysisOptions.strongMode, true);
2433 callbacks.currentContextFilePaths[projPath];
2434 expect(fileTimestamps, isNotEmpty);
2435 expect(callbacks.currentContext.analysisOptions.strongMode, true);
2436 } 2600 }
2437 } 2601 }
2438 2602
2439 class TestContextManagerCallbacks extends ContextManagerCallbacks { 2603 class TestContextManagerCallbacks extends ContextManagerCallbacks {
2440 /** 2604 /**
2441 * Source of timestamps stored in [currentContextFilePaths]. 2605 * Source of timestamps stored in [currentContextFilePaths].
2442 */ 2606 */
2443 int now = 0; 2607 int now = 0;
2444 2608
2445 /** 2609 /**
2446 * The analysis context that was created. 2610 * The analysis context that was created.
2447 */ 2611 */
2448 AnalysisContext currentContext; 2612 AnalysisContext currentContext;
2449 2613
2450 /** 2614 /**
2615 * The analysis driver that was created.
2616 */
2617 AnalysisDriver currentDriver;
2618
2619 /**
2451 * Map from context to the timestamp when the context was created. 2620 * Map from context to the timestamp when the context was created.
2452 */ 2621 */
2453 Map<String, int> currentContextTimestamps = <String, int>{}; 2622 Map<String, int> currentContextTimestamps = <String, int>{};
2454 2623
2455 /** 2624 /**
2456 * Map from context to (map from file path to timestamp of last event). 2625 * Map from context to (map from file path to timestamp of last event).
2457 */ 2626 */
2458 final Map<String, Map<String, int>> currentContextFilePaths = 2627 final Map<String, Map<String, int>> currentContextFilePaths =
2459 <String, Map<String, int>>{}; 2628 <String, Map<String, int>>{};
2460 2629
2461 /** 2630 /**
2462 * A map from the paths of contexts to a set of the sources that should be 2631 * A map from the paths of contexts to a set of the sources that should be
2463 * explicitly analyzed in those contexts. 2632 * explicitly analyzed in those contexts.
2464 */ 2633 */
2465 final Map<String, Set<Source>> currentContextSources = 2634 final Map<String, Set<Source>> currentContextSources =
2466 <String, Set<Source>>{}; 2635 <String, Set<Source>>{};
2467 2636
2468 /** 2637 /**
2469 * Resource provider used for this test. 2638 * Resource provider used for this test.
2470 */ 2639 */
2471 final ResourceProvider resourceProvider; 2640 final ResourceProvider resourceProvider;
2472 2641
2473 /** 2642 /**
2643 * The logger used by the scheduler and the driver.
2644 */
2645 final PerformanceLog logger;
2646
2647 /**
2648 * The scheduler used by the driver.
2649 */
2650 final AnalysisDriverScheduler scheduler;
2651
2652 /**
2474 * The list of `flushedFiles` in the last [removeContext] invocation. 2653 * The list of `flushedFiles` in the last [removeContext] invocation.
2475 */ 2654 */
2476 List<String> lastFlushedFiles; 2655 List<String> lastFlushedFiles;
2477 2656
2478 TestContextManagerCallbacks(this.resourceProvider); 2657 TestContextManagerCallbacks(
2658 this.resourceProvider, this.logger, this.scheduler);
2659
2660 /**
2661 * Return the current set of analysis options.
2662 */
2663 AnalysisOptions get analysisOptions => currentDriver == null
2664 ? currentContext.analysisOptions
2665 : currentDriver.analysisOptions;
2479 2666
2480 /** 2667 /**
2481 * Iterable of the paths to contexts that currently exist. 2668 * Iterable of the paths to contexts that currently exist.
2482 */ 2669 */
2483 Iterable<String> get currentContextPaths => currentContextTimestamps.keys; 2670 Iterable<String> get currentContextPaths => currentContextTimestamps.keys;
2484 2671
2672 /**
2673 * Return the current source factory.
2674 */
2675 SourceFactory get sourceFactory => currentDriver == null
2676 ? currentContext.sourceFactory
2677 : currentDriver.sourceFactory;
2678
2485 @override 2679 @override
2486 AnalysisDriver addAnalysisDriver(Folder folder, AnalysisOptions options) { 2680 AnalysisDriver addAnalysisDriver(Folder folder, AnalysisOptions options) {
2487 // TODO: implement addAnalysisDriver 2681 String path = folder.path;
2488 throw new UnimplementedError(); 2682 expect(currentContextPaths, isNot(contains(path)));
2683 currentContextTimestamps[path] = now;
2684
2685 ContextBuilder builder =
2686 createContextBuilder(folder, options, useSummaries: true);
2687 AnalysisContext context = builder.buildContext(folder.path);
2688 SourceFactory sourceFactory = context.sourceFactory;
2689 AnalysisOptions analysisOptions = context.analysisOptions;
2690 context.dispose();
2691
2692 currentDriver = new AnalysisDriver(
2693 scheduler,
2694 logger,
2695 resourceProvider,
2696 new MemoryByteStore(),
2697 new FileContentOverlay(),
2698 sourceFactory,
2699 analysisOptions);
2700 currentDriver.name = folder.shortName;
2701 currentDriver.exceptions.listen((ExceptionResult result) {
2702 AnalysisEngine.instance.logger
2703 .logError('Analysis failed: ${result.path}', result.exception);
2704 });
2705 return currentDriver;
2489 } 2706 }
2490 2707
2491 @override 2708 @override
2492 AnalysisContext addContext(Folder folder, AnalysisOptions options) { 2709 AnalysisContext addContext(Folder folder, AnalysisOptions options) {
2493 String path = folder.path; 2710 String path = folder.path;
2494 expect(currentContextPaths, isNot(contains(path))); 2711 expect(currentContextPaths, isNot(contains(path)));
2495 currentContextTimestamps[path] = now; 2712 currentContextTimestamps[path] = now;
2496 currentContextFilePaths[path] = <String, int>{}; 2713 currentContextFilePaths[path] = <String, int>{};
2497 currentContextSources[path] = new HashSet<Source>(); 2714 currentContextSources[path] = new HashSet<Source>();
2498 2715
2499 ContextBuilder builder = createContextBuilder(folder, options); 2716 ContextBuilder builder = createContextBuilder(folder, options);
2500 currentContext = builder.buildContext(folder.path); 2717 currentContext = builder.buildContext(folder.path);
2501 return currentContext; 2718 return currentContext;
2502 } 2719 }
2503 2720
2504 @override 2721 @override
2505 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { 2722 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) {
2506 Map<String, int> filePaths = currentContextFilePaths[contextFolder.path]; 2723 if (currentDriver != null) {
2507 Set<Source> sources = currentContextSources[contextFolder.path]; 2724 changeSet.addedSources.forEach((source) {
2725 currentDriver.addFile(source.fullName);
2726 });
2727 changeSet.changedSources.forEach((source) {
2728 currentDriver.changeFile(source.fullName);
2729 });
2730 changeSet.removedSources.forEach((source) {
2731 currentDriver.removeFile(source.fullName);
2732 });
2733 } else {
2734 Map<String, int> filePaths = currentContextFilePaths[contextFolder.path];
2735 Set<Source> sources = currentContextSources[contextFolder.path];
2508 2736
2509 for (Source source in changeSet.addedSources) { 2737 for (Source source in changeSet.addedSources) {
2510 expect(filePaths, isNot(contains(source.fullName))); 2738 expect(filePaths, isNot(contains(source.fullName)));
2511 filePaths[source.fullName] = now; 2739 filePaths[source.fullName] = now;
2512 sources.add(source); 2740 sources.add(source);
2741 }
2742 for (Source source in changeSet.removedSources) {
2743 expect(filePaths, contains(source.fullName));
2744 filePaths.remove(source.fullName);
2745 sources.remove(source);
2746 }
2747 for (Source source in changeSet.changedSources) {
2748 expect(filePaths, contains(source.fullName));
2749 filePaths[source.fullName] = now;
2750 }
2751
2752 currentContext.applyChanges(changeSet);
2513 } 2753 }
2514 for (Source source in changeSet.removedSources) {
2515 expect(filePaths, contains(source.fullName));
2516 filePaths.remove(source.fullName);
2517 sources.remove(source);
2518 }
2519 for (Source source in changeSet.changedSources) {
2520 expect(filePaths, contains(source.fullName));
2521 filePaths[source.fullName] = now;
2522 }
2523
2524 currentContext.applyChanges(changeSet);
2525 } 2754 }
2526 2755
2527 @override 2756 @override
2528 void applyFileRemoved(AnalysisDriver driver, String file) { 2757 void applyFileRemoved(AnalysisDriver driver, String file) {
2529 throw new StateError('Unexpected invocation of applyFileRemoved'); 2758 driver.removeFile(file);
2530 } 2759 }
2531 2760
2532 void assertContextFiles(String contextPath, List<String> expectedFiles) { 2761 void assertContextFiles(String contextPath, List<String> expectedFiles) {
2533 var actualFiles = currentContextFilePaths[contextPath].keys; 2762 var actualFiles = currentContextFilePaths[contextPath].keys;
2534 expect(actualFiles, unorderedEquals(expectedFiles)); 2763 expect(actualFiles, unorderedEquals(expectedFiles));
2535 } 2764 }
2536 2765
2537 void assertContextPaths(List<String> expected) { 2766 void assertContextPaths(List<String> expected) {
2538 expect(currentContextPaths, unorderedEquals(expected)); 2767 expect(currentContextPaths, unorderedEquals(expected));
2539 } 2768 }
2540 2769
2541 @override 2770 @override
2542 void computingPackageMap(bool computing) { 2771 void computingPackageMap(bool computing) {
2543 // Do nothing. 2772 // Do nothing.
2544 } 2773 }
2545 2774
2546 @override 2775 @override
2547 ContextBuilder createContextBuilder(Folder folder, AnalysisOptions options) { 2776 ContextBuilder createContextBuilder(Folder folder, AnalysisOptions options,
2548 DartSdkManager sdkManager = new DartSdkManager('/', false); 2777 {bool useSummaries = false}) {
2778 DartSdkManager sdkManager = new DartSdkManager('/', useSummaries);
2549 ContextBuilderOptions builderOptions = new ContextBuilderOptions(); 2779 ContextBuilderOptions builderOptions = new ContextBuilderOptions();
2550 builderOptions.defaultOptions = options; 2780 builderOptions.defaultOptions = options;
2551 ContextBuilder builder = new ContextBuilder( 2781 ContextBuilder builder = new ContextBuilder(
2552 resourceProvider, sdkManager, new ContentCache(), 2782 resourceProvider, sdkManager, new ContentCache(),
2553 options: builderOptions); 2783 options: builderOptions);
2554 return builder; 2784 return builder;
2555 } 2785 }
2556 2786
2557 @override 2787 @override
2558 void moveContext(Folder from, Folder to) { 2788 void moveContext(Folder from, Folder to) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2598 class TestUriResolver extends UriResolver { 2828 class TestUriResolver extends UriResolver {
2599 Map<Uri, Source> uriMap; 2829 Map<Uri, Source> uriMap;
2600 2830
2601 TestUriResolver(this.uriMap); 2831 TestUriResolver(this.uriMap);
2602 2832
2603 @override 2833 @override
2604 Source resolveAbsolute(Uri uri, [Uri actualUri]) { 2834 Source resolveAbsolute(Uri uri, [Uri actualUri]) {
2605 return uriMap[uri]; 2835 return uriMap[uri];
2606 } 2836 }
2607 } 2837 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698