| ... | @@ -169,26 +169,33 @@ pub const RunStep = struct { | ... | @@ -169,26 +169,33 @@ pub const RunStep = struct { |
| 169 | return err; | 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 | // TODO need to poll to read these streams to prevent a deadlock (or rely on evented I/O). | 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 | switch (self.stdout_action) { | 175 | switch (self.stdout_action) { |
| 178 | .expect_exact, .expect_matches => { | 176 | .expect_exact, .expect_matches => { |
| 179 | var stdout_file_in_stream = child.stdout.?.inStream(); | 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 | .inherit, .ignore => {}, | 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 | .expect_exact, .expect_matches => { | 189 | .expect_exact, .expect_matches => { |
| 187 | var stderr_file_in_stream = child.stderr.?.inStream(); | 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 | .inherit, .ignore => {}, | 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 | const term = child.wait() catch |err| { | 200 | const term = child.wait() catch |err| { |
| 194 | warn("Unable to spawn {}: {}\n", .{ argv[0], @errorName(err) }); | 201 | warn("Unable to spawn {}: {}\n", .{ argv[0], @errorName(err) }); |
| ... | @@ -216,7 +223,7 @@ pub const RunStep = struct { | ... | @@ -216,7 +223,7 @@ pub const RunStep = struct { |
| 216 | switch (self.stderr_action) { | 223 | switch (self.stderr_action) { |
| 217 | .inherit, .ignore => {}, | 224 | .inherit, .ignore => {}, |
| 218 | .expect_exact => |expected_bytes| { | 225 | .expect_exact => |expected_bytes| { |
| 219 | if (!mem.eql(u8, expected_bytes, stderr.toSliceConst())) { | 226 | if (!mem.eql(u8, expected_bytes, stderr)) { |
| 220 | warn( | 227 | warn( |
| 221 | \\ | 228 | \\ |
| 222 | \\========= Expected this stderr: ========= | 229 | \\========= Expected this stderr: ========= |
| ... | @@ -224,13 +231,13 @@ pub const RunStep = struct { | ... | @@ -224,13 +231,13 @@ pub const RunStep = struct { |
| 224 | \\========= But found: ==================== | 231 | \\========= But found: ==================== |
| 225 | \\{} | 232 | \\{} |
| 226 | \\ | 233 | \\ |
| 227 | , .{ expected_bytes, stderr.toSliceConst() }); | 234 | , .{ expected_bytes, stderr }); |
| 228 | printCmd(cwd, argv); | 235 | printCmd(cwd, argv); |
| 229 | return error.TestFailed; | 236 | return error.TestFailed; |
| 230 | } | 237 | } |
| 231 | }, | 238 | }, |
| 232 | .expect_matches => |matches| for (matches) |match| { | 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 | warn( | 241 | warn( |
| 235 | \\ | 242 | \\ |
| 236 | \\========= Expected to find in stderr: ========= | 243 | \\========= Expected to find in stderr: ========= |
| ... | @@ -238,7 +245,7 @@ pub const RunStep = struct { | ... | @@ -238,7 +245,7 @@ pub const RunStep = struct { |
| 238 | \\========= But stderr does not contain it: ===== | 245 | \\========= But stderr does not contain it: ===== |
| 239 | \\{} | 246 | \\{} |
| 240 | \\ | 247 | \\ |
| 241 | , .{ match, stderr.toSliceConst() }); | 248 | , .{ match, stderr }); |
| 242 | printCmd(cwd, argv); | 249 | printCmd(cwd, argv); |
| 243 | return error.TestFailed; | 250 | return error.TestFailed; |
| 244 | } | 251 | } |
| ... | @@ -248,7 +255,7 @@ pub const RunStep = struct { | ... | @@ -248,7 +255,7 @@ pub const RunStep = struct { |
| 248 | switch (self.stdout_action) { | 255 | switch (self.stdout_action) { |
| 249 | .inherit, .ignore => {}, | 256 | .inherit, .ignore => {}, |
| 250 | .expect_exact => |expected_bytes| { | 257 | .expect_exact => |expected_bytes| { |
| 251 | if (!mem.eql(u8, expected_bytes, stdout.toSliceConst())) { | 258 | if (!mem.eql(u8, expected_bytes, stdout)) { |
| 252 | warn( | 259 | warn( |
| 253 | \\ | 260 | \\ |
| 254 | \\========= Expected this stdout: ========= | 261 | \\========= Expected this stdout: ========= |
| ... | @@ -256,13 +263,13 @@ pub const RunStep = struct { | ... | @@ -256,13 +263,13 @@ pub const RunStep = struct { |
| 256 | \\========= But found: ==================== | 263 | \\========= But found: ==================== |
| 257 | \\{} | 264 | \\{} |
| 258 | \\ | 265 | \\ |
| 259 | , .{ expected_bytes, stdout.toSliceConst() }); | 266 | , .{ expected_bytes, stdout }); |
| 260 | printCmd(cwd, argv); | 267 | printCmd(cwd, argv); |
| 261 | return error.TestFailed; | 268 | return error.TestFailed; |
| 262 | } | 269 | } |
| 263 | }, | 270 | }, |
| 264 | .expect_matches => |matches| for (matches) |match| { | 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 | warn( | 273 | warn( |
| 267 | \\ | 274 | \\ |
| 268 | \\========= Expected to find in stdout: ========= | 275 | \\========= Expected to find in stdout: ========= |
| ... | @@ -270,7 +277,7 @@ pub const RunStep = struct { | ... | @@ -270,7 +277,7 @@ pub const RunStep = struct { |
| 270 | \\========= But stdout does not contain it: ===== | 277 | \\========= But stdout does not contain it: ===== |
| 271 | \\{} | 278 | \\{} |
| 272 | \\ | 279 | \\ |
| 273 | , .{ match, stdout.toSliceConst() }); | 280 | , .{ match, stdout }); |
| 274 | printCmd(cwd, argv); | 281 | printCmd(cwd, argv); |
| 275 | return error.TestFailed; | 282 | return error.TestFailed; |
| 276 | } | 283 | } |