@@ -18,15 +18,15 @@ import 'package:meta/meta.dart';
18
18
// once it is loaded you can call `M-x coverlay-display-stats` to get a summary
19
19
// of the files to look at.)
20
20
21
- // Please update these targets when you update this package.
22
- // Please ensure that test coverage continues to be 100%.
23
- // Don't forget to update the lastUpdate date too!
24
- const int targetLines = 3333 ;
25
- const String targetPercent = '100' ;
26
- const String lastUpdate = '2024-02-26' ;
21
+ // If Dart coverage increases the number of lines that could be covered, it is
22
+ // possible that this package will no longer report 100% coverage even though
23
+ // nothing has changed about the package itself. In the event that that happens,
24
+ // set this constant to the number of lines currently being covered and file a
25
+ // bug, cc'ing the current package owner (Hixie) so that they can add more tests.
26
+ const int ? targetLines = null ;
27
27
28
28
@immutable
29
- /* final */ class LcovLine {
29
+ final class LcovLine {
30
30
const LcovLine (this .filename, this .line);
31
31
final String filename;
32
32
final int line;
@@ -161,53 +161,42 @@ Future<void> main(List<String> arguments) async {
161
161
final String coveredPercent =
162
162
(100.0 * coveredLines / totalLines).toStringAsFixed (1 );
163
163
164
- // We only check the TARGET_LINES matches, not the TARGET_PERCENT,
165
- // because we expect the percentage to drop over time as Dart fixes
166
- // various bugs in how it determines what lines are coverable.
167
- if (coveredLines < targetLines && targetLines <= totalLines) {
164
+ if (targetLines != null ) {
165
+ if (targetLines! < totalLines) {
166
+ print (
167
+ 'Warning: test_coverage has an override set to reduce the expected number of covered lines from $totalLines to $targetLines .\n '
168
+ 'New tests should be written to cover all lines in the package.' ,
169
+ );
170
+ totalLines = targetLines! ;
171
+ } else if (targetLines == totalLines) {
172
+ print (
173
+ 'Warning: test_coverage has a redundant targetLines; it is equal to the actual number of coverable lines ($totalLines ).\n '
174
+ 'Update test_coverage.dart to set the targetLines constant to null.' ,
175
+ );
176
+ } else {
177
+ print (
178
+ 'Warning: test_coverage has an outdated targetLines ($targetLines ) that is above the total number of lines in the package ($totalLines ).\n '
179
+ 'Update test_coverage.dart to set the targetLines constant to null.' ,
180
+ );
181
+ }
182
+ }
183
+
184
+ if (coveredLines < totalLines) {
168
185
print ('' );
169
186
print (' ╭──────────────────────────────╮' );
170
187
print (' │ COVERAGE REGRESSION DETECTED │' );
171
188
print (' ╰──────────────────────────────╯' );
172
189
print ('' );
173
190
print (
174
- 'Coverage has reduced to only $coveredLines lines ($coveredPercent %). This is lower than' ,
175
- );
176
- print (
177
- 'it was as of $lastUpdate , when coverage was $targetPercent %, covering $targetLines lines.' ,
178
- );
179
- print (
180
- 'Please add sufficient tests to get coverage back to 100%, and update' ,
181
- );
182
- print (
183
- 'test_coverage/bin/test_coverage.dart to have the appropriate targets.' ,
191
+ 'Coverage has reduced to only $coveredLines lines ($coveredPercent %), out\n '
192
+ 'of $totalLines total lines; ${totalLines - coveredLines } lines are not covered by tests.\n '
193
+ 'Please add sufficient tests to get coverage back to 100%.' ,
184
194
);
185
195
print ('' );
186
196
print (
187
197
'When in doubt, ask @Hixie for advice. Thanks!' ,
188
198
);
189
199
exit (1 );
190
- } else {
191
- if (coveredLines < totalLines) {
192
- print (
193
- 'Warning: Coverage of package:rfw is no longer 100%. (Coverage is now $coveredPercent %, $coveredLines /$totalLines lines.)' ,
194
- );
195
- }
196
- if (coveredLines > targetLines) {
197
- print (
198
- 'Total lines of covered code has increased, and coverage script is now out of date.\n '
199
- 'Coverage is now $coveredPercent %, $coveredLines /$totalLines lines, whereas previously there were only $targetLines lines.\n '
200
- 'Update the "targetLines" constant at the top of rfw/test_coverage/bin/test_coverage.dart (to $coveredLines ).' ,
201
- );
202
- }
203
- if (targetLines > totalLines) {
204
- print (
205
- 'Total lines of code has reduced, and coverage script is now out of date.\n '
206
- 'Coverage is now $coveredPercent %, $coveredLines /$totalLines lines, but previously there were $targetLines lines.\n '
207
- 'Update the "targetLines" constant at the top of rfw/test_coverage/bin/test_coverage.dart (to $totalLines ).' ,
208
- );
209
- exit (1 );
210
- }
211
200
}
212
201
213
202
coverageDirectory.deleteSync (recursive: true );
0 commit comments