runReport function

Future<void> runReport([
  1. ReportConfig? config
])

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:

  1. Reading coverage data from the input LCOV file
  2. Applying filters (exclude patterns, uncovered-only)
  3. Generating the markdown report
  4. Outputting to file or stdout
  5. 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);
    }
  }
}