authorgravatar for 4678790+dweiller@users.noreply.github.comDominic <4678790+dweiller@users.noreply.github.com> 2022-10-25 16:52:29+11:00
committergravatar for 4678790+dweiller@users.noreply.github.comDominic <4678790+dweiller@users.noreply.github.com> 2022-11-02 12:54:35+11:00
log55c91fc42d048a18c724bdaffe3709bef8aa143e
tree36adf282f6f3509e97a6d348ceb96a712a240608
parentebf9ffd342a30c7c79657f5dbfc83fde0647e630

stage2: add test_runner_path for user provided test runner


2 files changed, 15 insertions(+), 6 deletions(-)

src/Compilation.zig+10-6
......@@ -994,6 +994,7 @@ pub const InitOptions = struct {
994994 reference_trace: ?u32 = null,
995995 test_filter: ?[]const u8 = null,
996996 test_name_prefix: ?[]const u8 = null,
997 test_runner_path: ?[]const u8 = null,
997998 subsystem: ?std.Target.SubSystem = null,
998999 /// WASI-only. Type of WASI execution model ("command" or "reactor").
9991000 wasi_exec_model: ?std.builtin.WasiExecModel = null,
......@@ -1578,12 +1579,15 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
15781579 errdefer std_pkg.destroy(gpa);
15791580
15801581 const root_pkg = if (options.is_test) root_pkg: {
1581 const test_pkg = try Package.createWithDir(
1582 gpa,
1583 options.zig_lib_directory,
1584 null,
1585 "test_runner.zig",
1586 );
1582 const test_pkg = if (options.test_runner_path) |test_runner|
1583 try Package.create(gpa, null, test_runner)
1584 else
1585 try Package.createWithDir(
1586 gpa,
1587 options.zig_lib_directory,
1588 null,
1589 "test_runner.zig",
1590 );
15871591 errdefer test_pkg.destroy(gpa);
15881592
15891593 break :root_pkg test_pkg;
src/main.zig+5
......@@ -503,6 +503,7 @@ const usage_build_generic =
503503 \\ --test-cmd-bin Appends test binary path to test cmd args
504504 \\ --test-evented-io Runs the test in evented I/O mode
505505 \\ --test-no-exec Compiles test binary without running it
506 \\ --test-runner [path] Specify a custom test runner
506507 \\
507508 \\Debug Options (Zig Compiler Development):
508509 \\ -ftime-report Print timing diagnostics
......@@ -726,6 +727,7 @@ fn buildOutputType(
726727 var runtime_args_start: ?usize = null;
727728 var test_filter: ?[]const u8 = null;
728729 var test_name_prefix: ?[]const u8 = null;
730 var test_runner_path: ?[]const u8 = null;
729731 var override_local_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LOCAL_CACHE_DIR");
730732 var override_global_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_GLOBAL_CACHE_DIR");
731733 var override_lib_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LIB_DIR");
......@@ -1043,6 +1045,8 @@ fn buildOutputType(
10431045 test_filter = args_iter.nextOrFatal();
10441046 } else if (mem.eql(u8, arg, "--test-name-prefix")) {
10451047 test_name_prefix = args_iter.nextOrFatal();
1048 } else if (mem.eql(u8, arg, "--test-runner")) {
1049 test_runner_path = args_iter.nextOrFatal();
10461050 } else if (mem.eql(u8, arg, "--test-cmd")) {
10471051 try test_exec_args.append(args_iter.nextOrFatal());
10481052 } else if (mem.eql(u8, arg, "--cache-dir")) {
......@@ -2943,6 +2947,7 @@ fn buildOutputType(
29432947 .test_evented_io = test_evented_io,
29442948 .test_filter = test_filter,
29452949 .test_name_prefix = test_name_prefix,
2950 .test_runner_path = test_runner_path,
29462951 .disable_lld_caching = !have_enable_cache,
29472952 .subsystem = subsystem,
29482953 .wasi_exec_model = wasi_exec_model,