| 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'; | |
| 11 import 'package:analyzer/src/generated/engine.dart'; | 10 import 'package:analyzer/src/generated/engine.dart'; |
| 12 import 'package:analyzer/src/generated/source.dart'; | 11 import 'package:analyzer/src/generated/source.dart'; |
| 13 import 'package:analyzer/src/task/options.dart' | |
| 14 show CONFIGURED_ERROR_PROCESSORS; | |
| 15 import 'package:analyzer/src/task/options.dart'; | 12 import 'package:analyzer/src/task/options.dart'; |
| 16 import 'package:analyzer/task/general.dart'; | 13 import 'package:analyzer/task/general.dart'; |
| 17 import 'package:analyzer/task/model.dart'; | 14 import 'package:analyzer/task/model.dart'; |
| 18 import 'package:test/test.dart'; | 15 import 'package:test/test.dart'; |
| 19 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 16 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 20 import 'package:yaml/yaml.dart'; | 17 import 'package:yaml/yaml.dart'; |
| 21 | 18 |
| 22 import '../../generated/test_support.dart'; | 19 import '../../generated/test_support.dart'; |
| 23 import '../context/abstract_context.dart'; | 20 import '../context/abstract_context.dart'; |
| 24 | 21 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 } | 80 } |
| 84 | 81 |
| 85 test_configure_error_processors() { | 82 test_configure_error_processors() { |
| 86 configureContext(''' | 83 configureContext(''' |
| 87 analyzer: | 84 analyzer: |
| 88 errors: | 85 errors: |
| 89 invalid_assignment: ignore | 86 invalid_assignment: ignore |
| 90 unused_local_variable: error | 87 unused_local_variable: error |
| 91 '''); | 88 '''); |
| 92 | 89 |
| 93 List<ErrorProcessor> processors = | 90 List<ErrorProcessor> processors = context.analysisOptions.errorProcessors; |
| 94 context.getConfigurationData(CONFIGURED_ERROR_PROCESSORS); | |
| 95 expect(processors, hasLength(2)); | 91 expect(processors, hasLength(2)); |
| 96 | 92 |
| 97 var unused_local = new AnalysisError( | 93 var unused_local = new AnalysisError( |
| 98 new TestSource(), 0, 1, HintCode.UNUSED_LOCAL_VARIABLE, [ | 94 new TestSource(), 0, 1, HintCode.UNUSED_LOCAL_VARIABLE, [ |
| 99 ['x'] | 95 ['x'] |
| 100 ]); | 96 ]); |
| 101 var invalid_assignment = | 97 var invalid_assignment = |
| 102 new AnalysisError(new TestSource(), 0, 1, HintCode.INVALID_ASSIGNMENT, [ | 98 new AnalysisError(new TestSource(), 0, 1, HintCode.INVALID_ASSIGNMENT, [ |
| 103 ['x'], | 99 ['x'], |
| 104 ['y'] | 100 ['y'] |
| (...skipping 10 matching lines...) Expand all Loading... |
| 115 } | 111 } |
| 116 | 112 |
| 117 test_configure_excludes() { | 113 test_configure_excludes() { |
| 118 configureContext(''' | 114 configureContext(''' |
| 119 analyzer: | 115 analyzer: |
| 120 exclude: | 116 exclude: |
| 121 - foo/bar.dart | 117 - foo/bar.dart |
| 122 - 'test/**' | 118 - 'test/**' |
| 123 '''); | 119 '''); |
| 124 | 120 |
| 125 List<String> excludes = context.getConfigurationData(CONTEXT_EXCLUDES); | 121 List<String> excludes = context.analysisOptions.excludePatterns; |
| 126 expect(excludes, unorderedEquals(['foo/bar.dart', 'test/**'])); | 122 expect(excludes, unorderedEquals(['foo/bar.dart', 'test/**'])); |
| 127 } | 123 } |
| 128 | 124 |
| 129 test_configure_strong_mode() { | 125 test_configure_strong_mode() { |
| 130 configureContext(''' | 126 configureContext(''' |
| 131 analyzer: | 127 analyzer: |
| 132 strong-mode: true | 128 strong-mode: true |
| 133 '''); | 129 '''); |
| 134 expect(analysisOptions.strongMode, true); | 130 expect(analysisOptions.strongMode, true); |
| 135 } | 131 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 '''; | 229 '''; |
| 234 AnalysisTarget target = newSource(optionsFilePath, code); | 230 AnalysisTarget target = newSource(optionsFilePath, code); |
| 235 computeResult(target, ANALYSIS_OPTIONS_ERRORS); | 231 computeResult(target, ANALYSIS_OPTIONS_ERRORS); |
| 236 expect(task, isGenerateOptionsErrorsTask); | 232 expect(task, isGenerateOptionsErrorsTask); |
| 237 List<AnalysisError> errors = | 233 List<AnalysisError> errors = |
| 238 outputs[ANALYSIS_OPTIONS_ERRORS] as List<AnalysisError>; | 234 outputs[ANALYSIS_OPTIONS_ERRORS] as List<AnalysisError>; |
| 239 expect(errors, hasLength(0)); | 235 expect(errors, hasLength(0)); |
| 240 } | 236 } |
| 241 | 237 |
| 242 test_perform_include_bad_value() { | 238 test_perform_include_bad_value() { |
| 243 newSource('/other_options.yaml', ''' | 239 newSource( |
| 240 '/other_options.yaml', |
| 241 ''' |
| 244 analyzer: | 242 analyzer: |
| 245 errors: | 243 errors: |
| 246 unused_local_variable: ftw | 244 unused_local_variable: ftw |
| 247 '''); | 245 '''); |
| 248 String code = r''' | 246 String code = r''' |
| 249 include: other_options.yaml | 247 include: other_options.yaml |
| 250 '''; | 248 '''; |
| 251 AnalysisTarget target = newSource(optionsFilePath, code); | 249 AnalysisTarget target = newSource(optionsFilePath, code); |
| 252 computeResult(target, ANALYSIS_OPTIONS_ERRORS); | 250 computeResult(target, ANALYSIS_OPTIONS_ERRORS); |
| 253 expect(task, isGenerateOptionsErrorsTask); | 251 expect(task, isGenerateOptionsErrorsTask); |
| 254 List<AnalysisError> errors = | 252 List<AnalysisError> errors = |
| 255 outputs[ANALYSIS_OPTIONS_ERRORS] as List<AnalysisError>; | 253 outputs[ANALYSIS_OPTIONS_ERRORS] as List<AnalysisError>; |
| 256 expect(errors, hasLength(1)); | 254 expect(errors, hasLength(1)); |
| 257 AnalysisError error = errors[0]; | 255 AnalysisError error = errors[0]; |
| 258 expect(error.errorCode, AnalysisOptionsWarningCode.INCLUDED_FILE_WARNING); | 256 expect(error.errorCode, AnalysisOptionsWarningCode.INCLUDED_FILE_WARNING); |
| 259 expect(error.source, target.source); | 257 expect(error.source, target.source); |
| 260 expect(error.offset, 10); | 258 expect(error.offset, 10); |
| 261 expect(error.length, 18); | 259 expect(error.length, 18); |
| 262 expect(error.message, contains('other_options.yaml(47..49)')); | 260 expect(error.message, contains('other_options.yaml(47..49)')); |
| 263 } | 261 } |
| 264 | 262 |
| 265 test_perform_include_bad_yaml() { | 263 test_perform_include_bad_yaml() { |
| 266 newSource('/other_options.yaml', ':'); | 264 newSource('/other_options.yaml', ':'); |
| 267 String code = r''' | 265 String code = r''' |
| 268 include: other_options.yaml | 266 include: other_options.yaml |
| 269 '''; | 267 '''; |
| 270 AnalysisTarget target = newSource(optionsFilePath, code); | 268 AnalysisTarget target = newSource(optionsFilePath, code); |
| 271 computeResult(target, ANALYSIS_OPTIONS_ERRORS); | 269 computeResult(target, ANALYSIS_OPTIONS_ERRORS); |
| 272 expect(task, isGenerateOptionsErrorsTask); | 270 expect(task, isGenerateOptionsErrorsTask); |
| 273 List<AnalysisError> errors = | 271 List<AnalysisError> errors = |
| 274 outputs[ANALYSIS_OPTIONS_ERRORS] as List<AnalysisError>; | 272 outputs[ANALYSIS_OPTIONS_ERRORS] as List<AnalysisError>; |
| 275 expect(errors, hasLength(1)); | 273 expect(errors, hasLength(1)); |
| 276 AnalysisError error = errors[0]; | 274 AnalysisError error = errors[0]; |
| 277 expect(error.errorCode, AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR); | 275 expect(error.errorCode, AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR); |
| 278 expect(error.source, target.source); | 276 expect(error.source, target.source); |
| 279 expect(error.offset, 10); | 277 expect(error.offset, 10); |
| 280 expect(error.length, 18); | 278 expect(error.length, 18); |
| 281 expect(error.message, contains('other_options.yaml(0..0)')); | 279 expect(error.message, contains('other_options.yaml(0..0)')); |
| 282 } | 280 } |
| 283 | 281 |
| 284 test_perform_include_missing() { | 282 test_perform_include_missing() { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUE]); | 461 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUE]); |
| 464 } | 462 } |
| 465 | 463 |
| 466 void validate(String source, List<ErrorCode> expected) { | 464 void validate(String source, List<ErrorCode> expected) { |
| 467 var options = optionsProvider.getOptionsFromString(source); | 465 var options = optionsProvider.getOptionsFromString(source); |
| 468 var errors = validator.validate(options); | 466 var errors = validator.validate(options); |
| 469 expect(errors.map((AnalysisError e) => e.errorCode), | 467 expect(errors.map((AnalysisError e) => e.errorCode), |
| 470 unorderedEquals(expected)); | 468 unorderedEquals(expected)); |
| 471 } | 469 } |
| 472 } | 470 } |
| OLD | NEW |