Index: pkg/analyzer/test/source/error_processor_test.dart |
diff --git a/pkg/analyzer/test/source/error_processor_test.dart b/pkg/analyzer/test/source/error_processor_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3c3facbdc62fb50dc132a8b29cdf23e23cdaaa26 |
--- /dev/null |
+++ b/pkg/analyzer/test/source/error_processor_test.dart |
@@ -0,0 +1,150 @@ |
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+library analyzer.test.source.error_processor; |
+ |
+import 'package:analyzer/source/analysis_options_provider.dart'; |
+import 'package:analyzer/source/error_processor.dart'; |
+import 'package:analyzer/src/context/context.dart'; |
+import 'package:analyzer/src/generated/engine.dart'; |
+import 'package:analyzer/src/generated/error.dart'; |
+import 'package:analyzer/src/task/options.dart'; |
+import 'package:plugin/manager.dart'; |
+import 'package:plugin/plugin.dart'; |
+import 'package:unittest/unittest.dart'; |
+import 'package:yaml/src/yaml_node.dart'; |
+ |
+import '../generated/test_support.dart'; |
+import '../utils.dart'; |
+ |
+main() { |
+ AnalysisError invalid_assignment = |
+ new AnalysisError(new TestSource(), 0, 1, HintCode.INVALID_ASSIGNMENT, [ |
+ ['x'], |
+ ['y'] |
+ ]); |
+ |
+ AnalysisError missing_return = |
+ new AnalysisError(new TestSource(), 0, 1, HintCode.MISSING_RETURN, [ |
+ ['x'] |
+ ]); |
+ |
+ AnalysisError unused_local_variable = new AnalysisError( |
+ new TestSource(), 0, 1, HintCode.UNUSED_LOCAL_VARIABLE, [ |
+ ['x'] |
+ ]); |
+ |
+ AnalysisError use_of_void_result = |
+ new AnalysisError(new TestSource(), 0, 1, HintCode.USE_OF_VOID_RESULT, [ |
+ ['x'] |
+ ]); |
+ |
+ initializeTestEnvironment(); |
+ oneTimeSetup(); |
+ |
+ setUp(() { |
+ context = new TestContext(); |
+ }); |
+ |
+ group('ErrorProcessorTest', () { |
+ test('configureOptions', () { |
+ configureOptions(''' |
+analyzer: |
+ errors: |
+ invalid_assignment: error # severity ERROR |
+ missing_return: false # ignore |
+ unused_local_variable: true # skipped |
+ use_of_void_result: unsupported_action # skipped |
+'''); |
+ expect(getProcessor(invalid_assignment).severity, ErrorSeverity.ERROR); |
+ expect(getProcessor(missing_return).severity, isNull); |
+ expect(getProcessor(unused_local_variable), isNull); |
+ expect(getProcessor(use_of_void_result), isNull); |
+ }); |
+ }); |
+ |
+ group('ErrorConfigTest', () { |
+ var config = ''' |
+analyzer: |
+ errors: |
+ invalid_assignment: unsupported_action # should be skipped |
+ missing_return: false |
+ unused_local_variable: error |
+'''; |
+ |
+ group('processing', () { |
+ test('yaml map', () { |
+ var options = optionsProvider.getOptionsFromString(config); |
+ var errorConfig = new ErrorConfig(options['analyzer']['errors']); |
+ expect(errorConfig.processors, hasLength(2)); |
+ |
+ // ignore |
+ var missingReturnProcessor = errorConfig.processors |
+ .firstWhere((p) => p.appliesTo(missing_return)); |
+ expect(missingReturnProcessor.severity, isNull); |
+ |
+ // error |
+ var unusedLocalProcessor = errorConfig.processors |
+ .firstWhere((p) => p.appliesTo(unused_local_variable)); |
+ expect(unusedLocalProcessor.severity, ErrorSeverity.ERROR); |
+ |
+ // skip |
+ var invalidAssignmentProcessor = errorConfig.processors.firstWhere( |
+ (p) => p.appliesTo(invalid_assignment), |
+ orElse: () => null); |
+ expect(invalidAssignmentProcessor, isNull); |
+ }); |
+ test('string map', () { |
+ var options = { |
+ 'invalid_assignment': 'unsupported_action', // should be skipped |
+ 'missing_return': 'false', |
+ 'unused_local_variable': 'error' |
+ }; |
+ var errorConfig = new ErrorConfig(options); |
+ expect(errorConfig.processors, hasLength(2)); |
+ |
+ // ignore |
+ var missingReturnProcessor = errorConfig.processors |
+ .firstWhere((p) => p.appliesTo(missing_return)); |
+ expect(missingReturnProcessor.severity, isNull); |
+ |
+ // error |
+ var unusedLocalProcessor = errorConfig.processors |
+ .firstWhere((p) => p.appliesTo(unused_local_variable)); |
+ expect(unusedLocalProcessor.severity, ErrorSeverity.ERROR); |
+ |
+ // skip |
+ var invalidAssignmentProcessor = errorConfig.processors.firstWhere( |
+ (p) => p.appliesTo(invalid_assignment), |
+ orElse: () => null); |
+ expect(invalidAssignmentProcessor, isNull); |
+ }); |
+ }); |
+ }); |
+} |
+ |
+TestContext context; |
+ |
+AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider(); |
+ErrorProcessor processor; |
+ |
+void configureOptions(String options) { |
+ Map<String, YamlNode> optionMap = |
+ optionsProvider.getOptionsFromString(options); |
+ configureContextOptions(context, optionMap); |
+} |
+ |
+ErrorProcessor getProcessor(AnalysisError error) => |
+ ErrorProcessor.getProcessor(context, error); |
+ |
+void oneTimeSetup() { |
+ List<Plugin> plugins = <Plugin>[]; |
+ plugins.addAll(AnalysisEngine.instance.requiredPlugins); |
+ plugins.add(AnalysisEngine.instance.commandLinePlugin); |
+ plugins.add(AnalysisEngine.instance.optionsPlugin); |
+ ExtensionManager manager = new ExtensionManager(); |
+ manager.processPlugins(plugins); |
+} |
+ |
+class TestContext extends AnalysisContextImpl {} |