| ... | @@ -21,32 +21,7 @@ const ErrorMsg = struct { | ... | @@ -21,32 +21,7 @@ const ErrorMsg = struct { |
| 21 | }; | 21 | }; |
| 22 | | 22 | |
| 23 | pub const TestContext = struct { | 23 | pub const TestContext = struct { |
| 24 | // TODO: remove these. They are deprecated. | 24 | zir_cases: std.ArrayList(Case), |
| 25 | zir_cmp_output_cases: std.ArrayList(ZIRCompareOutputCase), | | |
| 26 | | | |
| 27 | /// TODO: find a way to treat cases as individual tests (shouldn't show "1 test passed" if there are 200 cases) | | |
| 28 | zir_cases: std.ArrayList(ZIRCase), | | |
| 29 | | | |
| 30 | // TODO: remove | | |
| 31 | pub const ZIRCompareOutputCase = struct { | | |
| 32 | name: []const u8, | | |
| 33 | src_list: []const []const u8, | | |
| 34 | expected_stdout_list: []const []const u8, | | |
| 35 | }; | | |
| 36 | | | |
| 37 | pub const ZIRUpdateType = enum { | | |
| 38 | /// A transformation update transforms the input ZIR and tests against | | |
| 39 | /// the expected output | | |
| 40 | Transformation, | | |
| 41 | /// An error update attempts to compile bad code, and ensures that it | | |
| 42 | /// fails to compile, and for the expected reasons | | |
| 43 | Error, | | |
| 44 | /// An execution update compiles and runs the input ZIR, feeding in | | |
| 45 | /// provided input and ensuring that the outputs match what is expected | | |
| 46 | Execution, | | |
| 47 | /// A compilation update checks that the ZIR compiles without any issues | | |
| 48 | Compiles, | | |
| 49 | }; | | |
| 50 | | 25 | |
| 51 | pub const ZIRUpdate = struct { | 26 | pub const ZIRUpdate = struct { |
| 52 | /// The input to the current update. We simulate an incremental update | 27 | /// The input to the current update. We simulate an incremental update |
| ... | @@ -57,58 +32,55 @@ pub const TestContext = struct { | ... | @@ -57,58 +32,55 @@ pub const TestContext = struct { |
| 57 | /// you can keep it mostly consistent, with small changes, testing the | 32 | /// you can keep it mostly consistent, with small changes, testing the |
| 58 | /// effects of the incremental compilation. | 33 | /// effects of the incremental compilation. |
| 59 | src: [:0]const u8, | 34 | src: [:0]const u8, |
| 60 | case: union(ZIRUpdateType) { | 35 | case: union(enum) { |
| 61 | /// The expected output ZIR | 36 | /// A transformation update transforms the input ZIR and tests against |
| | 37 | /// the expected output ZIR. |
| 62 | Transformation: [:0]const u8, | 38 | Transformation: [:0]const u8, |
| | 39 | /// An error update attempts to compile bad code, and ensures that it |
| | 40 | /// fails to compile, and for the expected reasons. |
| 63 | /// A slice containing the expected errors *in sequential order*. | 41 | /// A slice containing the expected errors *in sequential order*. |
| 64 | Error: []const ErrorMsg, | 42 | Error: []const ErrorMsg, |
| 65 | | 43 | /// An execution update compiles and runs the input ZIR, feeding in |
| 66 | /// Input to feed to the program, and expected outputs. | 44 | /// provided input and ensuring that the stdout match what is expected. |
| 67 | /// | 45 | Execution: []const u8, |
| 68 | /// If stdout, stderr, and exit_code are all null, addZIRCase will | | |
| 69 | /// discard the test. To test for successful compilation, use a | | |
| 70 | /// dedicated Compile update instead. | | |
| 71 | Execution: struct { | | |
| 72 | stdin: ?[]const u8, | | |
| 73 | stdout: ?[]const u8, | | |
| 74 | stderr: ?[]const u8, | | |
| 75 | exit_code: ?u8, | | |
| 76 | }, | | |
| 77 | /// A Compiles test checks only that compilation of the given ZIR | | |
| 78 | /// succeeds. To test outputs, use an Execution test. It is good to | | |
| 79 | /// use a Compiles test before an Execution, as the overhead should | | |
| 80 | /// be low (due to incremental compilation) and TODO: provide a way | | |
| 81 | /// to check changed / new / etc decls in testing mode | | |
| 82 | /// (usingnamespace a debug info struct with a comptime flag?) | | |
| 83 | Compiles: void, | | |
| 84 | }, | 46 | }, |
| 85 | }; | 47 | }; |
| 86 | | 48 | |
| 87 | /// A ZIRCase consists of a set of *updates*. A update can transform ZIR, | 49 | /// A Case consists of a set of *updates*. A update can transform ZIR, |
| 88 | /// compile it, ensure that compilation fails, and more. The same Module is | 50 | /// compile it, ensure that compilation fails, and more. The same Module is |
| 89 | /// used for each update, so each update's source is treated as a single file | 51 | /// used for each update, so each update's source is treated as a single file |
| 90 | /// being updated by the test harness and incrementally compiled. | 52 | /// being updated by the test harness and incrementally compiled. |
| 91 | pub const ZIRCase = struct { | 53 | pub const Case = struct { |
| 92 | name: []const u8, | 54 | name: []const u8, |
| 93 | /// The platform the ZIR targets. For non-native platforms, an emulator | 55 | /// The platform the ZIR targets. For non-native platforms, an emulator |
| 94 | /// such as QEMU is required for tests to complete. | 56 | /// such as QEMU is required for tests to complete. |
| 95 | target: std.zig.CrossTarget, | 57 | target: std.zig.CrossTarget, |
| 96 | updates: std.ArrayList(ZIRUpdate), | 58 | updates: std.ArrayList(ZIRUpdate), |
| | 59 | output_mode: std.builtin.OutputMode, |
| | 60 | /// Either ".zir" or ".zig" |
| | 61 | extension: [4]u8, |
| 97 | | 62 | |
| 98 | /// Adds a subcase in which the module is updated with new ZIR, and the | 63 | /// Adds a subcase in which the module is updated with new ZIR, and the |
| 99 | /// resulting ZIR is validated. | 64 | /// resulting ZIR is validated. |
| 100 | pub fn addTransform(self: *ZIRCase, src: [:0]const u8, result: [:0]const u8) void { | 65 | pub fn addTransform(self: *Case, src: [:0]const u8, result: [:0]const u8) void { |
| 101 | self.updates.append(.{ | 66 | self.updates.append(.{ |
| 102 | .src = src, | 67 | .src = src, |
| 103 | .case = .{ .Transformation = result }, | 68 | .case = .{ .Transformation = result }, |
| 104 | }) catch unreachable; | 69 | }) catch unreachable; |
| 105 | } | 70 | } |
| 106 | | 71 | |
| | 72 | pub fn addCompareOutput(self: *Case, src: [:0]const u8, result: []const u8) void { |
| | 73 | self.updates.append(.{ |
| | 74 | .src = src, |
| | 75 | .case = .{ .Execution = result }, |
| | 76 | }) catch unreachable; |
| | 77 | } |
| | 78 | |
| 107 | /// Adds a subcase in which the module is updated with invalid ZIR, and | 79 | /// Adds a subcase in which the module is updated with invalid ZIR, and |
| 108 | /// ensures that compilation fails for the expected reasons. | 80 | /// ensures that compilation fails for the expected reasons. |
| 109 | /// | 81 | /// |
| 110 | /// Errors must be specified in sequential order. | 82 | /// Errors must be specified in sequential order. |
| 111 | pub fn addError(self: *ZIRCase, src: [:0]const u8, errors: []const []const u8) void { | 83 | pub fn addError(self: *Case, src: [:0]const u8, errors: []const []const u8) void { |
| 112 | var array = self.updates.allocator.alloc(ErrorMsg, errors.len) catch unreachable; | 84 | var array = self.updates.allocator.alloc(ErrorMsg, errors.len) catch unreachable; |
| 113 | for (errors) |e, i| { | 85 | for (errors) |e, i| { |
| 114 | if (e[0] != ':') { | 86 | if (e[0] != ':') { |
| ... | @@ -146,15 +118,65 @@ pub const TestContext = struct { | ... | @@ -146,15 +118,65 @@ pub const TestContext = struct { |
| 146 | } | 118 | } |
| 147 | }; | 119 | }; |
| 148 | | 120 | |
| 149 | pub fn addZIRMulti( | 121 | pub fn addExeZIR( |
| | 122 | ctx: *TestContext, |
| | 123 | name: []const u8, |
| | 124 | target: std.zig.CrossTarget, |
| | 125 | ) *Case { |
| | 126 | const case = Case{ |
| | 127 | .name = name, |
| | 128 | .target = target, |
| | 129 | .updates = std.ArrayList(ZIRUpdate).init(ctx.zir_cases.allocator), |
| | 130 | .output_mode = .Exe, |
| | 131 | .extension = ".zir".*, |
| | 132 | }; |
| | 133 | ctx.zir_cases.append(case) catch unreachable; |
| | 134 | return &ctx.zir_cases.items[ctx.zir_cases.items.len - 1]; |
| | 135 | } |
| | 136 | |
| | 137 | pub fn addObjZIR( |
| | 138 | ctx: *TestContext, |
| | 139 | name: []const u8, |
| | 140 | target: std.zig.CrossTarget, |
| | 141 | ) *Case { |
| | 142 | const case = Case{ |
| | 143 | .name = name, |
| | 144 | .target = target, |
| | 145 | .updates = std.ArrayList(ZIRUpdate).init(ctx.zir_cases.allocator), |
| | 146 | .output_mode = .Obj, |
| | 147 | .extension = ".zir".*, |
| | 148 | }; |
| | 149 | ctx.zir_cases.append(case) catch unreachable; |
| | 150 | return &ctx.zir_cases.items[ctx.zir_cases.items.len - 1]; |
| | 151 | } |
| | 152 | |
| | 153 | pub fn addExe( |
| 150 | ctx: *TestContext, | 154 | ctx: *TestContext, |
| 151 | name: []const u8, | 155 | name: []const u8, |
| 152 | target: std.zig.CrossTarget, | 156 | target: std.zig.CrossTarget, |
| 153 | ) *ZIRCase { | 157 | ) *Case { |
| 154 | const case = ZIRCase{ | 158 | const case = Case{ |
| 155 | .name = name, | 159 | .name = name, |
| 156 | .target = target, | 160 | .target = target, |
| 157 | .updates = std.ArrayList(ZIRUpdate).init(ctx.zir_cases.allocator), | 161 | .updates = std.ArrayList(ZIRUpdate).init(ctx.zir_cases.allocator), |
| | 162 | .output_mode = .Exe, |
| | 163 | .extension = ".zig".*, |
| | 164 | }; |
| | 165 | ctx.zir_cases.append(case) catch unreachable; |
| | 166 | return &ctx.zir_cases.items[ctx.zir_cases.items.len - 1]; |
| | 167 | } |
| | 168 | |
| | 169 | pub fn addObj( |
| | 170 | ctx: *TestContext, |
| | 171 | name: []const u8, |
| | 172 | target: std.zig.CrossTarget, |
| | 173 | ) *Case { |
| | 174 | const case = Case{ |
| | 175 | .name = name, |
| | 176 | .target = target, |
| | 177 | .updates = std.ArrayList(ZIRUpdate).init(ctx.zir_cases.allocator), |
| | 178 | .output_mode = .Obj, |
| | 179 | .extension = ".zig".*, |
| 158 | }; | 180 | }; |
| 159 | ctx.zir_cases.append(case) catch unreachable; | 181 | ctx.zir_cases.append(case) catch unreachable; |
| 160 | return &ctx.zir_cases.items[ctx.zir_cases.items.len - 1]; | 182 | return &ctx.zir_cases.items[ctx.zir_cases.items.len - 1]; |
| ... | @@ -163,14 +185,21 @@ pub const TestContext = struct { | ... | @@ -163,14 +185,21 @@ pub const TestContext = struct { |
| 163 | pub fn addZIRCompareOutput( | 185 | pub fn addZIRCompareOutput( |
| 164 | ctx: *TestContext, | 186 | ctx: *TestContext, |
| 165 | name: []const u8, | 187 | name: []const u8, |
| 166 | src_list: []const []const u8, | 188 | src: [:0]const u8, |
| 167 | expected_stdout_list: []const []const u8, | 189 | expected_stdout: []const u8, |
| 168 | ) void { | 190 | ) void { |
| 169 | ctx.zir_cmp_output_cases.append(.{ | 191 | var c = ctx.addExeZIR(name, .{}); |
| 170 | .name = name, | 192 | c.addCompareOutput(src, expected_stdout); |
| 171 | .src_list = src_list, | 193 | } |
| 172 | .expected_stdout_list = expected_stdout_list, | 194 | |
| 173 | }) catch unreachable; | 195 | pub fn addCompareOutput( |
| | 196 | ctx: *TestContext, |
| | 197 | name: []const u8, |
| | 198 | src: [:0]const u8, |
| | 199 | expected_stdout: []const u8, |
| | 200 | ) void { |
| | 201 | var c = ctx.addExe(name, .{}); |
| | 202 | c.addCompareOutput(src, expected_stdout); |
| 174 | } | 203 | } |
| 175 | | 204 | |
| 176 | pub fn addZIRTransform( | 205 | pub fn addZIRTransform( |
| ... | @@ -180,7 +209,7 @@ pub const TestContext = struct { | ... | @@ -180,7 +209,7 @@ pub const TestContext = struct { |
| 180 | src: [:0]const u8, | 209 | src: [:0]const u8, |
| 181 | result: [:0]const u8, | 210 | result: [:0]const u8, |
| 182 | ) void { | 211 | ) void { |
| 183 | var c = ctx.addZIRMulti(name, target); | 212 | var c = ctx.addObjZIR(name, target); |
| 184 | c.addTransform(src, result); | 213 | c.addTransform(src, result); |
| 185 | } | 214 | } |
| 186 | | 215 | |
| ... | @@ -191,20 +220,18 @@ pub const TestContext = struct { | ... | @@ -191,20 +220,18 @@ pub const TestContext = struct { |
| 191 | src: [:0]const u8, | 220 | src: [:0]const u8, |
| 192 | expected_errors: []const []const u8, | 221 | expected_errors: []const []const u8, |
| 193 | ) void { | 222 | ) void { |
| 194 | var c = ctx.addZIRMulti(name, target); | 223 | var c = ctx.addObjZIR(name, target); |
| 195 | c.addError(src, expected_errors); | 224 | c.addError(src, expected_errors); |
| 196 | } | 225 | } |
| 197 | | 226 | |
| 198 | fn init() TestContext { | 227 | fn init() TestContext { |
| 199 | const allocator = std.heap.page_allocator; | 228 | const allocator = std.heap.page_allocator; |
| 200 | return .{ | 229 | return .{ |
| 201 | .zir_cmp_output_cases = std.ArrayList(ZIRCompareOutputCase).init(allocator), | 230 | .zir_cases = std.ArrayList(Case).init(allocator), |
| 202 | .zir_cases = std.ArrayList(ZIRCase).init(allocator), | | |
| 203 | }; | 231 | }; |
| 204 | } | 232 | } |
| 205 | | 233 | |
| 206 | fn deinit(self: *TestContext) void { | 234 | fn deinit(self: *TestContext) void { |
| 207 | self.zir_cmp_output_cases.deinit(); | | |
| 208 | for (self.zir_cases.items) |c| { | 235 | for (self.zir_cases.items) |c| { |
| 209 | for (c.updates.items) |u| { | 236 | for (c.updates.items) |u| { |
| 210 | if (u.case == .Error) { | 237 | if (u.case == .Error) { |
| ... | @@ -235,34 +262,24 @@ pub const TestContext = struct { | ... | @@ -235,34 +262,24 @@ pub const TestContext = struct { |
| 235 | progress.refresh(); | 262 | progress.refresh(); |
| 236 | | 263 | |
| 237 | const info = try std.zig.system.NativeTargetInfo.detect(std.testing.allocator, case.target); | 264 | const info = try std.zig.system.NativeTargetInfo.detect(std.testing.allocator, case.target); |
| 238 | try self.runOneZIRCase(std.testing.allocator, &prg_node, case, info.target); | 265 | try self.runOneCase(std.testing.allocator, &prg_node, case, info.target); |
| 239 | try std.testing.allocator_instance.validate(); | | |
| 240 | } | | |
| 241 | | | |
| 242 | // TODO: wipe the rest of this function | | |
| 243 | for (self.zir_cmp_output_cases.items) |case| { | | |
| 244 | std.testing.base_allocator_instance.reset(); | | |
| 245 | | | |
| 246 | var prg_node = root_node.start(case.name, case.src_list.len); | | |
| 247 | prg_node.activate(); | | |
| 248 | defer prg_node.end(); | | |
| 249 | | | |
| 250 | // So that we can see which test case failed when the leak checker goes off. | | |
| 251 | progress.refresh(); | | |
| 252 | | | |
| 253 | try self.runOneZIRCmpOutputCase(std.testing.allocator, &prg_node, case, native_info.target); | | |
| 254 | try std.testing.allocator_instance.validate(); | 266 | try std.testing.allocator_instance.validate(); |
| 255 | } | 267 | } |
| 256 | } | 268 | } |
| 257 | | 269 | |
| 258 | fn runOneZIRCase(self: *TestContext, allocator: *Allocator, prg_node: *std.Progress.Node, case: ZIRCase, target: std.Target) !void { | 270 | fn runOneCase(self: *TestContext, allocator: *Allocator, prg_node: *std.Progress.Node, case: Case, target: std.Target) !void { |
| 259 | var tmp = std.testing.tmpDir(.{}); | 271 | var tmp = std.testing.tmpDir(.{}); |
| 260 | defer tmp.cleanup(); | 272 | defer tmp.cleanup(); |
| 261 | | 273 | |
| 262 | const tmp_src_path = "test_case.zir"; | 274 | const root_name = "test_case"; |
| | 275 | const tmp_src_path = try std.fmt.allocPrint(allocator, "{}{}", .{ root_name, case.extension }); |
| | 276 | defer allocator.free(tmp_src_path); |
| 263 | const root_pkg = try Package.create(allocator, tmp.dir, ".", tmp_src_path); | 277 | const root_pkg = try Package.create(allocator, tmp.dir, ".", tmp_src_path); |
| 264 | defer root_pkg.destroy(); | 278 | defer root_pkg.destroy(); |
| 265 | | 279 | |
| | 280 | const bin_name = try std.zig.binNameAlloc(allocator, root_name, target, case.output_mode, null); |
| | 281 | defer allocator.free(bin_name); |
| | 282 | |
| 266 | var module = try Module.init(allocator, .{ | 283 | var module = try Module.init(allocator, .{ |
| 267 | .target = target, | 284 | .target = target, |
| 268 | // This is an Executable, as opposed to e.g. a *library*. This does | 285 | // This is an Executable, as opposed to e.g. a *library*. This does |
| ... | @@ -271,17 +288,17 @@ pub const TestContext = struct { | ... | @@ -271,17 +288,17 @@ pub const TestContext = struct { |
| 271 | // TODO: support tests for object file building, and library builds | 288 | // TODO: support tests for object file building, and library builds |
| 272 | // and linking. This will require a rework to support multi-file | 289 | // and linking. This will require a rework to support multi-file |
| 273 | // tests. | 290 | // tests. |
| 274 | .output_mode = .Obj, | 291 | .output_mode = case.output_mode, |
| 275 | // TODO: support testing optimizations | 292 | // TODO: support testing optimizations |
| 276 | .optimize_mode = .Debug, | 293 | .optimize_mode = .Debug, |
| 277 | .bin_file_dir = tmp.dir, | 294 | .bin_file_dir = tmp.dir, |
| 278 | .bin_file_path = "test_case.o", | 295 | .bin_file_path = bin_name, |
| 279 | .root_pkg = root_pkg, | 296 | .root_pkg = root_pkg, |
| 280 | .keep_source_files_loaded = true, | 297 | .keep_source_files_loaded = true, |
| 281 | }); | 298 | }); |
| 282 | defer module.deinit(); | 299 | defer module.deinit(); |
| 283 | | 300 | |
| 284 | for (case.updates.items) |update| { | 301 | for (case.updates.items) |update, update_index| { |
| 285 | var update_node = prg_node.start("update", 4); | 302 | var update_node = prg_node.start("update", 4); |
| 286 | update_node.activate(); | 303 | update_node.activate(); |
| 287 | defer update_node.end(); | 304 | defer update_node.end(); |
| ... | @@ -293,6 +310,7 @@ pub const TestContext = struct { | ... | @@ -293,6 +310,7 @@ pub const TestContext = struct { |
| 293 | | 310 | |
| 294 | var module_node = update_node.start("parse/analysis/codegen", null); | 311 | var module_node = update_node.start("parse/analysis/codegen", null); |
| 295 | module_node.activate(); | 312 | module_node.activate(); |
| | 313 | try module.makeBinFileWritable(); |
| 296 | try module.update(); | 314 | try module.update(); |
| 297 | module_node.end(); | 315 | module_node.end(); |
| 298 | | 316 | |
| ... | @@ -341,78 +359,41 @@ pub const TestContext = struct { | ... | @@ -341,78 +359,41 @@ pub const TestContext = struct { |
| 341 | } | 359 | } |
| 342 | } | 360 | } |
| 343 | }, | 361 | }, |
| 344 | | 362 | .Execution => |expected_stdout| { |
| 345 | else => return error.Unimplemented, | 363 | var exec_result = x: { |
| 346 | } | 364 | var exec_node = update_node.start("execute", null); |
| 347 | } | 365 | exec_node.activate(); |
| 348 | } | 366 | defer exec_node.end(); |
| 349 | | 367 | |
| 350 | fn runOneZIRCmpOutputCase( | 368 | try module.makeBinFileExecutable(); |
| 351 | self: *TestContext, | 369 | |
| 352 | allocator: *Allocator, | 370 | const exe_path = try std.fmt.allocPrint(allocator, "." ++ std.fs.path.sep_str ++ "{}", .{bin_name}); |
| 353 | prg_node: *std.Progress.Node, | 371 | defer allocator.free(exe_path); |
| 354 | case: ZIRCompareOutputCase, | 372 | |
| 355 | target: std.Target, | 373 | break :x try std.ChildProcess.exec(.{ |
| 356 | ) !void { | 374 | .allocator = allocator, |
| 357 | var tmp = std.testing.tmpDir(.{}); | 375 | .argv = &[_][]const u8{exe_path}, |
| 358 | defer tmp.cleanup(); | 376 | .cwd_dir = tmp.dir, |
| 359 | | 377 | }); |
| 360 | const tmp_src_path = "test-case.zir"; | 378 | }; |
| 361 | const root_pkg = try Package.create(allocator, tmp.dir, ".", tmp_src_path); | 379 | defer allocator.free(exec_result.stdout); |
| 362 | defer root_pkg.destroy(); | 380 | defer allocator.free(exec_result.stderr); |
| 363 | | 381 | switch (exec_result.term) { |
| 364 | var module = try Module.init(allocator, .{ | 382 | .Exited => |code| { |
| 365 | .target = target, | 383 | if (code != 0) { |
| 366 | .output_mode = .Exe, | 384 | std.debug.warn("elf file exited with code {}\n", .{code}); |
| 367 | .optimize_mode = .Debug, | 385 | return error.BinaryBadExitCode; |
| 368 | .bin_file_dir = tmp.dir, | 386 | } |
| 369 | .bin_file_path = "a.out", | 387 | }, |
| 370 | .root_pkg = root_pkg, | 388 | else => return error.BinaryCrashed, |
| 371 | }); | 389 | } |
| 372 | defer module.deinit(); | 390 | if (!std.mem.eql(u8, expected_stdout, exec_result.stdout)) { |
| 373 | | 391 | std.debug.panic( |
| 374 | for (case.src_list) |source, i| { | 392 | "update index {}, mismatched stdout\n====Expected (len={}):====\n{}\n====Actual (len={}):====\n{}\n========\n", |
| 375 | var src_node = prg_node.start("update", 2); | 393 | .{ update_index, expected_stdout.len, expected_stdout, exec_result.stdout.len, exec_result.stdout }, |
| 376 | src_node.activate(); | 394 | ); |
| 377 | defer src_node.end(); | | |
| 378 | | | |
| 379 | try tmp.dir.writeFile(tmp_src_path, source); | | |
| 380 | | | |
| 381 | var update_node = src_node.start("parse,analysis,codegen", null); | | |
| 382 | update_node.activate(); | | |
| 383 | try module.makeBinFileWritable(); | | |
| 384 | try module.update(); | | |
| 385 | update_node.end(); | | |
| 386 | | | |
| 387 | var exec_result = x: { | | |
| 388 | var exec_node = src_node.start("execute", null); | | |
| 389 | exec_node.activate(); | | |
| 390 | defer exec_node.end(); | | |
| 391 | | | |
| 392 | try module.makeBinFileExecutable(); | | |
| 393 | break :x try std.ChildProcess.exec(.{ | | |
| 394 | .allocator = allocator, | | |
| 395 | .argv = &[_][]const u8{"./a.out"}, | | |
| 396 | .cwd_dir = tmp.dir, | | |
| 397 | }); | | |
| 398 | }; | | |
| 399 | defer allocator.free(exec_result.stdout); | | |
| 400 | defer allocator.free(exec_result.stderr); | | |
| 401 | switch (exec_result.term) { | | |
| 402 | .Exited => |code| { | | |
| 403 | if (code != 0) { | | |
| 404 | std.debug.warn("elf file exited with code {}\n", .{code}); | | |
| 405 | return error.BinaryBadExitCode; | | |
| 406 | } | 395 | } |
| 407 | }, | 396 | }, |
| 408 | else => return error.BinaryCrashed, | | |
| 409 | } | | |
| 410 | const expected_stdout = case.expected_stdout_list[i]; | | |
| 411 | if (!std.mem.eql(u8, expected_stdout, exec_result.stdout)) { | | |
| 412 | std.debug.panic( | | |
| 413 | "update index {}, mismatched stdout\n====Expected (len={}):====\n{}\n====Actual (len={}):====\n{}\n========\n", | | |
| 414 | .{ i, expected_stdout.len, expected_stdout, exec_result.stdout.len, exec_result.stdout }, | | |
| 415 | ); | | |
| 416 | } | 397 | } |
| 417 | } | 398 | } |
| 418 | } | 399 | } |