Skip to content

Commit

Permalink
Change test coverage logic to enforce 100% coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Hixie committed Mar 5, 2024
1 parent 4200177 commit 7aca5dc
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 47 deletions.
1 change: 1 addition & 0 deletions packages/rfw/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## 1.0.24

* Adds `InkResponse` material widget.
* Adds `Material` material widget.
* Adds the `child` to `Opacity` core widget.
Expand Down
2 changes: 1 addition & 1 deletion packages/rfw/lib/src/flutter/core_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ Map<String, LocalWidgetBuilder> get _coreWidgetsDefinitions => <String, LocalWid
clipBehavior: ArgumentDecoders.enumValue<Clip>(Clip.values, source, ['clipBehavior']) ?? Clip.antiAlias,
child: source.optionalChild(['child']),
);
},
},

'ColoredBox': (BuildContext context, DataSource source) {
return ColoredBox(
Expand Down
6 changes: 3 additions & 3 deletions packages/rfw/lib/src/flutter/runtime.dart
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,12 @@ class Runtime extends ChangeNotifier {
///
/// The returned map is an immutable view of the map updated by calls to
/// [update] and [clearLibraries].
///
///
/// The keys are instances [LibraryName] which encode fully qualified library
/// names, and the values are the corresponding [WidgetLibrary]s.
///
///
/// The returned map is an immutable copy of the registered libraries
/// at the time of this call.
/// at the time of this call.
///
/// See also:
///
Expand Down
2 changes: 1 addition & 1 deletion packages/rfw/test/core_widgets_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ void main() {
'''));
await tester.pump();
expect(find.byType(ClipRRect), findsOneWidget);
final RenderClipRRect renderClip = tester.allRenderObjects.whereType<RenderClipRRect>().first;
final RenderClipRRect renderClip = tester.allRenderObjects.whereType<RenderClipRRect>().first;
expect(renderClip.clipBehavior, equals(Clip.antiAlias));
expect(renderClip.borderRadius, equals(BorderRadius.zero));
});
Expand Down
73 changes: 31 additions & 42 deletions packages/rfw/test_coverage/bin/test_coverage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import 'package:meta/meta.dart';
// once it is loaded you can call `M-x coverlay-display-stats` to get a summary
// of the files to look at.)

// Please update these targets when you update this package.
// Please ensure that test coverage continues to be 100%.
// Don't forget to update the lastUpdate date too!
const int targetLines = 3333;
const String targetPercent = '100';
const String lastUpdate = '2024-02-26';
// If Dart coverage increases the number of lines that could be covered, it is
// possible that this package will no longer report 100% coverage even though
// nothing has changed about the package itself. In the event that that happens,
// set this constant to the number of lines currently being covered and file a
// bug, cc'ing the current package owner (Hixie) so that they can add more tests.
const int? targetLines = null;

@immutable
/* final */ class LcovLine {
final class LcovLine {
const LcovLine(this.filename, this.line);
final String filename;
final int line;
Expand Down Expand Up @@ -161,53 +161,42 @@ Future<void> main(List<String> arguments) async {
final String coveredPercent =
(100.0 * coveredLines / totalLines).toStringAsFixed(1);

// We only check the TARGET_LINES matches, not the TARGET_PERCENT,
// because we expect the percentage to drop over time as Dart fixes
// various bugs in how it determines what lines are coverable.
if (coveredLines < targetLines && targetLines <= totalLines) {
if (targetLines != null) {
if (targetLines! < totalLines) {
print(
'Warning: test_coverage has an override set to reduce the expected number of covered lines from $totalLines to $targetLines.\n'
'New tests should be written to cover all lines in the package.'
);
totalLines = targetLines!;
} else if (targetLines == totalLines) {
print(
'Warning: test_coverage has a redundant targetLines; it is equal to the actual number of coverable lines ($totalLines).\n'
'Update test_coverage.dart to set the targetLines constant to null.'
);
} else {
print(
'Warning: test_coverage has an outdated targetLines ($targetLines) that is above the total number of lines in the package ($totalLines).\n'
'Update test_coverage.dart to set the targetLines constant to null.'
);
}
}

if (coveredLines < totalLines) {
print('');
print(' ╭──────────────────────────────╮');
print(' │ COVERAGE REGRESSION DETECTED │');
print(' ╰──────────────────────────────╯');
print('');
print(
'Coverage has reduced to only $coveredLines lines ($coveredPercent%). This is lower than',
);
print(
'it was as of $lastUpdate, when coverage was $targetPercent%, covering $targetLines lines.',
);
print(
'Please add sufficient tests to get coverage back to 100%, and update',
);
print(
'test_coverage/bin/test_coverage.dart to have the appropriate targets.',
'Coverage has reduced to only $coveredLines lines ($coveredPercent%), out\n'
'of $totalLines total lines; ${totalLines - coveredLines} lines are not covered by tests.\n'
'Please add sufficient tests to get coverage back to 100%.',
);
print('');
print(
'When in doubt, ask @Hixie for advice. Thanks!',
);
exit(1);
} else {
if (coveredLines < totalLines) {
print(
'Warning: Coverage of package:rfw is no longer 100%. (Coverage is now $coveredPercent%, $coveredLines/$totalLines lines.)',
);
}
if (coveredLines > targetLines) {
print(
'Total lines of covered code has increased, and coverage script is now out of date.\n'
'Coverage is now $coveredPercent%, $coveredLines/$totalLines lines, whereas previously there were only $targetLines lines.\n'
'Update the "targetLines" constant at the top of rfw/test_coverage/bin/test_coverage.dart (to $coveredLines).',
);
}
if (targetLines > totalLines) {
print(
'Total lines of code has reduced, and coverage script is now out of date.\n'
'Coverage is now $coveredPercent%, $coveredLines/$totalLines lines, but previously there were $targetLines lines.\n'
'Update the "targetLines" constant at the top of rfw/test_coverage/bin/test_coverage.dart (to $totalLines).',
);
exit(1);
}
}

coverageDirectory.deleteSync(recursive: true);
Expand Down

0 comments on commit 7aca5dc

Please sign in to comment.