| author | |
| committer | |
| log | 8f627593ebb7ce073e43f06235fe1d9b9c1a1579 |
| tree | acc6c57ae7720c7109f079ebe4f47d5dc57300cf |
| parent | bcf56c32eb11306613c92128c1b95ff280ba4f68 |
| signature |
4 files changed, 37 insertions(+), 38 deletions(-)
lib/std/build.zig+3-5| ... | ... | @@ -926,11 +926,9 @@ pub const Builder = struct { |
| 926 | 926 | |
| 927 | 927 | try child.spawn(); |
| 928 | 928 | |
| 929 | var stdout = std.Buffer.initNull(self.allocator); | |
| 930 | defer std.Buffer.deinit(&stdout); | |
| 931 | ||
| 932 | 929 | var stdout_file_in_stream = child.stdout.?.inStream(); |
| 933 | try stdout_file_in_stream.stream.readAllBuffer(&stdout, max_output_size); | |
| 930 | const stdout = try stdout_file_in_stream.stream.readAllAlloc(self.allocator, max_output_size); | |
| 931 | errdefer self.allocator.free(stdout); | |
| 934 | 932 | |
| 935 | 933 | const term = try child.wait(); |
| 936 | 934 | switch (term) { |
| ... | ... | @@ -939,7 +937,7 @@ pub const Builder = struct { |
| 939 | 937 | out_code.* = @truncate(u8, code); |
| 940 | 938 | return error.ExitCodeFailure; |
| 941 | 939 | } |
| 942 | return stdout.toOwnedSlice(); | |
| 940 | return stdout; | |
| 943 | 941 | }, |
| 944 | 942 | .Signal, .Stopped, .Unknown => |code| { |
| 945 | 943 | out_code.* = @truncate(u8, code); |
lib/std/build/run.zig+21-14| ... | ... | @@ -169,26 +169,33 @@ pub const RunStep = struct { |
| 169 | 169 | return err; |
| 170 | 170 | }; |
| 171 | 171 | |
| 172 | var stdout = Buffer.initNull(self.builder.allocator); | |
| 173 | var stderr = Buffer.initNull(self.builder.allocator); | |
| 174 | ||
| 175 | 172 | // TODO need to poll to read these streams to prevent a deadlock (or rely on evented I/O). |
| 176 | 173 | |
| 174 | var stdout: []const u8 = undefined; | |
| 177 | 175 | switch (self.stdout_action) { |
| 178 | 176 | .expect_exact, .expect_matches => { |
| 179 | 177 | var stdout_file_in_stream = child.stdout.?.inStream(); |
| 180 | stdout_file_in_stream.stream.readAllBuffer(&stdout, max_stdout_size) catch unreachable; | |
| 178 | stdout = stdout_file_in_stream.stream.readAllAlloc(self.builder.allocator, max_stdout_size) catch unreachable; | |
| 181 | 179 | }, |
| 182 | 180 | .inherit, .ignore => {}, |
| 183 | 181 | } |
| 182 | defer switch (self.stdout_action) { | |
| 183 | .expect_exact, .expect_matches => self.builder.allocator.free(stdout), | |
| 184 | .inherit, .ignore => {}, | |
| 185 | }; | |
| 184 | 186 | |
| 185 | switch (self.stdout_action) { | |
| 187 | var stderr: []const u8 = undefined; | |
| 188 | switch (self.stdout_behavior) { | |
| 186 | 189 | .expect_exact, .expect_matches => { |
| 187 | 190 | var stderr_file_in_stream = child.stderr.?.inStream(); |
| 188 | stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable; | |
| 191 | stderr = stderr_file_in_stream.stream.readAllAlloc(self.builder.allocator, max_stdout_size) catch unreachable; | |
| 189 | 192 | }, |
| 190 | 193 | .inherit, .ignore => {}, |
| 191 | 194 | } |
| 195 | defer switch (self.stderr_action) { | |
| 196 | .expect_exact, .expect_matches => self.builder.allocator.free(stderr), | |
| 197 | .inherit, .ignore => {}, | |
| 198 | }; | |
| 192 | 199 | |
| 193 | 200 | const term = child.wait() catch |err| { |
| 194 | 201 | warn("Unable to spawn {}: {}\n", .{ argv[0], @errorName(err) }); |
| ... | ... | @@ -216,7 +223,7 @@ pub const RunStep = struct { |
| 216 | 223 | switch (self.stderr_action) { |
| 217 | 224 | .inherit, .ignore => {}, |
| 218 | 225 | .expect_exact => |expected_bytes| { |
| 219 | if (!mem.eql(u8, expected_bytes, stderr.toSliceConst())) { | |
| 226 | if (!mem.eql(u8, expected_bytes, stderr)) { | |
| 220 | 227 | warn( |
| 221 | 228 | \\ |
| 222 | 229 | \\========= Expected this stderr: ========= |
| ... | ... | @@ -224,13 +231,13 @@ pub const RunStep = struct { |
| 224 | 231 | \\========= But found: ==================== |
| 225 | 232 | \\{} |
| 226 | 233 | \\ |
| 227 | , .{ expected_bytes, stderr.toSliceConst() }); | |
| 234 | , .{ expected_bytes, stderr }); | |
| 228 | 235 | printCmd(cwd, argv); |
| 229 | 236 | return error.TestFailed; |
| 230 | 237 | } |
| 231 | 238 | }, |
| 232 | 239 | .expect_matches => |matches| for (matches) |match| { |
| 233 | if (mem.indexOf(u8, stderr.toSliceConst(), match) == null) { | |
| 240 | if (mem.indexOf(u8, stderr, match) == null) { | |
| 234 | 241 | warn( |
| 235 | 242 | \\ |
| 236 | 243 | \\========= Expected to find in stderr: ========= |
| ... | ... | @@ -238,7 +245,7 @@ pub const RunStep = struct { |
| 238 | 245 | \\========= But stderr does not contain it: ===== |
| 239 | 246 | \\{} |
| 240 | 247 | \\ |
| 241 | , .{ match, stderr.toSliceConst() }); | |
| 248 | , .{ match, stderr }); | |
| 242 | 249 | printCmd(cwd, argv); |
| 243 | 250 | return error.TestFailed; |
| 244 | 251 | } |
| ... | ... | @@ -248,7 +255,7 @@ pub const RunStep = struct { |
| 248 | 255 | switch (self.stdout_action) { |
| 249 | 256 | .inherit, .ignore => {}, |
| 250 | 257 | .expect_exact => |expected_bytes| { |
| 251 | if (!mem.eql(u8, expected_bytes, stdout.toSliceConst())) { | |
| 258 | if (!mem.eql(u8, expected_bytes, stdout)) { | |
| 252 | 259 | warn( |
| 253 | 260 | \\ |
| 254 | 261 | \\========= Expected this stdout: ========= |
| ... | ... | @@ -256,13 +263,13 @@ pub const RunStep = struct { |
| 256 | 263 | \\========= But found: ==================== |
| 257 | 264 | \\{} |
| 258 | 265 | \\ |
| 259 | , .{ expected_bytes, stdout.toSliceConst() }); | |
| 266 | , .{ expected_bytes, stdout }); | |
| 260 | 267 | printCmd(cwd, argv); |
| 261 | 268 | return error.TestFailed; |
| 262 | 269 | } |
| 263 | 270 | }, |
| 264 | 271 | .expect_matches => |matches| for (matches) |match| { |
| 265 | if (mem.indexOf(u8, stdout.toSliceConst(), match) == null) { | |
| 272 | if (mem.indexOf(u8, stdout, match) == null) { | |
| 266 | 273 | warn( |
| 267 | 274 | \\ |
| 268 | 275 | \\========= Expected to find in stdout: ========= |
| ... | ... | @@ -270,7 +277,7 @@ pub const RunStep = struct { |
| 270 | 277 | \\========= But stdout does not contain it: ===== |
| 271 | 278 | \\{} |
| 272 | 279 | \\ |
| 273 | , .{ match, stdout.toSliceConst() }); | |
| 280 | , .{ match, stdout }); | |
| 274 | 281 | printCmd(cwd, argv); |
| 275 | 282 | return error.TestFailed; |
| 276 | 283 | } |
lib/std/child_process.zig+7-9| ... | ... | @@ -217,21 +217,19 @@ pub const ChildProcess = struct { |
| 217 | 217 | |
| 218 | 218 | try child.spawn(); |
| 219 | 219 | |
| 220 | var stdout = Buffer.initNull(args.allocator); | |
| 221 | var stderr = Buffer.initNull(args.allocator); | |
| 222 | defer Buffer.deinit(&stdout); | |
| 223 | defer Buffer.deinit(&stderr); | |
| 224 | ||
| 225 | 220 | var stdout_file_in_stream = child.stdout.?.inStream(); |
| 226 | 221 | var stderr_file_in_stream = child.stderr.?.inStream(); |
| 227 | 222 | |
| 228 | try stdout_file_in_stream.stream.readAllBuffer(&stdout, args.max_output_bytes); | |
| 229 | try stderr_file_in_stream.stream.readAllBuffer(&stderr, args.max_output_bytes); | |
| 223 | // TODO need to poll to read these streams to prevent a deadlock (or rely on evented I/O). | |
| 224 | const stdout = try stdout_file_in_stream.stream.readAllAlloc(args.allocator, args.max_output_bytes); | |
| 225 | errdefer args.allocator.free(stdout); | |
| 226 | const stderr = try stderr_file_in_stream.stream.readAllAlloc(args.allocator, args.max_output_bytes); | |
| 227 | errdefer args.allocator.free(stderr); | |
| 230 | 228 | |
| 231 | 229 | return ExecResult{ |
| 232 | 230 | .term = try child.wait(), |
| 233 | .stdout = stdout.toOwnedSlice(), | |
| 234 | .stderr = stderr.toOwnedSlice(), | |
| 231 | .stdout = stdout, | |
| 232 | .stderr = stderr, | |
| 235 | 233 | }; |
| 236 | 234 | } |
| 237 | 235 |
test/tests.zig+6-10| ... | ... | @@ -566,14 +566,13 @@ pub const StackTracesContext = struct { |
| 566 | 566 | } |
| 567 | 567 | child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) }); |
| 568 | 568 | |
| 569 | var stdout = Buffer.initNull(b.allocator); | |
| 570 | var stderr = Buffer.initNull(b.allocator); | |
| 571 | ||
| 572 | 569 | var stdout_file_in_stream = child.stdout.?.inStream(); |
| 573 | 570 | var stderr_file_in_stream = child.stderr.?.inStream(); |
| 574 | 571 | |
| 575 | stdout_file_in_stream.stream.readAllBuffer(&stdout, max_stdout_size) catch unreachable; | |
| 576 | stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable; | |
| 572 | const stdout = stdout_file_in_stream.stream.readAllAlloc(b.allocator, max_stdout_size) catch unreachable; | |
| 573 | defer b.allocator.free(stdout); | |
| 574 | const stderr = stderr_file_in_stream.stream.readAllAlloc(b.allocator, max_stdout_size) catch unreachable; | |
| 575 | defer b.allocator.free(stderr); | |
| 577 | 576 | |
| 578 | 577 | const term = child.wait() catch |err| { |
| 579 | 578 | debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) }); |
| ... | ... | @@ -616,11 +615,8 @@ pub const StackTracesContext = struct { |
| 616 | 615 | const got: []const u8 = got_result: { |
| 617 | 616 | var buf = try Buffer.initSize(b.allocator, 0); |
| 618 | 617 | defer buf.deinit(); |
| 619 | const bytes = if (stderr.endsWith("\n")) | |
| 620 | stderr.toSliceConst()[0 .. stderr.len() - 1] | |
| 621 | else | |
| 622 | stderr.toSliceConst()[0..stderr.len()]; | |
| 623 | var it = mem.separate(bytes, "\n"); | |
| 618 | if (stderr.len != 0 and stderr[stderr.len - 1] == '\n') stderr = stderr[0 .. stderr.len - 1]; | |
| 619 | var it = mem.separate(stderr, "\n"); | |
| 624 | 620 | process_lines: while (it.next()) |line| { |
| 625 | 621 | if (line.len == 0) continue; |
| 626 | 622 | const delims = [_][]const u8{ ":", ":", ":", " in " }; |