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/context/context_root.dart'; | 7 import 'package:analyzer/context/context_root.dart'; |
8 import 'package:analyzer/file_system/file_system.dart'; | 8 import 'package:analyzer/file_system/file_system.dart'; |
9 import 'package:analyzer/file_system/memory_file_system.dart'; | 9 import 'package:analyzer/file_system/memory_file_system.dart'; |
10 import 'package:analyzer/source/package_map_resolver.dart'; | 10 import 'package:analyzer/source/package_map_resolver.dart'; |
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 ''' | 808 ''' |
809 analyzer: | 809 analyzer: |
810 language: | 810 language: |
811 enableSuperMixins : true | 811 enableSuperMixins : true |
812 '''); | 812 '''); |
813 | 813 |
814 AnalysisOptions options = builder.getAnalysisOptions(path); | 814 AnalysisOptions options = builder.getAnalysisOptions(path); |
815 _expectEqualOptions(options, expected); | 815 _expectEqualOptions(options, expected); |
816 } | 816 } |
817 | 817 |
| 818 void test_getAnalysisOptions_gnWorkspace() { |
| 819 String _p(String path) => resourceProvider.convertPath(path); |
| 820 String projectPath = _p('/workspace/some/path'); |
| 821 resourceProvider.newFolder(_p('/workspace/.jiri_root')); |
| 822 resourceProvider.newFile( |
| 823 _p('/workspace/out/debug/gen/dart.sources/foo_pkg'), |
| 824 _p('/workspace/foo_pkg/lib')); |
| 825 resourceProvider.newFolder(projectPath); |
| 826 ArgParser argParser = new ArgParser(); |
| 827 defineAnalysisArguments(argParser); |
| 828 ArgResults argResults = argParser.parse([]); |
| 829 builderOptions = createContextBuilderOptions(argResults); |
| 830 expect(builderOptions.packageDefaultAnalysisOptions, isTrue); |
| 831 builder = new ContextBuilder(resourceProvider, sdkManager, contentCache, |
| 832 options: builderOptions); |
| 833 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); |
| 834 AnalysisOptions options = builder.getAnalysisOptions(projectPath); |
| 835 _expectEqualOptions(options, expected); |
| 836 } |
| 837 |
818 void test_getAnalysisOptions_includes() { | 838 void test_getAnalysisOptions_includes() { |
819 _defineMockLintRules(); | 839 _defineMockLintRules(); |
820 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); | 840 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); |
821 defaultOptions.enableSuperMixins = false; | 841 defaultOptions.enableSuperMixins = false; |
822 builderOptions.defaultOptions = defaultOptions; | 842 builderOptions.defaultOptions = defaultOptions; |
823 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); | 843 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); |
824 expected.enableSuperMixins = true; | 844 expected.enableSuperMixins = true; |
825 expected.lint = true; | 845 expected.lint = true; |
826 expected.lintRules = <Linter>[ | 846 expected.lintRules = <Linter>[ |
827 _mockLintRule, | 847 _mockLintRule, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 ''' | 906 ''' |
887 linter: | 907 linter: |
888 rules: | 908 rules: |
889 - empty_constructor_bodies | 909 - empty_constructor_bodies |
890 '''); | 910 '''); |
891 | 911 |
892 AnalysisOptions options = builder.getAnalysisOptions(path); | 912 AnalysisOptions options = builder.getAnalysisOptions(path); |
893 _expectEqualOptions(options, new AnalysisOptionsImpl()); | 913 _expectEqualOptions(options, new AnalysisOptionsImpl()); |
894 } | 914 } |
895 | 915 |
896 void test_getAnalysisOptions_optionsPath() { | |
897 String path = resourceProvider.convertPath('/some/directory/path'); | |
898 String filePath = | |
899 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); | |
900 resourceProvider.newFile( | |
901 filePath, | |
902 ''' | |
903 linter: | |
904 rules: | |
905 - empty_constructor_bodies | |
906 '''); | |
907 | |
908 ContextRoot root = new ContextRoot(path, []); | |
909 builder.getAnalysisOptions(path, contextRoot: root); | |
910 expect(root.optionsFilePath, equals(filePath)); | |
911 } | |
912 | |
913 void test_getAnalysisOptions_noDefault_overrides() { | 916 void test_getAnalysisOptions_noDefault_overrides() { |
914 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); | 917 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); |
915 expected.enableSuperMixins = true; | 918 expected.enableSuperMixins = true; |
916 String path = resourceProvider.convertPath('/some/directory/path'); | 919 String path = resourceProvider.convertPath('/some/directory/path'); |
917 String filePath = | 920 String filePath = |
918 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); | 921 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); |
919 resourceProvider.newFile( | 922 resourceProvider.newFile( |
920 filePath, | 923 filePath, |
921 ''' | 924 ''' |
922 analyzer: | 925 analyzer: |
923 language: | 926 language: |
924 enableSuperMixins : true | 927 enableSuperMixins : true |
925 '''); | 928 '''); |
926 | 929 |
927 AnalysisOptions options = builder.getAnalysisOptions(path); | 930 AnalysisOptions options = builder.getAnalysisOptions(path); |
928 _expectEqualOptions(options, expected); | 931 _expectEqualOptions(options, expected); |
929 } | 932 } |
930 | 933 |
931 void test_getAnalysisOptions_gnWorkspace() { | 934 void test_getAnalysisOptions_optionsPath() { |
932 String _p(String path) => resourceProvider.convertPath(path); | 935 String path = resourceProvider.convertPath('/some/directory/path'); |
933 String projectPath = _p('/workspace/some/path'); | 936 String filePath = |
934 resourceProvider.newFolder(_p('/workspace/.jiri_root')); | 937 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); |
935 resourceProvider.newFile( | 938 resourceProvider.newFile( |
936 _p('/workspace/out/debug/gen/dart.sources/foo_pkg'), | 939 filePath, |
937 _p('/workspace/foo_pkg/lib')); | 940 ''' |
938 resourceProvider.newFolder(projectPath); | 941 linter: |
939 ArgParser argParser = new ArgParser(); | 942 rules: |
940 defineAnalysisArguments(argParser); | 943 - empty_constructor_bodies |
941 ArgResults argResults = argParser.parse([]); | 944 '''); |
942 builderOptions = createContextBuilderOptions(argResults); | 945 |
943 expect(builderOptions.packageDefaultAnalysisOptions, isTrue); | 946 ContextRoot root = new ContextRoot(path, []); |
944 builder = new ContextBuilder(resourceProvider, sdkManager, contentCache, | 947 builder.getAnalysisOptions(path, contextRoot: root); |
945 options: builderOptions); | 948 expect(root.optionsFilePath, equals(filePath)); |
946 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); | |
947 AnalysisOptions options = builder.getAnalysisOptions(projectPath); | |
948 _expectEqualOptions(options, expected); | |
949 } | 949 } |
950 | 950 |
951 void test_getOptionsFile_explicit() { | 951 void test_getOptionsFile_explicit() { |
952 String path = resourceProvider.convertPath('/some/directory/path'); | 952 String path = resourceProvider.convertPath('/some/directory/path'); |
953 String filePath = resourceProvider.convertPath('/options/analysis.yaml'); | 953 String filePath = resourceProvider.convertPath('/options/analysis.yaml'); |
954 resourceProvider.newFile(filePath, ''); | 954 resourceProvider.newFile(filePath, ''); |
955 | 955 |
956 builderOptions.defaultAnalysisOptionsFilePath = filePath; | 956 builderOptions.defaultAnalysisOptionsFilePath = filePath; |
957 File result = builder.getOptionsFile(path); | 957 File result = builder.getOptionsFile(path); |
958 expect(result, isNotNull); | 958 expect(result, isNotNull); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1077 class _MockLintRule implements LintRule { | 1077 class _MockLintRule implements LintRule { |
1078 final String _name; | 1078 final String _name; |
1079 | 1079 |
1080 _MockLintRule(this._name); | 1080 _MockLintRule(this._name); |
1081 | 1081 |
1082 @override | 1082 @override |
1083 String get name => _name; | 1083 String get name => _name; |
1084 | 1084 |
1085 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 1085 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
1086 } | 1086 } |
OLD | NEW |