zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 3b51b43dc890dd8df17cb647ff7e1d3a53c438e7 (tree)
parent 4a2b23c2beb043c1e5368d3737893494d61d4060
Author: Alex Rønne Petersen <alex@alexrp.com>
Date:   Tue, 13 Aug 2024 23:59:50 +0200

build/test: Add -Dtest-target-filter for filtering module tests by target triple.

This is useful during porting work where you're not interested in running all
targets all the time while iterating on changes.

Diffstat:
Mbuild.zig | 6++++++
Mtest/tests.zig | 9++++++++-
2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/build.zig b/build.zig @@ -379,6 +379,7 @@ pub fn build(b: *std.Build) !void { } const test_filters = b.option([]const []const u8, "test-filter", "Skip tests that do not match any filter") orelse &[0][]const u8{}; + const test_target_filters = b.option([]const []const u8, "test-target-filter", "Skip tests whose target triple do not match any filter") orelse &[0][]const u8{}; const test_cases_options = b.addOptions(); @@ -457,6 +458,7 @@ pub fn build(b: *std.Build) !void { test_step.dependOn(tests.addModuleTests(b, .{ .test_filters = test_filters, + .test_target_filters = test_target_filters, .root_src = "test/behavior.zig", .name = "behavior", .desc = "Run the behavior tests", @@ -470,6 +472,7 @@ pub fn build(b: *std.Build) !void { test_step.dependOn(tests.addModuleTests(b, .{ .test_filters = test_filters, + .test_target_filters = test_target_filters, .root_src = "test/c_import.zig", .name = "c-import", .desc = "Run the @cImport tests", @@ -482,6 +485,7 @@ pub fn build(b: *std.Build) !void { test_step.dependOn(tests.addModuleTests(b, .{ .test_filters = test_filters, + .test_target_filters = test_target_filters, .root_src = "lib/compiler_rt.zig", .name = "compiler-rt", .desc = "Run the compiler_rt tests", @@ -495,6 +499,7 @@ pub fn build(b: *std.Build) !void { test_step.dependOn(tests.addModuleTests(b, .{ .test_filters = test_filters, + .test_target_filters = test_target_filters, .root_src = "lib/c.zig", .name = "universal-libc", .desc = "Run the universal libc tests", @@ -521,6 +526,7 @@ pub fn build(b: *std.Build) !void { test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filters, optimization_modes)); test_step.dependOn(tests.addModuleTests(b, .{ .test_filters = test_filters, + .test_target_filters = test_target_filters, .root_src = "lib/std/std.zig", .name = "std", .desc = "Run the standard library tests", diff --git a/test/tests.zig b/test/tests.zig @@ -965,6 +965,7 @@ pub fn addRunTranslatedCTests( const ModuleTestOptions = struct { test_filters: []const []const u8, + test_target_filters: []const []const u8, root_src: []const u8, name: []const u8, desc: []const u8, @@ -986,6 +987,13 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { const resolved_target = b.resolveTargetQuery(test_target.target); const target = resolved_target.result; + const triple_txt = target.zigTriple(b.allocator) catch @panic("OOM"); + + if (options.test_target_filters.len > 0) { + for (options.test_target_filters) |filter| { + if (std.mem.indexOf(u8, triple_txt, filter) != null) break; + } else continue; + } if (options.skip_libc and test_target.link_libc == true) continue; @@ -1034,7 +1042,6 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { if (!want_this_mode) continue; const libc_suffix = if (test_target.link_libc == true) "-libc" else ""; - const triple_txt = target.zigTriple(b.allocator) catch @panic("OOM"); const model_txt = target.cpu.model.name; // wasm32-wasi builds need more RAM, idk why