| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 test.src.task.options_test; | 5 library test.src.task.options_test; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/source/analysis_options_provider.dart'; | 8 import 'package:analyzer/source/analysis_options_provider.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 import 'package:analyzer/src/generated/source.dart'; | 10 import 'package:analyzer/src/generated/source.dart'; |
| 11 import 'package:analyzer/src/task/options.dart'; | 11 import 'package:analyzer/src/task/options.dart'; |
| 12 import 'package:analyzer/task/model.dart'; | 12 import 'package:analyzer/task/model.dart'; |
| 13 import 'package:unittest/unittest.dart'; | 13 import 'package:unittest/unittest.dart'; |
| 14 | 14 |
| 15 import '../../generated/test_support.dart'; |
| 15 import '../../reflective_tests.dart'; | 16 import '../../reflective_tests.dart'; |
| 16 import '../../utils.dart'; | 17 import '../../utils.dart'; |
| 17 import '../context/abstract_context.dart'; | 18 import '../context/abstract_context.dart'; |
| 18 | 19 |
| 19 main() { | 20 main() { |
| 20 initializeTestEnvironment(); | 21 initializeTestEnvironment(); |
| 21 runReflectiveTests(GenerateOptionsErrorsTaskTest); | 22 runReflectiveTests(GenerateOptionsErrorsTaskTest); |
| 22 runReflectiveTests(OptionsFileValidatorTest); | 23 runReflectiveTests(OptionsFileValidatorTest); |
| 23 } | 24 } |
| 24 | 25 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 : | 77 : |
| 77 '''; | 78 '''; |
| 78 AnalysisTarget target = newSource(optionsFilePath, code); | 79 AnalysisTarget target = newSource(optionsFilePath, code); |
| 79 computeResult(target, ANALYSIS_OPTIONS_ERRORS); | 80 computeResult(target, ANALYSIS_OPTIONS_ERRORS); |
| 80 expect(task, isGenerateOptionsErrorsTask); | 81 expect(task, isGenerateOptionsErrorsTask); |
| 81 List<AnalysisError> errors = outputs[ANALYSIS_OPTIONS_ERRORS]; | 82 List<AnalysisError> errors = outputs[ANALYSIS_OPTIONS_ERRORS]; |
| 82 expect(errors, hasLength(1)); | 83 expect(errors, hasLength(1)); |
| 83 expect(errors[0].errorCode, AnalysisOptionsErrorCode.PARSE_ERROR); | 84 expect(errors[0].errorCode, AnalysisOptionsErrorCode.PARSE_ERROR); |
| 84 } | 85 } |
| 85 | 86 |
| 87 test_perform_OK() { |
| 88 String code = r''' |
| 89 analyzer: |
| 90 strong-mode: true |
| 91 '''; |
| 92 AnalysisTarget target = newSource(optionsFilePath, code); |
| 93 computeResult(target, ANALYSIS_OPTIONS_ERRORS); |
| 94 expect(task, isGenerateOptionsErrorsTask); |
| 95 expect(outputs[ANALYSIS_OPTIONS_ERRORS], isEmpty); |
| 96 } |
| 97 |
| 86 test_perform_unsupported_analyzer_option() { | 98 test_perform_unsupported_analyzer_option() { |
| 87 String code = r''' | 99 String code = r''' |
| 88 analyzer: | 100 analyzer: |
| 89 not_supported: true | 101 not_supported: true |
| 90 '''; | 102 '''; |
| 91 AnalysisTarget target = newSource(optionsFilePath, code); | 103 AnalysisTarget target = newSource(optionsFilePath, code); |
| 92 computeResult(target, ANALYSIS_OPTIONS_ERRORS); | 104 computeResult(target, ANALYSIS_OPTIONS_ERRORS); |
| 93 expect(task, isGenerateOptionsErrorsTask); | 105 expect(task, isGenerateOptionsErrorsTask); |
| 94 List<AnalysisError> errors = outputs[ANALYSIS_OPTIONS_ERRORS]; | 106 List<AnalysisError> errors = outputs[ANALYSIS_OPTIONS_ERRORS]; |
| 95 expect(errors, hasLength(1)); | 107 expect(errors, hasLength(1)); |
| 96 expect(errors[0].errorCode, AnalysisOptionsWarningCode.UNSUPPORTED_OPTION); | 108 expect(errors[0].errorCode, AnalysisOptionsWarningCode.UNSUPPORTED_OPTION); |
| 97 expect(errors[0].message, | 109 expect(errors[0].message, |
| 98 "The option 'not_supported' is not supported by analyzer"); | 110 "The option 'not_supported' is not supported by analyzer"); |
| 99 } | 111 } |
| 100 | |
| 101 test_perform_OK() { | |
| 102 String code = r''' | |
| 103 analyzer: | |
| 104 strong-mode: true | |
| 105 '''; | |
| 106 AnalysisTarget target = newSource(optionsFilePath, code); | |
| 107 computeResult(target, ANALYSIS_OPTIONS_ERRORS); | |
| 108 expect(task, isGenerateOptionsErrorsTask); | |
| 109 expect(outputs[ANALYSIS_OPTIONS_ERRORS], isEmpty); | |
| 110 } | |
| 111 } | 112 } |
| 112 | 113 |
| 113 @reflectiveTest | 114 @reflectiveTest |
| 114 class OptionsFileValidatorTest { | 115 class OptionsFileValidatorTest { |
| 115 final OptionsFileValidator validator = new OptionsFileValidator(null); | 116 final OptionsFileValidator validator = |
| 117 new OptionsFileValidator(new TestSource()); |
| 116 final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider(); | 118 final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider(); |
| 117 | 119 |
| 118 test_analyzer_supported_exclude() { | 120 test_analyzer_supported_exclude() { |
| 119 validate( | 121 validate( |
| 120 ''' | 122 ''' |
| 121 analyzer: | 123 analyzer: |
| 122 exclude: | 124 exclude: |
| 123 - test/_data/p4/lib/lib1.dart | 125 - test/_data/p4/lib/lib1.dart |
| 124 ''', | 126 ''', |
| 125 []); | 127 []); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 136 | 138 |
| 137 test_analyzer_unsupported_option() { | 139 test_analyzer_unsupported_option() { |
| 138 validate( | 140 validate( |
| 139 ''' | 141 ''' |
| 140 analyzer: | 142 analyzer: |
| 141 not_supported: true | 143 not_supported: true |
| 142 ''', | 144 ''', |
| 143 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION]); | 145 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION]); |
| 144 } | 146 } |
| 145 | 147 |
| 148 test_linter_supported_rules() { |
| 149 validate( |
| 150 ''' |
| 151 linter: |
| 152 rules: |
| 153 - camel_case_types |
| 154 ''', |
| 155 []); |
| 156 } |
| 157 |
| 158 test_linter_unssupported_option() { |
| 159 validate( |
| 160 ''' |
| 161 linter: |
| 162 unsupported: true |
| 163 ''', |
| 164 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION]); |
| 165 } |
| 166 |
| 146 void validate(String source, List<AnalysisOptionsErrorCode> expected) { | 167 void validate(String source, List<AnalysisOptionsErrorCode> expected) { |
| 147 var options = optionsProvider.getOptionsFromString(source); | 168 var options = optionsProvider.getOptionsFromString(source); |
| 148 var errors = validator.validate(options); | 169 var errors = validator.validate(options); |
| 149 expect(errors.map((AnalysisError e) => e.errorCode), | 170 expect(errors.map((AnalysisError e) => e.errorCode), |
| 150 unorderedEquals(expected)); | 171 unorderedEquals(expected)); |
| 151 } | 172 } |
| 152 } | 173 } |
| OLD | NEW |