| author | |
| committer | |
| log | 85b10eb07c27d021804473ee54a0b5942e4784d5 |
| tree | 1c3450ba81bed2e4125bf21e21ce2e03631ca53e |
| parent | 5523e2061b37de2b884c1c53fdcefb823755c7d0 |
No longer introduce build options for tests. Instead, ZIG_EXE
environment variable is added to any invocation of `zig run` or `zig
test`.
The end result of this branch is the same: there is no longer a
mandatory positional command line argument when invoking zig test
binaries directly.3 files changed, 13 insertions(+), 9 deletions(-)
build.zig+1-6| ... | ... | @@ -40,17 +40,12 @@ pub fn build(b: *Builder) !void { |
| 40 | 40 | const docs_step = b.step("docs", "Build documentation"); |
| 41 | 41 | docs_step.dependOn(&docgen_cmd.step); |
| 42 | 42 | |
| 43 | var test_cases = b.addTest("src/test.zig"); | |
| 43 | const test_cases = b.addTest("src/test.zig"); | |
| 44 | 44 | test_cases.stack_size = stack_size; |
| 45 | 45 | test_cases.setBuildMode(mode); |
| 46 | 46 | test_cases.addPackagePath("test_cases", "test/cases.zig"); |
| 47 | 47 | test_cases.single_threaded = single_threaded; |
| 48 | 48 | |
| 49 | const test_options = b.addOptions(); | |
| 50 | test_options.addOption([]const u8, "zig_exe_path", b.zig_exe); | |
| 51 | test_cases.addOptions("test_options", test_options); | |
| 52 | test_cases.step.dependOn(&test_options.step); | |
| 53 | ||
| 54 | 49 | const fmt_build_zig = b.addFmt(&[_][]const u8{"build.zig"}); |
| 55 | 50 | |
| 56 | 51 | const skip_debug = b.option(bool, "skip-debug", "Main test suite skips debug builds") orelse false; |
src/main.zig+9-1| ... | ... | @@ -3057,6 +3057,7 @@ fn buildOutputType( |
| 3057 | 3057 | gpa, |
| 3058 | 3058 | arena, |
| 3059 | 3059 | test_exec_args.items, |
| 3060 | self_exe_path, | |
| 3060 | 3061 | arg_mode, |
| 3061 | 3062 | target_info, |
| 3062 | 3063 | watch, |
| ... | ... | @@ -3128,6 +3129,7 @@ fn buildOutputType( |
| 3128 | 3129 | gpa, |
| 3129 | 3130 | arena, |
| 3130 | 3131 | test_exec_args.items, |
| 3132 | self_exe_path, | |
| 3131 | 3133 | arg_mode, |
| 3132 | 3134 | target_info, |
| 3133 | 3135 | watch, |
| ... | ... | @@ -3152,6 +3154,7 @@ fn buildOutputType( |
| 3152 | 3154 | gpa, |
| 3153 | 3155 | arena, |
| 3154 | 3156 | test_exec_args.items, |
| 3157 | self_exe_path, | |
| 3155 | 3158 | arg_mode, |
| 3156 | 3159 | target_info, |
| 3157 | 3160 | watch, |
| ... | ... | @@ -3230,6 +3233,7 @@ fn runOrTest( |
| 3230 | 3233 | gpa: Allocator, |
| 3231 | 3234 | arena: Allocator, |
| 3232 | 3235 | test_exec_args: []const ?[]const u8, |
| 3236 | self_exe_path: []const u8, | |
| 3233 | 3237 | arg_mode: ArgMode, |
| 3234 | 3238 | target_info: std.zig.system.NativeTargetInfo, |
| 3235 | 3239 | watch: bool, |
| ... | ... | @@ -3258,16 +3262,20 @@ fn runOrTest( |
| 3258 | 3262 | if (runtime_args_start) |i| { |
| 3259 | 3263 | try argv.appendSlice(all_args[i..]); |
| 3260 | 3264 | } |
| 3265 | var env_map = try std.process.getEnvMap(arena); | |
| 3266 | try env_map.put("ZIG_EXE", self_exe_path); | |
| 3267 | ||
| 3261 | 3268 | // We do not execve for tests because if the test fails we want to print |
| 3262 | 3269 | // the error message and invocation below. |
| 3263 | 3270 | if (std.process.can_execv and arg_mode == .run and !watch) { |
| 3264 | 3271 | // execv releases the locks; no need to destroy the Compilation here. |
| 3265 | const err = std.process.execv(gpa, argv.items); | |
| 3272 | const err = std.process.execve(gpa, argv.items, &env_map); | |
| 3266 | 3273 | try warnAboutForeignBinaries(arena, arg_mode, target_info, link_libc); |
| 3267 | 3274 | const cmd = try std.mem.join(arena, " ", argv.items); |
| 3268 | 3275 | fatal("the following command failed to execve with '{s}':\n{s}", .{ @errorName(err), cmd }); |
| 3269 | 3276 | } else if (std.process.can_spawn) { |
| 3270 | 3277 | var child = std.ChildProcess.init(argv.items, gpa); |
| 3278 | child.env_map = &env_map; | |
| 3271 | 3279 | child.stdin_behavior = .Inherit; |
| 3272 | 3280 | child.stdout_behavior = .Inherit; |
| 3273 | 3281 | child.stderr_behavior = .Inherit; |
src/test.zig+3-2| ... | ... | @@ -1214,6 +1214,7 @@ pub const TestContext = struct { |
| 1214 | 1214 | |
| 1215 | 1215 | fn run(self: *TestContext) !void { |
| 1216 | 1216 | const host = try std.zig.system.NativeTargetInfo.detect(.{}); |
| 1217 | const zig_exe_path = try std.process.getEnvVarOwned(self.arena, "ZIG_EXE"); | |
| 1217 | 1218 | |
| 1218 | 1219 | var progress = std.Progress{}; |
| 1219 | 1220 | const root_node = progress.start("compiler", self.cases.items.len); |
| ... | ... | @@ -1272,6 +1273,7 @@ pub const TestContext = struct { |
| 1272 | 1273 | &prg_node, |
| 1273 | 1274 | case.*, |
| 1274 | 1275 | zig_lib_directory, |
| 1276 | zig_exe_path, | |
| 1275 | 1277 | &aux_thread_pool, |
| 1276 | 1278 | global_cache_directory, |
| 1277 | 1279 | host, |
| ... | ... | @@ -1298,6 +1300,7 @@ pub const TestContext = struct { |
| 1298 | 1300 | root_node: *std.Progress.Node, |
| 1299 | 1301 | case: Case, |
| 1300 | 1302 | zig_lib_directory: Compilation.Directory, |
| 1303 | zig_exe_path: []const u8, | |
| 1301 | 1304 | thread_pool: *ThreadPool, |
| 1302 | 1305 | global_cache_directory: Compilation.Directory, |
| 1303 | 1306 | host: std.zig.system.NativeTargetInfo, |
| ... | ... | @@ -1329,8 +1332,6 @@ pub const TestContext = struct { |
| 1329 | 1332 | &[_][]const u8{ tmp_dir_path, "zig-cache" }, |
| 1330 | 1333 | ); |
| 1331 | 1334 | |
| 1332 | const zig_exe_path = @import("test_options").zig_exe_path; | |
| 1333 | ||
| 1334 | 1335 | for (case.files.items) |file| { |
| 1335 | 1336 | try tmp.dir.writeFile(file.path, file.src); |
| 1336 | 1337 | } |