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 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'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
10 import 'package:analyzer/src/generated/source.dart'; | 10 import 'package:analyzer/src/generated/source.dart'; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 test_perform_unsupported_analyzer_option() { | 118 test_perform_unsupported_analyzer_option() { |
119 String code = r''' | 119 String code = r''' |
120 analyzer: | 120 analyzer: |
121 not_supported: true | 121 not_supported: true |
122 '''; | 122 '''; |
123 AnalysisTarget target = newSource(optionsFilePath, code); | 123 AnalysisTarget target = newSource(optionsFilePath, code); |
124 computeResult(target, ANALYSIS_OPTIONS_ERRORS); | 124 computeResult(target, ANALYSIS_OPTIONS_ERRORS); |
125 expect(task, isGenerateOptionsErrorsTask); | 125 expect(task, isGenerateOptionsErrorsTask); |
126 List<AnalysisError> errors = outputs[ANALYSIS_OPTIONS_ERRORS]; | 126 List<AnalysisError> errors = outputs[ANALYSIS_OPTIONS_ERRORS]; |
127 expect(errors, hasLength(1)); | 127 expect(errors, hasLength(1)); |
128 expect(errors[0].errorCode, AnalysisOptionsWarningCode.UNSUPPORTED_OPTION); | 128 expect(errors[0].errorCode, |
129 expect(errors[0].message, | 129 AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES); |
130 "The option 'not_supported' is not supported by analyzer"); | 130 expect( |
| 131 errors[0].message, |
| 132 "The option 'not_supported' is not supported by analyzer, " |
| 133 "supported values are 'errors', 'exclude', 'plugins' and 'strong-mode'")
; |
131 } | 134 } |
132 } | 135 } |
133 | 136 |
134 @reflectiveTest | 137 @reflectiveTest |
135 class OptionsFileValidatorTest { | 138 class OptionsFileValidatorTest { |
136 final OptionsFileValidator validator = | 139 final OptionsFileValidator validator = |
137 new OptionsFileValidator(new TestSource()); | 140 new OptionsFileValidator(new TestSource()); |
138 final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider(); | 141 final AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider(); |
139 | 142 |
| 143 test_analyzer_error_code_supported() { |
| 144 validate( |
| 145 ''' |
| 146 analyzer: |
| 147 errors: |
| 148 unused_local_variable: ignore |
| 149 ''', |
| 150 []); |
| 151 } |
| 152 |
| 153 test_analyzer_error_code_supported_bad_value() { |
| 154 validate( |
| 155 ''' |
| 156 analyzer: |
| 157 errors: |
| 158 unused_local_variable: ftw |
| 159 ''', |
| 160 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES]); |
| 161 } |
| 162 |
| 163 test_analyzer_error_code_unsupported() { |
| 164 validate( |
| 165 ''' |
| 166 analyzer: |
| 167 errors: |
| 168 not_supported: ignore |
| 169 ''', |
| 170 [AnalysisOptionsWarningCode.UNRECOGNIZED_ERROR_CODE]); |
| 171 } |
| 172 |
140 test_analyzer_supported_exclude() { | 173 test_analyzer_supported_exclude() { |
141 validate( | 174 validate( |
142 ''' | 175 ''' |
143 analyzer: | 176 analyzer: |
144 exclude: | 177 exclude: |
145 - test/_data/p4/lib/lib1.dart | 178 - test/_data/p4/lib/lib1.dart |
146 ''', | 179 ''', |
147 []); | 180 []); |
148 } | 181 } |
149 | |
150 test_analyzer_supported_filter() { | |
151 validate( | |
152 ''' | |
153 analyzer: | |
154 errors: | |
155 unused_local_variable: ignore | |
156 ''', | |
157 []); | |
158 } | |
159 | 182 |
160 test_analyzer_supported_strong_mode() { | 183 test_analyzer_supported_strong_mode() { |
161 validate( | 184 validate( |
162 ''' | 185 ''' |
163 analyzer: | 186 analyzer: |
164 strong-mode: true | 187 strong-mode: true |
165 ''', | 188 ''', |
166 []); | 189 []); |
167 } | 190 } |
168 | 191 |
169 test_analyzer_unsupported_option() { | 192 test_analyzer_unsupported_option() { |
170 validate( | 193 validate( |
171 ''' | 194 ''' |
172 analyzer: | 195 analyzer: |
173 not_supported: true | 196 not_supported: true |
174 ''', | 197 ''', |
175 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION]); | 198 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUES]); |
176 } | 199 } |
177 | 200 |
178 test_linter_supported_rules() { | 201 test_linter_supported_rules() { |
179 validate( | 202 validate( |
180 ''' | 203 ''' |
181 linter: | 204 linter: |
182 rules: | 205 rules: |
183 - camel_case_types | 206 - camel_case_types |
184 ''', | 207 ''', |
185 []); | 208 []); |
186 } | 209 } |
187 | 210 |
188 test_linter_unsupported_option() { | 211 test_linter_unsupported_option() { |
189 validate( | 212 validate( |
190 ''' | 213 ''' |
191 linter: | 214 linter: |
192 unsupported: true | 215 unsupported: true |
193 ''', | 216 ''', |
194 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION]); | 217 [AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUE]); |
195 } | 218 } |
196 | 219 |
197 void validate(String source, List<AnalysisOptionsErrorCode> expected) { | 220 void validate(String source, List<AnalysisOptionsErrorCode> expected) { |
198 var options = optionsProvider.getOptionsFromString(source); | 221 var options = optionsProvider.getOptionsFromString(source); |
199 var errors = validator.validate(options); | 222 var errors = validator.validate(options); |
200 expect(errors.map((AnalysisError e) => e.errorCode), | 223 expect(errors.map((AnalysisError e) => e.errorCode), |
201 unorderedEquals(expected)); | 224 unorderedEquals(expected)); |
202 } | 225 } |
203 } | 226 } |
OLD | NEW |