2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
+ // ignore_for_file: unnecessary_this
6
+
5
7
import 'package:glob/glob.dart' ;
6
8
import 'package:path/path.dart' as p;
7
9
@@ -78,26 +80,27 @@ extension FileHitMapsFormatter on Map<String, HitMap> {
78
80
String ? basePath,
79
81
List <String >? reportOn,
80
82
Set <Glob >? ignoreGlobs,
83
+ bool Function (String path)? includeUncovered,
81
84
}) {
82
85
final pathFilter = _getPathFilter (
83
86
reportOn: reportOn,
84
87
ignoreGlobs: ignoreGlobs,
85
88
);
86
89
final buf = StringBuffer ();
90
+
91
+ // Get all Dart files in the project
92
+ final allDartFiles = resolver.listAllDartFiles ().toSet ();
93
+ final coveredFiles = this .keys.toSet ();
94
+ final uncoveredFiles = allDartFiles.difference (coveredFiles);
95
+
87
96
for (final entry in entries) {
88
97
final v = entry.value;
89
98
final lineHits = v.lineHits;
90
99
final funcHits = v.funcHits;
91
100
final funcNames = v.funcNames;
92
101
final branchHits = v.branchHits;
93
102
var source = resolver.resolve (entry.key);
94
- if (source == null ) {
95
- continue ;
96
- }
97
-
98
- if (! pathFilter (source)) {
99
- continue ;
100
- }
103
+ if (source == null || ! pathFilter (source)) continue ;
101
104
102
105
if (basePath != null ) {
103
106
source = p.relative (source, from: basePath);
@@ -129,6 +132,21 @@ extension FileHitMapsFormatter on Map<String, HitMap> {
129
132
buf.write ('end_of_record\n ' );
130
133
}
131
134
135
+ // Add uncovered files if allowed
136
+ for (final file in uncoveredFiles) {
137
+ if (includeUncovered != null && ! includeUncovered (file)) continue ;
138
+ var source = resolver.resolve (file);
139
+ if (source == null || ! pathFilter (source)) continue ;
140
+ if (basePath != null ) {
141
+ source = p.relative (source, from: basePath);
142
+ }
143
+
144
+ buf.write ('SF:$source \n ' );
145
+ buf.write ('LF:0\n ' );
146
+ buf.write ('LH:0\n ' );
147
+ buf.write ('end_of_record\n ' );
148
+ }
149
+
132
150
return buf.toString ();
133
151
}
134
152
@@ -144,12 +162,19 @@ extension FileHitMapsFormatter on Map<String, HitMap> {
144
162
Set <Glob >? ignoreGlobs,
145
163
bool reportFuncs = false ,
146
164
bool reportBranches = false ,
165
+ bool Function (String path)? includeUncovered,
147
166
}) async {
148
167
final pathFilter = _getPathFilter (
149
168
reportOn: reportOn,
150
169
ignoreGlobs: ignoreGlobs,
151
170
);
152
171
final buf = StringBuffer ();
172
+
173
+ // Get all Dart files in the project
174
+ final allDartFiles = resolver.listAllDartFiles ().toSet ();
175
+ final coveredFiles = this .keys.toSet ();
176
+ final uncoveredFiles = allDartFiles.difference (coveredFiles);
177
+
153
178
for (final entry in entries) {
154
179
final v = entry.value;
155
180
if (reportFuncs && v.funcHits == null ) {
@@ -171,18 +196,10 @@ extension FileHitMapsFormatter on Map<String, HitMap> {
171
196
? v.branchHits!
172
197
: v.lineHits;
173
198
final source = resolver.resolve (entry.key);
174
- if (source == null ) {
175
- continue ;
176
- }
177
-
178
- if (! pathFilter (source)) {
179
- continue ;
180
- }
199
+ if (source == null || ! pathFilter (source)) continue ;
181
200
182
201
final lines = await loader.load (source);
183
- if (lines == null ) {
184
- continue ;
185
- }
202
+ if (lines == null ) continue ;
186
203
buf.writeln (source);
187
204
for (var line = 1 ; line <= lines.length; line++ ) {
188
205
var prefix = _prefix;
@@ -193,6 +210,20 @@ extension FileHitMapsFormatter on Map<String, HitMap> {
193
210
}
194
211
}
195
212
213
+ // Add uncovered files if allowed
214
+ for (final file in uncoveredFiles) {
215
+ if (includeUncovered != null && ! includeUncovered (file)) continue ;
216
+ final source = resolver.resolve (file);
217
+ if (source == null || ! pathFilter (source)) continue ;
218
+
219
+ final lines = await loader.load (source);
220
+ if (lines == null ) continue ;
221
+ buf.writeln (source);
222
+ for (final line in lines) {
223
+ buf.writeln (' |$line ' );
224
+ }
225
+ }
226
+
196
227
return buf.toString ();
197
228
}
198
229
}
@@ -221,3 +252,4 @@ _PathFilter _getPathFilter({List<String>? reportOn, Set<Glob>? ignoreGlobs}) {
221
252
return true ;
222
253
};
223
254
}
255
+
0 commit comments