| ... | ... | @@ -3492,3 +3492,58 @@ test "LibExeObjStep.addPackage" { |
| 3492 | 3492 | const dupe = exe.packages.items[0]; |
| 3493 | 3493 | try std.testing.expectEqualStrings(pkg_top.name, dupe.name); |
| 3494 | 3494 | } |
| 3495 | |
| 3496 | test "build_runner issue 10381" { |
| 3497 | if (builtin.os.tag == .wasi) return error.SkipZigTest; |
| 3498 | |
| 3499 | const progstr = |
| 3500 | \\ pub fn main() u8 { |
| 3501 | \\ return 1; |
| 3502 | \\ } |
| 3503 | ; |
| 3504 | |
| 3505 | const buildstr = |
| 3506 | \\ const std = @import("std"); |
| 3507 | \\ pub fn build(b: *std.build.Builder) void { |
| 3508 | \\ const exe = b.addExecutable("source", "source.zig"); |
| 3509 | \\ exe.install(); |
| 3510 | \\ const run_cmd = exe.run(); |
| 3511 | \\ run_cmd.step.dependOn(b.getInstallStep()); |
| 3512 | \\ const run_step = b.step("run", "Run"); |
| 3513 | \\ run_step.dependOn(&run_cmd.step); |
| 3514 | \\ } |
| 3515 | ; |
| 3516 | |
| 3517 | const testing = std.testing; |
| 3518 | const allocator = testing.allocator; |
| 3519 | |
| 3520 | var it = try std.process.argsWithAllocator(allocator); |
| 3521 | defer it.deinit(); |
| 3522 | const testargs = try testing.getTestArgs(&it); |
| 3523 | |
| 3524 | var tmpdir = testing.tmpDir(.{ .no_follow = true }); |
| 3525 | defer tmpdir.cleanup(); |
| 3526 | const tmpdir_path = try tmpdir.getFullPath(allocator); |
| 3527 | defer allocator.free(tmpdir_path); |
| 3528 | |
| 3529 | try tmpdir.dir.writeFile("source.zig", progstr); |
| 3530 | try tmpdir.dir.writeFile("build.zig", buildstr); |
| 3531 | |
| 3532 | const cwd_path = try std.process.getCwdAlloc(allocator); |
| 3533 | defer allocator.free(cwd_path); |
| 3534 | const lib_dir = try std.fs.path.join(allocator, &.{ cwd_path, "lib" }); |
| 3535 | defer allocator.free(lib_dir); |
| 3536 | |
| 3537 | const result = try testing.runZigBuild(testargs.zigexec, .{ |
| 3538 | .subcmd = "run", |
| 3539 | .cwd = tmpdir_path, |
| 3540 | .lib_dir = lib_dir, |
| 3541 | }); |
| 3542 | defer { |
| 3543 | allocator.free(result.stdout); |
| 3544 | allocator.free(result.stderr); |
| 3545 | } |
| 3546 | |
| 3547 | try testing.expectEqual(result.term, .{ .Exited = 1 }); |
| 3548 | try testing.expect(std.mem.indexOf(u8, result.stderr, "error: UnexpectedExitCode") == null); |
| 3549 | } |