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'; ...@@ -30,6 +30,7 @@ const String _kOptionTestDirectory = 'test-directory';
const String _kOptionSdkRoot = 'sdk-root'; const String _kOptionSdkRoot = 'sdk-root';
const String _kOptionIcudtl = 'icudtl'; const String _kOptionIcudtl = 'icudtl';
const String _kOptionTests = 'tests'; const String _kOptionTests = 'tests';
const String _kOptionCoverageDirectory = 'coverage-directory';
const List<String> _kRequiredOptions = <String>[ const List<String> _kRequiredOptions = <String>[
_kOptionPackages, _kOptionPackages,
_kOptionShell, _kOptionShell,
...@@ -55,6 +56,7 @@ Future<Null> run(List<String> args) async { ...@@ -55,6 +56,7 @@ Future<Null> run(List<String> args) async {
..addOption(_kOptionSdkRoot, help: 'Path to the SDK platform files') ..addOption(_kOptionSdkRoot, help: 'Path to the SDK platform files')
..addOption(_kOptionIcudtl, help: 'Path to the ICU data file') ..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(_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, ..addFlag(_kOptionCoverage,
defaultsTo: false, defaultsTo: false,
negatable: false, negatable: false,
...@@ -85,6 +87,14 @@ Future<Null> run(List<String> args) async { ...@@ -85,6 +87,14 @@ Future<Null> run(List<String> args) async {
if (!fs.isDirectorySync(sdkRootSrc.path)) { if (!fs.isDirectorySync(sdkRootSrc.path)) {
throwToolExit('Cannot find SDK files at ${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. // Put the tester shell where runTests expects it.
// TODO(tvolkert,garymm): Switch to a Fuchsia-specific Artifacts impl. // TODO(tvolkert,garymm): Switch to a Fuchsia-specific Artifacts impl.
...@@ -131,9 +141,14 @@ Future<Null> run(List<String> args) async { ...@@ -131,9 +141,14 @@ Future<Null> run(List<String> args) async {
if (collector != null) { if (collector != null) {
// collector expects currentDirectory to be the root of the dart // 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,
fs.currentDirectory = testDirectory.parent; // test files may appear to be in the root directory.
if (!await collector.collectCoverageData(argResults[_kOptionCoveragePath])) if (coverageDirectory == null) {
fs.currentDirectory = testDirectory.parent;
} else {
fs.currentDirectory = testDirectory;
}
if (!await collector.collectCoverageData(argResults[_kOptionCoveragePath], coverageDirectory: coverageDirectory))
throwToolExit('Failed to collect coverage data'); throwToolExit('Failed to collect coverage data');
} }
} finally { } finally {
......
...@@ -83,6 +83,7 @@ class CoverageCollector extends TestWatcher { ...@@ -83,6 +83,7 @@ class CoverageCollector extends TestWatcher {
Future<String> finalizeCoverage({ Future<String> finalizeCoverage({
coverage.Formatter formatter, coverage.Formatter formatter,
Duration timeout, Duration timeout,
Directory coverageDirectory,
}) async { }) async {
printTrace('formating coverage data'); printTrace('formating coverage data');
if (_globalHitmap == null) if (_globalHitmap == null)
...@@ -90,7 +91,9 @@ class CoverageCollector extends TestWatcher { ...@@ -90,7 +91,9 @@ class CoverageCollector extends TestWatcher {
if (formatter == null) { if (formatter == null) {
final coverage.Resolver resolver = coverage.Resolver(packagesPath: PackageMap.globalPackagesPath); final coverage.Resolver resolver = coverage.Resolver(packagesPath: PackageMap.globalPackagesPath);
final String packagePath = fs.currentDirectory.path; 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); formatter = coverage.LcovFormatter(resolver, reportOn: reportOn, basePath: packagePath);
} }
final String result = await formatter.format(_globalHitmap); final String result = await formatter.format(_globalHitmap);
...@@ -98,10 +101,11 @@ class CoverageCollector extends TestWatcher { ...@@ -98,10 +101,11 @@ class CoverageCollector extends TestWatcher {
return result; 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 Status status = logger.startProgress('Collecting coverage information...');
final String coverageData = await finalizeCoverage( final String coverageData = await finalizeCoverage(
timeout: const Duration(seconds: 30), timeout: const Duration(seconds: 30),
coverageDirectory: coverageDirectory,
); );
status.stop(); status.stop();
printTrace('coverage information collection complete'); 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