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/generated/engine.dart'; | 10 import 'package:analyzer/src/generated/engine.dart'; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 configureContext(''' | 136 configureContext(''' |
137 analyzer: | 137 analyzer: |
138 strong-mode: foo | 138 strong-mode: foo |
139 '''); | 139 '''); |
140 expect(analysisOptions.strongMode, false); | 140 expect(analysisOptions.strongMode, false); |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 @reflectiveTest | 144 @reflectiveTest |
145 class GenerateNewOptionsErrorsTaskTest extends GenerateOptionsErrorsTaskTest { | 145 class GenerateNewOptionsErrorsTaskTest extends GenerateOptionsErrorsTaskTest { |
146 bool get isOptionsFileDeprecated => false; | |
147 String get optionsFilePath => '/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}'; | 146 String get optionsFilePath => '/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}'; |
148 } | 147 } |
149 | 148 |
150 @reflectiveTest | 149 @reflectiveTest |
151 class GenerateOldOptionsErrorsTaskTest extends GenerateOptionsErrorsTaskTest { | 150 class GenerateOldOptionsErrorsTaskTest extends GenerateOptionsErrorsTaskTest { |
152 bool get isOptionsFileDeprecated => true; | |
153 String get optionsFilePath => '/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}'; | 151 String get optionsFilePath => '/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}'; |
154 } | 152 } |
155 | 153 |
156 abstract class GenerateOptionsErrorsTaskTest extends AbstractContextTest { | 154 abstract class GenerateOptionsErrorsTaskTest extends AbstractContextTest { |
157 Source source; | 155 Source source; |
158 | 156 |
159 bool get isOptionsFileDeprecated; | |
160 | |
161 String get optionsFilePath; | 157 String get optionsFilePath; |
162 | |
163 LineInfo lineInfo(String source) => | 158 LineInfo lineInfo(String source) => |
164 GenerateOptionsErrorsTask.computeLineInfo(source); | 159 GenerateOptionsErrorsTask.computeLineInfo(source); |
165 | 160 |
166 @override | 161 @override |
167 setUp() { | 162 setUp() { |
168 super.setUp(); | 163 super.setUp(); |
169 source = newSource(optionsFilePath); | 164 source = newSource(optionsFilePath); |
170 } | 165 } |
171 | 166 |
172 test_buildInputs() { | 167 test_buildInputs() { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 GenerateOptionsErrorsTask task = | 204 GenerateOptionsErrorsTask task = |
210 new GenerateOptionsErrorsTask(null, source); | 205 new GenerateOptionsErrorsTask(null, source); |
211 expect(task.description, isNotNull); | 206 expect(task.description, isNotNull); |
212 } | 207 } |
213 | 208 |
214 test_descriptor() { | 209 test_descriptor() { |
215 TaskDescriptor descriptor = GenerateOptionsErrorsTask.DESCRIPTOR; | 210 TaskDescriptor descriptor = GenerateOptionsErrorsTask.DESCRIPTOR; |
216 expect(descriptor, isNotNull); | 211 expect(descriptor, isNotNull); |
217 } | 212 } |
218 | 213 |
219 @override | |
220 void computeResult(AnalysisTarget target, ResultDescriptor result, | |
221 {isInstanceOf matcher: null}) { | |
222 super.computeResult(target, result, matcher: matcher); | |
223 if (isOptionsFileDeprecated) { | |
224 bool found = false; | |
225 var errors = outputs[ANALYSIS_OPTIONS_ERRORS] as List<dynamic>; | |
226 for (var error in errors) { | |
227 if (error is AnalysisError && | |
228 error.errorCode == | |
229 AnalysisOptionsWarningCode | |
230 .DEPRECATED_ANALYSIS_OPTIONS_FILE_NAME) { | |
231 errors.remove(error); | |
232 found = true; | |
233 break; | |
234 } | |
235 } | |
236 if (!found) { | |
237 fail('Expected deprecated analysis options file name warning'); | |
238 } | |
239 } | |
240 } | |
241 | |
242 test_perform_bad_yaml() { | 214 test_perform_bad_yaml() { |
243 String code = r''' | 215 String code = r''' |
244 : | 216 : |
245 '''; | 217 '''; |
246 AnalysisTarget target = newSource(optionsFilePath, code); | 218 AnalysisTarget target = newSource(optionsFilePath, code); |
247 computeResult(target, ANALYSIS_OPTIONS_ERRORS); | 219 computeResult(target, ANALYSIS_OPTIONS_ERRORS); |
248 expect(task, isGenerateOptionsErrorsTask); | 220 expect(task, isGenerateOptionsErrorsTask); |
249 List<AnalysisError> errors = | 221 List<AnalysisError> errors = |
250 outputs[ANALYSIS_OPTIONS_ERRORS] as List<AnalysisError>; | 222 outputs[ANALYSIS_OPTIONS_ERRORS] as List<AnalysisError>; |
251 expect(errors, hasLength(1)); | 223 expect(errors, hasLength(1)); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 var options = optionsProvider.getOptionsFromString(source); | 468 var options = optionsProvider.getOptionsFromString(source); |
497 var errors = validator.validate(options); | 469 var errors = validator.validate(options); |
498 expect(errors.map((AnalysisError e) => e.errorCode), | 470 expect(errors.map((AnalysisError e) => e.errorCode), |
499 unorderedEquals(expected)); | 471 unorderedEquals(expected)); |
500 } | 472 } |
501 } | 473 } |
502 | 474 |
503 class TestRule extends LintRule { | 475 class TestRule extends LintRule { |
504 TestRule() : super(name: 'fantastic_test_rule'); | 476 TestRule() : super(name: 'fantastic_test_rule'); |
505 } | 477 } |
OLD | NEW |