@@ -18,15 +18,15 @@ import 'package:meta/meta.dart';
1818// once it is loaded you can call `M-x coverlay-display-stats` to get a summary
1919// of the files to look at.)
2020
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 ;
2727
2828@immutable
29- /* final */ class LcovLine {
29+ final class LcovLine {
3030 const LcovLine (this .filename, this .line);
3131 final String filename;
3232 final int line;
@@ -161,53 +161,42 @@ Future<void> main(List<String> arguments) async {
161161 final String coveredPercent =
162162 (100.0 * coveredLines / totalLines).toStringAsFixed (1 );
163163
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) {
168185 print ('' );
169186 print (' ╭──────────────────────────────╮' );
170187 print (' │ COVERAGE REGRESSION DETECTED │' );
171188 print (' ╰──────────────────────────────╯' );
172189 print ('' );
173190 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%.' ,
184194 );
185195 print ('' );
186196 print (
187197 'When in doubt, ask @Hixie for advice. Thanks!' ,
188198 );
189199 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- }
211200 }
212201
213202 coverageDirectory.deleteSync (recursive: true );
0 commit comments