From 5228c8902fe178834f678cb5bec12a5a32d5df2f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 5 Aug 2026 16:31:10 -0700 Subject: [PATCH] tests: use skip_foreign_checks rather than dead branch Configuration logic, in general, should not try to guess whether an executable will be able to be run on the host. This can only be determined by trying to, and encountering failure, for example because binfmt_misc might be installed. OS might handle illegal instruction traps and emulate CPU features not available, etc. skip_foreign_checks is the mechanism intended to handle this use case. --- test/src/ErrorTrace.zig | 2 + test/src/StackTrace.zig | 2 + test/tests.zig | 84 +++++++++++++++++++---------------------- 3 files changed, 42 insertions(+), 46 deletions(-) diff --git a/test/src/ErrorTrace.zig b/test/src/ErrorTrace.zig index b0ce8b05bb39687429ffb8eec893f254d4c4813a..d570cf406ae4d248ff106c7b304cc77eb9097eef 100644 --- a/test/src/ErrorTrace.zig +++ b/test/src/ErrorTrace.zig @@ -105,6 +105,7 @@ fn addCaseConfig( exe.bundle_ubsan_rt = false; const run = b.addRunArtifact(exe); + run.skip_foreign_checks = true; run.removeEnvironmentVariable("CLICOLOR_FORCE"); run.setEnvironmentVariable("NO_COLOR", "1"); run.expectExitCode(1); @@ -116,6 +117,7 @@ fn addCaseConfig( }; const check_run = b.addRunArtifact(self.convert_exe); + check_run.skip_foreign_checks = true; check_run.setName(annotated_case_name); check_run.addFileArg(run.captureStdErr(.{})); check_run.expectStdOutEqual(expected_stderr); diff --git a/test/src/StackTrace.zig b/test/src/StackTrace.zig index 23938cbf1ade2733f8220bbb03612c183ad7e27a..ae2abdd21eddebbf2af40382404644de9d71277f 100644 --- a/test/src/StackTrace.zig +++ b/test/src/StackTrace.zig @@ -224,6 +224,7 @@ fn addCaseInstance( exe.bundle_ubsan_rt = false; const run = b.addRunArtifact(exe); + run.skip_foreign_checks = true; run.removeEnvironmentVariable("CLICOLOR_FORCE"); run.setEnvironmentVariable("NO_COLOR", "1"); run.addCheck(.{ .expect_term = term: { @@ -234,6 +235,7 @@ fn addCaseInstance( run.expectStdOutEqual(""); const check_run = b.addRunArtifact(self.convert_exe); + check_run.skip_foreign_checks = true; check_run.setName(annotated_case_name); check_run.addFileArg(run.captureStdErr(.{})); check_run.expectExitCode(0); diff --git a/test/tests.zig b/test/tests.zig index e2f62400d1d0efa4d40966263e64d4d80e0f2306..bf72b15cf3eb42ab4de671277aeb6555bd5a5867 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -2455,29 +2455,25 @@ pub fn addStackTraceTests( }; stack_traces.addCases(host_cases, b.graph.host.result.os.tag); - if (b.enable_wine) { - const wine_cases = b.allocator.create(StackTracesContext) catch @panic("OOM"); - wine_cases.* = .{ - .b = b, - .step = step, - .test_filters = test_filters, - .targets = wineAndCompatible32bit(b, skip_non_native), - .convert_exe = convert_exe, - }; - stack_traces.addCases(wine_cases, .windows); - } + const wine_cases = b.allocator.create(StackTracesContext) catch @panic("OOM"); + wine_cases.* = .{ + .b = b, + .step = step, + .test_filters = test_filters, + .targets = wineAndCompatible32bit(b, skip_non_native), + .convert_exe = convert_exe, + }; + stack_traces.addCases(wine_cases, .windows); - if (b.enable_darling) { - const darling_cases = b.allocator.create(StackTracesContext) catch @panic("OOM"); - darling_cases.* = .{ - .b = b, - .step = step, - .test_filters = test_filters, - .targets = darlingTargets(b), - .convert_exe = convert_exe, - }; - stack_traces.addCases(darling_cases, .macos); - } + const darling_cases = b.allocator.create(StackTracesContext) catch @panic("OOM"); + darling_cases.* = .{ + .b = b, + .step = step, + .test_filters = test_filters, + .targets = darlingTargets(b), + .convert_exe = convert_exe, + }; + stack_traces.addCases(darling_cases, .macos); return step; } @@ -2510,31 +2506,27 @@ pub fn addErrorTraceTests( }; error_traces.addCases(host_cases, b.graph.host.result.os.tag); - if (b.enable_wine) { - const wine_cases = b.allocator.create(ErrorTracesContext) catch @panic("OOM"); - wine_cases.* = .{ - .b = b, - .step = step, - .test_filters = test_filters, - .targets = wineAndCompatible32bit(b, skip_non_native), - .optimize_modes = optimize_modes, - .convert_exe = convert_exe, - }; - error_traces.addCases(wine_cases, .windows); - } + const wine_cases = b.allocator.create(ErrorTracesContext) catch @panic("OOM"); + wine_cases.* = .{ + .b = b, + .step = step, + .test_filters = test_filters, + .targets = wineAndCompatible32bit(b, skip_non_native), + .optimize_modes = optimize_modes, + .convert_exe = convert_exe, + }; + error_traces.addCases(wine_cases, .windows); - if (b.enable_darling) { - const darling_cases = b.allocator.create(ErrorTracesContext) catch @panic("OOM"); - darling_cases.* = .{ - .b = b, - .step = step, - .test_filters = test_filters, - .targets = darlingTargets(b), - .optimize_modes = optimize_modes, - .convert_exe = convert_exe, - }; - error_traces.addCases(darling_cases, .macos); - } + const darling_cases = b.allocator.create(ErrorTracesContext) catch @panic("OOM"); + darling_cases.* = .{ + .b = b, + .step = step, + .test_filters = test_filters, + .targets = darlingTargets(b), + .optimize_modes = optimize_modes, + .convert_exe = convert_exe, + }; + error_traces.addCases(darling_cases, .macos); return step; } -- 2.54.0