| 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' hide AnalysisContextImpl; |
| 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/general.dart'; | 12 import 'package:analyzer/task/general.dart'; |
| 13 import 'package:analyzer/task/model.dart'; | 13 import 'package:analyzer/task/model.dart'; |
| 14 import 'package:unittest/unittest.dart'; | 14 import 'package:unittest/unittest.dart'; |
| 15 import 'package:yaml/yaml.dart'; |
| 15 | 16 |
| 16 import '../../generated/test_support.dart'; | 17 import '../../generated/test_support.dart'; |
| 17 import '../../reflective_tests.dart'; | 18 import '../../reflective_tests.dart'; |
| 18 import '../../utils.dart'; | 19 import '../../utils.dart'; |
| 19 import '../context/abstract_context.dart'; | 20 import '../context/abstract_context.dart'; |
| 20 | 21 |
| 21 main() { | 22 main() { |
| 22 initializeTestEnvironment(); | 23 initializeTestEnvironment(); |
| 24 runReflectiveTests(ContextConfigurationTest); |
| 23 runReflectiveTests(GenerateOptionsErrorsTaskTest); | 25 runReflectiveTests(GenerateOptionsErrorsTaskTest); |
| 24 runReflectiveTests(OptionsFileValidatorTest); | 26 runReflectiveTests(OptionsFileValidatorTest); |
| 25 } | 27 } |
| 26 | 28 |
| 27 isInstanceOf isGenerateOptionsErrorsTask = | 29 isInstanceOf isGenerateOptionsErrorsTask = |
| 28 new isInstanceOf<GenerateOptionsErrorsTask>(); | 30 new isInstanceOf<GenerateOptionsErrorsTask>(); |
| 29 | 31 |
| 30 @reflectiveTest | 32 @reflectiveTest |
| 33 class ContextConfigurationTest extends AbstractContextTest { |
| 34 final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider(); |
| 35 |
| 36 AnalysisOptions get analysisOptions => context.analysisOptions; |
| 37 |
| 38 configureContext(String optionsSource) => |
| 39 configureContextOptions(context, parseOptions(optionsSource)); |
| 40 |
| 41 Map<String, YamlNode> parseOptions(String source) => |
| 42 optionsProvider.getOptionsFromString(source); |
| 43 |
| 44 test_configure_enableSuperMixins() { |
| 45 configureContext(''' |
| 46 analyzer: |
| 47 language: |
| 48 enableSuperMixins: true |
| 49 '''); |
| 50 expect(analysisOptions.enableSuperMixins, true); |
| 51 } |
| 52 |
| 53 test_configure_error_filters() { |
| 54 configureContext(''' |
| 55 analyzer: |
| 56 errors: |
| 57 invalid_assignment: ignore |
| 58 unused_local_variable: ignore |
| 59 '''); |
| 60 |
| 61 List<ErrorFilter> filters = |
| 62 context.getConfigurationData(CONFIGURED_ERROR_FILTERS); |
| 63 expect(filters, hasLength(2)); |
| 64 |
| 65 var unused_error = new AnalysisError( |
| 66 new TestSource(), 0, 1, HintCode.UNUSED_LOCAL_VARIABLE, [ |
| 67 ['x'] |
| 68 ]); |
| 69 var invalid_assignment_error = |
| 70 new AnalysisError(new TestSource(), 0, 1, HintCode.INVALID_ASSIGNMENT, [ |
| 71 ['x'], |
| 72 ['y'] |
| 73 ]); |
| 74 |
| 75 expect(filters.any((filter) => filter(unused_error)), isTrue); |
| 76 expect(filters.any((filter) => filter(invalid_assignment_error)), isTrue); |
| 77 } |
| 78 |
| 79 test_configure_strong_mode() { |
| 80 configureContext(''' |
| 81 analyzer: |
| 82 strong-mode: true |
| 83 '''); |
| 84 expect(analysisOptions.strongMode, true); |
| 85 } |
| 86 } |
| 87 |
| 88 @reflectiveTest |
| 31 class GenerateOptionsErrorsTaskTest extends AbstractContextTest { | 89 class GenerateOptionsErrorsTaskTest extends AbstractContextTest { |
| 32 final optionsFilePath = '/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}'; | 90 final optionsFilePath = '/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}'; |
| 33 | 91 |
| 34 Source source; | 92 Source source; |
| 35 LineInfo lineInfo(String source) => | 93 LineInfo lineInfo(String source) => |
| 36 GenerateOptionsErrorsTask.computeLineInfo(source); | 94 GenerateOptionsErrorsTask.computeLineInfo(source); |
| 37 | 95 |
| 38 @override | 96 @override |
| 39 setUp() { | 97 setUp() { |
| 40 super.setUp(); | 98 super.setUp(); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 '''; | 180 '''; |
| 123 AnalysisTarget target = newSource(optionsFilePath, code); | 181 AnalysisTarget target = newSource(optionsFilePath, code); |
| 124 computeResult(target, ANALYSIS_OPTIONS_ERRORS); | 182 computeResult(target, ANALYSIS_OPTIONS_ERRORS); |
| 125 expect(task, isGenerateOptionsErrorsTask); | 183 expect(task, isGenerateOptionsErrorsTask); |
| 126 List<AnalysisError> errors = outputs[ANALYSIS_OPTIONS_ERRORS]; | 184 List<AnalysisError> errors = outputs[ANALYSIS_OPTIONS_ERRORS]; |
| 127 expect(errors, hasLength(1)); | 185 expect(errors, hasLength(1)); |
| 128 expect(errors[0].errorCode, | 186 expect(errors[0].errorCode, |
| 129 AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES); | 187 AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES); |
| 130 expect( | 188 expect( |
| 131 errors[0].message, | 189 errors[0].message, |
| 132 "The option 'not_supported' is not supported by analyzer, " | 190 "The option 'not_supported' is not supported by analyzer, supported " |
| 133 "supported values are 'errors', 'exclude', 'plugins' and 'strong-mode'")
; | 191 "values are 'errors', 'exclude', 'language', 'plugins' and 'strong-mode'
"); |
| 134 } | 192 } |
| 135 } | 193 } |
| 136 | 194 |
| 137 @reflectiveTest | 195 @reflectiveTest |
| 138 class OptionsFileValidatorTest { | 196 class OptionsFileValidatorTest { |
| 139 final OptionsFileValidator validator = | 197 final OptionsFileValidator validator = |
| 140 new OptionsFileValidator(new TestSource()); | 198 new OptionsFileValidator(new TestSource()); |
| 141 final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider(); | 199 final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider(); |
| 142 | 200 |
| 143 test_analyzer_error_code_supported() { | 201 test_analyzer_error_code_supported() { |
| 144 validate( | 202 validate( |
| 145 ''' | 203 ''' |
| 146 analyzer: | 204 analyzer: |
| 147 errors: | 205 errors: |
| 148 unused_local_variable: ignore | 206 unused_local_variable: ignore |
| 149 ''', | 207 ''', |
| 150 []); | 208 []); |
| 151 } | 209 } |
| 152 | 210 |
| 153 test_analyzer_error_code_supported_bad_value() { | 211 test_analyzer_error_code_supported_bad_value() { |
| 154 validate( | 212 validate( |
| 155 ''' | 213 ''' |
| 156 analyzer: | 214 analyzer: |
| 157 errors: | 215 errors: |
| 158 unused_local_variable: ftw | 216 unused_local_variable: ftw |
| 159 ''', | 217 ''', |
| 160 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES]); | 218 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES]); |
| 161 } | 219 } |
| 162 | 220 |
| 163 test_analyzer_error_code_unsupported() { | 221 test_analyzer_error_code_unsupported() { |
| 164 validate( | 222 validate( |
| 165 ''' | 223 ''' |
| 166 analyzer: | 224 analyzer: |
| 167 errors: | 225 errors: |
| 168 not_supported: ignore | 226 not_supported: ignore |
| 169 ''', | 227 ''', |
| 170 [AnalysisOptionsWarningCode.UNRECOGNIZED_ERROR_CODE]); | 228 [AnalysisOptionsWarningCode.UNRECOGNIZED_ERROR_CODE]); |
| 171 } | 229 } |
| 172 | 230 |
| 231 test_analyzer_language_supported() { |
| 232 validate( |
| 233 ''' |
| 234 analyzer: |
| 235 language: |
| 236 enableSuperMixins: true |
| 237 ''', |
| 238 []); |
| 239 } |
| 240 |
| 241 test_analyzer_language_unsupported_key() { |
| 242 validate( |
| 243 ''' |
| 244 analyzer: |
| 245 language: |
| 246 unsupported: true |
| 247 ''', |
| 248 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUE]); |
| 249 } |
| 250 |
| 251 test_analyzer_language_unsupported_value() { |
| 252 validate( |
| 253 ''' |
| 254 analyzer: |
| 255 language: |
| 256 enableSuperMixins: foo |
| 257 ''', |
| 258 [AnalysisOptionsWarningCode.UNSUPPORTED_VALUE]); |
| 259 } |
| 260 |
| 173 test_analyzer_supported_exclude() { | 261 test_analyzer_supported_exclude() { |
| 174 validate( | 262 validate( |
| 175 ''' | 263 ''' |
| 176 analyzer: | 264 analyzer: |
| 177 exclude: | 265 exclude: |
| 178 - test/_data/p4/lib/lib1.dart | 266 - test/_data/p4/lib/lib1.dart |
| 179 ''', | 267 ''', |
| 180 []); | 268 []); |
| 181 } | 269 } |
| 182 | 270 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUE]); | 305 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUE]); |
| 218 } | 306 } |
| 219 | 307 |
| 220 void validate(String source, List<AnalysisOptionsErrorCode> expected) { | 308 void validate(String source, List<AnalysisOptionsErrorCode> expected) { |
| 221 var options = optionsProvider.getOptionsFromString(source); | 309 var options = optionsProvider.getOptionsFromString(source); |
| 222 var errors = validator.validate(options); | 310 var errors = validator.validate(options); |
| 223 expect(errors.map((AnalysisError e) => e.errorCode), | 311 expect(errors.map((AnalysisError e) => e.errorCode), |
| 224 unorderedEquals(expected)); | 312 unorderedEquals(expected)); |
| 225 } | 313 } |
| 226 } | 314 } |
| OLD | NEW |