Index: pkg/analyzer/test/src/task/options_test.dart |
diff --git a/pkg/analyzer/test/src/task/options_test.dart b/pkg/analyzer/test/src/task/options_test.dart |
index 01ece33608643fadae7691a6e386fc36020cf415..cf8155c81493f3afc1af1c82b7ea41498e01014e 100644 |
--- a/pkg/analyzer/test/src/task/options_test.dart |
+++ b/pkg/analyzer/test/src/task/options_test.dart |
@@ -4,6 +4,8 @@ |
library analyzer.test.src.task.options_test; |
+import 'dart:mirrors'; |
+ |
import 'package:analyzer/analyzer.dart'; |
import 'package:analyzer/source/analysis_options_provider.dart'; |
import 'package:analyzer/source/error_processor.dart'; |
@@ -24,6 +26,7 @@ import '../context/abstract_context.dart'; |
main() { |
defineReflectiveSuite(() { |
defineReflectiveTests(ContextConfigurationTest); |
+ defineReflectiveTests(ErrorCodeValuesTest); |
defineReflectiveTests(GenerateNewOptionsErrorsTaskTest); |
defineReflectiveTests(GenerateOldOptionsErrorsTaskTest); |
defineReflectiveTests(OptionsFileValidatorTest); |
@@ -142,6 +145,120 @@ analyzer: |
} |
@reflectiveTest |
+class ErrorCodeValuesTest { |
+ test_errorCodes() { |
+ var errorTypeMap = <Type, List<ErrorCode>>{}; |
+ for (ErrorCode code in errorCodeValues) { |
+ errorTypeMap.putIfAbsent(code.runtimeType, () => <ErrorCode>[]).add(code); |
+ } |
+ |
+ int totalCount = 0; |
+ int missingErrorCodeCount = 0; |
+ errorTypeMap.forEach((Type errorType, List<ErrorCode> codes) { |
+ var listedNames = codes.map((ErrorCode code) => code.name).toSet(); |
+ |
+ var declaredNames = reflectClass(errorType) |
+ .declarations |
+ .values |
+ .map((DeclarationMirror declarationMirror) { |
+ String name = declarationMirror.simpleName.toString(); |
+ //TODO(danrubel): find a better way to extract the text from the symbol |
+ assert(name.startsWith('Symbol("') && name.endsWith('")')); |
+ return name.substring(8, name.length - 2); |
+ }).where((String name) { |
+ return name == name.toUpperCase(); |
+ }).toList(); |
+ |
+ // Remove declared names that are not supposed to be in errorCodeValues |
+ |
+ if (errorType == AnalysisOptionsErrorCode) { |
+ declaredNames |
+ .remove(AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR.name); |
+ } else if (errorType == AnalysisOptionsWarningCode) { |
+ declaredNames |
+ .remove(AnalysisOptionsWarningCode.INCLUDE_FILE_NOT_FOUND.name); |
+ declaredNames |
+ .remove(AnalysisOptionsWarningCode.INCLUDED_FILE_WARNING.name); |
+ } else if (errorType == StaticWarningCode) { |
+ declaredNames.remove( |
+ StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS.name); |
+ } else if (errorType == StrongModeCode) { |
+ declaredNames.remove(StrongModeCode.DOWN_CAST_COMPOSITE.name); |
+ declaredNames.remove(StrongModeCode.DOWN_CAST_IMPLICIT.name); |
+ declaredNames.remove(StrongModeCode.DOWN_CAST_IMPLICIT_ASSIGN.name); |
+ declaredNames.remove(StrongModeCode.DYNAMIC_CAST.name); |
+ declaredNames.remove(StrongModeCode.ASSIGNMENT_CAST.name); |
+ declaredNames.remove(StrongModeCode.INVALID_PARAMETER_DECLARATION.name); |
+ declaredNames.remove(StrongModeCode.COULD_NOT_INFER.name); |
+ declaredNames.remove(StrongModeCode.INFERRED_TYPE.name); |
+ declaredNames.remove(StrongModeCode.INFERRED_TYPE_LITERAL.name); |
+ declaredNames.remove(StrongModeCode.INFERRED_TYPE_ALLOCATION.name); |
+ declaredNames.remove(StrongModeCode.INFERRED_TYPE_CLOSURE.name); |
+ declaredNames.remove(StrongModeCode.INVALID_CAST_LITERAL.name); |
+ declaredNames.remove(StrongModeCode.INVALID_CAST_LITERAL_LIST.name); |
+ declaredNames.remove(StrongModeCode.INVALID_CAST_LITERAL_MAP.name); |
+ declaredNames.remove(StrongModeCode.INVALID_CAST_FUNCTION_EXPR.name); |
+ declaredNames.remove(StrongModeCode.INVALID_CAST_NEW_EXPR.name); |
+ declaredNames.remove(StrongModeCode.INVALID_CAST_METHOD.name); |
+ declaredNames.remove(StrongModeCode.INVALID_CAST_FUNCTION.name); |
+ declaredNames.remove(StrongModeCode.INVALID_SUPER_INVOCATION.name); |
+ declaredNames.remove(StrongModeCode.NON_GROUND_TYPE_CHECK_INFO.name); |
+ declaredNames.remove(StrongModeCode.DYNAMIC_INVOKE.name); |
+ declaredNames.remove(StrongModeCode.INVALID_METHOD_OVERRIDE.name); |
+ declaredNames |
+ .remove(StrongModeCode.INVALID_METHOD_OVERRIDE_FROM_BASE.name); |
+ declaredNames |
+ .remove(StrongModeCode.INVALID_METHOD_OVERRIDE_FROM_MIXIN.name); |
+ declaredNames.remove(StrongModeCode.INVALID_FIELD_OVERRIDE.name); |
+ declaredNames.remove(StrongModeCode.IMPLICIT_DYNAMIC_PARAMETER.name); |
+ declaredNames.remove(StrongModeCode.IMPLICIT_DYNAMIC_RETURN.name); |
+ declaredNames.remove(StrongModeCode.IMPLICIT_DYNAMIC_VARIABLE.name); |
+ declaredNames.remove(StrongModeCode.IMPLICIT_DYNAMIC_FIELD.name); |
+ declaredNames.remove(StrongModeCode.IMPLICIT_DYNAMIC_TYPE.name); |
+ declaredNames.remove(StrongModeCode.IMPLICIT_DYNAMIC_LIST_LITERAL.name); |
+ declaredNames.remove(StrongModeCode.IMPLICIT_DYNAMIC_MAP_LITERAL.name); |
+ declaredNames.remove(StrongModeCode.IMPLICIT_DYNAMIC_FUNCTION.name); |
+ declaredNames.remove(StrongModeCode.IMPLICIT_DYNAMIC_METHOD.name); |
+ declaredNames.remove(StrongModeCode.IMPLICIT_DYNAMIC_INVOKE.name); |
+ declaredNames.remove(StrongModeCode.NO_DEFAULT_BOUNDS.name); |
+ declaredNames.remove(StrongModeCode.NOT_INSTANTIATED_BOUND.name); |
+ declaredNames.remove(StrongModeCode.TOP_LEVEL_CYCLE.name); |
+ declaredNames |
+ .remove(StrongModeCode.TOP_LEVEL_FUNCTION_LITERAL_BLOCK.name); |
+ declaredNames |
+ .remove(StrongModeCode.TOP_LEVEL_FUNCTION_LITERAL_PARAMETER.name); |
+ declaredNames.remove(StrongModeCode.TOP_LEVEL_IDENTIFIER_NO_TYPE.name); |
+ declaredNames.remove(StrongModeCode.TOP_LEVEL_INSTANCE_GETTER.name); |
+ declaredNames.remove(StrongModeCode.TOP_LEVEL_TYPE_ARGUMENTS.name); |
+ declaredNames.remove(StrongModeCode.TOP_LEVEL_UNSUPPORTED.name); |
+ declaredNames |
+ .remove(StrongModeCode.UNSAFE_BLOCK_CLOSURE_INFERENCE.name); |
+ } else if (errorType == TodoCode) { |
+ declaredNames.remove('TODO_REGEX'); |
+ } |
+ |
+ // Assert that all remaining declared names are in errorCodeValues |
+ |
+ for (String declaredName in declaredNames) { |
+ ++totalCount; |
+ if (!listedNames.contains(declaredName)) { |
+ ++missingErrorCodeCount; |
+ print(' errorCodeValues is missing $errorType $declaredName'); |
+ } |
+ } |
+ }); |
+ expect(missingErrorCodeCount, 0, reason: 'missing error code names'); |
+ |
+ // Apparently, duplicate error codes are allowed |
+ // expect( |
+ // ErrorFilterOptionValidator.errorCodes.length, |
+ // errorCodeValues.length, |
+ // reason: 'some errorCodeValues have the same name', |
+ // ); |
+ } |
+} |
+ |
+@reflectiveTest |
class GenerateNewOptionsErrorsTaskTest extends GenerateOptionsErrorsTaskTest { |
String get optionsFilePath => '/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}'; |
} |