aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-12-28 20:00:34 -0700
committerAndrew Kelley <andrew@ziglang.org>2020-12-28 20:00:34 -0700
commit7ca9f3bc7ba1a413ea7f8b88dfafba3d0f842f6e (patch)
treef326c402505227073fcd57142debe09c5c83cdf0 /lib
parenta54ccd85374407a5015c5d8e0173089e75da9be4 (diff)
downloadzig-7ca9f3bc7ba1a413ea7f8b88dfafba3d0f842f6e.tar.gz
zig-7ca9f3bc7ba1a413ea7f8b88dfafba3d0f842f6e.zip
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`.
Diffstat (limited to 'lib')
-rw-r--r--lib/std/special/test_runner.zig8
-rw-r--r--lib/std/testing.zig4
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/std/special/test_runner.zig b/lib/std/special/test_runner.zig
index 4bb9202858..e8996e3ef1 100644
--- a/lib/std/special/test_runner.zig
+++ b/lib/std/special/test_runner.zig
@@ -11,7 +11,15 @@ pub const io_mode: io.Mode = builtin.test_io_mode;
var log_err_count: usize = 0;
+var args_buffer: [std.fs.MAX_PATH_BYTES + std.mem.page_size]u8 = undefined;
+var args_allocator = std.heap.FixedBufferAllocator.init(&args_buffer);
+
pub fn main() anyerror!void {
+ const args = std.process.argsAlloc(&args_allocator.allocator) catch {
+ @panic("Too many bytes passed over the CLI to the test runner");
+ };
+ std.testing.zig_exe_path = args[1];
+
const test_fn_list = builtin.test_functions;
var ok_count: usize = 0;
var skip_count: usize = 0;
diff --git a/lib/std/testing.zig b/lib/std/testing.zig
index 8e17c4e9f8..9b7010a08e 100644
--- a/lib/std/testing.zig
+++ b/lib/std/testing.zig
@@ -21,6 +21,10 @@ pub var base_allocator_instance = std.heap.FixedBufferAllocator.init("");
/// TODO https://github.com/ziglang/zig/issues/5738
pub var log_level = std.log.Level.warn;
+/// This is available to any test that wants to execute Zig in a child process.
+/// It will be the same executable that is running `zig test`.
+pub var zig_exe_path: []const u8 = undefined;
+
/// This function is intended to be used only in tests. It prints diagnostics to stderr
/// and then aborts when actual_error_union is not expected_error.
pub fn expectError(expected_error: anyerror, actual_error_union: anytype) void {