-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathparse_all_coverage.dart
More file actions
53 lines (48 loc) · 1.38 KB
/
parse_all_coverage.dart
File metadata and controls
53 lines (48 loc) · 1.38 KB
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
// ignore_for_file: avoid_print
import 'dart:io';
void main() {
final file = File('coverage/lcov.info');
if (!file.existsSync()) {
print('lcov.info not found');
return;
}
final lines = file.readAsLinesSync();
String? currentFile;
int foundLines = 0;
int hitLines = 0;
final results = <Map<String, dynamic>>[];
for (final line in lines) {
if (line.startsWith('SF:')) {
currentFile = line.substring(3);
} else if (line.startsWith('LF:')) {
foundLines = int.parse(line.substring(3));
} else if (line.startsWith('LH:')) {
hitLines = int.parse(line.substring(3));
if (foundLines > 0) {
final percentage = (hitLines / foundLines * 100);
results.add({
'file': currentFile,
'percentage': percentage,
'hit': hitLines,
'total': foundLines,
});
}
}
}
results.sort(
(a, b) => (a['percentage'] as num).compareTo(b['percentage'] as num),
);
print('### Global Coverage Report (Sorted by lowest first) ###');
for (var res in results) {
// Skip autogenerated files
final fileName = res['file'] as String;
if (fileName.contains('.pb.') ||
fileName.contains('.g.dart') ||
fileName.contains('.mocks.dart')) {
continue;
}
print(
'${res['percentage'].toStringAsFixed(2)}% (${res['hit']}/${res['total']}) - ${res['file']}',
);
}
}