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

Side by Side Diff: pkg/analyzer/test/src/context/builder_test.dart

Issue 2425423009: Split out options from ContextBuilder (Closed)
Patch Set: Created 4 years, 2 months 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 analyzer.test.src.context.context_builder_test; 5 library analyzer.test.src.context.context_builder_test;
6 6
7 import 'package:analyzer/file_system/file_system.dart'; 7 import 'package:analyzer/file_system/file_system.dart';
8 import 'package:analyzer/file_system/memory_file_system.dart'; 8 import 'package:analyzer/file_system/memory_file_system.dart';
9 import 'package:analyzer/plugin/options.dart'; 9 import 'package:analyzer/plugin/options.dart';
10 import 'package:analyzer/src/context/builder.dart'; 10 import 'package:analyzer/src/context/builder.dart';
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 * The SDK manager used by the tests; 48 * The SDK manager used by the tests;
49 */ 49 */
50 DartSdkManager sdkManager; 50 DartSdkManager sdkManager;
51 51
52 /** 52 /**
53 * The content cache used by the tests. 53 * The content cache used by the tests.
54 */ 54 */
55 ContentCache contentCache; 55 ContentCache contentCache;
56 56
57 /** 57 /**
58 * The options passed to the context builder.
59 */
60 ContextBuilderOptions builderOptions = new ContextBuilderOptions();
61
62 /**
58 * The context builder to be used in the test. 63 * The context builder to be used in the test.
59 */ 64 */
60 ContextBuilder builder; 65 ContextBuilder builder;
61 66
62 /** 67 /**
63 * The path to the default SDK, or `null` if the test has not explicitly 68 * The path to the default SDK, or `null` if the test has not explicitly
64 * invoked [createDefaultSdk]. 69 * invoked [createDefaultSdk].
65 */ 70 */
66 String defaultSdkPath = null; 71 String defaultSdkPath = null;
67 72
68 Uri convertedDirectoryUri(String directoryPath) { 73 Uri convertedDirectoryUri(String directoryPath) {
69 return new Uri.directory(resourceProvider.convertPath(directoryPath), 74 return new Uri.directory(resourceProvider.convertPath(directoryPath),
70 windows: pathContext.style == path.windows.style); 75 windows: pathContext.style == path.windows.style);
71 } 76 }
72 77
73 void createDefaultSdk(Folder sdkDir) { 78 void createDefaultSdk(Folder sdkDir) {
74 defaultSdkPath = pathContext.join(sdkDir.path, 'default', 'sdk'); 79 defaultSdkPath = pathContext.join(sdkDir.path, 'default', 'sdk');
75 String librariesFilePath = pathContext.join(defaultSdkPath, 'lib', 80 String librariesFilePath = pathContext.join(defaultSdkPath, 'lib',
76 '_internal', 'sdk_library_metadata', 'lib', 'libraries.dart'); 81 '_internal', 'sdk_library_metadata', 'lib', 'libraries.dart');
77 resourceProvider.newFile( 82 resourceProvider.newFile(
78 librariesFilePath, 83 librariesFilePath,
79 r''' 84 r'''
80 const Map<String, LibraryInfo> libraries = const { 85 const Map<String, LibraryInfo> libraries = const {
81 "async": const LibraryInfo("async/async.dart"), 86 "async": const LibraryInfo("async/async.dart"),
82 "core": const LibraryInfo("core/core.dart"), 87 "core": const LibraryInfo("core/core.dart"),
83 }; 88 };
84 '''); 89 ''');
85 sdkManager = new DartSdkManager(defaultSdkPath, false); 90 sdkManager = new DartSdkManager(defaultSdkPath, false);
86 builder = new ContextBuilder(resourceProvider, sdkManager, contentCache); 91 builder = new ContextBuilder(resourceProvider, sdkManager, contentCache,
92 options: builderOptions);
87 } 93 }
88 94
89 void createFile(String path, String content) { 95 void createFile(String path, String content) {
90 resourceProvider.newFile(path, content); 96 resourceProvider.newFile(path, content);
91 } 97 }
92 98
93 @override 99 @override
94 void setUp() { 100 void setUp() {
95 resourceProvider = new MemoryResourceProvider(); 101 resourceProvider = new MemoryResourceProvider();
96 pathContext = resourceProvider.pathContext; 102 pathContext = resourceProvider.pathContext;
97 new MockSdk(resourceProvider: resourceProvider); 103 new MockSdk(resourceProvider: resourceProvider);
98 sdkManager = 104 sdkManager =
99 new DartSdkManager(resourceProvider.convertPath('/sdk'), false); 105 new DartSdkManager(resourceProvider.convertPath('/sdk'), false);
100 contentCache = new ContentCache(); 106 contentCache = new ContentCache();
101 builder = new ContextBuilder(resourceProvider, sdkManager, contentCache); 107 builder = new ContextBuilder(resourceProvider, sdkManager, contentCache,
108 options: builderOptions);
102 } 109 }
103 110
104 @failingTest 111 @failingTest
105 void test_buildContext() { 112 void test_buildContext() {
106 fail('Incomplete test'); 113 fail('Incomplete test');
107 } 114 }
108 115
109 void test_convertPackagesToMap_noPackages() { 116 void test_convertPackagesToMap_noPackages() {
110 expect(builder.convertPackagesToMap(Packages.noPackages), isEmpty); 117 expect(builder.convertPackagesToMap(Packages.noPackages), isEmpty);
111 } 118 }
(...skipping 23 matching lines...) Expand all
135 void test_createDefaultOptions_default() { 142 void test_createDefaultOptions_default() {
136 // Invert a subset of the options to ensure that the default options are 143 // Invert a subset of the options to ensure that the default options are
137 // being returned. 144 // being returned.
138 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); 145 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl();
139 defaultOptions.dart2jsHint = !defaultOptions.dart2jsHint; 146 defaultOptions.dart2jsHint = !defaultOptions.dart2jsHint;
140 defaultOptions.enableAssertMessage = !defaultOptions.enableAssertMessage; 147 defaultOptions.enableAssertMessage = !defaultOptions.enableAssertMessage;
141 defaultOptions.enableGenericMethods = !defaultOptions.enableGenericMethods; 148 defaultOptions.enableGenericMethods = !defaultOptions.enableGenericMethods;
142 defaultOptions.enableStrictCallChecks = 149 defaultOptions.enableStrictCallChecks =
143 !defaultOptions.enableStrictCallChecks; 150 !defaultOptions.enableStrictCallChecks;
144 defaultOptions.enableSuperMixins = !defaultOptions.enableSuperMixins; 151 defaultOptions.enableSuperMixins = !defaultOptions.enableSuperMixins;
145 builder.defaultOptions = defaultOptions; 152 builderOptions.defaultOptions = defaultOptions;
146 AnalysisOptions options = builder.createDefaultOptions(); 153 AnalysisOptions options = builder.createDefaultOptions();
147 _expectEqualOptions(options, defaultOptions); 154 _expectEqualOptions(options, defaultOptions);
148 } 155 }
149 156
150 void test_createDefaultOptions_noDefault() { 157 void test_createDefaultOptions_noDefault() {
151 AnalysisOptions options = builder.createDefaultOptions(); 158 AnalysisOptions options = builder.createDefaultOptions();
152 _expectEqualOptions(options, new AnalysisOptionsImpl()); 159 _expectEqualOptions(options, new AnalysisOptionsImpl());
153 } 160 }
154 161
155 void test_createPackageMap_fromPackageDirectory_explicit() { 162 void test_createPackageMap_fromPackageDirectory_explicit() {
156 // Use a package directory that is outside the project directory. 163 // Use a package directory that is outside the project directory.
157 String rootPath = resourceProvider.convertPath('/root'); 164 String rootPath = resourceProvider.convertPath('/root');
158 String projectPath = pathContext.join(rootPath, 'project'); 165 String projectPath = pathContext.join(rootPath, 'project');
159 String packageDirPath = pathContext.join(rootPath, 'packages'); 166 String packageDirPath = pathContext.join(rootPath, 'packages');
160 String fooName = 'foo'; 167 String fooName = 'foo';
161 String fooPath = pathContext.join(packageDirPath, fooName); 168 String fooPath = pathContext.join(packageDirPath, fooName);
162 String barName = 'bar'; 169 String barName = 'bar';
163 String barPath = pathContext.join(packageDirPath, barName); 170 String barPath = pathContext.join(packageDirPath, barName);
164 resourceProvider.newFolder(projectPath); 171 resourceProvider.newFolder(projectPath);
165 resourceProvider.newFolder(fooPath); 172 resourceProvider.newFolder(fooPath);
166 resourceProvider.newFolder(barPath); 173 resourceProvider.newFolder(barPath);
167 174
168 builder.defaultPackagesDirectoryPath = packageDirPath; 175 builderOptions.defaultPackagesDirectoryPath = packageDirPath;
169 176
170 Packages packages = builder.createPackageMap(projectPath); 177 Packages packages = builder.createPackageMap(projectPath);
171 expect(packages, isNotNull); 178 expect(packages, isNotNull);
172 Map<String, Uri> map = packages.asMap(); 179 Map<String, Uri> map = packages.asMap();
173 expect(map, hasLength(2)); 180 expect(map, hasLength(2));
174 expect(map[fooName], convertedDirectoryUri(fooPath)); 181 expect(map[fooName], convertedDirectoryUri(fooPath));
175 expect(map[barName], convertedDirectoryUri(barPath)); 182 expect(map[barName], convertedDirectoryUri(barPath));
176 } 183 }
177 184
178 void test_createPackageMap_fromPackageDirectory_inRoot() { 185 void test_createPackageMap_fromPackageDirectory_inRoot() {
(...skipping 23 matching lines...) Expand all
202 resourceProvider.newFolder(projectPath); 209 resourceProvider.newFolder(projectPath);
203 Uri fooUri = convertedDirectoryUri('/pkg/foo'); 210 Uri fooUri = convertedDirectoryUri('/pkg/foo');
204 Uri barUri = convertedDirectoryUri('/pkg/bar'); 211 Uri barUri = convertedDirectoryUri('/pkg/bar');
205 createFile( 212 createFile(
206 packageFilePath, 213 packageFilePath,
207 ''' 214 '''
208 foo:$fooUri 215 foo:$fooUri
209 bar:$barUri 216 bar:$barUri
210 '''); 217 ''');
211 218
212 builder.defaultPackageFilePath = packageFilePath; 219 builderOptions.defaultPackageFilePath = packageFilePath;
213 Packages packages = builder.createPackageMap(projectPath); 220 Packages packages = builder.createPackageMap(projectPath);
214 expect(packages, isNotNull); 221 expect(packages, isNotNull);
215 Map<String, Uri> map = packages.asMap(); 222 Map<String, Uri> map = packages.asMap();
216 expect(map, hasLength(2)); 223 expect(map, hasLength(2));
217 expect(map['foo'], fooUri); 224 expect(map['foo'], fooUri);
218 expect(map['bar'], barUri); 225 expect(map['bar'], barUri);
219 } 226 }
220 227
221 void test_createPackageMap_fromPackageFile_inParentOfRoot() { 228 void test_createPackageMap_fromPackageFile_inParentOfRoot() {
222 // Use a package file that is inside the parent of the project directory. 229 // Use a package file that is inside the parent of the project directory.
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 pathContext.join(defaultSdkPath, 'lib', 'core', 'core.dart')); 410 pathContext.join(defaultSdkPath, 'lib', 'core', 'core.dart'));
404 411
405 Source packageSource = factory.forUri('package:a/a.dart'); 412 Source packageSource = factory.forUri('package:a/a.dart');
406 expect(packageSource, isNotNull); 413 expect(packageSource, isNotNull);
407 expect(packageSource.fullName, pathContext.join(packageA, 'a.dart')); 414 expect(packageSource.fullName, pathContext.join(packageA, 'a.dart'));
408 } 415 }
409 416
410 void test_declareVariables_emptyMap() { 417 void test_declareVariables_emptyMap() {
411 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); 418 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
412 Iterable<String> expected = context.declaredVariables.variableNames; 419 Iterable<String> expected = context.declaredVariables.variableNames;
413 builder.declaredVariables = <String, String>{}; 420 builderOptions.declaredVariables = <String, String>{};
414 421
415 builder.declareVariables(context); 422 builder.declareVariables(context);
416 expect(context.declaredVariables.variableNames, unorderedEquals(expected)); 423 expect(context.declaredVariables.variableNames, unorderedEquals(expected));
417 } 424 }
418 425
419 void test_declareVariables_nonEmptyMap() { 426 void test_declareVariables_nonEmptyMap() {
420 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); 427 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
421 List<String> expected = context.declaredVariables.variableNames.toList(); 428 List<String> expected = context.declaredVariables.variableNames.toList();
422 expect(expected, isNot(contains('a'))); 429 expect(expected, isNot(contains('a')));
423 expect(expected, isNot(contains('b'))); 430 expect(expected, isNot(contains('b')));
424 expected.addAll(['a', 'b']); 431 expected.addAll(['a', 'b']);
425 builder.declaredVariables = <String, String>{'a': 'a', 'b': 'b'}; 432 builderOptions.declaredVariables = <String, String>{'a': 'a', 'b': 'b'};
426 433
427 builder.declareVariables(context); 434 builder.declareVariables(context);
428 expect(context.declaredVariables.variableNames, unorderedEquals(expected)); 435 expect(context.declaredVariables.variableNames, unorderedEquals(expected));
429 } 436 }
430 437
431 void test_declareVariables_null() { 438 void test_declareVariables_null() {
432 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); 439 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
433 Iterable<String> expected = context.declaredVariables.variableNames; 440 Iterable<String> expected = context.declaredVariables.variableNames;
434 441
435 builder.declareVariables(context); 442 builder.declareVariables(context);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 expect( 491 expect(
485 htmlSource.fullName, 492 htmlSource.fullName,
486 resourceProvider 493 resourceProvider
487 .convertPath('/sdk/lib/html/dart2js/html_dart2js.dart')); 494 .convertPath('/sdk/lib/html/dart2js/html_dart2js.dart'));
488 expect(htmlSource.exists(), isTrue); 495 expect(htmlSource.exists(), isTrue);
489 } 496 }
490 497
491 void test_getAnalysisOptions_default_noOverrides() { 498 void test_getAnalysisOptions_default_noOverrides() {
492 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); 499 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl();
493 defaultOptions.enableGenericMethods = true; 500 defaultOptions.enableGenericMethods = true;
494 builder.defaultOptions = defaultOptions; 501 builderOptions.defaultOptions = defaultOptions;
495 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); 502 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
496 expected.enableGenericMethods = true; 503 expected.enableGenericMethods = true;
497 String path = resourceProvider.convertPath('/some/directory/path'); 504 String path = resourceProvider.convertPath('/some/directory/path');
498 String filePath = 505 String filePath =
499 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); 506 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
500 resourceProvider.newFile( 507 resourceProvider.newFile(
501 filePath, 508 filePath,
502 ''' 509 '''
503 linter: 510 linter:
504 rules: 511 rules:
505 - empty_constructor_bodies 512 - empty_constructor_bodies
506 '''); 513 ''');
507 514
508 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); 515 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
509 AnalysisOptions options = builder.getAnalysisOptions(context, path); 516 AnalysisOptions options = builder.getAnalysisOptions(context, path);
510 _expectEqualOptions(options, expected); 517 _expectEqualOptions(options, expected);
511 } 518 }
512 519
513 void test_getAnalysisOptions_default_overrides() { 520 void test_getAnalysisOptions_default_overrides() {
514 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); 521 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl();
515 defaultOptions.enableGenericMethods = true; 522 defaultOptions.enableGenericMethods = true;
516 builder.defaultOptions = defaultOptions; 523 builderOptions.defaultOptions = defaultOptions;
517 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); 524 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
518 expected.enableSuperMixins = true; 525 expected.enableSuperMixins = true;
519 expected.enableGenericMethods = true; 526 expected.enableGenericMethods = true;
520 String path = resourceProvider.convertPath('/some/directory/path'); 527 String path = resourceProvider.convertPath('/some/directory/path');
521 String filePath = 528 String filePath =
522 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); 529 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
523 resourceProvider.newFile( 530 resourceProvider.newFile(
524 filePath, 531 filePath,
525 ''' 532 '''
526 analyzer: 533 analyzer:
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); 611 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
605 AnalysisOptions options = builder.getAnalysisOptions(context, path); 612 AnalysisOptions options = builder.getAnalysisOptions(context, path);
606 _expectEqualOptions(options, expected); 613 _expectEqualOptions(options, expected);
607 } 614 }
608 615
609 void test_getOptionsFile_explicit() { 616 void test_getOptionsFile_explicit() {
610 String path = resourceProvider.convertPath('/some/directory/path'); 617 String path = resourceProvider.convertPath('/some/directory/path');
611 String filePath = resourceProvider.convertPath('/options/analysis.yaml'); 618 String filePath = resourceProvider.convertPath('/options/analysis.yaml');
612 resourceProvider.newFile(filePath, ''); 619 resourceProvider.newFile(filePath, '');
613 620
614 builder.defaultAnalysisOptionsFilePath = filePath; 621 builderOptions.defaultAnalysisOptionsFilePath = filePath;
615 File result = builder.getOptionsFile(path); 622 File result = builder.getOptionsFile(path);
616 expect(result, isNotNull); 623 expect(result, isNotNull);
617 expect(result.path, filePath); 624 expect(result.path, filePath);
618 } 625 }
619 626
620 void test_getOptionsFile_inParentOfRoot_new() { 627 void test_getOptionsFile_inParentOfRoot_new() {
621 String parentPath = resourceProvider.convertPath('/some/directory'); 628 String parentPath = resourceProvider.convertPath('/some/directory');
622 String path = pathContext.join(parentPath, 'path'); 629 String path = pathContext.join(parentPath, 'path');
623 String filePath = 630 String filePath =
624 pathContext.join(parentPath, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); 631 pathContext.join(parentPath, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 fail('Unexpected invocation of optionsProcessed'); 743 fail('Unexpected invocation of optionsProcessed');
737 } 744 }
738 expect(options, hasLength(expectedOptions.length)); 745 expect(options, hasLength(expectedOptions.length));
739 for (String key in expectedOptions.keys) { 746 for (String key in expectedOptions.keys) {
740 expect(options.containsKey(key), isTrue, reason: 'missing key $key'); 747 expect(options.containsKey(key), isTrue, reason: 'missing key $key');
741 expect(options[key], expectedOptions[key], 748 expect(options[key], expectedOptions[key],
742 reason: 'values for key $key do not match'); 749 reason: 'values for key $key do not match');
743 } 750 }
744 } 751 }
745 } 752 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/context/builder.dart ('k') | pkg/analyzer/test/stress/for_git_repository.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698