authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-28 20:00:34-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-28 20:00:34-07:00
log7ca9f3bc7ba1a413ea7f8b88dfafba3d0f842f6e
treef326c402505227073fcd57142debe09c5c83cdf0
parenta54ccd85374407a5015c5d8e0173089e75da9be4

zig test: std.testing.zig_exe_path is now available

it will be set to the path of the zig executable which is running `zig test`.

3 files changed, 15 insertions(+), 1 deletions(-)

lib/std/special/test_runner.zig+8
...@@ -11,7 +11,15 @@ pub const io_mode: io.Mode = builtin.test_io_mode;...@@ -11,7 +11,15 @@ pub const io_mode: io.Mode = builtin.test_io_mode;
1111
12var log_err_count: usize = 0;12var log_err_count: usize = 0;
1313
14var args_buffer: [std.fs.MAX_PATH_BYTES + std.mem.page_size]u8 = undefined;
15var args_allocator = std.heap.FixedBufferAllocator.init(&args_buffer);
16
14pub fn main() anyerror!void {17pub fn main() anyerror!void {
18 const args = std.process.argsAlloc(&args_allocator.allocator) catch {
19 @panic("Too many bytes passed over the CLI to the test runner");
20 };
21 std.testing.zig_exe_path = args[1];
22
15 const test_fn_list = builtin.test_functions;23 const test_fn_list = builtin.test_functions;
16 var ok_count: usize = 0;24 var ok_count: usize = 0;
17 var skip_count: usize = 0;25 var skip_count: usize = 0;
lib/std/testing.zig+4
...@@ -21,6 +21,10 @@ pub var base_allocator_instance = std.heap.FixedBufferAllocator.init("");...@@ -21,6 +21,10 @@ pub var base_allocator_instance = std.heap.FixedBufferAllocator.init("");
21/// TODO https://github.com/ziglang/zig/issues/573821/// TODO https://github.com/ziglang/zig/issues/5738
22pub var log_level = std.log.Level.warn;22pub var log_level = std.log.Level.warn;
2323
24/// This is available to any test that wants to execute Zig in a child process.
25/// It will be the same executable that is running `zig test`.
26pub var zig_exe_path: []const u8 = undefined;
27
24/// This function is intended to be used only in tests. It prints diagnostics to stderr28/// This function is intended to be used only in tests. It prints diagnostics to stderr
25/// and then aborts when actual_error_union is not expected_error.29/// and then aborts when actual_error_union is not expected_error.
26pub fn expectError(expected_error: anyerror, actual_error_union: anytype) void {30pub fn expectError(expected_error: anyerror, actual_error_union: anytype) void {
src/main.zig+3-1
...@@ -1828,7 +1828,9 @@ fn buildOutputType(...@@ -1828,7 +1828,9 @@ fn buildOutputType(
1828 else => unreachable,1828 else => unreachable,
1829 }1829 }
1830 }1830 }
1831 try argv.append(exe_path);1831 try argv.appendSlice(&[_][]const u8{
1832 exe_path, self_exe_path,
1833 });
1832 } else {1834 } else {
1833 for (test_exec_args.items) |arg| {1835 for (test_exec_args.items) |arg| {
1834 try argv.append(arg orelse exe_path);1836 try argv.append(arg orelse exe_path);