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

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

Issue 1441323003: Strong Mode option value validation. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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 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' hide AnalysisContextImpl; 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';
(...skipping 23 matching lines...) Expand all
34 final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider(); 34 final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider();
35 35
36 AnalysisOptions get analysisOptions => context.analysisOptions; 36 AnalysisOptions get analysisOptions => context.analysisOptions;
37 37
38 configureContext(String optionsSource) => 38 configureContext(String optionsSource) =>
39 configureContextOptions(context, parseOptions(optionsSource)); 39 configureContextOptions(context, parseOptions(optionsSource));
40 40
41 Map<String, YamlNode> parseOptions(String source) => 41 Map<String, YamlNode> parseOptions(String source) =>
42 optionsProvider.getOptionsFromString(source); 42 optionsProvider.getOptionsFromString(source);
43 43
44 test_configure_bad_options_contents() {
45 configureContext('''
46 analyzer:
47 strong-mode:true # misformatted
48 ''');
49 expect(analysisOptions.strongMode, false);
50 }
51
44 test_configure_enableGenericMethods() { 52 test_configure_enableGenericMethods() {
45 expect(analysisOptions.enableGenericMethods, false); 53 expect(analysisOptions.enableGenericMethods, false);
46 configureContext(''' 54 configureContext('''
47 analyzer: 55 analyzer:
48 language: 56 language:
49 enableGenericMethods: true 57 enableGenericMethods: true
50 '''); 58 ''');
51 expect(analysisOptions.enableGenericMethods, true); 59 expect(analysisOptions.enableGenericMethods, true);
52 } 60 }
53 61
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 expect(analysisOptions.strongMode, true); 102 expect(analysisOptions.strongMode, true);
95 } 103 }
96 104
97 test_configure_strong_mode_bad_value() { 105 test_configure_strong_mode_bad_value() {
98 configureContext(''' 106 configureContext('''
99 analyzer: 107 analyzer:
100 strong-mode: foo 108 strong-mode: foo
101 '''); 109 ''');
102 expect(analysisOptions.strongMode, false); 110 expect(analysisOptions.strongMode, false);
103 } 111 }
104
105 test_configure_bad_options_contents() {
106 configureContext('''
107 analyzer:
108 strong-mode:true # misformatted
109 ''');
110 expect(analysisOptions.strongMode, false);
111 }
112 } 112 }
113 113
114 @reflectiveTest 114 @reflectiveTest
115 class GenerateOptionsErrorsTaskTest extends AbstractContextTest { 115 class GenerateOptionsErrorsTaskTest extends AbstractContextTest {
116 final optionsFilePath = '/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}'; 116 final optionsFilePath = '/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}';
117 117
118 Source source; 118 Source source;
119 LineInfo lineInfo(String source) => 119 LineInfo lineInfo(String source) =>
120 GenerateOptionsErrorsTask.computeLineInfo(source); 120 GenerateOptionsErrorsTask.computeLineInfo(source);
121 121
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 296
297 test_analyzer_supported_strong_mode() { 297 test_analyzer_supported_strong_mode() {
298 validate( 298 validate(
299 ''' 299 '''
300 analyzer: 300 analyzer:
301 strong-mode: true 301 strong-mode: true
302 ''', 302 ''',
303 []); 303 []);
304 } 304 }
305 305
306 test_analyzer_supported_strong_mode_supported_bad_value() {
307 validate(
308 '''
309 analyzer:
310 strong-mode: w00t
311 ''',
312 [AnalysisOptionsWarningCode.UNSUPPORTED_VALUE]);
313 }
314
306 test_analyzer_unsupported_option() { 315 test_analyzer_unsupported_option() {
307 validate( 316 validate(
308 ''' 317 '''
309 analyzer: 318 analyzer:
310 not_supported: true 319 not_supported: true
311 ''', 320 ''',
312 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES]); 321 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES]);
313 } 322 }
314 323
315 test_linter_supported_rules() { 324 test_linter_supported_rules() {
(...skipping 15 matching lines...) Expand all
331 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUE]); 340 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUE]);
332 } 341 }
333 342
334 void validate(String source, List<AnalysisOptionsErrorCode> expected) { 343 void validate(String source, List<AnalysisOptionsErrorCode> expected) {
335 var options = optionsProvider.getOptionsFromString(source); 344 var options = optionsProvider.getOptionsFromString(source);
336 var errors = validator.validate(options); 345 var errors = validator.validate(options);
337 expect(errors.map((AnalysisError e) => e.errorCode), 346 expect(errors.map((AnalysisError e) => e.errorCode),
338 unorderedEquals(expected)); 347 unorderedEquals(expected));
339 } 348 }
340 } 349 }
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