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

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

Issue 2660173002: implement default analysis options in bazel (Closed)
Patch Set: Created 3 years, 10 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/src/command_line/arguments.dart'; 9 import 'package:analyzer/src/command_line/arguments.dart';
10 import 'package:analyzer/src/context/builder.dart'; 10 import 'package:analyzer/src/context/builder.dart';
11 import 'package:analyzer/src/context/source.dart'; 11 import 'package:analyzer/src/context/source.dart';
12 import 'package:analyzer/src/generated/bazel.dart'; 12 import 'package:analyzer/src/generated/bazel.dart';
13 import 'package:analyzer/src/generated/engine.dart'; 13 import 'package:analyzer/src/generated/engine.dart';
14 import 'package:analyzer/src/generated/sdk.dart'; 14 import 'package:analyzer/src/generated/sdk.dart';
15 import 'package:analyzer/src/generated/source.dart'; 15 import 'package:analyzer/src/generated/source.dart';
16 import 'package:analyzer/src/lint/linter.dart';
17 import 'package:analyzer/src/lint/registry.dart';
18 import 'package:analyzer/src/services/lint.dart';
16 import 'package:args/args.dart'; 19 import 'package:args/args.dart';
17 import 'package:package_config/packages.dart'; 20 import 'package:package_config/packages.dart';
18 import 'package:package_config/src/packages_impl.dart'; 21 import 'package:package_config/src/packages_impl.dart';
19 import 'package:path/path.dart' as path; 22 import 'package:path/path.dart' as path;
20 import 'package:test/test.dart'; 23 import 'package:test/test.dart';
21 import 'package:test_reflective_loader/test_reflective_loader.dart'; 24 import 'package:test_reflective_loader/test_reflective_loader.dart';
22 25
23 import '../../embedder_tests.dart'; 26 import '../../embedder_tests.dart';
24 import '../../generated/test_support.dart'; 27 import '../../generated/test_support.dart';
25 import 'mock_sdk.dart'; 28 import 'mock_sdk.dart';
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 ArgResults argResults = argParser.parse(['--$enableStrictCallChecksFlag']); 121 ArgResults argResults = argParser.parse(['--$enableStrictCallChecksFlag']);
119 var builder = new ContextBuilder(resourceProvider, sdkManager, contentCache, 122 var builder = new ContextBuilder(resourceProvider, sdkManager, contentCache,
120 options: createContextBuilderOptions(argResults)); 123 options: createContextBuilderOptions(argResults));
121 124
122 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); 125 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
123 expected.enableSuperMixins = true; 126 expected.enableSuperMixins = true;
124 expected.enableStrictCallChecks = true; 127 expected.enableStrictCallChecks = true;
125 128
126 String path = resourceProvider.convertPath('/some/directory/path'); 129 String path = resourceProvider.convertPath('/some/directory/path');
127 String filePath = 130 String filePath =
128 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); 131 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
129 resourceProvider.newFile( 132 resourceProvider.newFile(
130 filePath, 133 filePath,
131 ''' 134 '''
132 analyzer: 135 analyzer:
133 language: 136 language:
134 enableSuperMixins : true 137 enableSuperMixins : true
135 enableStrictCallChecks : false 138 enableStrictCallChecks : false
136 '''); 139 ''');
137 140
138 AnalysisOptions options = builder.getAnalysisOptions(path); 141 AnalysisOptions options = builder.getAnalysisOptions(path);
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 builder.findSdk(null, new AnalysisOptionsImpl()..strongMode = true); 517 builder.findSdk(null, new AnalysisOptionsImpl()..strongMode = true);
515 expect(sdk, isNotNull); 518 expect(sdk, isNotNull);
516 Source htmlSource = sdk.mapDartUri('dart:html'); 519 Source htmlSource = sdk.mapDartUri('dart:html');
517 expect( 520 expect(
518 htmlSource.fullName, 521 htmlSource.fullName,
519 resourceProvider 522 resourceProvider
520 .convertPath('/sdk/lib/html/dart2js/html_dart2js.dart')); 523 .convertPath('/sdk/lib/html/dart2js/html_dart2js.dart'));
521 expect(htmlSource.exists(), isTrue); 524 expect(htmlSource.exists(), isTrue);
522 } 525 }
523 526
527 void test_getAnalysisOptions_default_bazel() {
Brian Wilkerson 2017/01/30 14:56:05 Should we have a similar test for Gn?
danrubel 2017/01/30 19:00:44 Good point, but I don't know an appropriate defaul
528 MockLintRule mockLintRule = new MockLintRule('mock_lint_rule');
529 Registry.ruleRegistry.register(mockLintRule);
530 MockLintRule mockLintRule2 = new MockLintRule('mock_lint_rule2');
531 Registry.ruleRegistry.register(mockLintRule2);
532 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl();
533 builderOptions.defaultOptions = defaultOptions;
534 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
535 expected.lint = true;
536 expected.lintRules = <Linter>[mockLintRule];
537 createFile(resourceProvider.convertPath('/root/WORKSPACE'), '');
538 createFile(
539 resourceProvider
540 .convertPath('/root/dart/analysis_options/lib/default.yaml'),
541 '''
542 linter:
543 rules:
544 - mock_lint_rule
545 ''');
546 createFile(
547 resourceProvider
548 .convertPath('/root/dart/analysis_options/lib/flutter.yaml'),
549 '''
550 linter:
551 rules:
552 - mock_lint_rule2
553 ''');
554 AnalysisOptions options = builder
555 .getAnalysisOptions(resourceProvider.convertPath('/root/some/path'));
556 _expectEqualOptions(options, expected);
557 }
558
524 void test_getAnalysisOptions_default_noOverrides() { 559 void test_getAnalysisOptions_default_noOverrides() {
525 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); 560 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl();
526 defaultOptions.enableLazyAssignmentOperators = true; 561 defaultOptions.enableLazyAssignmentOperators = true;
527 builderOptions.defaultOptions = defaultOptions; 562 builderOptions.defaultOptions = defaultOptions;
528 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); 563 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
529 expected.enableLazyAssignmentOperators = true; 564 expected.enableLazyAssignmentOperators = true;
530 String path = resourceProvider.convertPath('/some/directory/path'); 565 String path = resourceProvider.convertPath('/some/directory/path');
531 String filePath = 566 String filePath =
532 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); 567 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
533 resourceProvider.newFile( 568 resourceProvider.newFile(
534 filePath, 569 filePath,
535 ''' 570 '''
536 linter: 571 linter:
537 rules: 572 rules:
538 - empty_constructor_bodies 573 - empty_constructor_bodies
539 '''); 574 ''');
540 575
541 AnalysisOptions options = builder.getAnalysisOptions(path); 576 AnalysisOptions options = builder.getAnalysisOptions(path);
542 _expectEqualOptions(options, expected); 577 _expectEqualOptions(options, expected);
543 } 578 }
544 579
545 void test_getAnalysisOptions_default_overrides() { 580 void test_getAnalysisOptions_default_overrides() {
546 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); 581 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl();
582 defaultOptions.enableSuperMixins = false;
547 defaultOptions.enableLazyAssignmentOperators = true; 583 defaultOptions.enableLazyAssignmentOperators = true;
548 builderOptions.defaultOptions = defaultOptions; 584 builderOptions.defaultOptions = defaultOptions;
549 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); 585 AnalysisOptionsImpl expected = new AnalysisOptionsImpl();
550 expected.enableSuperMixins = true; 586 expected.enableSuperMixins = true;
551 expected.enableLazyAssignmentOperators = true; 587 expected.enableLazyAssignmentOperators = true;
552 String path = resourceProvider.convertPath('/some/directory/path'); 588 String path = resourceProvider.convertPath('/some/directory/path');
553 String filePath = 589 String filePath =
554 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); 590 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE);
555 resourceProvider.newFile( 591 resourceProvider.newFile(
556 filePath, 592 filePath,
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 expect(actual.enableStrictCallChecks, expected.enableStrictCallChecks); 749 expect(actual.enableStrictCallChecks, expected.enableStrictCallChecks);
714 expect(actual.enableSuperMixins, expected.enableSuperMixins); 750 expect(actual.enableSuperMixins, expected.enableSuperMixins);
715 expect(actual.enableTiming, expected.enableTiming); 751 expect(actual.enableTiming, expected.enableTiming);
716 expect(actual.generateImplicitErrors, expected.generateImplicitErrors); 752 expect(actual.generateImplicitErrors, expected.generateImplicitErrors);
717 expect(actual.generateSdkErrors, expected.generateSdkErrors); 753 expect(actual.generateSdkErrors, expected.generateSdkErrors);
718 expect(actual.hint, expected.hint); 754 expect(actual.hint, expected.hint);
719 expect(actual.incremental, expected.incremental); 755 expect(actual.incremental, expected.incremental);
720 expect(actual.incrementalApi, expected.incrementalApi); 756 expect(actual.incrementalApi, expected.incrementalApi);
721 expect(actual.incrementalValidation, expected.incrementalValidation); 757 expect(actual.incrementalValidation, expected.incrementalValidation);
722 expect(actual.lint, expected.lint); 758 expect(actual.lint, expected.lint);
759 expect(
760 actual.lintRules.map((l) => l.name),
761 unorderedEquals(expected.lintRules.map((l) => l.name)),
762 );
723 expect(actual.preserveComments, expected.preserveComments); 763 expect(actual.preserveComments, expected.preserveComments);
724 expect(actual.strongMode, expected.strongMode); 764 expect(actual.strongMode, expected.strongMode);
725 expect(actual.strongModeHints, expected.strongModeHints); 765 expect(actual.strongModeHints, expected.strongModeHints);
726 expect(actual.implicitCasts, expected.implicitCasts); 766 expect(actual.implicitCasts, expected.implicitCasts);
727 expect(actual.implicitDynamic, expected.implicitDynamic); 767 expect(actual.implicitDynamic, expected.implicitDynamic);
728 expect(actual.trackCacheDependencies, expected.trackCacheDependencies); 768 expect(actual.trackCacheDependencies, expected.trackCacheDependencies);
729 expect(actual.disableCacheFlushing, expected.disableCacheFlushing); 769 expect(actual.disableCacheFlushing, expected.disableCacheFlushing);
730 expect(actual.finerGrainedInvalidation, expected.finerGrainedInvalidation); 770 expect(actual.finerGrainedInvalidation, expected.finerGrainedInvalidation);
731 } 771 }
732 772
(...skipping 18 matching lines...) Expand all
751 expect(locator.embedderYamls, hasLength(0)); 791 expect(locator.embedderYamls, hasLength(0));
752 } 792 }
753 793
754 void test_valid() { 794 void test_valid() {
755 EmbedderYamlLocator locator = new EmbedderYamlLocator({ 795 EmbedderYamlLocator locator = new EmbedderYamlLocator({
756 'fox': <Folder>[pathTranslator.getResource(foxLib)] 796 'fox': <Folder>[pathTranslator.getResource(foxLib)]
757 }); 797 });
758 expect(locator.embedderYamls, hasLength(1)); 798 expect(locator.embedderYamls, hasLength(1));
759 } 799 }
760 } 800 }
801
802 class MockLintRule implements LintRule {
803 final String _name;
804
805 MockLintRule(this._name);
806
807 @override
808 String get name => _name;
809
810 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
811 }
OLDNEW
« pkg/analyzer/lib/src/context/builder.dart ('K') | « pkg/analyzer/lib/src/generated/workspace.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698