| author | |
| committer | |
| log | 5523e2061b37de2b884c1c53fdcefb823755c7d0 |
| tree | ca47846fc11ebbbefd0d2c8d1f35b17887407ec1 |
| parent | 61aaef0b074dc2567e4c35c9cb55cb042c18d065 |
6 files changed, 12 insertions(+), 46 deletions(-)
build.zig+5| ... | ... | @@ -46,6 +46,11 @@ pub fn build(b: *Builder) !void { |
| 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 | ||
| 49 | 54 | const fmt_build_zig = b.addFmt(&[_][]const u8{"build.zig"}); |
| 50 | 55 | |
| 51 | 56 | const skip_debug = b.option(bool, "skip-debug", "Main test suite skips debug builds") orelse false; |
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+2-21| ... | ... | @@ -3057,7 +3057,6 @@ fn buildOutputType( |
| 3057 | 3057 | gpa, |
| 3058 | 3058 | arena, |
| 3059 | 3059 | test_exec_args.items, |
| 3060 | self_exe_path, | |
| 3061 | 3060 | arg_mode, |
| 3062 | 3061 | target_info, |
| 3063 | 3062 | watch, |
| ... | ... | @@ -3129,7 +3128,6 @@ fn buildOutputType( |
| 3129 | 3128 | gpa, |
| 3130 | 3129 | arena, |
| 3131 | 3130 | test_exec_args.items, |
| 3132 | self_exe_path, | |
| 3133 | 3131 | arg_mode, |
| 3134 | 3132 | target_info, |
| 3135 | 3133 | watch, |
| ... | ... | @@ -3154,7 +3152,6 @@ fn buildOutputType( |
| 3154 | 3152 | gpa, |
| 3155 | 3153 | arena, |
| 3156 | 3154 | test_exec_args.items, |
| 3157 | self_exe_path, | |
| 3158 | 3155 | arg_mode, |
| 3159 | 3156 | target_info, |
| 3160 | 3157 | watch, |
| ... | ... | @@ -3233,7 +3230,6 @@ fn runOrTest( |
| 3233 | 3230 | gpa: Allocator, |
| 3234 | 3231 | arena: Allocator, |
| 3235 | 3232 | test_exec_args: []const ?[]const u8, |
| 3236 | self_exe_path: []const u8, | |
| 3237 | 3233 | arg_mode: ArgMode, |
| 3238 | 3234 | target_info: std.zig.system.NativeTargetInfo, |
| 3239 | 3235 | watch: bool, |
| ... | ... | @@ -3253,25 +3249,10 @@ fn runOrTest( |
| 3253 | 3249 | defer argv.deinit(); |
| 3254 | 3250 | |
| 3255 | 3251 | 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 | }); | |
| 3252 | try argv.append(exe_path); | |
| 3266 | 3253 | } else { |
| 3267 | 3254 | 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 | } | |
| 3255 | try argv.append(arg orelse exe_path); | |
| 3275 | 3256 | } |
| 3276 | 3257 | } |
| 3277 | 3258 | if (runtime_args_start) |i| { |
src/test.zig+5-3| ... | ... | @@ -1329,6 +1329,8 @@ pub const TestContext = struct { |
| 1329 | 1329 | &[_][]const u8{ tmp_dir_path, "zig-cache" }, |
| 1330 | 1330 | ); |
| 1331 | 1331 | |
| 1332 | const zig_exe_path = @import("test_options").zig_exe_path; | |
| 1333 | ||
| 1332 | 1334 | for (case.files.items) |file| { |
| 1333 | 1335 | try tmp.dir.writeFile(file.path, file.src); |
| 1334 | 1336 | } |
| ... | ... | @@ -1351,7 +1353,7 @@ pub const TestContext = struct { |
| 1351 | 1353 | try tmp.dir.writeFile(tmp_src_path, update.src); |
| 1352 | 1354 | |
| 1353 | 1355 | var zig_args = std.ArrayList([]const u8).init(arena); |
| 1354 | try zig_args.append(std.testing.zig_exe_path); | |
| 1356 | try zig_args.append(zig_exe_path); | |
| 1355 | 1357 | |
| 1356 | 1358 | if (case.is_test) { |
| 1357 | 1359 | try zig_args.append("test"); |
| ... | ... | @@ -1545,7 +1547,7 @@ pub const TestContext = struct { |
| 1545 | 1547 | .link_libc = case.link_libc, |
| 1546 | 1548 | .use_llvm = use_llvm, |
| 1547 | 1549 | .use_stage1 = null, // We already handled stage1 tests |
| 1548 | .self_exe_path = std.testing.zig_exe_path, | |
| 1550 | .self_exe_path = zig_exe_path, | |
| 1549 | 1551 | // TODO instead of turning off color, pass in a std.Progress.Node |
| 1550 | 1552 | .color = .off, |
| 1551 | 1553 | // TODO: force self-hosted linkers with stage2 backend to avoid LLD creeping in |
| ... | ... | @@ -1795,7 +1797,7 @@ pub const TestContext = struct { |
| 1795 | 1797 | continue :update; // Pass test. |
| 1796 | 1798 | } |
| 1797 | 1799 | try argv.appendSlice(&[_][]const u8{ |
| 1798 | std.testing.zig_exe_path, | |
| 1800 | zig_exe_path, | |
| 1799 | 1801 | "run", |
| 1800 | 1802 | "-cflags", |
| 1801 | 1803 | "-std=c99", |