This repository has been archived by the owner on Jul 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 258
/
lint_console_reporter_test.dart
137 lines (118 loc) · 4.87 KB
/
lint_console_reporter_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import 'dart:io';
import 'package:ansicolor/ansicolor.dart';
import 'package:dart_code_metrics/src/analyzers/lint_analyzer/reporters/lint_report_params.dart';
import 'package:dart_code_metrics/src/analyzers/lint_analyzer/reporters/reporters_list/console/lint_console_reporter.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';
import '../report_example.dart';
class IOSinkMock extends Mock implements IOSink {}
void main() {
group('LintConsoleReporter reports in plain text format', () {
late IOSinkMock output; // ignore: close_sinks
late IOSinkMock verboseOutput; // ignore: close_sinks
late LintConsoleReporter reporter;
late LintConsoleReporter verboseReporter;
setUp(() {
output = IOSinkMock();
verboseOutput = IOSinkMock();
ansiColorDisabled = false;
reporter = LintConsoleReporter(output);
verboseReporter = LintConsoleReporter(verboseOutput, reportAll: true);
});
group('empty report', () {
test('with congratulate param', () async {
const congratulate = LintReportParams(congratulate: true);
await reporter.report([], additionalParams: congratulate);
await verboseReporter.report([], additionalParams: congratulate);
final captured =
verify(() => output.writeln(captureAny())).captured.cast<String>();
final capturedVerbose =
verify(() => verboseOutput.writeln(captureAny()))
.captured
.cast<String>();
expect(captured, equals(['\x1B[38;5;20m✔\x1B[0m no issues found!']));
expect(capturedVerbose, equals(captured));
});
test('without congratulate param', () async {
const noCongratulate = LintReportParams(congratulate: false);
await reporter.report([], additionalParams: noCongratulate);
await verboseReporter.report([], additionalParams: noCongratulate);
verifyNever(() => output.writeln(any()));
verifyNever(() => verboseOutput.writeln(any()));
});
});
test('complex report', () async {
await reporter.report(testReport);
await verboseReporter.report(testReport);
final captured = verify(
() => output.writeln(captureAny()),
).captured.cast<String>();
final capturedVerbose = verify(
() => verboseOutput.writeln(captureAny()),
).captured.cast<String>();
expect(
captured,
equals(
[
'test/resources/abstract_class.dart:',
'\x1B[38;5;180mWARNING \x1B[0mmetric1: \x1B[38;5;180m100 units\x1B[0m',
'',
'\x1B[38;5;167mALARM \x1B[0mclass.constructor',
' metric2: \x1B[38;5;167m10\x1B[0m',
'',
'',
'test/resources/class_with_factory_constructors.dart:',
'\x1B[38;5;180mWARNING \x1B[0msimple message',
' at \x1B[38;5;39mtest/resources/class_with_factory_constructors.dart:0:0\x1B[0m',
' id : https://documentation.com',
'',
'\x1B[38;5;20mSTYLE \x1B[0msimple design message',
' at \x1B[38;5;39mtest/resources/class_with_factory_constructors.dart:0:0\x1B[0m',
' designId : https://documentation.com',
'',
'\x1B[38;5;180mWARNING \x1B[0mfunction',
' metric4: \x1B[38;5;180m5 units\x1B[0m',
'',
'',
],
),
);
expect(
capturedVerbose,
equals(
[
'test/resources/abstract_class.dart:',
'\x1B[38;5;180mWARNING \x1B[0mmetric1: \x1B[38;5;180m100 units\x1B[0m',
'',
'\x1B[38;5;7mNONE \x1B[0mclass',
' metric1: \x1B[38;5;7m0\x1B[0m',
'',
'\x1B[38;5;167mALARM \x1B[0mclass.constructor',
' metric2: \x1B[38;5;167m10\x1B[0m',
'',
'\x1B[38;5;7mNONE \x1B[0mclass.method',
' metric3: \x1B[38;5;7m1\x1B[0m',
'',
'',
'test/resources/class_with_factory_constructors.dart:',
'\x1B[38;5;7mNONE \x1B[0mmetric1: \x1B[38;5;7m0\x1B[0m',
' metric2: \x1B[38;5;7m1\x1B[0m',
'',
'\x1B[38;5;180mWARNING \x1B[0msimple message',
' at \x1B[38;5;39mtest/resources/class_with_factory_constructors.dart:0:0\x1B[0m',
' id : https://documentation.com',
'',
'\x1B[38;5;20mSTYLE \x1B[0msimple design message',
' at \x1B[38;5;39mtest/resources/class_with_factory_constructors.dart:0:0\x1B[0m',
' designId : https://documentation.com',
'',
'\x1B[38;5;180mWARNING \x1B[0mfunction',
' metric4: \x1B[38;5;180m5 units\x1B[0m',
'',
'',
],
),
);
});
});
}