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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library analyzer.test.source.error_processor;
6
7 import 'package:analyzer/source/analysis_options_provider.dart';
8 import 'package:analyzer/source/error_processor.dart';
9 import 'package:analyzer/src/context/context.dart';
10 import 'package:analyzer/src/generated/engine.dart';
11 import 'package:analyzer/src/generated/error.dart';
12 import 'package:analyzer/src/task/options.dart';
13 import 'package:plugin/manager.dart';
14 import 'package:plugin/plugin.dart';
15 import 'package:unittest/unittest.dart';
16 import 'package:yaml/src/yaml_node.dart';
17
18 import '../generated/test_support.dart';
19 import '../utils.dart';
20
21 main() {
22 AnalysisError invalid_assignment =
23 new AnalysisError(new TestSource(), 0, 1, HintCode.INVALID_ASSIGNMENT, [
24 ['x'],
25 ['y']
26 ]);
27
28 AnalysisError missing_return =
29 new AnalysisError(new TestSource(), 0, 1, HintCode.MISSING_RETURN, [
30 ['x']
31 ]);
32
33 AnalysisError unused_local_variable = new AnalysisError(
34 new TestSource(), 0, 1, HintCode.UNUSED_LOCAL_VARIABLE, [
35 ['x']
36 ]);
37
38 AnalysisError use_of_void_result =
39 new AnalysisError(new TestSource(), 0, 1, HintCode.USE_OF_VOID_RESULT, [
40 ['x']
41 ]);
42
43 initializeTestEnvironment();
44 oneTimeSetup();
45
46 setUp(() {
47 context = new TestContext();
48 });
49
50 group('ErrorProcessorTest', () {
51 test('configureOptions', () {
52 configureOptions('''
53 analyzer:
54 errors:
55 invalid_assignment: error # severity ERROR
56 missing_return: false # ignore
57 unused_local_variable: true # skipped
58 use_of_void_result: unsupported_action # skipped
59 ''');
60 expect(getProcessor(invalid_assignment).severity, ErrorSeverity.ERROR);
61 expect(getProcessor(missing_return).severity, isNull);
62 expect(getProcessor(unused_local_variable), isNull);
63 expect(getProcessor(use_of_void_result), isNull);
64 });
65 });
66
67 group('ErrorConfigTest', () {
68 var config = '''
69 analyzer:
70 errors:
71 invalid_assignment: unsupported_action # should be skipped
72 missing_return: false
73 unused_local_variable: error
74 ''';
75
76 group('processing', () {
77 test('yaml map', () {
78 var options = optionsProvider.getOptionsFromString(config);
79 var errorConfig = new ErrorConfig(options['analyzer']['errors']);
80 expect(errorConfig.processors, hasLength(2));
81
82 // ignore
83 var missingReturnProcessor = errorConfig.processors
84 .firstWhere((p) => p.appliesTo(missing_return));
85 expect(missingReturnProcessor.severity, isNull);
86
87 // error
88 var unusedLocalProcessor = errorConfig.processors
89 .firstWhere((p) => p.appliesTo(unused_local_variable));
90 expect(unusedLocalProcessor.severity, ErrorSeverity.ERROR);
91
92 // skip
93 var invalidAssignmentProcessor = errorConfig.processors.firstWhere(
94 (p) => p.appliesTo(invalid_assignment),
95 orElse: () => null);
96 expect(invalidAssignmentProcessor, isNull);
97 });
98 test('string map', () {
99 var options = {
100 'invalid_assignment': 'unsupported_action', // should be skipped
101 'missing_return': 'false',
102 'unused_local_variable': 'error'
103 };
104 var errorConfig = new ErrorConfig(options);
105 expect(errorConfig.processors, hasLength(2));
106
107 // ignore
108 var missingReturnProcessor = errorConfig.processors
109 .firstWhere((p) => p.appliesTo(missing_return));
110 expect(missingReturnProcessor.severity, isNull);
111
112 // error
113 var unusedLocalProcessor = errorConfig.processors
114 .firstWhere((p) => p.appliesTo(unused_local_variable));
115 expect(unusedLocalProcessor.severity, ErrorSeverity.ERROR);
116
117 // skip
118 var invalidAssignmentProcessor = errorConfig.processors.firstWhere(
119 (p) => p.appliesTo(invalid_assignment),
120 orElse: () => null);
121 expect(invalidAssignmentProcessor, isNull);
122 });
123 });
124 });
125 }
126
127 TestContext context;
128
129 AnalysisOptionsProvider optionsProvider = new AnalysisOptionsProvider();
130 ErrorProcessor processor;
131
132 void configureOptions(String options) {
133 Map<String, YamlNode> optionMap =
134 optionsProvider.getOptionsFromString(options);
135 configureContextOptions(context, optionMap);
136 }
137
138 ErrorProcessor getProcessor(AnalysisError error) =>
139 ErrorProcessor.getProcessor(context, error);
140
141 void oneTimeSetup() {
142 List<Plugin> plugins = <Plugin>[];
143 plugins.addAll(AnalysisEngine.instance.requiredPlugins);
144 plugins.add(AnalysisEngine.instance.commandLinePlugin);
145 plugins.add(AnalysisEngine.instance.optionsPlugin);
146 ExtensionManager manager = new ExtensionManager();
147 manager.processPlugins(plugins);
148 }
149
150 class TestContext extends AnalysisContextImpl {}
OLDNEW
« 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