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
/
unused_files_console_reporter_test.dart
103 lines (81 loc) · 3.01 KB
/
unused_files_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
import 'dart:io';
import 'package:ansicolor/ansicolor.dart';
import 'package:dart_code_metrics/src/analyzers/unused_files_analyzer/models/unused_files_file_report.dart';
import 'package:dart_code_metrics/src/analyzers/unused_files_analyzer/reporters/reporters_list/console/unused_files_console_reporter.dart';
import 'package:dart_code_metrics/src/analyzers/unused_files_analyzer/reporters/unused_files_report_params.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';
class IOSinkMock extends Mock implements IOSink {}
void main() {
group('UnusedFilesConsoleReporter reports', () {
const fullPath = '/home/developer/work/project/example.dart';
late IOSinkMock output; // ignore: close_sinks
late UnusedFilesConsoleReporter reporter;
setUp(() {
output = IOSinkMock();
ansiColorDisabled = false;
reporter = UnusedFilesConsoleReporter(output);
});
group('empty report', () {
test('with congratulate param', () async {
const congratulate = UnusedFilesReportParams(
congratulate: true,
deleteUnusedFiles: false,
);
await reporter.report([], additionalParams: congratulate);
final captured =
verify(() => output.writeln(captureAny())).captured.cast<String>();
expect(
captured,
equals(['\x1B[38;5;20m✔\x1B[0m no unused files found!']),
);
});
test('without congratulate param', () async {
const noCongratulate = UnusedFilesReportParams(
congratulate: false,
deleteUnusedFiles: false,
);
await reporter.report([], additionalParams: noCongratulate);
verifyNever(() => output.writeln(any()));
});
});
group('unused files', () {
test('without deleting flag', () async {
const record =
UnusedFilesFileReport(path: fullPath, relativePath: 'example.dart');
await reporter.report([record]);
final captured =
verify(() => output.writeln(captureAny())).captured.cast<String>();
expect(
captured,
equals([
'\x1B[38;5;180m⚠\x1B[0m unused file: $fullPath',
'',
'\x1B[38;5;167m✖\x1B[0m total unused files - \x1B[38;5;167m1\x1B[0m',
]),
);
});
test('with deleting flag', () async {
const record =
UnusedFilesFileReport(path: fullPath, relativePath: 'example.dart');
await reporter.report(
[record],
additionalParams: const UnusedFilesReportParams(
congratulate: true,
deleteUnusedFiles: true,
),
);
final captured =
verify(() => output.writeln(captureAny())).captured.cast<String>();
expect(
captured,
equals([
'\x1B[38;5;180m⚠\x1B[0m unused file: $fullPath',
'',
'\x1B[38;5;20m✔\x1B[0m \x1B[38;5;167m1\x1B[0m files were successfully deleted',
]),
);
});
});
});
}