| 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); |
| 3 | |
| 4 | pub fn build(b: *std.Build) void { |
| 5 | const test_step = b.step("test", "Test it"); |
| 6 | b.default_step = test_step; |
| 7 | |
| 8 | const optimize: std.builtin.Optimize = .debug; |
| 9 | const target = b.graph.host; |
| 10 | |
| 11 | if (builtin.os.tag == .wasi) return; |
| 12 | |
| 13 | const child = b.addExecutable(.{ |
| 14 | .name = "child", |
| 15 | .root_module = b.createModule(.{ |
| 16 | .root_source_file = b.path("child.zig"), |
| 17 | .optimize = optimize, |
| 18 | .target = target, |
| 19 | }), |
| 20 | }); |
| 21 | |
| 22 | const main = b.addExecutable(.{ |
| 23 | .name = "main", |
| 24 | .root_module = b.createModule(.{ |
| 25 | .root_source_file = b.path("main.zig"), |
| 26 | .optimize = optimize, |
| 27 | .target = target, |
| 28 | }), |
| 29 | }); |
| 30 | const run = b.addRunArtifact(main); |
| 31 | run.addArtifactArg(child); |
| 32 | run.expectExitCode(0); |
| 33 | |
| 34 | // Use a temporary directory within the cache as the CWD to test |
| 35 | // spawning the child using a path that contains a leading `..` component. |
| 36 | const run_relative = b.addRunArtifact(main); |
| 37 | run_relative.addArtifactArg(child); |
| 38 | const write_tmp_dir = b.addWriteFiles(); |
| 39 | const tmp_cwd = write_tmp_dir.getDirectory(); |
| 40 | run_relative.addDirectoryArg(tmp_cwd); |
| 41 | run_relative.setCwd(tmp_cwd); |
| 42 | run_relative.expectExitCode(0); |
| 43 | |
| 44 | test_step.dependOn(&run.step); |
| 45 | test_step.dependOn(&run_relative.step); |
| 46 | } |