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

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

Issue 1418533004: Unsupported analysis option validation. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Warning type fix. Created 5 years, 2 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 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/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
9 import 'package:analyzer/src/generated/source.dart'; 10 import 'package:analyzer/src/generated/source.dart';
10 import 'package:analyzer/src/task/options.dart'; 11 import 'package:analyzer/src/task/options.dart';
11 import 'package:analyzer/task/model.dart'; 12 import 'package:analyzer/task/model.dart';
12 import 'package:unittest/unittest.dart'; 13 import 'package:unittest/unittest.dart';
13 14
14 import '../../reflective_tests.dart'; 15 import '../../reflective_tests.dart';
15 import '../../utils.dart'; 16 import '../../utils.dart';
16 import '../context/abstract_context.dart'; 17 import '../context/abstract_context.dart';
17 18
18 main() { 19 main() {
19 initializeTestEnvironment(); 20 initializeTestEnvironment();
20 runReflectiveTests(GenerateOptionsErrorsTaskTest); 21 runReflectiveTests(GenerateOptionsErrorsTaskTest);
22 runReflectiveTests(OptionsFileValidatorTest);
21 } 23 }
22 24
23 isInstanceOf isGenerateOptionsErrorsTask = 25 isInstanceOf isGenerateOptionsErrorsTask =
24 new isInstanceOf<GenerateOptionsErrorsTask>(); 26 new isInstanceOf<GenerateOptionsErrorsTask>();
25 27
26 @reflectiveTest 28 @reflectiveTest
27 class GenerateOptionsErrorsTaskTest extends AbstractContextTest { 29 class GenerateOptionsErrorsTaskTest extends AbstractContextTest {
28 final optionsFilePath = '/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}'; 30 final optionsFilePath = '/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}';
29 31
30 Source source; 32 Source source;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 : 76 :
75 '''; 77 ''';
76 AnalysisTarget target = newSource(optionsFilePath, code); 78 AnalysisTarget target = newSource(optionsFilePath, code);
77 computeResult(target, ANALYSIS_OPTIONS_ERRORS); 79 computeResult(target, ANALYSIS_OPTIONS_ERRORS);
78 expect(task, isGenerateOptionsErrorsTask); 80 expect(task, isGenerateOptionsErrorsTask);
79 List<AnalysisError> errors = outputs[ANALYSIS_OPTIONS_ERRORS]; 81 List<AnalysisError> errors = outputs[ANALYSIS_OPTIONS_ERRORS];
80 expect(errors, hasLength(1)); 82 expect(errors, hasLength(1));
81 expect(errors[0].errorCode, AnalysisOptionsErrorCode.PARSE_ERROR); 83 expect(errors[0].errorCode, AnalysisOptionsErrorCode.PARSE_ERROR);
82 } 84 }
83 85
86 test_perform_unsupported_analyzer_option() {
87 String code = r'''
88 analyzer:
89 not_supported: true
90 ''';
91 AnalysisTarget target = newSource(optionsFilePath, code);
92 computeResult(target, ANALYSIS_OPTIONS_ERRORS);
93 expect(task, isGenerateOptionsErrorsTask);
94 List<AnalysisError> errors = outputs[ANALYSIS_OPTIONS_ERRORS];
95 expect(errors, hasLength(1));
96 expect(errors[0].errorCode, AnalysisOptionsWarningCode.UNSUPPORTED_OPTION);
97 expect(errors[0].message,
98 "The option 'not_supported' is not supported by analyzer");
99 }
100
84 test_perform_OK() { 101 test_perform_OK() {
85 String code = r''' 102 String code = r'''
86 analyzer: 103 analyzer:
87 strong-mode: true 104 strong-mode: true
88 '''; 105 ''';
89 AnalysisTarget target = newSource(optionsFilePath, code); 106 AnalysisTarget target = newSource(optionsFilePath, code);
90 computeResult(target, ANALYSIS_OPTIONS_ERRORS); 107 computeResult(target, ANALYSIS_OPTIONS_ERRORS);
91 expect(task, isGenerateOptionsErrorsTask); 108 expect(task, isGenerateOptionsErrorsTask);
92 expect(outputs[ANALYSIS_OPTIONS_ERRORS], isEmpty); 109 expect(outputs[ANALYSIS_OPTIONS_ERRORS], isEmpty);
93 } 110 }
94 } 111 }
112
113 @reflectiveTest
114 class OptionsFileValidatorTest {
115 final OptionsFileValidator validator = new OptionsFileValidator(null);
116 final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider();
117
118 test_analyzer_supported_exclude() {
119 validate(
120 '''
121 analyzer:
122 exclude:
123 - test/_data/p4/lib/lib1.dart
124 ''',
125 []);
126 }
127
128 test_analyzer_supported_strong_mode() {
129 validate(
130 '''
131 analyzer:
132 strong-mode: true
133 ''',
134 []);
135 }
136
137 test_analyzer_unsupported_option() {
138 validate(
139 '''
140 analyzer:
141 not_supported: true
142 ''',
143 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION]);
144 }
145
146 void validate(String source, List<AnalysisOptionsErrorCode> expected) {
147 var options = optionsProvider.getOptionsFromString(source);
148 var errors = validator.validate(options);
149 expect(errors.map((AnalysisError e) => e.errorCode),
150 unorderedEquals(expected));
151 }
152 }
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