runReport function
Main entry point for the Buggy.
Generates a coverage report based on the provided config.
If no configuration is provided, uses default settings.
The process includes:
- Reading coverage data from the input LCOV file
- Applying filters (exclude patterns, uncovered-only)
- Generating the markdown report
- Outputting to file or stdout
- Checking coverage thresholds and exiting with appropriate code
Example:
// Use default configuration
await runReport();
// Use custom configuration
final config = ReportConfig(
inputPath: 'my_coverage.info',
outputPath: 'report.md',
failUnder: 80.0,
);
await runReport(config);
Throws Exception if the input file doesn't exist or is malformed.
Exits with code 1 if coverage is below the threshold specified in config.
Implementation
Future<void> runReport([ReportConfig? config]) async {
final cfg = config ?? const ReportConfig();
final coverageData = await _readCoverageData(cfg.inputPath);
final filteredData = _applyFilters(coverageData, cfg);
final report = await _generateMarkdownReport(filteredData, cfg);
await _outputReport(report, cfg);
// Check coverage threshold and exit if needed
if (cfg.failUnder != null) {
final totalCoverage = _calculateTotalCoverageValue(filteredData);
if (totalCoverage < cfg.failUnder!) {
stderr.writeln(
'Coverage ${totalCoverage.toStringAsFixed(1)}% is below threshold '
'${cfg.failUnder}%',
);
exit(1);
}
}
}