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

Unified Diff: pkg/analyzer/test/src/task/options_test.dart

Issue 2932483002: update errorCodeValues (Closed)
Patch Set: Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/error/error.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..f7e543fd03ef67ccfec121e5c024a29b0c365a35 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(ErrorFilterOptionValidatorTest);
defineReflectiveTests(GenerateNewOptionsErrorsTaskTest);
defineReflectiveTests(GenerateOldOptionsErrorsTaskTest);
defineReflectiveTests(OptionsFileValidatorTest);
@@ -142,6 +145,111 @@ analyzer:
}
@reflectiveTest
+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.
+ 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('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.
+ } else if (errorType == AnalysisOptionsWarningCode) {
+ declaredNames.remove('INCLUDE_FILE_NOT_FOUND');
+ declaredNames.remove('INCLUDED_FILE_WARNING');
+ } else if (errorType == StaticWarningCode) {
+ declaredNames.remove('FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS');
+ } else if (errorType == StrongModeCode) {
+ declaredNames.remove('DOWN_CAST_COMPOSITE');
+ declaredNames.remove('DOWN_CAST_IMPLICIT');
+ declaredNames.remove('DOWN_CAST_IMPLICIT_ASSIGN');
+ declaredNames.remove('DYNAMIC_CAST');
+ declaredNames.remove('ASSIGNMENT_CAST');
+ declaredNames.remove('INVALID_PARAMETER_DECLARATION');
+ declaredNames.remove('COULD_NOT_INFER');
+ declaredNames.remove('INFERRED_TYPE');
+ declaredNames.remove('INFERRED_TYPE_LITERAL');
+ declaredNames.remove('INFERRED_TYPE_ALLOCATION');
+ declaredNames.remove('INFERRED_TYPE_CLOSURE');
+ declaredNames.remove('INVALID_CAST_LITERAL');
+ declaredNames.remove('INVALID_CAST_LITERAL_LIST');
+ declaredNames.remove('INVALID_CAST_LITERAL_MAP');
+ declaredNames.remove('INVALID_CAST_FUNCTION_EXPR');
+ declaredNames.remove('INVALID_CAST_NEW_EXPR');
+ declaredNames.remove('INVALID_CAST_METHOD');
+ declaredNames.remove('INVALID_CAST_FUNCTION');
+ declaredNames.remove('INVALID_SUPER_INVOCATION');
+ declaredNames.remove('NON_GROUND_TYPE_CHECK_INFO');
+ declaredNames.remove('DYNAMIC_INVOKE');
+ declaredNames.remove('INVALID_METHOD_OVERRIDE');
+ declaredNames.remove('INVALID_METHOD_OVERRIDE_FROM_BASE');
+ declaredNames.remove('INVALID_METHOD_OVERRIDE_FROM_MIXIN');
+ declaredNames.remove('INVALID_FIELD_OVERRIDE');
+ declaredNames.remove('IMPLICIT_DYNAMIC_PARAMETER');
+ declaredNames.remove('IMPLICIT_DYNAMIC_RETURN');
+ declaredNames.remove('IMPLICIT_DYNAMIC_VARIABLE');
+ declaredNames.remove('IMPLICIT_DYNAMIC_FIELD');
+ declaredNames.remove('IMPLICIT_DYNAMIC_TYPE');
+ declaredNames.remove('IMPLICIT_DYNAMIC_LIST_LITERAL');
+ declaredNames.remove('IMPLICIT_DYNAMIC_MAP_LITERAL');
+ declaredNames.remove('IMPLICIT_DYNAMIC_FUNCTION');
+ declaredNames.remove('IMPLICIT_DYNAMIC_METHOD');
+ declaredNames.remove('IMPLICIT_DYNAMIC_INVOKE');
+ declaredNames.remove('NO_DEFAULT_BOUNDS');
+ declaredNames.remove('NOT_INSTANTIATED_BOUND');
+ declaredNames.remove('TOP_LEVEL_CYCLE');
+ declaredNames.remove('TOP_LEVEL_FUNCTION_LITERAL_BLOCK');
+ declaredNames.remove('TOP_LEVEL_FUNCTION_LITERAL_PARAMETER');
+ declaredNames.remove('TOP_LEVEL_IDENTIFIER_NO_TYPE');
+ declaredNames.remove('TOP_LEVEL_INSTANCE_GETTER');
+ declaredNames.remove('TOP_LEVEL_TYPE_ARGUMENTS');
+ declaredNames.remove('TOP_LEVEL_UNSUPPORTED');
+ declaredNames.remove('UNSAFE_BLOCK_CLOSURE_INFERENCE');
+ } 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}';
}
« no previous file with comments | « pkg/analyzer/lib/error/error.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698