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_checkstyle_reporter_test.dart
75 lines (61 loc) · 2.73 KB
/
lint_checkstyle_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
import 'dart:io';
import 'package:dart_code_metrics/src/analyzers/lint_analyzer/reporters/reporters_list/checkstyle/lint_checkstyle_reporter.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';
import 'package:xml/xml.dart';
import '../report_example.dart';
class IOSinkMock extends Mock implements IOSink {}
void main() {
group('LintCheckstyleReporter reports in json format', () {
// ignore: close_sinks
late IOSinkMock output;
setUp(() {
output = IOSinkMock();
});
test('empty report', () {
LintCheckstyleReporter(output).report([]);
verifyNever(() => output.write(captureAny()));
});
test('complex report', () {
LintCheckstyleReporter(output).report(testReport, summary: testSummary);
final captured = verify(
() => output.writeln(captureAny()),
).captured.first as String;
final report = XmlDocument.parse(captured);
final file = report.findAllElements('file');
expect(
file.first.getAttribute('name'),
equals('test/resources/abstract_class.dart'),
);
expect(
file.last.getAttribute('name'),
equals('test/resources/class_with_factory_constructors.dart'),
);
var errors = file.first.findAllElements('error').toList();
expect(errors.first.getAttribute('line'), equals('0'));
expect(errors.first.getAttribute('severity'), equals('warning'));
expect(errors.first.getAttribute('message'), equals('metric comment'));
expect(errors.first.getAttribute('source'), equals('file-metric-id'));
expect(errors.last.getAttribute('line'), equals('0'));
expect(errors.last.getAttribute('severity'), equals('error'));
expect(errors.last.getAttribute('message'), equals('metric comment'));
expect(errors.last.getAttribute('source'), equals('id'));
errors = file.last.findAllElements('error').toList();
expect(errors.first.getAttribute('line'), equals('0'));
expect(errors.first.getAttribute('severity'), equals('warning'));
expect(errors.first.getAttribute('message'), equals('simple message'));
expect(errors.first.getAttribute('source'), equals('id'));
expect(errors[1].getAttribute('line'), equals('0'));
expect(errors[1].getAttribute('severity'), equals('info'));
expect(
errors[1].getAttribute('message'),
equals('simple design message'),
);
expect(errors[1].getAttribute('source'), equals('designId'));
expect(errors.last.getAttribute('line'), equals('0'));
expect(errors.last.getAttribute('severity'), equals('warning'));
expect(errors.last.getAttribute('message'), equals('metric comment'));
expect(errors.last.getAttribute('source'), equals('id'));
});
});
}