cover 0.8.0
cover: ^0.8.0 copied to clipboard
A simple and efficient tool for comprehensive code coverage analysis.
cover ๐ฏ #
cover is the simplest and most robust way to check your Dart/Flutter code coverage directly from the terminal or your scripts.
โจ Features #
- ๐ Clear Reports: Generates an elegant table with coverage summaries per file.
- ๐ CI/CD Ready: Returns explicit exit codes to fail pipelines if coverage is insufficient.
- ๐ Missing Lines: Shows exactly which line numbers are missing coverage with
--show-uncovered. - ๐งน Smart Filters: Ignore generated files (
.g.dart,.freezed.dart, etc.) with a single flag. - ๐ค JSON Output: Perfect for integration with other tools.
- ๐ GitHub Actions: Generate coverage annotations for CI/CD pipelines with
--github-annotations. - ๐ Regression Detection: Compare current coverage against a baseline file using
--baseline. - ๐ก๏ธ Secure: Protected against ANSI injection attacks and features robust error handling.
๐ฆ Installation #
Global Usage (Recommended) #
dart pub global activate cover
As a Dev Dependency #
Add it to your pubspec.yaml:
dev_dependencies:
cover: ^0.5.2
๐ CLI Usage #
# Basic check (looks for coverage/lcov.info by default)
$ cover check
# Enforce minimum coverage and show missing lines
$ cover check --min-coverage 90 --show-uncovered
# Ignore generated files and exclude specific paths
$ cover check --exclude-generated --excluded-paths "lib/generated, lib/src/legacy"
# Get output in JSON format
$ cover check --json
# Generate GitHub Actions annotations
$ cover check --github-annotations
# Compare against a baseline (e.g. from main branch)
$ cover check --baseline coverage/lcov.base.info
Available Flags #
| Flag | Abbr | Description | Default |
|---|---|---|---|
--path |
-p |
Path to the lcov.info file |
coverage/lcov.info |
--min-coverage |
-m |
Minimum required coverage percentage | 100.0 |
--show-uncovered |
-u |
Displays line numbers for missing coverage | false |
--exclude-generated |
Ignores .g.dart, .freezed.dart, etc. |
false |
|
--excluded-paths |
-e |
Comma-separated paths to exclude | "" |
--json |
-j |
Output in JSON format | false |
--github-annotations |
-g |
Output GitHub Actions annotations | false |
--baseline |
-b |
Baseline LCOV file to compare with | null |
๐ ๏ธ Programmatic Usage #
You can integrate cover directly into your Dart logic:
import 'package:cover/cover.dart';
void main() async {
final service = CoverageService();
final result = await service.checkCoverage(
filePath: 'coverage/lcov.info',
minCoverage: 80.0,
excludeGenerated: true,
);
print('Total coverage: ${result.coverage}%');
}
๐ธ Output Example #
๐ค Issues and Feedback #
If you find a bug or have a feature request, please open an issue in our issue tracker.