Skip to content

Commit 4b2bbb6

Browse files
feat: add analysis options tests related to errors severities
1 parent d9e8ff1 commit 4b2bbb6

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
import 'dart:convert';
2+
import 'dart:io';
3+
4+
import 'package:analyzer/error/error.dart';
5+
import 'package:test/test.dart';
6+
7+
import 'cli_process_test.dart';
8+
import 'create_project.dart';
9+
import 'peer_project_meta.dart';
10+
11+
void main() {
12+
group('Errors severities override', () {
13+
Future<ProcessResult> runProcess(String workingDirectoryPath) async =>
14+
Process.run(
15+
'dart',
16+
[customLintBinPath],
17+
workingDirectory: workingDirectoryPath,
18+
stdoutEncoding: utf8,
19+
stderrEncoding: utf8,
20+
);
21+
22+
Directory createLintUsageWith({
23+
required Uri pluginUri,
24+
required String analysisOptions,
25+
}) =>
26+
createLintUsage(
27+
name: 'test_app',
28+
source: {'lib/main.dart': 'void fn() {}'},
29+
plugins: {'test_lint': pluginUri},
30+
analysisOptions: analysisOptions,
31+
);
32+
33+
Directory createTestPlugin({
34+
ErrorSeverity errorSeverity = ErrorSeverity.INFO,
35+
}) =>
36+
createPlugin(
37+
name: 'test_lint',
38+
main: createPluginSource([
39+
TestLintRule(
40+
code: 'test_lint',
41+
message: 'Test lint message',
42+
errorSeverity: errorSeverity,
43+
),
44+
]),
45+
);
46+
test('correctly applies error severity from analysis_options.yaml',
47+
() async {
48+
final plugin = createTestPlugin(errorSeverity: ErrorSeverity.ERROR);
49+
50+
final app = createLintUsageWith(
51+
pluginUri: plugin.uri,
52+
analysisOptions: '''
53+
custom_lint:
54+
errors:
55+
test_lint: error
56+
''',
57+
);
58+
59+
final process = await runProcess(app.path);
60+
61+
expect(trimDependencyOverridesWarning(process.stderr), isEmpty);
62+
expect(process.stdout, '''
63+
Analyzing...
64+
65+
lib/main.dart:1:6 • Test lint message • test_lint • ERROR
66+
67+
1 issue found.
68+
''');
69+
expect(process.exitCode, 1);
70+
});
71+
72+
test('correctly applies warning severity from analysis_options.yaml',
73+
() async {
74+
final plugin = createTestPlugin();
75+
76+
final app = createLintUsageWith(
77+
pluginUri: plugin.uri,
78+
analysisOptions: '''
79+
custom_lint:
80+
errors:
81+
test_lint: warning
82+
''',
83+
);
84+
85+
final process = await runProcess(app.path);
86+
87+
expect(trimDependencyOverridesWarning(process.stderr), isEmpty);
88+
expect(process.stdout, '''
89+
Analyzing...
90+
91+
lib/main.dart:1:6 • Test lint message • test_lint • WARNING
92+
93+
1 issue found.
94+
''');
95+
expect(process.exitCode, 1);
96+
});
97+
98+
test('correctly applies info severity from analysis_options.yaml',
99+
() async {
100+
final plugin = createTestPlugin();
101+
102+
final app = createLintUsageWith(
103+
pluginUri: plugin.uri,
104+
analysisOptions: '''
105+
custom_lint:
106+
errors:
107+
test_lint: info
108+
''',
109+
);
110+
111+
final process = await runProcess(app.path);
112+
113+
expect(trimDependencyOverridesWarning(process.stderr), isEmpty);
114+
expect(process.stdout, '''
115+
Analyzing...
116+
117+
lib/main.dart:1:6 • Test lint message • test_lint • INFO
118+
119+
1 issue found.
120+
''');
121+
expect(process.exitCode, 1);
122+
});
123+
124+
test('correctly applies none severity from analysis_options.yaml',
125+
() async {
126+
final plugin = createTestPlugin();
127+
128+
final app = createLintUsageWith(
129+
pluginUri: plugin.uri,
130+
analysisOptions: '''
131+
custom_lint:
132+
errors:
133+
test_lint: none
134+
''',
135+
);
136+
137+
final process = await runProcess(app.path);
138+
139+
expect(trimDependencyOverridesWarning(process.stderr), isEmpty);
140+
expect(process.stdout, '''
141+
Analyzing...
142+
143+
No issues found!
144+
''');
145+
expect(process.exitCode, 0);
146+
});
147+
});
148+
}

packages/custom_lint/test/create_project.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ Directory createLintUsage({
219219
Directory? parent,
220220
Map<String, Uri> plugins = const {},
221221
Map<String, String> source = const {},
222+
String? analysisOptions,
222223
Map<String, Uri> extraPackageConfig = const {},
223224
bool installAsDevDependency = true,
224225
required String name,
@@ -239,6 +240,7 @@ analyzer:
239240
plugins:
240241
- custom_lint
241242
243+
${analysisOptions ?? ''}
242244
''',
243245
pubspec: '''
244246
name: $name

0 commit comments

Comments
 (0)