diff --git a/std/os/child_process.zig b/std/os/child_process.zig index 8c09f25bee724732a6196531c65824ccab7e0f44..bb5b2eb187d99a9ddc6e89244aa2c46e6e85b536 100644 --- a/std/os/child_process.zig +++ b/std/os/child_process.zig @@ -66,10 +66,9 @@ pub const ChildProcess = struct { break; } - // TODO oops! test (self.stdin) |*stdin| { stdin.close(); } - test (self.stdin) |*stdout| { stdout.close(); } - test (self.stdin) |*stderr| { stderr.close(); } + test (self.stdout) |*stdout| { stdout.close(); } + test (self.stderr) |*stderr| { stderr.close(); } // Write @maxValue(ErrInt) to the write end of the err_pipe. This is after // waitpid, so this write is guaranteed to be after the child diff --git a/test/tests.zig b/test/tests.zig index 354776140e0e32e7dc6438099d453e13d11fdccb..97ae39309d8d3e6013d49478e808ab888237e5a8 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -195,28 +195,29 @@ pub const CompareOutputContext = struct { debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err)); }; - const term = child.wait() %% |err| { - debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err)); - }; - switch (term) { - Term.Clean => |code| { - if (code != 0) { - %%io.stderr.printf("Process {} exited with error code {}\n", full_exe_path, code); - return error.TestFailed; - } - }, - else => { - %%io.stderr.printf("Process {} terminated unexpectedly\n", full_exe_path); - return error.TestFailed; - }, - }; - var stdout = Buffer.initNull(b.allocator); var stderr = Buffer.initNull(b.allocator); %%(??child.stdout).readAll(&stdout); %%(??child.stderr).readAll(&stderr); + const term = child.wait() %% |err| { + debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err)); + }; + switch (term) { + Term.Clean => |code| { + if (code != 0) { + %%io.stderr.printf("Process {} exited with error code {}\n", full_exe_path, code); + return error.TestFailed; + } + }, + else => { + %%io.stderr.printf("Process {} terminated unexpectedly\n", full_exe_path); + return error.TestFailed; + }, + }; + + if (!mem.eql(u8, self.expected_output, stdout.toSliceConst())) { %%io.stderr.printf( \\ @@ -521,6 +522,12 @@ pub const CompileErrorContext = struct { debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err)); }; + var stdout_buf = Buffer.initNull(b.allocator); + var stderr_buf = Buffer.initNull(b.allocator); + + %%(??child.stdout).readAll(&stdout_buf); + %%(??child.stderr).readAll(&stderr_buf); + const term = child.wait() %% |err| { debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err)); }; @@ -537,11 +544,6 @@ pub const CompileErrorContext = struct { }, }; - var stdout_buf = Buffer.initNull(b.allocator); - var stderr_buf = Buffer.initNull(b.allocator); - - %%(??child.stdout).readAll(&stdout_buf); - %%(??child.stderr).readAll(&stderr_buf); const stdout = stdout_buf.toSliceConst(); const stderr = stderr_buf.toSliceConst(); @@ -783,6 +785,12 @@ pub const ParseHContext = struct { debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err)); }; + var stdout_buf = Buffer.initNull(b.allocator); + var stderr_buf = Buffer.initNull(b.allocator); + + %%(??child.stdout).readAll(&stdout_buf); + %%(??child.stderr).readAll(&stderr_buf); + const term = child.wait() %% |err| { debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err)); }; @@ -803,12 +811,6 @@ pub const ParseHContext = struct { }, }; - var stdout_buf = Buffer.initNull(b.allocator); - var stderr_buf = Buffer.initNull(b.allocator); - - %%(??child.stdout).readAll(&stdout_buf); - %%(??child.stderr).readAll(&stderr_buf); - const stdout = stdout_buf.toSliceConst(); const stderr = stderr_buf.toSliceConst();