Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: pkg/analyzer/test/src/task/options_test.dart

Issue 2654043003: add warning for deprecated .analysis_options file name (Closed)
Patch Set: merge Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/src/task/options.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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;
146 String get optionsFilePath => '/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}'; 147 String get optionsFilePath => '/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}';
147 } 148 }
148 149
149 @reflectiveTest 150 @reflectiveTest
150 class GenerateOldOptionsErrorsTaskTest extends GenerateOptionsErrorsTaskTest { 151 class GenerateOldOptionsErrorsTaskTest extends GenerateOptionsErrorsTaskTest {
152 bool get isOptionsFileDeprecated => true;
151 String get optionsFilePath => '/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}'; 153 String get optionsFilePath => '/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}';
152 } 154 }
153 155
154 abstract class GenerateOptionsErrorsTaskTest extends AbstractContextTest { 156 abstract class GenerateOptionsErrorsTaskTest extends AbstractContextTest {
155 Source source; 157 Source source;
156 158
159 bool get isOptionsFileDeprecated;
160
157 String get optionsFilePath; 161 String get optionsFilePath;
162
158 LineInfo lineInfo(String source) => 163 LineInfo lineInfo(String source) =>
159 GenerateOptionsErrorsTask.computeLineInfo(source); 164 GenerateOptionsErrorsTask.computeLineInfo(source);
160 165
161 @override 166 @override
162 setUp() { 167 setUp() {
163 super.setUp(); 168 super.setUp();
164 source = newSource(optionsFilePath); 169 source = newSource(optionsFilePath);
165 } 170 }
166 171
167 test_buildInputs() { 172 test_buildInputs() {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 GenerateOptionsErrorsTask task = 209 GenerateOptionsErrorsTask task =
205 new GenerateOptionsErrorsTask(null, source); 210 new GenerateOptionsErrorsTask(null, source);
206 expect(task.description, isNotNull); 211 expect(task.description, isNotNull);
207 } 212 }
208 213
209 test_descriptor() { 214 test_descriptor() {
210 TaskDescriptor descriptor = GenerateOptionsErrorsTask.DESCRIPTOR; 215 TaskDescriptor descriptor = GenerateOptionsErrorsTask.DESCRIPTOR;
211 expect(descriptor, isNotNull); 216 expect(descriptor, isNotNull);
212 } 217 }
213 218
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
214 test_perform_bad_yaml() { 242 test_perform_bad_yaml() {
215 String code = r''' 243 String code = r'''
216 : 244 :
217 '''; 245 ''';
218 AnalysisTarget target = newSource(optionsFilePath, code); 246 AnalysisTarget target = newSource(optionsFilePath, code);
219 computeResult(target, ANALYSIS_OPTIONS_ERRORS); 247 computeResult(target, ANALYSIS_OPTIONS_ERRORS);
220 expect(task, isGenerateOptionsErrorsTask); 248 expect(task, isGenerateOptionsErrorsTask);
221 List<AnalysisError> errors = 249 List<AnalysisError> errors =
222 outputs[ANALYSIS_OPTIONS_ERRORS] as List<AnalysisError>; 250 outputs[ANALYSIS_OPTIONS_ERRORS] as List<AnalysisError>;
223 expect(errors, hasLength(1)); 251 expect(errors, hasLength(1));
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 var options = optionsProvider.getOptionsFromString(source); 496 var options = optionsProvider.getOptionsFromString(source);
469 var errors = validator.validate(options); 497 var errors = validator.validate(options);
470 expect(errors.map((AnalysisError e) => e.errorCode), 498 expect(errors.map((AnalysisError e) => e.errorCode),
471 unorderedEquals(expected)); 499 unorderedEquals(expected));
472 } 500 }
473 } 501 }
474 502
475 class TestRule extends LintRule { 503 class TestRule extends LintRule {
476 TestRule() : super(name: 'fantastic_test_rule'); 504 TestRule() : super(name: 'fantastic_test_rule');
477 } 505 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/options.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698