Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkgs/test/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.9.1

* Depend on latest `test_core`.

## 1.9.0

* Implement code coverage collection for VM based tests
Expand Down
4 changes: 2 additions & 2 deletions pkgs/test/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: test
version: 1.9.0
version: 1.9.1
author: Dart Team <misc@dartlang.org>
description: A full featured library for writing and running Dart tests.
homepage: https://github.com/dart-lang/test/blob/master/pkgs/test
Expand Down Expand Up @@ -32,7 +32,7 @@ dependencies:
yaml: ^2.0.0
# Use an exact version until the test_api and test_core package are stable.
test_api: 0.2.8
test_core: 0.2.11
test_core: 0.2.12

dev_dependencies:
fake_async: ^1.0.0
Expand Down
5 changes: 5 additions & 0 deletions pkgs/test_core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.2.12

* Conditionally import coverage logic in `engine.dart`. This ensures the engine
is platform agnostic.

## 0.2.11

* Implement code coverage gathering for VM tests.
Expand Down
34 changes: 34 additions & 0 deletions pkgs/test_core/lib/src/runner/coverage.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:convert';
import 'dart:io';

import 'package:coverage/coverage.dart';
import 'package:path/path.dart' as p;

import 'live_suite_controller.dart';
import 'runner_suite.dart';

/// Collects coverage and outputs to the [coverage] path.
Future<void> gatherCoverage(
String coverage, LiveSuiteController controller) async {
final RunnerSuite suite = controller.liveSuite.suite;

if (!suite.platform.runtime.isDartVM) return;

final String isolateId = Uri.parse(suite.environment.observatoryUrl.fragment)
.queryParameters['isolateId'];

final cov = await collect(
suite.environment.observatoryUrl, false, false, false, Set(),
isolateIds: {isolateId});

final outfile = File(p.join('$coverage', '${suite.path}.vm.json'))
..createSync(recursive: true);
final IOSink out = outfile.openWrite();
out.write(json.encode(cov));
await out.flush();
await out.close();
}
9 changes: 9 additions & 0 deletions pkgs/test_core/lib/src/runner/coverage_stub.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'live_suite_controller.dart';

Future<void> gatherCoverage(String coverage, LiveSuiteController controller) =>
throw UnsupportedError(
'Coverage is only supported through the test runner.');
33 changes: 3 additions & 30 deletions pkgs/test_core/lib/src/runner/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@

import 'dart:async';
import 'dart:collection';
import 'dart:convert';
import 'dart:io';

import 'package:async/async.dart' hide Result;
import 'package:collection/collection.dart';
import 'package:coverage/coverage.dart';
import 'package:path/path.dart' as p;
import 'package:pedantic/pedantic.dart';
import 'package:pool/pool.dart';

import 'package:test_api/src/backend/group.dart'; // ignore: implementation_imports
import 'package:test_api/src/backend/invoker.dart'; // ignore: implementation_imports
import 'package:test_api/src/backend/live_test.dart'; // ignore: implementation_imports
Expand All @@ -23,10 +18,11 @@ import 'package:test_api/src/backend/state.dart'; // ignore: implementation_impo
import 'package:test_api/src/backend/test.dart'; // ignore: implementation_imports
import 'package:test_api/src/util/iterable_set.dart'; // ignore: implementation_imports

import 'runner_suite.dart';
import 'coverage_stub.dart' if (dart.library.io) 'coverage.dart';
import 'live_suite.dart';
import 'live_suite_controller.dart';
import 'load_suite.dart';
import 'runner_suite.dart';

/// An [Engine] manages a run that encompasses multiple test suites.
///
Expand Down Expand Up @@ -288,7 +284,7 @@ class Engine {
if (_closed) return;
await _runGroup(controller, controller.liveSuite.suite.group, []);
controller.noMoreLiveTests();
await _gatherCoverage(controller);
if (_coverage != null) await gatherCoverage(_coverage, controller);
loadResource.allowRelease(() => controller.close());
});
}());
Expand All @@ -303,29 +299,6 @@ class Engine {
return success;
}

Future<Null> _gatherCoverage(LiveSuiteController controller) async {
if (_coverage == null) return;

final RunnerSuite suite = controller.liveSuite.suite;

if (!suite.platform.runtime.isDartVM) return;

final String isolateId =
Uri.parse(suite.environment.observatoryUrl.fragment)
.queryParameters['isolateId'];

final cov = await collect(
suite.environment.observatoryUrl, false, false, false, Set(),
isolateIds: {isolateId});

final outfile = File(p.join('$_coverage', '${suite.path}.vm.json'))
..createSync(recursive: true);
final IOSink out = outfile.openWrite();
out.write(json.encode(cov));
await out.flush();
await out.close();
}

/// Runs all the entries in [group] in sequence.
///
/// [suiteController] is the controller fo the suite that contains [group].
Expand Down
2 changes: 1 addition & 1 deletion pkgs/test_core/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: test_core
version: 0.2.11
version: 0.2.12
author: Dart Team <misc@dartlang.org>
description: A basic library for writing tests and running them on the VM.
homepage: https://github.com/dart-lang/test/blob/master/pkgs/test_core
Expand Down