Reintroduce the ability to override the coverage formatter (#100320)

This commit is contained in:
Liam Appelbe
2022-03-17 13:38:36 -07:00
committed by GitHub
parent 25fc01acd1
commit 1d2f9c975b

View File

@@ -123,18 +123,23 @@ class CoverageCollector extends TestWatcher {
/// This will not start any collection tasks. It us up to the caller of to
/// call [collectCoverage] for each process first.
String finalizeCoverage({
String Function(Map<String, coverage.HitMap> hitmap) formatter,
coverage.Resolver resolver,
Directory coverageDirectory,
}) {
if (_globalHitmap == null) {
return null;
}
resolver ??= coverage.Resolver(packagesPath: packagesPath);
final String packagePath = globals.fs.currentDirectory.path;
final List<String> reportOn = coverageDirectory == null
? <String>[globals.fs.path.join(packagePath, 'lib')]
: <String>[coverageDirectory.path];
final String result = _globalHitmap.formatLcov(resolver, reportOn: reportOn, basePath: packagePath);
if (formatter == null) {
resolver ??= coverage.Resolver(packagesPath: packagesPath);
final String packagePath = globals.fs.currentDirectory.path;
final List<String> reportOn = coverageDirectory == null
? <String>[globals.fs.path.join(packagePath, 'lib')]
: <String>[coverageDirectory.path];
formatter = (Map<String, coverage.HitMap> hitmap) => hitmap
.formatLcov(resolver, reportOn: reportOn, basePath: packagePath);
}
final String result = formatter(_globalHitmap);
_globalHitmap = null;
return result;
}