Add pid and exitCode getters. This makes the API more similar to dart:io's Process.
diff --git a/pkgs/test_process/lib/test_process.dart b/pkgs/test_process/lib/test_process.dart index 1ad3279..3584ab5 100644 --- a/pkgs/test_process/lib/test_process.dart +++ b/pkgs/test_process/lib/test_process.dart
@@ -54,10 +54,17 @@ /// Whether [_log] has been passed to [printOnFailure] yet. bool _loggedOutput = false; + /// Returns a [Future] which completes to the exit code of the process, once + /// it completes. + Future<int> get exitCode => _process.exitCode; + + /// The process ID of the process. + int get pid => _process.pid; + /// Completes to [_process]'s exit code if it's exited, otherwise completes to /// `null` immediately. Future<int> get _exitCodeOrNull async => - await _process.exitCode.timeout(Duration.ZERO, onTimeout: () => null); + await exitCode.timeout(Duration.ZERO, onTimeout: () => null); /// Starts a process. /// @@ -153,7 +160,7 @@ if (_loggedOutput) return; _loggedOutput = true; - var exitCode = await _exitCodeOrNull; + var exitCodeOrNull = await _exitCodeOrNull; // Wait a timer tick to ensure that all available lines have been flushed to // [_log]. @@ -161,10 +168,10 @@ var buffer = new StringBuffer(); buffer.write("Process `$description` "); - if ((await _exitCodeOrNull) == null) { + if (exitCodeOrNull == null) { buffer.writeln("was killed with SIGKILL in a tear-down. Output:"); } else { - buffer.writeln("exited with exitCode $exitCode. Output:"); + buffer.writeln("exited with exitCode $exitCodeOrNull. Output:"); } buffer.writeln(_log.join("\n")); @@ -210,7 +217,7 @@ /// If this is called after the process is already dead, it does nothing. Future kill() async { _process.kill(ProcessSignal.SIGKILL); - await _process.exitCode; + await exitCode; } /// Waits for the process to exit, and verifies that the exit code matches @@ -219,7 +226,7 @@ /// If this is called after the process is already dead, it verifies its /// existing exit code. Future shouldExit([expectedExitCode]) async { - var exitCode = await _process.exitCode; + var exitCode = await this.exitCode; if (expectedExitCode == null) return; expect(exitCode, expectedExitCode, reason: "Process `$description` had an unexpected exit code.");
diff --git a/pkgs/test_process/test/test_process_test.dart b/pkgs/test_process/test/test_process_test.dart index 8acf2a6..81d27e1 100644 --- a/pkgs/test_process/test/test_process_test.dart +++ b/pkgs/test_process/test/test_process_test.dart
@@ -17,16 +17,19 @@ group("shouldExit()", () { test("succeeds when the process exits with the given exit code", () async { var process = await startDartProcess('exitCode = 42;'); + expect(process.exitCode, completion(equals(42))); await process.shouldExit(greaterThan(12)); }); test("fails when the process exits with a different exit code", () async { var process = await startDartProcess('exitCode = 1;'); + expect(process.exitCode, completion(equals(1))); expect(process.shouldExit(greaterThan(12)), throwsTestFailure); }); test("allows any exit code without an assertion", () async { var process = await startDartProcess('exitCode = 1;'); + expect(process.exitCode, completion(equals(1))); await process.shouldExit(); }); });