Skip to content

Commit 10cd61c

Browse files
authored
[rfw] Change test coverage logic to enforce 100% coverage (flutter#6272)
1 parent b5fe05d commit 10cd61c

File tree

5 files changed

+37
-47
lines changed

5 files changed

+37
-47
lines changed

packages/rfw/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## 1.0.24
2+
23
* Adds `InkResponse` material widget.
34
* Adds `Material` material widget.
45
* Adds the `child` to `Opacity` core widget.

packages/rfw/lib/src/flutter/core_widgets.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ Map<String, LocalWidgetBuilder> get _coreWidgetsDefinitions => <String, LocalWid
277277
clipBehavior: ArgumentDecoders.enumValue<Clip>(Clip.values, source, ['clipBehavior']) ?? Clip.antiAlias,
278278
child: source.optionalChild(['child']),
279279
);
280-
},
280+
},
281281

282282
'ColoredBox': (BuildContext context, DataSource source) {
283283
return ColoredBox(

packages/rfw/lib/src/flutter/runtime.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,12 @@ class Runtime extends ChangeNotifier {
249249
///
250250
/// The returned map is an immutable view of the map updated by calls to
251251
/// [update] and [clearLibraries].
252-
///
252+
///
253253
/// The keys are instances [LibraryName] which encode fully qualified library
254254
/// names, and the values are the corresponding [WidgetLibrary]s.
255-
///
255+
///
256256
/// The returned map is an immutable copy of the registered libraries
257-
/// at the time of this call.
257+
/// at the time of this call.
258258
///
259259
/// See also:
260260
///

packages/rfw/test/core_widgets_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ void main() {
293293
'''));
294294
await tester.pump();
295295
expect(find.byType(ClipRRect), findsOneWidget);
296-
final RenderClipRRect renderClip = tester.allRenderObjects.whereType<RenderClipRRect>().first;
296+
final RenderClipRRect renderClip = tester.allRenderObjects.whereType<RenderClipRRect>().first;
297297
expect(renderClip.clipBehavior, equals(Clip.antiAlias));
298298
expect(renderClip.borderRadius, equals(BorderRadius.zero));
299299
});

packages/rfw/test_coverage/bin/test_coverage.dart

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)