| OLD | NEW |
| 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 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 builder.findSdk(null, new AnalysisOptionsImpl()..strongMode = true); | 523 builder.findSdk(null, new AnalysisOptionsImpl()..strongMode = true); |
| 521 expect(sdk, isNotNull); | 524 expect(sdk, isNotNull); |
| 522 Source htmlSource = sdk.mapDartUri('dart:html'); | 525 Source htmlSource = sdk.mapDartUri('dart:html'); |
| 523 expect( | 526 expect( |
| 524 htmlSource.fullName, | 527 htmlSource.fullName, |
| 525 resourceProvider | 528 resourceProvider |
| 526 .convertPath('/sdk/lib/html/dart2js/html_dart2js.dart')); | 529 .convertPath('/sdk/lib/html/dart2js/html_dart2js.dart')); |
| 527 expect(htmlSource.exists(), isTrue); | 530 expect(htmlSource.exists(), isTrue); |
| 528 } | 531 } |
| 529 | 532 |
| 533 void test_getAnalysisOptions_default_bazel() { |
| 534 MockLintRule mockLintRule = new MockLintRule('mock_lint_rule'); |
| 535 Registry.ruleRegistry.register(mockLintRule); |
| 536 MockLintRule mockLintRule2 = new MockLintRule('mock_lint_rule2'); |
| 537 Registry.ruleRegistry.register(mockLintRule2); |
| 538 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); |
| 539 builderOptions.defaultOptions = defaultOptions; |
| 540 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); |
| 541 expected.lint = true; |
| 542 expected.lintRules = <Linter>[mockLintRule]; |
| 543 createFile(resourceProvider.convertPath('/root/WORKSPACE'), ''); |
| 544 createFile( |
| 545 resourceProvider |
| 546 .convertPath('/root/dart/analysis_options/lib/default.yaml'), |
| 547 ''' |
| 548 linter: |
| 549 rules: |
| 550 - mock_lint_rule |
| 551 '''); |
| 552 createFile( |
| 553 resourceProvider |
| 554 .convertPath('/root/dart/analysis_options/lib/flutter.yaml'), |
| 555 ''' |
| 556 linter: |
| 557 rules: |
| 558 - mock_lint_rule2 |
| 559 '''); |
| 560 AnalysisOptions options = builder |
| 561 .getAnalysisOptions(resourceProvider.convertPath('/root/some/path')); |
| 562 _expectEqualOptions(options, expected); |
| 563 } |
| 564 |
| 530 void test_getAnalysisOptions_default_noOverrides() { | 565 void test_getAnalysisOptions_default_noOverrides() { |
| 531 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); | 566 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); |
| 532 defaultOptions.enableLazyAssignmentOperators = true; | 567 defaultOptions.enableLazyAssignmentOperators = true; |
| 533 builderOptions.defaultOptions = defaultOptions; | 568 builderOptions.defaultOptions = defaultOptions; |
| 534 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); | 569 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); |
| 535 expected.enableLazyAssignmentOperators = true; | 570 expected.enableLazyAssignmentOperators = true; |
| 536 String path = resourceProvider.convertPath('/some/directory/path'); | 571 String path = resourceProvider.convertPath('/some/directory/path'); |
| 537 String filePath = | 572 String filePath = |
| 538 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); | 573 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); |
| 539 resourceProvider.newFile( | 574 resourceProvider.newFile( |
| 540 filePath, | 575 filePath, |
| 541 ''' | 576 ''' |
| 542 linter: | 577 linter: |
| 543 rules: | 578 rules: |
| 544 - empty_constructor_bodies | 579 - empty_constructor_bodies |
| 545 '''); | 580 '''); |
| 546 | 581 |
| 547 AnalysisOptions options = builder.getAnalysisOptions(path); | 582 AnalysisOptions options = builder.getAnalysisOptions(path); |
| 548 _expectEqualOptions(options, expected); | 583 _expectEqualOptions(options, expected); |
| 549 } | 584 } |
| 550 | 585 |
| 551 void test_getAnalysisOptions_default_overrides() { | 586 void test_getAnalysisOptions_default_overrides() { |
| 552 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); | 587 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); |
| 588 defaultOptions.enableSuperMixins = false; |
| 553 defaultOptions.enableLazyAssignmentOperators = true; | 589 defaultOptions.enableLazyAssignmentOperators = true; |
| 554 builderOptions.defaultOptions = defaultOptions; | 590 builderOptions.defaultOptions = defaultOptions; |
| 555 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); | 591 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); |
| 556 expected.enableSuperMixins = true; | 592 expected.enableSuperMixins = true; |
| 557 expected.enableLazyAssignmentOperators = true; | 593 expected.enableLazyAssignmentOperators = true; |
| 558 String path = resourceProvider.convertPath('/some/directory/path'); | 594 String path = resourceProvider.convertPath('/some/directory/path'); |
| 559 String filePath = | 595 String filePath = |
| 560 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); | 596 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); |
| 561 resourceProvider.newFile( | 597 resourceProvider.newFile( |
| 562 filePath, | 598 filePath, |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 expect(actual.enableStrictCallChecks, expected.enableStrictCallChecks); | 755 expect(actual.enableStrictCallChecks, expected.enableStrictCallChecks); |
| 720 expect(actual.enableSuperMixins, expected.enableSuperMixins); | 756 expect(actual.enableSuperMixins, expected.enableSuperMixins); |
| 721 expect(actual.enableTiming, expected.enableTiming); | 757 expect(actual.enableTiming, expected.enableTiming); |
| 722 expect(actual.generateImplicitErrors, expected.generateImplicitErrors); | 758 expect(actual.generateImplicitErrors, expected.generateImplicitErrors); |
| 723 expect(actual.generateSdkErrors, expected.generateSdkErrors); | 759 expect(actual.generateSdkErrors, expected.generateSdkErrors); |
| 724 expect(actual.hint, expected.hint); | 760 expect(actual.hint, expected.hint); |
| 725 expect(actual.incremental, expected.incremental); | 761 expect(actual.incremental, expected.incremental); |
| 726 expect(actual.incrementalApi, expected.incrementalApi); | 762 expect(actual.incrementalApi, expected.incrementalApi); |
| 727 expect(actual.incrementalValidation, expected.incrementalValidation); | 763 expect(actual.incrementalValidation, expected.incrementalValidation); |
| 728 expect(actual.lint, expected.lint); | 764 expect(actual.lint, expected.lint); |
| 765 expect( |
| 766 actual.lintRules.map((l) => l.name), |
| 767 unorderedEquals(expected.lintRules.map((l) => l.name)), |
| 768 ); |
| 729 expect(actual.preserveComments, expected.preserveComments); | 769 expect(actual.preserveComments, expected.preserveComments); |
| 730 expect(actual.strongMode, expected.strongMode); | 770 expect(actual.strongMode, expected.strongMode); |
| 731 expect(actual.strongModeHints, expected.strongModeHints); | 771 expect(actual.strongModeHints, expected.strongModeHints); |
| 732 expect(actual.implicitCasts, expected.implicitCasts); | 772 expect(actual.implicitCasts, expected.implicitCasts); |
| 733 expect(actual.implicitDynamic, expected.implicitDynamic); | 773 expect(actual.implicitDynamic, expected.implicitDynamic); |
| 734 expect(actual.trackCacheDependencies, expected.trackCacheDependencies); | 774 expect(actual.trackCacheDependencies, expected.trackCacheDependencies); |
| 735 expect(actual.disableCacheFlushing, expected.disableCacheFlushing); | 775 expect(actual.disableCacheFlushing, expected.disableCacheFlushing); |
| 736 expect(actual.finerGrainedInvalidation, expected.finerGrainedInvalidation); | 776 expect(actual.finerGrainedInvalidation, expected.finerGrainedInvalidation); |
| 737 } | 777 } |
| 738 | 778 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 757 expect(locator.embedderYamls, hasLength(0)); | 797 expect(locator.embedderYamls, hasLength(0)); |
| 758 } | 798 } |
| 759 | 799 |
| 760 void test_valid() { | 800 void test_valid() { |
| 761 EmbedderYamlLocator locator = new EmbedderYamlLocator({ | 801 EmbedderYamlLocator locator = new EmbedderYamlLocator({ |
| 762 'fox': <Folder>[pathTranslator.getResource(foxLib)] | 802 'fox': <Folder>[pathTranslator.getResource(foxLib)] |
| 763 }); | 803 }); |
| 764 expect(locator.embedderYamls, hasLength(1)); | 804 expect(locator.embedderYamls, hasLength(1)); |
| 765 } | 805 } |
| 766 } | 806 } |
| 807 |
| 808 class MockLintRule implements LintRule { |
| 809 final String _name; |
| 810 |
| 811 MockLintRule(this._name); |
| 812 |
| 813 @override |
| 814 String get name => _name; |
| 815 |
| 816 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 817 } |
| OLD | NEW |