test: use TestProcess more places (#406)
Makes debugging a lot easier
diff --git a/lib/src/run_and_collect.dart b/lib/src/run_and_collect.dart
index b6e6288..b9a0932 100644
--- a/lib/src/run_and_collect.dart
+++ b/lib/src/run_and_collect.dart
@@ -30,7 +30,7 @@
final process = await Process.start(Platform.executable, dartArgs);
- final serviceUri = await serviceUriFromProcess(process);
+ final serviceUri = await serviceUriFromProcess(process.stdout.lines());
Map<String, dynamic> coverage;
try {
coverage = await collect(serviceUri, true, true, includeDart, <String>{},
diff --git a/lib/src/util.dart b/lib/src/util.dart
index 42b1466..a85de49 100644
--- a/lib/src/util.dart
+++ b/lib/src/util.dart
@@ -145,10 +145,10 @@
transform(SystemEncoding().decoder).transform(const LineSplitter());
}
-Future<Uri> serviceUriFromProcess(Process sampleProcess) {
+Future<Uri> serviceUriFromProcess(Stream<String> procStdout) {
// Capture the VM service URI.
final serviceUriCompleter = Completer<Uri>();
- sampleProcess.stdout.lines().listen((line) {
+ procStdout.listen((line) {
if (!serviceUriCompleter.isCompleted) {
final serviceUri = extractVMServiceUri(line);
if (serviceUri != null) {
diff --git a/test/collect_coverage_api_test.dart b/test/collect_coverage_api_test.dart
index d387a8c..9fa1c0a 100644
--- a/test/collect_coverage_api_test.dart
+++ b/test/collect_coverage_api_test.dart
@@ -111,7 +111,7 @@
// run the sample app, with the right flags
final sampleProcess = await runTestApp(openPort);
- final serviceUri = await serviceUriFromProcess(sampleProcess);
+ final serviceUri = await serviceUriFromProcess(sampleProcess.stdoutStream());
final isolateIdSet = isolateIds ? <String>{} : null;
return collect(serviceUri, true, true, false, scopedOutput,
diff --git a/test/collect_coverage_test.dart b/test/collect_coverage_test.dart
index 7cf33e2..cc3c84f 100644
--- a/test/collect_coverage_test.dart
+++ b/test/collect_coverage_test.dart
@@ -350,7 +350,7 @@
final sampleProcess = await runTestApp(openPort);
// Capture the VM service URI.
- final serviceUri = await serviceUriFromProcess(sampleProcess);
+ final serviceUri = await serviceUriFromProcess(sampleProcess.stdoutStream());
// Run the collection tool.
// TODO: need to get all of this functionality in the lib
@@ -368,8 +368,7 @@
throw 'We timed out waiting for the tool to finish.';
});
- await sampleProcess.exitCode;
- await sampleProcess.stderr.drain();
+ await sampleProcess.shouldExit();
return toolResult.stdoutStream().join('\n');
}
diff --git a/test/function_coverage_test.dart b/test/function_coverage_test.dart
index 81ccea7..5eb71be 100644
--- a/test/function_coverage_test.dart
+++ b/test/function_coverage_test.dart
@@ -79,13 +79,13 @@
final openPort = await getOpenPort();
// Run the sample app with the right flags.
- final sampleProcess = await Process.start(Platform.resolvedExecutable, [
+ final sampleProcess = await TestProcess.start(Platform.resolvedExecutable, [
'--enable-vm-service=$openPort',
'--pause_isolates_on_exit',
_funcCovApp
]);
- final serviceUri = await serviceUriFromProcess(sampleProcess);
+ final serviceUri = await serviceUriFromProcess(sampleProcess.stdoutStream());
// Run the collection tool.
final toolResult = await TestProcess.start(Platform.resolvedExecutable, [
@@ -101,8 +101,7 @@
throw 'We timed out waiting for the tool to finish.';
});
- await sampleProcess.exitCode;
- await sampleProcess.stderr.drain();
+ await sampleProcess.shouldExit();
return toolResult.stdoutStream().join('\n');
}
diff --git a/test/lcov_test.dart b/test/lcov_test.dart
index 5d40bf6..773c46c 100644
--- a/test/lcov_test.dart
+++ b/test/lcov_test.dart
@@ -9,6 +9,7 @@
import 'package:coverage/src/util.dart';
import 'package:path/path.dart' as p;
import 'package:test/test.dart';
+import 'package:test_process/test_process.dart';
import 'test_util.dart';
@@ -262,9 +263,9 @@
_sampleAppPath
];
final sampleProcess =
- await Process.start(Platform.resolvedExecutable, sampleAppArgs);
+ await TestProcess.start(Platform.resolvedExecutable, sampleAppArgs);
- final serviceUri = await serviceUriFromProcess(sampleProcess);
+ final serviceUri = await serviceUriFromProcess(sampleProcess.stdoutStream());
// collect hit map.
final coverageJson = (await collect(serviceUri, true, true, false, <String>{},
@@ -272,12 +273,7 @@
branchCoverage: true))['coverage'] as List<Map<String, dynamic>>;
final hitMap = HitMap.parseJson(coverageJson);
- // wait for sample app to terminate.
- final exitCode = await sampleProcess.exitCode;
- if (exitCode != 0) {
- throw ProcessException(Platform.resolvedExecutable, sampleAppArgs,
- 'Fatal error. Exit code: $exitCode', exitCode);
- }
- await sampleProcess.stderr.drain();
+ await sampleProcess.shouldExit(0);
+
return hitMap;
}
diff --git a/test/test_util.dart b/test/test_util.dart
index 6eac431..9274f63 100644
--- a/test/test_util.dart
+++ b/test/test_util.dart
@@ -6,20 +6,22 @@
import 'dart:io';
import 'package:path/path.dart' as p;
+import 'package:test_process/test_process.dart';
final String testAppPath = p.join('test', 'test_files', 'test_app.dart');
const Duration timeout = Duration(seconds: 20);
-Future<Process> runTestApp(int openPort) async {
- return Process.start(Platform.resolvedExecutable, [
- '--enable-vm-service=$openPort',
- '--pause_isolates_on_exit',
- // Dart VM versions before 2.17 don't support branch coverage.
- if (platformVersionCheck(2, 17)) '--branch-coverage',
- testAppPath
- ]);
-}
+Future<TestProcess> runTestApp(int openPort) => TestProcess.start(
+ Platform.resolvedExecutable,
+ [
+ '--enable-vm-service=$openPort',
+ '--pause_isolates_on_exit',
+ // Dart VM versions before 2.17 don't support branch coverage.
+ if (platformVersionCheck(2, 17)) '--branch-coverage',
+ testAppPath
+ ],
+ );
final _versionPattern = RegExp('([0-9]+)\\.([0-9]+)\\.([0-9]+)');
bool platformVersionCheck(int minMajor, int minMinor) {