Chromium Code Reviews| 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 'dart:mirrors'; | |
| 8 | |
| 7 import 'package:analyzer/analyzer.dart'; | 9 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/source/analysis_options_provider.dart'; | 10 import 'package:analyzer/source/analysis_options_provider.dart'; |
| 9 import 'package:analyzer/source/error_processor.dart'; | 11 import 'package:analyzer/source/error_processor.dart'; |
| 10 import 'package:analyzer/src/generated/engine.dart'; | 12 import 'package:analyzer/src/generated/engine.dart'; |
| 11 import 'package:analyzer/src/generated/source.dart'; | 13 import 'package:analyzer/src/generated/source.dart'; |
| 12 import 'package:analyzer/src/lint/linter.dart'; | 14 import 'package:analyzer/src/lint/linter.dart'; |
| 13 import 'package:analyzer/src/lint/registry.dart'; | 15 import 'package:analyzer/src/lint/registry.dart'; |
| 14 import 'package:analyzer/src/task/options.dart'; | 16 import 'package:analyzer/src/task/options.dart'; |
| 15 import 'package:analyzer/task/general.dart'; | 17 import 'package:analyzer/task/general.dart'; |
| 16 import 'package:analyzer/task/model.dart'; | 18 import 'package:analyzer/task/model.dart'; |
| 17 import 'package:test/test.dart'; | 19 import 'package:test/test.dart'; |
| 18 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 20 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 19 import 'package:yaml/yaml.dart'; | 21 import 'package:yaml/yaml.dart'; |
| 20 | 22 |
| 21 import '../../generated/test_support.dart'; | 23 import '../../generated/test_support.dart'; |
| 22 import '../context/abstract_context.dart'; | 24 import '../context/abstract_context.dart'; |
| 23 | 25 |
| 24 main() { | 26 main() { |
| 25 defineReflectiveSuite(() { | 27 defineReflectiveSuite(() { |
| 26 defineReflectiveTests(ContextConfigurationTest); | 28 defineReflectiveTests(ContextConfigurationTest); |
| 29 defineReflectiveTests(ErrorFilterOptionValidatorTest); | |
| 27 defineReflectiveTests(GenerateNewOptionsErrorsTaskTest); | 30 defineReflectiveTests(GenerateNewOptionsErrorsTaskTest); |
| 28 defineReflectiveTests(GenerateOldOptionsErrorsTaskTest); | 31 defineReflectiveTests(GenerateOldOptionsErrorsTaskTest); |
| 29 defineReflectiveTests(OptionsFileValidatorTest); | 32 defineReflectiveTests(OptionsFileValidatorTest); |
| 30 }); | 33 }); |
| 31 } | 34 } |
| 32 | 35 |
| 33 isInstanceOf isGenerateOptionsErrorsTask = | 36 isInstanceOf isGenerateOptionsErrorsTask = |
| 34 new isInstanceOf<GenerateOptionsErrorsTask>(); | 37 new isInstanceOf<GenerateOptionsErrorsTask>(); |
| 35 | 38 |
| 36 @reflectiveTest | 39 @reflectiveTest |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 test_configure_strong_mode_bad_value() { | 138 test_configure_strong_mode_bad_value() { |
| 136 configureContext(''' | 139 configureContext(''' |
| 137 analyzer: | 140 analyzer: |
| 138 strong-mode: foo | 141 strong-mode: foo |
| 139 '''); | 142 '''); |
| 140 expect(analysisOptions.strongMode, false); | 143 expect(analysisOptions.strongMode, false); |
| 141 } | 144 } |
| 142 } | 145 } |
| 143 | 146 |
| 144 @reflectiveTest | 147 @reflectiveTest |
| 148 class ErrorFilterOptionValidatorTest { | |
|
scheglov
2017/06/07 18:09:51
Hm... The name of the test is strange.
Why is it a
danrubel
2017/06/07 18:43:06
Good point. Renamed.
| |
| 149 test_errorCodes() { | |
| 150 var errorTypeMap = <Type, List<ErrorCode>>{}; | |
| 151 for (ErrorCode code in errorCodeValues) { | |
| 152 errorTypeMap.putIfAbsent(code.runtimeType, () => <ErrorCode>[]).add(code); | |
| 153 } | |
| 154 | |
| 155 int totalCount = 0; | |
| 156 int missingErrorCodeCount = 0; | |
| 157 errorTypeMap.forEach((Type errorType, List<ErrorCode> codes) { | |
| 158 var listedNames = codes.map((ErrorCode code) => code.name).toSet(); | |
| 159 | |
| 160 var declaredNames = reflectClass(errorType) | |
| 161 .declarations | |
| 162 .values | |
| 163 .map((DeclarationMirror declarationMirror) { | |
| 164 String name = declarationMirror.simpleName.toString(); | |
| 165 //TODO(danrubel): find a better way to extract the text from the symbol | |
| 166 assert(name.startsWith('Symbol("') && name.endsWith('")')); | |
| 167 return name.substring(8, name.length - 2); | |
| 168 }).where((String name) { | |
| 169 return name == name.toUpperCase(); | |
| 170 }).toList(); | |
| 171 | |
| 172 // Remove declared names that are not supposed to be in errorCodeValues | |
| 173 | |
| 174 if (errorType == AnalysisOptionsErrorCode) { | |
| 175 declaredNames.remove('INCLUDED_FILE_PARSE_ERROR'); | |
|
scheglov
2017/06/07 18:09:51
I don't like using string names.
Could we use Anal
danrubel
2017/06/07 18:43:05
Great suggestion. Refactored.
| |
| 176 } else if (errorType == AnalysisOptionsWarningCode) { | |
| 177 declaredNames.remove('INCLUDE_FILE_NOT_FOUND'); | |
| 178 declaredNames.remove('INCLUDED_FILE_WARNING'); | |
| 179 } else if (errorType == StaticWarningCode) { | |
| 180 declaredNames.remove('FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS'); | |
| 181 } else if (errorType == StrongModeCode) { | |
| 182 declaredNames.remove('DOWN_CAST_COMPOSITE'); | |
| 183 declaredNames.remove('DOWN_CAST_IMPLICIT'); | |
| 184 declaredNames.remove('DOWN_CAST_IMPLICIT_ASSIGN'); | |
| 185 declaredNames.remove('DYNAMIC_CAST'); | |
| 186 declaredNames.remove('ASSIGNMENT_CAST'); | |
| 187 declaredNames.remove('INVALID_PARAMETER_DECLARATION'); | |
| 188 declaredNames.remove('COULD_NOT_INFER'); | |
| 189 declaredNames.remove('INFERRED_TYPE'); | |
| 190 declaredNames.remove('INFERRED_TYPE_LITERAL'); | |
| 191 declaredNames.remove('INFERRED_TYPE_ALLOCATION'); | |
| 192 declaredNames.remove('INFERRED_TYPE_CLOSURE'); | |
| 193 declaredNames.remove('INVALID_CAST_LITERAL'); | |
| 194 declaredNames.remove('INVALID_CAST_LITERAL_LIST'); | |
| 195 declaredNames.remove('INVALID_CAST_LITERAL_MAP'); | |
| 196 declaredNames.remove('INVALID_CAST_FUNCTION_EXPR'); | |
| 197 declaredNames.remove('INVALID_CAST_NEW_EXPR'); | |
| 198 declaredNames.remove('INVALID_CAST_METHOD'); | |
| 199 declaredNames.remove('INVALID_CAST_FUNCTION'); | |
| 200 declaredNames.remove('INVALID_SUPER_INVOCATION'); | |
| 201 declaredNames.remove('NON_GROUND_TYPE_CHECK_INFO'); | |
| 202 declaredNames.remove('DYNAMIC_INVOKE'); | |
| 203 declaredNames.remove('INVALID_METHOD_OVERRIDE'); | |
| 204 declaredNames.remove('INVALID_METHOD_OVERRIDE_FROM_BASE'); | |
| 205 declaredNames.remove('INVALID_METHOD_OVERRIDE_FROM_MIXIN'); | |
| 206 declaredNames.remove('INVALID_FIELD_OVERRIDE'); | |
| 207 declaredNames.remove('IMPLICIT_DYNAMIC_PARAMETER'); | |
| 208 declaredNames.remove('IMPLICIT_DYNAMIC_RETURN'); | |
| 209 declaredNames.remove('IMPLICIT_DYNAMIC_VARIABLE'); | |
| 210 declaredNames.remove('IMPLICIT_DYNAMIC_FIELD'); | |
| 211 declaredNames.remove('IMPLICIT_DYNAMIC_TYPE'); | |
| 212 declaredNames.remove('IMPLICIT_DYNAMIC_LIST_LITERAL'); | |
| 213 declaredNames.remove('IMPLICIT_DYNAMIC_MAP_LITERAL'); | |
| 214 declaredNames.remove('IMPLICIT_DYNAMIC_FUNCTION'); | |
| 215 declaredNames.remove('IMPLICIT_DYNAMIC_METHOD'); | |
| 216 declaredNames.remove('IMPLICIT_DYNAMIC_INVOKE'); | |
| 217 declaredNames.remove('NO_DEFAULT_BOUNDS'); | |
| 218 declaredNames.remove('NOT_INSTANTIATED_BOUND'); | |
| 219 declaredNames.remove('TOP_LEVEL_CYCLE'); | |
| 220 declaredNames.remove('TOP_LEVEL_FUNCTION_LITERAL_BLOCK'); | |
| 221 declaredNames.remove('TOP_LEVEL_FUNCTION_LITERAL_PARAMETER'); | |
| 222 declaredNames.remove('TOP_LEVEL_IDENTIFIER_NO_TYPE'); | |
| 223 declaredNames.remove('TOP_LEVEL_INSTANCE_GETTER'); | |
| 224 declaredNames.remove('TOP_LEVEL_TYPE_ARGUMENTS'); | |
| 225 declaredNames.remove('TOP_LEVEL_UNSUPPORTED'); | |
| 226 declaredNames.remove('UNSAFE_BLOCK_CLOSURE_INFERENCE'); | |
| 227 } else if (errorType == TodoCode) { | |
| 228 declaredNames.remove('TODO_REGEX'); | |
| 229 } | |
| 230 | |
| 231 // Assert that all remaining declared names are in errorCodeValues | |
| 232 | |
| 233 for (String declaredName in declaredNames) { | |
| 234 ++totalCount; | |
| 235 if (!listedNames.contains(declaredName)) { | |
| 236 ++missingErrorCodeCount; | |
| 237 print(' errorCodeValues is missing $errorType $declaredName'); | |
| 238 } | |
| 239 } | |
| 240 }); | |
| 241 expect(missingErrorCodeCount, 0, reason: 'missing error code names'); | |
| 242 | |
| 243 // Apparently, duplicate error codes are allowed | |
| 244 // expect( | |
| 245 // ErrorFilterOptionValidator.errorCodes.length, | |
| 246 // errorCodeValues.length, | |
| 247 // reason: 'some errorCodeValues have the same name', | |
| 248 // ); | |
| 249 } | |
| 250 } | |
| 251 | |
| 252 @reflectiveTest | |
| 145 class GenerateNewOptionsErrorsTaskTest extends GenerateOptionsErrorsTaskTest { | 253 class GenerateNewOptionsErrorsTaskTest extends GenerateOptionsErrorsTaskTest { |
| 146 String get optionsFilePath => '/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}'; | 254 String get optionsFilePath => '/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}'; |
| 147 } | 255 } |
| 148 | 256 |
| 149 @reflectiveTest | 257 @reflectiveTest |
| 150 class GenerateOldOptionsErrorsTaskTest extends GenerateOptionsErrorsTaskTest { | 258 class GenerateOldOptionsErrorsTaskTest extends GenerateOptionsErrorsTaskTest { |
| 151 String get optionsFilePath => '/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}'; | 259 String get optionsFilePath => '/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}'; |
| 152 } | 260 } |
| 153 | 261 |
| 154 abstract class GenerateOptionsErrorsTaskTest extends AbstractContextTest { | 262 abstract class GenerateOptionsErrorsTaskTest extends AbstractContextTest { |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 468 var options = optionsProvider.getOptionsFromString(source); | 576 var options = optionsProvider.getOptionsFromString(source); |
| 469 var errors = validator.validate(options); | 577 var errors = validator.validate(options); |
| 470 expect(errors.map((AnalysisError e) => e.errorCode), | 578 expect(errors.map((AnalysisError e) => e.errorCode), |
| 471 unorderedEquals(expected)); | 579 unorderedEquals(expected)); |
| 472 } | 580 } |
| 473 } | 581 } |
| 474 | 582 |
| 475 class TestRule extends LintRule { | 583 class TestRule extends LintRule { |
| 476 TestRule() : super(name: 'fantastic_test_rule'); | 584 TestRule() : super(name: 'fantastic_test_rule'); |
| 477 } | 585 } |
| OLD | NEW |