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

Unified Diff: pkg/analyzer/test/source/error_processor_test.dart

Issue 1517723002: Server custom error severity support (#24452). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: lib_renames Created 5 years 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/src/task/options.dart ('k') | pkg/analyzer/test/source/test_all.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {}
« no previous file with comments | « pkg/analyzer/lib/src/task/options.dart ('k') | pkg/analyzer/test/source/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698