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

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

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 4 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library analyzer.test.src.context.context_builder_test;
6
7 import 'package:analyzer/file_system/file_system.dart';
8 import 'package:analyzer/file_system/memory_file_system.dart';
9 import 'package:analyzer/plugin/options.dart';
10 import 'package:analyzer/source/package_map_resolver.dart';
11 import 'package:analyzer/src/context/builder.dart';
12 import 'package:analyzer/src/context/source.dart';
13 import 'package:analyzer/src/generated/engine.dart';
14 import 'package:analyzer/src/generated/sdk.dart';
15 import 'package:analyzer/src/generated/source.dart';
16 import 'package:analyzer/src/plugin/options_plugin.dart';
17 import 'package:package_config/packages.dart';
18 import 'package:package_config/src/packages_impl.dart';
19 import 'package:path/path.dart' as path;
20 import 'package:plugin/src/plugin_impl.dart';
21 import 'package:test_reflective_loader/test_reflective_loader.dart';
22 import 'package:unittest/unittest.dart';
23
24 import '../../embedder_tests.dart';
25 import '../../generated/test_support.dart';
26 import '../../utils.dart';
27 import 'mock_sdk.dart';
28
29 main() {
30 initializeTestEnvironment();
31 defineReflectiveTests(ContextBuilderTest);
32 defineReflectiveTests(EmbedderYamlLocatorTest);
33 }
34
35 @reflectiveTest
36 class ContextBuilderTest extends EngineTestCase {
37 /**
38 * The resource provider to be used by tests.
39 */
40 MemoryResourceProvider resourceProvider;
41
42 /**
43 * The path context used to manipulate file paths.
44 */
45 path.Context pathContext;
46
47 /**
48 * The SDK manager used by the tests;
49 */
50 DartSdkManager sdkManager;
51
52 /**
53 * The content cache used by the tests.
54 */
55 ContentCache contentCache;
56
57 /**
58 * The context builder to be used in the test.
59 */
60 ContextBuilder builder;
61
62 /**
63 * The path to the default SDK, or `null` if the test has not explicitly
64 * invoked [createDefaultSdk].
65 */
66 String defaultSdkPath = null;
67
68 void createDefaultSdk(Folder sdkDir) {
69 defaultSdkPath = pathContext.join(sdkDir.path, 'default', 'sdk');
70 String librariesFilePath = pathContext.join(defaultSdkPath, 'lib',
71 '_internal', 'sdk_library_metadata', 'lib', 'libraries.dart');
72 resourceProvider.newFile(
73 librariesFilePath,
74 r'''
75 const Map<String, LibraryInfo> libraries = const {
76 "async": const LibraryInfo("async/async.dart"),
77 "core": const LibraryInfo("core/core.dart"),
78 };
79 ''');
80 sdkManager =
81 new DartSdkManager(defaultSdkPath, false, (_) => new MockSdk());
82 builder = new ContextBuilder(resourceProvider, sdkManager, contentCache);
83 }
84
85 void createFile(String path, String content) {
86 resourceProvider.newFile(path, content);
87 }
88
89 @override
90 void setUp() {
91 resourceProvider = new MemoryResourceProvider();
92 pathContext = resourceProvider.pathContext;
93 new MockSdk(resourceProvider: resourceProvider);
94 sdkManager = new DartSdkManager('/', false, (_) {
95 fail('Should not be used to create an SDK');
96 });
97 contentCache = new ContentCache();
98 builder = new ContextBuilder(resourceProvider, sdkManager, contentCache);
99 }
100
101 @failingTest
102 void test_buildContext() {
103 fail('Incomplete test');
104 }
105
106 void test_convertPackagesToMap_noPackages() {
107 expect(builder.convertPackagesToMap(Packages.noPackages), isEmpty);
108 }
109
110 void test_convertPackagesToMap_null() {
111 expect(builder.convertPackagesToMap(null), isEmpty);
112 }
113
114 void test_convertPackagesToMap_packages() {
115 String fooName = 'foo';
116 String fooPath = '/pkg/foo';
117 Uri fooUri = new Uri.directory(fooPath);
118 String barName = 'bar';
119 String barPath = '/pkg/bar';
120 Uri barUri = new Uri.directory(barPath);
121
122 MapPackages packages = new MapPackages({fooName: fooUri, barName: barUri});
123 Map<String, List<Folder>> result = builder.convertPackagesToMap(packages);
124 expect(result, isNotNull);
125 expect(result, hasLength(2));
126 expect(result[fooName], hasLength(1));
127 expect(result[fooName][0].path, fooPath);
128 expect(result[barName], hasLength(1));
129 expect(result[barName][0].path, barPath);
130 }
131
132 void test_createDefaultOptions_default() {
133 // Invert a subset of the options to ensure that the default options are
134 // being returned.
135 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl();
136 defaultOptions.dart2jsHint = !defaultOptions.dart2jsHint;
137 defaultOptions.enableAssertMessage = !defaultOptions.enableAssertMessage;
138 defaultOptions.enableGenericMethods = !defaultOptions.enableGenericMethods;
139 defaultOptions.enableStrictCallChecks =
140 !defaultOptions.enableStrictCallChecks;
141 defaultOptions.enableSuperMixins = !defaultOptions.enableSuperMixins;
142 builder.defaultOptions = defaultOptions;
143 AnalysisOptions options = builder.createDefaultOptions();
144 _expectEqualOptions(options, defaultOptions);
145 }
146
147 void test_createDefaultOptions_noDefault() {
148 AnalysisOptions options = builder.createDefaultOptions();
149 _expectEqualOptions(options, new AnalysisOptionsImpl());
150 }
151
152 void test_createPackageMap_fromPackageDirectory_explicit() {
153 // Use a package directory that is outside the project directory.
154 String rootPath = '/root';
155 String projectPath = pathContext.join(rootPath, 'project');
156 String packageDirPath = pathContext.join(rootPath, 'packages');
157 String fooName = 'foo';
158 String fooPath = pathContext.join(packageDirPath, fooName);
159 String barName = 'bar';
160 String barPath = pathContext.join(packageDirPath, barName);
161 resourceProvider.newFolder(projectPath);
162 resourceProvider.newFolder(fooPath);
163 resourceProvider.newFolder(barPath);
164
165 builder.defaultPackagesDirectoryPath = packageDirPath;
166
167 Packages packages = builder.createPackageMap(projectPath);
168 expect(packages, isNotNull);
169 Map<String, Uri> map = packages.asMap();
170 expect(map, hasLength(2));
171 expect(map[fooName], new Uri.directory(fooPath));
172 expect(map[barName], new Uri.directory(barPath));
173 }
174
175 void test_createPackageMap_fromPackageDirectory_inRoot() {
176 // Use a package directory that is inside the project directory.
177 String projectPath = '/root/project';
178 String packageDirPath = pathContext.join(projectPath, 'packages');
179 String fooName = 'foo';
180 String fooPath = pathContext.join(packageDirPath, fooName);
181 String barName = 'bar';
182 String barPath = pathContext.join(packageDirPath, barName);
183 resourceProvider.newFolder(fooPath);
184 resourceProvider.newFolder(barPath);
185
186 Packages packages = builder.createPackageMap(projectPath);
187 expect(packages, isNotNull);
188 Map<String, Uri> map = packages.asMap();
189 expect(map, hasLength(2));
190 expect(map[fooName], new Uri.directory(fooPath));
191 expect(map[barName], new Uri.directory(barPath));
192 }
193
194 void test_createPackageMap_fromPackageFile_explicit() {
195 // Use a package file that is outside the project directory's hierarchy.
196 String rootPath = '/root';
197 String projectPath = pathContext.join(rootPath, 'project');
198 String packageFilePath = pathContext.join(rootPath, 'child', '.packages');
199 resourceProvider.newFolder(projectPath);
200 createFile(
201 packageFilePath,
202 r'''
203 foo:/pkg/foo
204 bar:/pkg/bar
205 ''');
206
207 builder.defaultPackageFilePath = packageFilePath;
208 Packages packages = builder.createPackageMap(projectPath);
209 expect(packages, isNotNull);
210 Map<String, Uri> map = packages.asMap();
211 expect(map, hasLength(2));
212 expect(map['foo'], new Uri.directory('/pkg/foo'));
213 expect(map['bar'], new Uri.directory('/pkg/bar'));
214 }
215
216 void test_createPackageMap_fromPackageFile_inParentOfRoot() {
217 // Use a package file that is inside the parent of the project directory.
218 String rootPath = '/root';
219 String projectPath = pathContext.join(rootPath, 'project');
220 String packageFilePath = pathContext.join(rootPath, '.packages');
221 resourceProvider.newFolder(projectPath);
222 createFile(
223 packageFilePath,
224 r'''
225 foo:/pkg/foo
226 bar:/pkg/bar
227 ''');
228
229 Packages packages = builder.createPackageMap(projectPath);
230 expect(packages, isNotNull);
231 Map<String, Uri> map = packages.asMap();
232 expect(map, hasLength(2));
233 expect(map['foo'], new Uri.directory('/pkg/foo'));
234 expect(map['bar'], new Uri.directory('/pkg/bar'));
235 }
236
237 void test_createPackageMap_fromPackageFile_inRoot() {
238 // Use a package file that is inside the project directory.
239 String rootPath = '/root';
240 String projectPath = pathContext.join(rootPath, 'project');
241 String packageFilePath = pathContext.join(projectPath, '.packages');
242 resourceProvider.newFolder(projectPath);
243 createFile(
244 packageFilePath,
245 r'''
246 foo:/pkg/foo
247 bar:/pkg/bar
248 ''');
249
250 Packages packages = builder.createPackageMap(projectPath);
251 expect(packages, isNotNull);
252 Map<String, Uri> map = packages.asMap();
253 expect(map, hasLength(2));
254 expect(map['foo'], new Uri.directory('/pkg/foo'));
255 expect(map['bar'], new Uri.directory('/pkg/bar'));
256 }
257
258 void test_createPackageMap_none() {
259 String rootPath = '/root';
260 Packages packages = builder.createPackageMap(rootPath);
261 expect(packages, same(Packages.noPackages));
262 }
263
264 void test_createSourceFactory_fileProvider() {
265 String rootPath = '/root';
266 Folder rootFolder = resourceProvider.getFolder(rootPath);
267 createDefaultSdk(rootFolder);
268 String projectPath = pathContext.join(rootPath, 'project');
269 String packageFilePath = pathContext.join(projectPath, '.packages');
270 String packageA = pathContext.join(rootPath, 'pkgs', 'a');
271 String packageB = pathContext.join(rootPath, 'pkgs', 'b');
272 createFile(
273 packageFilePath,
274 '''
275 a:${pathContext.toUri(packageA)}
276 b:${pathContext.toUri(packageB)}
277 ''');
278 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
279 UriResolver resolver = new ResourceUriResolver(resourceProvider);
280 builder.fileResolverProvider = (folder) => resolver;
281 SourceFactoryImpl factory =
282 builder.createSourceFactory(projectPath, options);
283 expect(factory.resolvers, contains(same(resolver)));
284 }
285
286 void test_createSourceFactory_noProvider_packages_embedder_extensions() {
287 String rootPath = '/root';
288 Folder rootFolder = resourceProvider.getFolder(rootPath);
289 createDefaultSdk(rootFolder);
290 String projectPath = pathContext.join(rootPath, 'project');
291 String packageFilePath = pathContext.join(projectPath, '.packages');
292 String packageA = pathContext.join(rootPath, 'pkgs', 'a');
293 String embedderPath = pathContext.join(packageA, '_embedder.yaml');
294 String packageB = pathContext.join(rootPath, 'pkgs', 'b');
295 String extensionPath = pathContext.join(packageB, '_sdkext');
296 createFile(
297 packageFilePath,
298 '''
299 a:${pathContext.toUri(packageA)}
300 b:${pathContext.toUri(packageB)}
301 ''');
302 String asyncPath = pathContext.join(packageA, 'sdk', 'async.dart');
303 String corePath = pathContext.join(packageA, 'sdk', 'core.dart');
304 createFile(
305 embedderPath,
306 '''
307 embedded_libs:
308 "dart:async": ${_relativeUri(asyncPath, from: packageA)}
309 "dart:core": ${_relativeUri(corePath, from: packageA)}
310 ''');
311 String fooPath = pathContext.join(packageB, 'ext', 'foo.dart');
312 createFile(
313 extensionPath,
314 '''{
315 "dart:foo": "${_relativeUri(fooPath, from: packageB)}"
316 }''');
317 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
318
319 SourceFactory factory = builder.createSourceFactory(projectPath, options);
320
321 Source asyncSource = factory.forUri('dart:async');
322 expect(asyncSource, isNotNull);
323 expect(asyncSource.fullName, asyncPath);
324
325 Source fooSource = factory.forUri('dart:foo');
326 expect(fooSource, isNotNull);
327 expect(fooSource.fullName, fooPath);
328
329 Source packageSource = factory.forUri('package:b/b.dart');
330 expect(packageSource, isNotNull);
331 expect(packageSource.fullName, pathContext.join(packageB, 'b.dart'));
332 }
333
334 void test_createSourceFactory_noProvider_packages_embedder_noExtensions() {
335 String rootPath = '/root';
336 Folder rootFolder = resourceProvider.getFolder(rootPath);
337 createDefaultSdk(rootFolder);
338 String projectPath = pathContext.join(rootPath, 'project');
339 String packageFilePath = pathContext.join(projectPath, '.packages');
340 String packageA = pathContext.join(rootPath, 'pkgs', 'a');
341 String embedderPath = pathContext.join(packageA, '_embedder.yaml');
342 String packageB = pathContext.join(rootPath, 'pkgs', 'b');
343 createFile(
344 packageFilePath,
345 '''
346 a:${pathContext.toUri(packageA)}
347 b:${pathContext.toUri(packageB)}
348 ''');
349 String asyncPath = pathContext.join(packageA, 'sdk', 'async.dart');
350 String corePath = pathContext.join(packageA, 'sdk', 'core.dart');
351 createFile(
352 embedderPath,
353 '''
354 embedded_libs:
355 "dart:async": ${_relativeUri(asyncPath, from: packageA)}
356 "dart:core": ${_relativeUri(corePath, from: packageA)}
357 ''');
358 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
359
360 SourceFactory factory = builder.createSourceFactory(projectPath, options);
361
362 Source dartSource = factory.forUri('dart:async');
363 expect(dartSource, isNotNull);
364 expect(dartSource.fullName, asyncPath);
365
366 Source packageSource = factory.forUri('package:b/b.dart');
367 expect(packageSource, isNotNull);
368 expect(packageSource.fullName, pathContext.join(packageB, 'b.dart'));
369 }
370
371 @failingTest
372 void test_createSourceFactory_noProvider_packages_noEmbedder_extensions() {
373 fail('Incomplete test');
374 }
375
376 void test_createSourceFactory_noProvider_packages_noEmbedder_noExtensions() {
377 String rootPath = '/root';
378 Folder rootFolder = resourceProvider.getFolder(rootPath);
379 createDefaultSdk(rootFolder);
380 String projectPath = pathContext.join(rootPath, 'project');
381 String packageFilePath = pathContext.join(projectPath, '.packages');
382 String packageA = pathContext.join(rootPath, 'pkgs', 'a');
383 String packageB = pathContext.join(rootPath, 'pkgs', 'b');
384 createFile(
385 packageFilePath,
386 '''
387 a:${pathContext.toUri(packageA)}
388 b:${pathContext.toUri(packageB)}
389 ''');
390 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
391
392 SourceFactory factory = builder.createSourceFactory(projectPath, options);
393
394 Source dartSource = factory.forUri('dart:core');
395 expect(dartSource, isNotNull);
396 expect(dartSource.fullName, '$defaultSdkPath/lib/core/core.dart');
397
398 Source packageSource = factory.forUri('package:a/a.dart');
399 expect(packageSource, isNotNull);
400 expect(packageSource.fullName, pathContext.join(packageA, 'a.dart'));
401 }
402
403 void test_createSourceFactory_packageProvider() {
404 String rootPath = '/root';
405 Folder rootFolder = resourceProvider.getFolder(rootPath);
406 createDefaultSdk(rootFolder);
407 String projectPath = pathContext.join(rootPath, 'project');
408 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
409 UriResolver resolver = new PackageMapUriResolver(resourceProvider, {});
410 builder.packageResolverProvider = (folder) => resolver;
411 SourceFactoryImpl factory =
412 builder.createSourceFactory(projectPath, options);
413 expect(factory.resolvers, contains(same(resolver)));
414 }
415
416 void test_declareVariables_emptyMap() {
417 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
418 Iterable<String> expected = context.declaredVariables.variableNames;
419 builder.declaredVariables = <String, String>{};
420
421 builder.declareVariables(context);
422 expect(context.declaredVariables.variableNames, unorderedEquals(expected));
423 }
424
425 void test_declareVariables_nonEmptyMap() {
426 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
427 List<String> expected = context.declaredVariables.variableNames.toList();
428 expect(expected, isNot(contains('a')));
429 expect(expected, isNot(contains('b')));
430 expected.addAll(['a', 'b']);
431 builder.declaredVariables = <String, String>{'a': 'a', 'b': 'b'};
432
433 builder.declareVariables(context);
434 expect(context.declaredVariables.variableNames, unorderedEquals(expected));
435 }
436
437 void test_declareVariables_null() {
438 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
439 Iterable<String> expected = context.declaredVariables.variableNames;
440
441 builder.declareVariables(context);
442 expect(context.declaredVariables.variableNames, unorderedEquals(expected));
443 }
444
445 @failingTest
446 void test_findSdk_embedder_extensions() {
447 // See test_createSourceFactory_noProvider_packages_embedder_extensions
448 fail('Incomplete test');
449 }
450
451 @failingTest
452 void test_findSdk_embedder_noExtensions() {
453 // See test_createSourceFactory_noProvider_packages_embedder_noExtensions
454 fail('Incomplete test');
455 }
456
457 @failingTest
458 void test_findSdk_noEmbedder_extensions() {
459 // See test_createSourceFactory_noProvider_packages_noEmbedder_extensions
460 fail('Incomplete test');
461 }
462
463 @failingTest
464 void test_findSdk_noEmbedder_noExtensions() {
465 // See test_createSourceFactory_noProvider_packages_noEmbedder_noExtensions
466 fail('Incomplete test');
467 }
468
469 void test_findSdk_noPackageMap() {
470 DartSdk sdk = builder.findSdk(null, new AnalysisOptionsImpl());
471 expect(sdk, isNotNull);
472 }
473
474 void test_getAnalysisOptions_default_noOverrides() {
475 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl();
476 defaultOptions.enableGenericMethods = true;
477 builder.defaultOptions = defaultOptions;
478 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
479 expected.enableGenericMethods = true;
480 String path = '/some/directory/path';
481 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}';
482 resourceProvider.newFile(
483 filePath,
484 '''
485 linter:
486 rules:
487 - empty_constructor_bodies
488 ''');
489
490 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
491 AnalysisOptions options = builder.getAnalysisOptions(context, path);
492 _expectEqualOptions(options, expected);
493 }
494
495 void test_getAnalysisOptions_default_overrides() {
496 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl();
497 defaultOptions.enableGenericMethods = true;
498 builder.defaultOptions = defaultOptions;
499 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
500 expected.enableSuperMixins = true;
501 expected.enableGenericMethods = true;
502 String path = '/some/directory/path';
503 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}';
504 resourceProvider.newFile(
505 filePath,
506 '''
507 analyzer:
508 language:
509 enableSuperMixins : true
510 ''');
511
512 AnalysisEngine engine = AnalysisEngine.instance;
513 OptionsPlugin plugin = engine.optionsPlugin;
514 plugin.registerExtensionPoints((_) {});
515 try {
516 _TestOptionsProcessor processor = new _TestOptionsProcessor();
517 processor.expectedOptions = <String, Object>{
518 'analyzer': {
519 'language': {'enableSuperMixins': true}
520 }
521 };
522 (plugin.optionsProcessorExtensionPoint as ExtensionPointImpl)
523 .add(processor);
524 AnalysisContext context = engine.createAnalysisContext();
525 AnalysisOptions options = builder.getAnalysisOptions(context, path);
526 _expectEqualOptions(options, expected);
527 } finally {
528 plugin.registerExtensionPoints((_) {});
529 }
530 }
531
532 void test_getAnalysisOptions_invalid() {
533 String path = '/some/directory/path';
534 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}';
535 resourceProvider.newFile(filePath, ';');
536
537 AnalysisEngine engine = AnalysisEngine.instance;
538 OptionsPlugin plugin = engine.optionsPlugin;
539 plugin.registerExtensionPoints((_) {});
540 try {
541 _TestOptionsProcessor processor = new _TestOptionsProcessor();
542 (plugin.optionsProcessorExtensionPoint as ExtensionPointImpl)
543 .add(processor);
544 AnalysisContext context = engine.createAnalysisContext();
545 AnalysisOptions options = builder.getAnalysisOptions(context, path);
546 expect(options, isNotNull);
547 expect(processor.errorCount, 1);
548 } finally {
549 plugin.registerExtensionPoints((_) {});
550 }
551 }
552
553 void test_getAnalysisOptions_noDefault_noOverrides() {
554 String path = '/some/directory/path';
555 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}';
556 resourceProvider.newFile(
557 filePath,
558 '''
559 linter:
560 rules:
561 - empty_constructor_bodies
562 ''');
563
564 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
565 AnalysisOptions options = builder.getAnalysisOptions(context, path);
566 _expectEqualOptions(options, new AnalysisOptionsImpl());
567 }
568
569 void test_getAnalysisOptions_noDefault_overrides() {
570 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
571 expected.enableSuperMixins = true;
572 String path = '/some/directory/path';
573 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}';
574 resourceProvider.newFile(
575 filePath,
576 '''
577 analyzer:
578 language:
579 enableSuperMixins : true
580 ''');
581
582 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
583 AnalysisOptions options = builder.getAnalysisOptions(context, path);
584 _expectEqualOptions(options, expected);
585 }
586
587 void test_getOptionsFile_explicit() {
588 String path = '/some/directory/path';
589 String filePath = '/options/analysis.yaml';
590 resourceProvider.newFile(filePath, '');
591
592 builder.defaultAnalysisOptionsFilePath = filePath;
593 File result = builder.getOptionsFile(path);
594 expect(result, isNotNull);
595 expect(result.path, filePath);
596 }
597
598 void test_getOptionsFile_inParentOfRoot_new() {
599 String parentPath = '/some/directory';
600 String path = '$parentPath/path';
601 String filePath =
602 '$parentPath/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}';
603 resourceProvider.newFile(filePath, '');
604
605 File result = builder.getOptionsFile(path);
606 expect(result, isNotNull);
607 expect(result.path, filePath);
608 }
609
610 void test_getOptionsFile_inParentOfRoot_old() {
611 String parentPath = '/some/directory';
612 String path = '$parentPath/path';
613 String filePath = '$parentPath/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}';
614 resourceProvider.newFile(filePath, '');
615
616 File result = builder.getOptionsFile(path);
617 expect(result, isNotNull);
618 expect(result.path, filePath);
619 }
620
621 void test_getOptionsFile_inRoot_new() {
622 String path = '/some/directory/path';
623 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}';
624 resourceProvider.newFile(filePath, '');
625
626 File result = builder.getOptionsFile(path);
627 expect(result, isNotNull);
628 expect(result.path, filePath);
629 }
630
631 void test_getOptionsFile_inRoot_old() {
632 String path = '/some/directory/path';
633 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}';
634 resourceProvider.newFile(filePath, '');
635
636 File result = builder.getOptionsFile(path);
637 expect(result, isNotNull);
638 expect(result.path, filePath);
639 }
640
641 void _expectEqualOptions(
642 AnalysisOptionsImpl actual, AnalysisOptionsImpl expected) {
643 // TODO(brianwilkerson) Consider moving this to AnalysisOptionsImpl.==.
644 expect(actual.analyzeFunctionBodiesPredicate,
645 same(expected.analyzeFunctionBodiesPredicate));
646 expect(actual.cacheSize, expected.cacheSize);
647 expect(actual.dart2jsHint, expected.dart2jsHint);
648 expect(actual.enableAssertMessage, expected.enableAssertMessage);
649 expect(actual.enableStrictCallChecks, expected.enableStrictCallChecks);
650 expect(actual.enableGenericMethods, expected.enableGenericMethods);
651 expect(actual.enableSuperMixins, expected.enableSuperMixins);
652 expect(actual.enableTiming, expected.enableTiming);
653 expect(actual.generateImplicitErrors, expected.generateImplicitErrors);
654 expect(actual.generateSdkErrors, expected.generateSdkErrors);
655 expect(actual.hint, expected.hint);
656 expect(actual.incremental, expected.incremental);
657 expect(actual.incrementalApi, expected.incrementalApi);
658 expect(actual.incrementalValidation, expected.incrementalValidation);
659 expect(actual.lint, expected.lint);
660 expect(actual.preserveComments, expected.preserveComments);
661 expect(actual.strongMode, expected.strongMode);
662 expect(actual.strongModeHints, expected.strongModeHints);
663 expect(actual.implicitCasts, expected.implicitCasts);
664 expect(actual.implicitDynamic, expected.implicitDynamic);
665 expect(actual.trackCacheDependencies, expected.trackCacheDependencies);
666 expect(actual.disableCacheFlushing, expected.disableCacheFlushing);
667 expect(actual.finerGrainedInvalidation, expected.finerGrainedInvalidation);
668 }
669
670 Uri _relativeUri(String path, {String from}) {
671 String relativePath = pathContext.relative(path, from: from);
672 return pathContext.toUri(relativePath);
673 }
674 }
675
676 @reflectiveTest
677 class EmbedderYamlLocatorTest extends EmbedderRelatedTest {
678 void test_empty() {
679 EmbedderYamlLocator locator = new EmbedderYamlLocator({
680 'fox': <Folder>[pathTranslator.getResource(emptyPath)]
681 });
682 expect(locator.embedderYamls, hasLength(0));
683 }
684
685 void test_invalid() {
686 EmbedderYamlLocator locator = new EmbedderYamlLocator(null);
687 locator.addEmbedderYaml(null, r'''{{{,{{}}},}}''');
688 expect(locator.embedderYamls, hasLength(0));
689 }
690
691 void test_valid() {
692 EmbedderYamlLocator locator = new EmbedderYamlLocator({
693 'fox': <Folder>[pathTranslator.getResource(foxLib)]
694 });
695 expect(locator.embedderYamls, hasLength(1));
696 }
697 }
698
699 class _TestOptionsProcessor implements OptionsProcessor {
700 Map<String, Object> expectedOptions = null;
701
702 int errorCount = 0;
703
704 @override
705 void onError(Exception exception) {
706 errorCount++;
707 }
708
709 @override
710 void optionsProcessed(AnalysisContext context, Map<String, Object> options) {
711 if (expectedOptions == null) {
712 fail('Unexpected invocation of optionsProcessed');
713 }
714 expect(options, hasLength(expectedOptions.length));
715 for (String key in expectedOptions.keys) {
716 expect(options.containsKey(key), isTrue, reason: 'missing key $key');
717 expect(options[key], expectedOptions[key],
718 reason: 'values for key $key do not match');
719 }
720 }
721 }
OLDNEW
« no previous file with comments | « packages/analyzer/test/src/context/abstract_context.dart ('k') | packages/analyzer/test/src/context/cache_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698