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 analyzer.test.src.task.options_test; | 5 library analyzer.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/source/error_processor.dart'; | 9 import 'package:analyzer/source/error_processor.dart'; |
10 import 'package:analyzer/src/context/context.dart'; | 10 import 'package:analyzer/src/context/context.dart'; |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 '''; | 219 '''; |
220 AnalysisTarget target = newSource(optionsFilePath, code); | 220 AnalysisTarget target = newSource(optionsFilePath, code); |
221 computeResult(target, ANALYSIS_OPTIONS_ERRORS); | 221 computeResult(target, ANALYSIS_OPTIONS_ERRORS); |
222 expect(task, isGenerateOptionsErrorsTask); | 222 expect(task, isGenerateOptionsErrorsTask); |
223 List<AnalysisError> errors = | 223 List<AnalysisError> errors = |
224 outputs[ANALYSIS_OPTIONS_ERRORS] as List<AnalysisError>; | 224 outputs[ANALYSIS_OPTIONS_ERRORS] as List<AnalysisError>; |
225 expect(errors, hasLength(1)); | 225 expect(errors, hasLength(1)); |
226 expect(errors[0].errorCode, AnalysisOptionsErrorCode.PARSE_ERROR); | 226 expect(errors[0].errorCode, AnalysisOptionsErrorCode.PARSE_ERROR); |
227 } | 227 } |
228 | 228 |
| 229 test_perform_include() { |
| 230 newSource('/other_options.yaml', ''); |
| 231 String code = r''' |
| 232 include: other_options.yaml |
| 233 '''; |
| 234 AnalysisTarget target = newSource(optionsFilePath, code); |
| 235 computeResult(target, ANALYSIS_OPTIONS_ERRORS); |
| 236 expect(task, isGenerateOptionsErrorsTask); |
| 237 List<AnalysisError> errors = |
| 238 outputs[ANALYSIS_OPTIONS_ERRORS] as List<AnalysisError>; |
| 239 expect(errors, hasLength(0)); |
| 240 } |
| 241 |
| 242 test_perform_include_bad_value() { |
| 243 newSource('/other_options.yaml', ''' |
| 244 analyzer: |
| 245 errors: |
| 246 unused_local_variable: ftw |
| 247 '''); |
| 248 String code = r''' |
| 249 include: other_options.yaml |
| 250 '''; |
| 251 AnalysisTarget target = newSource(optionsFilePath, code); |
| 252 computeResult(target, ANALYSIS_OPTIONS_ERRORS); |
| 253 expect(task, isGenerateOptionsErrorsTask); |
| 254 List<AnalysisError> errors = |
| 255 outputs[ANALYSIS_OPTIONS_ERRORS] as List<AnalysisError>; |
| 256 expect(errors, hasLength(1)); |
| 257 AnalysisError error = errors[0]; |
| 258 expect(error.errorCode, AnalysisOptionsWarningCode.INCLUDED_FILE_WARNING); |
| 259 expect(error.source, target.source); |
| 260 expect(error.offset, 10); |
| 261 expect(error.length, 18); |
| 262 expect(error.message, contains('other_options.yaml(47..49)')); |
| 263 } |
| 264 |
| 265 test_perform_include_bad_yaml() { |
| 266 newSource('/other_options.yaml', ':'); |
| 267 String code = r''' |
| 268 include: other_options.yaml |
| 269 '''; |
| 270 AnalysisTarget target = newSource(optionsFilePath, code); |
| 271 computeResult(target, ANALYSIS_OPTIONS_ERRORS); |
| 272 expect(task, isGenerateOptionsErrorsTask); |
| 273 List<AnalysisError> errors = |
| 274 outputs[ANALYSIS_OPTIONS_ERRORS] as List<AnalysisError>; |
| 275 expect(errors, hasLength(1)); |
| 276 AnalysisError error = errors[0]; |
| 277 expect(error.errorCode, AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR); |
| 278 expect(error.source, target.source); |
| 279 expect(error.offset, 10); |
| 280 expect(error.length, 18); |
| 281 expect(error.message, contains('other_options.yaml(0..0)')); |
| 282 } |
| 283 |
| 284 test_perform_include_missing() { |
| 285 String code = r''' |
| 286 include: other_options.yaml |
| 287 '''; |
| 288 AnalysisTarget target = newSource(optionsFilePath, code); |
| 289 computeResult(target, ANALYSIS_OPTIONS_ERRORS); |
| 290 expect(task, isGenerateOptionsErrorsTask); |
| 291 List<AnalysisError> errors = |
| 292 outputs[ANALYSIS_OPTIONS_ERRORS] as List<AnalysisError>; |
| 293 expect(errors, hasLength(1)); |
| 294 AnalysisError error = errors[0]; |
| 295 expect(error.errorCode, AnalysisOptionsWarningCode.INCLUDE_FILE_NOT_FOUND); |
| 296 expect(error.offset, 10); |
| 297 expect(error.length, 18); |
| 298 } |
| 299 |
229 test_perform_OK() { | 300 test_perform_OK() { |
230 String code = r''' | 301 String code = r''' |
231 analyzer: | 302 analyzer: |
232 strong-mode: true | 303 strong-mode: true |
233 '''; | 304 '''; |
234 AnalysisTarget target = newSource(optionsFilePath, code); | 305 AnalysisTarget target = newSource(optionsFilePath, code); |
235 computeResult(target, ANALYSIS_OPTIONS_ERRORS); | 306 computeResult(target, ANALYSIS_OPTIONS_ERRORS); |
236 expect(task, isGenerateOptionsErrorsTask); | 307 expect(task, isGenerateOptionsErrorsTask); |
237 expect(outputs[ANALYSIS_OPTIONS_ERRORS], isEmpty); | 308 expect(outputs[ANALYSIS_OPTIONS_ERRORS], isEmpty); |
238 LineInfo lineInfo = outputs[LINE_INFO]; | 309 LineInfo lineInfo = outputs[LINE_INFO]; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUE]); | 463 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUE]); |
393 } | 464 } |
394 | 465 |
395 void validate(String source, List<ErrorCode> expected) { | 466 void validate(String source, List<ErrorCode> expected) { |
396 var options = optionsProvider.getOptionsFromString(source); | 467 var options = optionsProvider.getOptionsFromString(source); |
397 var errors = validator.validate(options); | 468 var errors = validator.validate(options); |
398 expect(errors.map((AnalysisError e) => e.errorCode), | 469 expect(errors.map((AnalysisError e) => e.errorCode), |
399 unorderedEquals(expected)); | 470 unorderedEquals(expected)); |
400 } | 471 } |
401 } | 472 } |
OLD | NEW |