Unverified Commit 63f2fb9f authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Add coverage directory to fuchsia coverage script (#22236)

parent 84c61ad6
......@@ -30,6 +30,7 @@ const String _kOptionTestDirectory = 'test-directory';
const String _kOptionSdkRoot = 'sdk-root';
const String _kOptionIcudtl = 'icudtl';
const String _kOptionTests = 'tests';
const String _kOptionCoverageDirectory = 'coverage-directory';
const List<String> _kRequiredOptions = <String>[
_kOptionPackages,
_kOptionShell,
......@@ -55,6 +56,7 @@ Future<Null> run(List<String> args) async {
..addOption(_kOptionSdkRoot, help: 'Path to the SDK platform files')
..addOption(_kOptionIcudtl, help: 'Path to the ICU data file')
..addOption(_kOptionTests, help: 'Path to json file that maps Dart test files to precompiled dill files')
..addOption(_kOptionCoverageDirectory, help: 'The path to the directory that will have coverage collected')
..addFlag(_kOptionCoverage,
defaultsTo: false,
negatable: false,
......@@ -85,6 +87,14 @@ Future<Null> run(List<String> args) async {
if (!fs.isDirectorySync(sdkRootSrc.path)) {
throwToolExit('Cannot find SDK files at ${sdkRootSrc.path}');
}
Directory coverageDirectory;
final String coverageDirectoryPath = argResults[_kOptionCoverageDirectory];
if (coverageDirectoryPath != null) {
if (!fs.isDirectorySync(coverageDirectoryPath)) {
throwToolExit('Cannot find coverage directory at $coverageDirectoryPath');
}
coverageDirectory = fs.directory(coverageDirectoryPath);
}
// Put the tester shell where runTests expects it.
// TODO(tvolkert,garymm): Switch to a Fuchsia-specific Artifacts impl.
......@@ -131,9 +141,14 @@ Future<Null> run(List<String> args) async {
if (collector != null) {
// collector expects currentDirectory to be the root of the dart
// package (i.e. contains lib/ and test/ sub-dirs).
// package (i.e. contains lib/ and test/ sub-dirs). In some cases,
// test files may appear to be in the root directory.
if (coverageDirectory == null) {
fs.currentDirectory = testDirectory.parent;
if (!await collector.collectCoverageData(argResults[_kOptionCoveragePath]))
} else {
fs.currentDirectory = testDirectory;
}
if (!await collector.collectCoverageData(argResults[_kOptionCoveragePath], coverageDirectory: coverageDirectory))
throwToolExit('Failed to collect coverage data');
}
} finally {
......
......@@ -83,6 +83,7 @@ class CoverageCollector extends TestWatcher {
Future<String> finalizeCoverage({
coverage.Formatter formatter,
Duration timeout,
Directory coverageDirectory,
}) async {
printTrace('formating coverage data');
if (_globalHitmap == null)
......@@ -90,7 +91,9 @@ class CoverageCollector extends TestWatcher {
if (formatter == null) {
final coverage.Resolver resolver = coverage.Resolver(packagesPath: PackageMap.globalPackagesPath);
final String packagePath = fs.currentDirectory.path;
final List<String> reportOn = <String>[fs.path.join(packagePath, 'lib')];
final List<String> reportOn = coverageDirectory == null
? <String>[fs.path.join(packagePath, 'lib')]
: <String>[coverageDirectory.path];
formatter = coverage.LcovFormatter(resolver, reportOn: reportOn, basePath: packagePath);
}
final String result = await formatter.format(_globalHitmap);
......@@ -98,10 +101,11 @@ class CoverageCollector extends TestWatcher {
return result;
}
Future<bool> collectCoverageData(String coveragePath, { bool mergeCoverageData = false }) async {
Future<bool> collectCoverageData(String coveragePath, { bool mergeCoverageData = false, Directory coverageDirectory }) async {
final Status status = logger.startProgress('Collecting coverage information...');
final String coverageData = await finalizeCoverage(
timeout: const Duration(seconds: 30),
coverageDirectory: coverageDirectory,
);
status.stop();
printTrace('coverage information collection complete');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment