Skip to content

Commit 9ef4bdf

Browse files
committed
test: Respect various test skip options in test-cases
1 parent aa15561 commit 9ef4bdf

File tree

3 files changed

+56
-13
lines changed

3 files changed

+56
-13
lines changed

build.zig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,18 @@ pub fn build(b: *std.Build) !void {
415415
test_step.dependOn(check_fmt);
416416

417417
const test_cases_step = b.step("test-cases", "Run the main compiler test cases");
418-
try tests.addCases(b, test_cases_step, test_filters, test_target_filters, target, .{
418+
try tests.addCases(b, test_cases_step, target, .{
419+
.test_filters = test_filters,
420+
.test_target_filters = test_target_filters,
421+
.skip_non_native = skip_non_native,
422+
.skip_freebsd = skip_freebsd,
423+
.skip_netbsd = skip_netbsd,
424+
.skip_windows = skip_windows,
425+
.skip_macos = skip_macos,
426+
.skip_linux = skip_linux,
427+
.skip_llvm = skip_llvm,
428+
.skip_libc = skip_libc,
429+
}, .{
419430
.skip_translate_c = skip_translate_c,
420431
.skip_run_translated_c = skip_run_translated_c,
421432
}, .{

test/src/Cases.zig

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -594,30 +594,57 @@ pub fn lowerToTranslateCSteps(
594594
};
595595
}
596596

597+
pub const CaseTestOptions = struct {
598+
test_filters: []const []const u8,
599+
test_target_filters: []const []const u8,
600+
skip_non_native: bool,
601+
skip_freebsd: bool,
602+
skip_netbsd: bool,
603+
skip_windows: bool,
604+
skip_macos: bool,
605+
skip_linux: bool,
606+
skip_llvm: bool,
607+
skip_libc: bool,
608+
};
609+
597610
pub fn lowerToBuildSteps(
598611
self: *Cases,
599612
b: *std.Build,
600613
parent_step: *std.Build.Step,
601-
test_filters: []const []const u8,
602-
test_target_filters: []const []const u8,
614+
options: CaseTestOptions,
603615
) void {
604616
const host = std.zig.system.resolveTargetQuery(.{}) catch |err|
605617
std.debug.panic("unable to detect native host: {s}\n", .{@errorName(err)});
606618
const cases_dir_path = b.build_root.join(b.allocator, &.{ "test", "cases" }) catch @panic("OOM");
607619

608620
for (self.cases.items) |case| {
609-
for (test_filters) |test_filter| {
621+
for (options.test_filters) |test_filter| {
610622
if (std.mem.indexOf(u8, case.name, test_filter)) |_| break;
611-
} else if (test_filters.len > 0) continue;
623+
} else if (options.test_filters.len > 0) continue;
624+
625+
if (options.skip_non_native and !case.target.query.isNative())
626+
continue;
627+
628+
if (options.skip_freebsd and case.target.query.os_tag == .freebsd) continue;
629+
if (options.skip_netbsd and case.target.query.os_tag == .netbsd) continue;
630+
if (options.skip_windows and case.target.query.os_tag == .windows) continue;
631+
if (options.skip_macos and case.target.query.os_tag == .macos) continue;
632+
if (options.skip_linux and case.target.query.os_tag == .linux) continue;
633+
634+
const would_use_llvm = @import("../tests.zig").wouldUseLlvm(case.backend == .llvm, case.target.query, case.optimize_mode);
635+
if (options.skip_llvm and would_use_llvm) continue;
612636

613637
const triple_txt = case.target.query.zigTriple(b.allocator) catch @panic("OOM");
614638

615-
if (test_target_filters.len > 0) {
616-
for (test_target_filters) |filter| {
639+
if (options.test_target_filters.len > 0) {
640+
for (options.test_target_filters) |filter| {
617641
if (std.mem.indexOf(u8, triple_txt, filter) != null) break;
618642
} else continue;
619643
}
620644

645+
if (options.skip_libc and case.link_libc)
646+
continue;
647+
621648
const writefiles = b.addWriteFiles();
622649
var file_sources = std.StringHashMap(std.Build.LazyPath).init(b.allocator);
623650
defer file_sources.deinit();

test/tests.zig

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,7 +2517,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
25172517
return step;
25182518
}
25192519

2520-
fn wouldUseLlvm(use_llvm: ?bool, query: std.Target.Query, optimize_mode: OptimizeMode) bool {
2520+
pub fn wouldUseLlvm(use_llvm: ?bool, query: std.Target.Query, optimize_mode: OptimizeMode) bool {
25212521
if (use_llvm) |x| return x;
25222522
if (query.ofmt == .c) return false;
25232523
switch (optimize_mode) {
@@ -2629,9 +2629,8 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {
26292629
pub fn addCases(
26302630
b: *std.Build,
26312631
parent_step: *Step,
2632-
test_filters: []const []const u8,
2633-
test_target_filters: []const []const u8,
26342632
target: std.Build.ResolvedTarget,
2633+
case_test_options: @import("src/Cases.zig").CaseTestOptions,
26352634
translate_c_options: @import("src/Cases.zig").TranslateCOptions,
26362635
build_options: @import("cases.zig").BuildOptions,
26372636
) !void {
@@ -2646,13 +2645,19 @@ pub fn addCases(
26462645
cases.addFromDir(dir, b);
26472646
try @import("cases.zig").addCases(&cases, build_options, b);
26482647

2649-
cases.lowerToTranslateCSteps(b, parent_step, test_filters, test_target_filters, target, translate_c_options);
2648+
cases.lowerToTranslateCSteps(
2649+
b,
2650+
parent_step,
2651+
case_test_options.test_filters,
2652+
case_test_options.test_target_filters,
2653+
target,
2654+
translate_c_options,
2655+
);
26502656

26512657
cases.lowerToBuildSteps(
26522658
b,
26532659
parent_step,
2654-
test_filters,
2655-
test_target_filters,
2660+
case_test_options,
26562661
);
26572662
}
26582663

0 commit comments

Comments
 (0)