| author | |
| committer | |
| log | d834b180118cf336b09b8f664e294ec2222e6d16 |
| tree | 1c3450ba81bed2e4125bf21e21ce2e03631ca53e |
| parent | 61aaef0b074dc2567e4c35c9cb55cb042c18d065 |
| parent | 85b10eb07c27d021804473ee54a0b5942e4784d5 |
| signature |
Remove `std.testing.zig_exe_path` in favor of `ZIG_EXE` environment variable6 files changed, 14 insertions(+), 44 deletions(-)
build.zig+1-1| ... | ... | @@ -40,7 +40,7 @@ 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"); |
lib/std/process.zig-1| ... | ... | @@ -822,7 +822,6 @@ test "args iterator" { |
| 822 | 822 | const given_suffix = std.fs.path.basename(prog_name); |
| 823 | 823 | |
| 824 | 824 | try testing.expect(mem.eql(u8, expected_suffix, given_suffix)); |
| 825 | try testing.expect(it.skip()); // Skip over zig_exe_path, passed to the test runner | |
| 826 | 825 | try testing.expect(it.next() == null); |
| 827 | 826 | try testing.expect(!it.skip()); |
| 828 | 827 | } |
lib/std/testing.zig-4| ... | ... | @@ -22,10 +22,6 @@ pub var base_allocator_instance = std.heap.FixedBufferAllocator.init(""); |
| 22 | 22 | /// TODO https://github.com/ziglang/zig/issues/5738 |
| 23 | 23 | pub var log_level = std.log.Level.warn; |
| 24 | 24 | |
| 25 | /// This is available to any test that wants to execute Zig in a child process. | |
| 26 | /// It will be the same executable that is running `zig test`. | |
| 27 | pub var zig_exe_path: []const u8 = undefined; | |
| 28 | ||
| 29 | 25 | /// This function is intended to be used only in tests. It prints diagnostics to stderr |
| 30 | 26 | /// and then returns a test failure error when actual_error_union is not expected_error. |
| 31 | 27 | pub fn expectError(expected_error: anyerror, actual_error_union: anytype) !void { |
lib/test_runner.zig-17| ... | ... | @@ -6,29 +6,12 @@ pub const io_mode: io.Mode = builtin.test_io_mode; |
| 6 | 6 | |
| 7 | 7 | var log_err_count: usize = 0; |
| 8 | 8 | |
| 9 | var args_buffer: [std.fs.MAX_PATH_BYTES + std.mem.page_size]u8 = undefined; | |
| 10 | var args_allocator = std.heap.FixedBufferAllocator.init(&args_buffer); | |
| 11 | ||
| 12 | fn processArgs() void { | |
| 13 | const args = std.process.argsAlloc(args_allocator.allocator()) catch { | |
| 14 | @panic("Too many bytes passed over the CLI to the test runner"); | |
| 15 | }; | |
| 16 | if (args.len != 2) { | |
| 17 | const self_name = if (args.len >= 1) args[0] else if (builtin.os.tag == .windows) "test.exe" else "test"; | |
| 18 | const zig_ext = if (builtin.os.tag == .windows) ".exe" else ""; | |
| 19 | std.debug.print("Usage: {s} path/to/zig{s}\n", .{ self_name, zig_ext }); | |
| 20 | @panic("Wrong number of command line arguments"); | |
| 21 | } | |
| 22 | std.testing.zig_exe_path = args[1]; | |
| 23 | } | |
| 24 | ||
| 25 | 9 | pub fn main() void { |
| 26 | 10 | if (builtin.zig_backend != .stage1 and |
| 27 | 11 | (builtin.zig_backend != .stage2_llvm or builtin.cpu.arch == .wasm32)) |
| 28 | 12 | { |
| 29 | 13 | return main2() catch @panic("test failure"); |
| 30 | 14 | } |
| 31 | processArgs(); | |
| 32 | 15 | const test_fn_list = builtin.test_functions; |
| 33 | 16 | var ok_count: usize = 0; |
| 34 | 17 | var skip_count: usize = 0; |
src/main.zig+7-18| ... | ... | @@ -3253,40 +3253,29 @@ fn runOrTest( |
| 3253 | 3253 | defer argv.deinit(); |
| 3254 | 3254 | |
| 3255 | 3255 | if (test_exec_args.len == 0) { |
| 3256 | // when testing pass the zig_exe_path to argv | |
| 3257 | if (arg_mode == .zig_test) | |
| 3258 | try argv.appendSlice(&[_][]const u8{ | |
| 3259 | exe_path, self_exe_path, | |
| 3260 | }) | |
| 3261 | // when running just pass the current exe | |
| 3262 | else | |
| 3263 | try argv.appendSlice(&[_][]const u8{ | |
| 3264 | exe_path, | |
| 3265 | }); | |
| 3256 | try argv.append(exe_path); | |
| 3266 | 3257 | } else { |
| 3267 | 3258 | for (test_exec_args) |arg| { |
| 3268 | if (arg) |a| { | |
| 3269 | try argv.append(a); | |
| 3270 | } else { | |
| 3271 | try argv.appendSlice(&[_][]const u8{ | |
| 3272 | exe_path, self_exe_path, | |
| 3273 | }); | |
| 3274 | } | |
| 3259 | try argv.append(arg orelse exe_path); | |
| 3275 | 3260 | } |
| 3276 | 3261 | } |
| 3277 | 3262 | if (runtime_args_start) |i| { |
| 3278 | 3263 | try argv.appendSlice(all_args[i..]); |
| 3279 | 3264 | } |
| 3265 | var env_map = try std.process.getEnvMap(arena); | |
| 3266 | try env_map.put("ZIG_EXE", self_exe_path); | |
| 3267 | ||
| 3280 | 3268 | // We do not execve for tests because if the test fails we want to print |
| 3281 | 3269 | // the error message and invocation below. |
| 3282 | 3270 | if (std.process.can_execv and arg_mode == .run and !watch) { |
| 3283 | 3271 | // execv releases the locks; no need to destroy the Compilation here. |
| 3284 | const err = std.process.execv(gpa, argv.items); | |
| 3272 | const err = std.process.execve(gpa, argv.items, &env_map); | |
| 3285 | 3273 | try warnAboutForeignBinaries(arena, arg_mode, target_info, link_libc); |
| 3286 | 3274 | const cmd = try std.mem.join(arena, " ", argv.items); |
| 3287 | 3275 | fatal("the following command failed to execve with '{s}':\n{s}", .{ @errorName(err), cmd }); |
| 3288 | 3276 | } else if (std.process.can_spawn) { |
| 3289 | 3277 | var child = std.ChildProcess.init(argv.items, gpa); |
| 3278 | child.env_map = &env_map; | |
| 3290 | 3279 | child.stdin_behavior = .Inherit; |
| 3291 | 3280 | child.stdout_behavior = .Inherit; |
| 3292 | 3281 | child.stderr_behavior = .Inherit; |
src/test.zig+6-3| ... | ... | @@ -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, |
| ... | ... | @@ -1351,7 +1354,7 @@ pub const TestContext = struct { |
| 1351 | 1354 | try tmp.dir.writeFile(tmp_src_path, update.src); |
| 1352 | 1355 | |
| 1353 | 1356 | var zig_args = std.ArrayList([]const u8).init(arena); |
| 1354 | try zig_args.append(std.testing.zig_exe_path); | |
| 1357 | try zig_args.append(zig_exe_path); | |
| 1355 | 1358 | |
| 1356 | 1359 | if (case.is_test) { |
| 1357 | 1360 | try zig_args.append("test"); |
| ... | ... | @@ -1545,7 +1548,7 @@ pub const TestContext = struct { |
| 1545 | 1548 | .link_libc = case.link_libc, |
| 1546 | 1549 | .use_llvm = use_llvm, |
| 1547 | 1550 | .use_stage1 = null, // We already handled stage1 tests |
| 1548 | .self_exe_path = std.testing.zig_exe_path, | |
| 1551 | .self_exe_path = zig_exe_path, | |
| 1549 | 1552 | // TODO instead of turning off color, pass in a std.Progress.Node |
| 1550 | 1553 | .color = .off, |
| 1551 | 1554 | // TODO: force self-hosted linkers with stage2 backend to avoid LLD creeping in |
| ... | ... | @@ -1795,7 +1798,7 @@ pub const TestContext = struct { |
| 1795 | 1798 | continue :update; // Pass test. |
| 1796 | 1799 | } |
| 1797 | 1800 | try argv.appendSlice(&[_][]const u8{ |
| 1798 | std.testing.zig_exe_path, | |
| 1801 | zig_exe_path, | |
| 1799 | 1802 | "run", |
| 1800 | 1803 | "-cflags", |
| 1801 | 1804 | "-std=c99", |