Skip to content

Commit d656c2a

Browse files
jacobly0andrewrk
authored andcommitted
test: rework how filtering works
* make test names contain the fully qualified name * make test filters match the fully qualified name * allow multiple test filters, where a test is skipped if it does not match any of the specified filters
1 parent 429e542 commit d656c2a

26 files changed

+494
-506
lines changed

build.zig

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ pub fn build(b: *std.Build) !void {
390390
}
391391
}
392392

393-
const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");
393+
const test_filters = b.option([]const []const u8, "test-filter", "Skip tests that do not match any filter") orelse &[0][]const u8{};
394394

395395
const test_cases_options = b.addOptions();
396396
check_case_exe.root_module.addOptions("build_options", test_cases_options);
@@ -418,7 +418,7 @@ pub fn build(b: *std.Build) !void {
418418
test_cases_options.addOption(?[]const u8, "glibc_runtimes_dir", b.glibc_runtimes_dir);
419419
test_cases_options.addOption([:0]const u8, "version", version);
420420
test_cases_options.addOption(std.SemanticVersion, "semver", semver);
421-
test_cases_options.addOption(?[]const u8, "test_filter", test_filter);
421+
test_cases_options.addOption([]const []const u8, "test_filters", test_filters);
422422

423423
var chosen_opt_modes_buf: [4]builtin.OptimizeMode = undefined;
424424
var chosen_mode_index: usize = 0;
@@ -454,7 +454,7 @@ pub fn build(b: *std.Build) !void {
454454
}).step);
455455

456456
const test_cases_step = b.step("test-cases", "Run the main compiler test cases");
457-
try tests.addCases(b, test_cases_step, test_filter, check_case_exe, .{
457+
try tests.addCases(b, test_cases_step, test_filters, check_case_exe, .{
458458
.enable_llvm = enable_llvm,
459459
.llvm_has_m68k = llvm_has_m68k,
460460
.llvm_has_csky = llvm_has_csky,
@@ -464,7 +464,7 @@ pub fn build(b: *std.Build) !void {
464464
test_step.dependOn(test_cases_step);
465465

466466
test_step.dependOn(tests.addModuleTests(b, .{
467-
.test_filter = test_filter,
467+
.test_filters = test_filters,
468468
.root_src = "test/behavior.zig",
469469
.name = "behavior",
470470
.desc = "Run the behavior tests",
@@ -477,7 +477,7 @@ pub fn build(b: *std.Build) !void {
477477
}));
478478

479479
test_step.dependOn(tests.addModuleTests(b, .{
480-
.test_filter = test_filter,
480+
.test_filters = test_filters,
481481
.root_src = "test/c_import.zig",
482482
.name = "c-import",
483483
.desc = "Run the @cImport tests",
@@ -489,7 +489,7 @@ pub fn build(b: *std.Build) !void {
489489
}));
490490

491491
test_step.dependOn(tests.addModuleTests(b, .{
492-
.test_filter = test_filter,
492+
.test_filters = test_filters,
493493
.root_src = "lib/compiler_rt.zig",
494494
.name = "compiler-rt",
495495
.desc = "Run the compiler_rt tests",
@@ -501,7 +501,7 @@ pub fn build(b: *std.Build) !void {
501501
}));
502502

503503
test_step.dependOn(tests.addModuleTests(b, .{
504-
.test_filter = test_filter,
504+
.test_filters = test_filters,
505505
.root_src = "lib/c.zig",
506506
.name = "universal-libc",
507507
.desc = "Run the universal libc tests",
@@ -512,7 +512,7 @@ pub fn build(b: *std.Build) !void {
512512
.skip_libc = true,
513513
}));
514514

515-
test_step.dependOn(tests.addCompareOutputTests(b, test_filter, optimization_modes));
515+
test_step.dependOn(tests.addCompareOutputTests(b, test_filters, optimization_modes));
516516
test_step.dependOn(tests.addStandaloneTests(
517517
b,
518518
optimization_modes,
@@ -523,16 +523,16 @@ pub fn build(b: *std.Build) !void {
523523
));
524524
test_step.dependOn(tests.addCAbiTests(b, skip_non_native, skip_release));
525525
test_step.dependOn(tests.addLinkTests(b, enable_macos_sdk, enable_ios_sdk, false, enable_symlinks_windows));
526-
test_step.dependOn(tests.addStackTraceTests(b, test_filter, optimization_modes));
526+
test_step.dependOn(tests.addStackTraceTests(b, test_filters, optimization_modes));
527527
test_step.dependOn(tests.addCliTests(b));
528-
test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, optimization_modes));
529-
test_step.dependOn(tests.addTranslateCTests(b, test_filter));
528+
test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filters, optimization_modes));
529+
test_step.dependOn(tests.addTranslateCTests(b, test_filters));
530530
if (!skip_run_translated_c) {
531-
test_step.dependOn(tests.addRunTranslatedCTests(b, test_filter, target));
531+
test_step.dependOn(tests.addRunTranslatedCTests(b, test_filters, target));
532532
}
533533

534534
test_step.dependOn(tests.addModuleTests(b, .{
535-
.test_filter = test_filter,
535+
.test_filters = test_filters,
536536
.root_src = "lib/std/std.zig",
537537
.name = "std",
538538
.desc = "Run the standard library tests",

doc/langref.html.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -988,13 +988,13 @@ fn addOne(number: i32) i32 {
988988
printed to standard error by the default test runner:
989989
</p>
990990
<dl>
991-
<dt><samp>Test [1/2] test.expect addOne adds one to 41...</samp></dt>
991+
<dt><samp>1/2 testing_introduction.test.expect addOne adds one to 41...</samp></dt>
992992
<dd>Lines like this indicate which test, out of the total number of tests, is being run.
993-
In this case, <samp>[1/2]</samp> indicates that the first test, out of a total of
994-
two test, is being run. Note that, when the test runner program's standard error is output
993+
In this case, <samp>1/2</samp> indicates that the first test, out of a total of two tests,
994+
is being run. Note that, when the test runner program's standard error is output
995995
to the terminal, these lines are cleared when a test succeeds.
996996
</dd>
997-
<dt><samp>Test [2/2] decltest.addOne...</samp></dt>
997+
<dt><samp>2/2 testing_introduction.decltest.addOne...</samp></dt>
998998
<dd>When the test name is an identifier, the default test runner uses the text
999999
decltest instead of test.
10001000
</dd>

lib/std/Build.zig

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,9 @@ pub const TestOptions = struct {
855855
optimize: std.builtin.OptimizeMode = .Debug,
856856
version: ?std.SemanticVersion = null,
857857
max_rss: usize = 0,
858+
/// deprecated: use `.filters = &.{filter}` instead of `.filter = filter`.
858859
filter: ?[]const u8 = null,
860+
filters: []const []const u8 = &.{},
859861
test_runner: ?[]const u8 = null,
860862
link_libc: ?bool = null,
861863
single_threaded: ?bool = null,
@@ -888,7 +890,12 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile {
888890
.error_tracing = options.error_tracing,
889891
},
890892
.max_rss = options.max_rss,
891-
.filter = options.filter,
893+
.filters = if (options.filter != null and options.filters.len > 0) filters: {
894+
const filters = b.allocator.alloc([]const u8, 1 + options.filters.len) catch @panic("OOM");
895+
filters[0] = b.dupe(options.filter.?);
896+
for (filters[1..], options.filters) |*dest, source| dest.* = b.dupe(source);
897+
break :filters filters;
898+
} else b.dupeStrings(if (options.filter) |filter| &.{filter} else options.filters),
892899
.test_runner = options.test_runner,
893900
.use_llvm = options.use_llvm,
894901
.use_lld = options.use_lld,
@@ -993,9 +1000,7 @@ pub fn dupe(self: *Build, bytes: []const u8) []u8 {
9931000
/// Duplicates an array of strings without the need to handle out of memory.
9941001
pub fn dupeStrings(self: *Build, strings: []const []const u8) [][]u8 {
9951002
const array = self.allocator.alloc([]u8, strings.len) catch @panic("OOM");
996-
for (strings, 0..) |s, i| {
997-
array[i] = self.dupe(s);
998-
}
1003+
for (array, strings) |*dest, source| dest.* = self.dupe(source);
9991004
return array;
10001005
}
10011006

lib/std/Build/Step/Compile.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ global_base: ?u64 = null,
5454
/// Set via options; intended to be read-only after that.
5555
zig_lib_dir: ?LazyPath,
5656
exec_cmd_args: ?[]const ?[]const u8,
57-
filter: ?[]const u8,
57+
filters: []const []const u8,
5858
test_runner: ?[]const u8,
5959
test_server_mode: bool,
6060
wasi_exec_model: ?std.builtin.WasiExecModel = null,
@@ -223,7 +223,7 @@ pub const Options = struct {
223223
linkage: ?Linkage = null,
224224
version: ?std.SemanticVersion = null,
225225
max_rss: usize = 0,
226-
filter: ?[]const u8 = null,
226+
filters: []const []const u8 = &.{},
227227
test_runner: ?[]const u8 = null,
228228
use_llvm: ?bool = null,
229229
use_lld: ?bool = null,
@@ -310,7 +310,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
310310
.installed_headers = ArrayList(*Step).init(owner.allocator),
311311
.zig_lib_dir = null,
312312
.exec_cmd_args = null,
313-
.filter = options.filter,
313+
.filters = options.filters,
314314
.test_runner = options.test_runner,
315315
.test_server_mode = options.test_runner == null,
316316
.rdynamic = false,
@@ -1297,7 +1297,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
12971297
try zig_args.append(b.fmt("0x{x}", .{image_base}));
12981298
}
12991299

1300-
if (self.filter) |filter| {
1300+
for (self.filters) |filter| {
13011301
try zig_args.append("--test-filter");
13021302
try zig_args.append(filter);
13031303
}

src/Compilation.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ libcxx_abi_version: libcxx.AbiVersion = libcxx.AbiVersion.default,
217217
/// This mutex guards all `Compilation` mutable state.
218218
mutex: std.Thread.Mutex = .{},
219219

220-
test_filter: ?[]const u8,
220+
test_filters: []const []const u8,
221221
test_name_prefix: ?[]const u8,
222222

223223
emit_asm: ?EmitLoc,
@@ -1097,7 +1097,7 @@ pub const CreateOptions = struct {
10971097
native_system_include_paths: []const []const u8 = &.{},
10981098
clang_preprocessor_mode: ClangPreprocessorMode = .no,
10991099
reference_trace: ?u32 = null,
1100-
test_filter: ?[]const u8 = null,
1100+
test_filters: []const []const u8 = &.{},
11011101
test_name_prefix: ?[]const u8 = null,
11021102
test_runner_path: ?[]const u8 = null,
11031103
subsystem: ?std.Target.SubSystem = null,
@@ -1506,7 +1506,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
15061506
.formatted_panics = formatted_panics,
15071507
.time_report = options.time_report,
15081508
.stack_report = options.stack_report,
1509-
.test_filter = options.test_filter,
1509+
.test_filters = options.test_filters,
15101510
.test_name_prefix = options.test_name_prefix,
15111511
.debug_compiler_runtime_libs = options.debug_compiler_runtime_libs,
15121512
.debug_compile_errors = options.debug_compile_errors,
@@ -1613,7 +1613,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
16131613
hash.add(options.config.use_lib_llvm);
16141614
hash.add(options.config.dll_export_fns);
16151615
hash.add(options.config.is_test);
1616-
hash.addOptionalBytes(options.test_filter);
1616+
hash.addListOfBytes(options.test_filters);
16171617
hash.addOptionalBytes(options.test_name_prefix);
16181618
hash.add(options.skip_linker_dependencies);
16191619
hash.add(formatted_panics);
@@ -2475,7 +2475,7 @@ fn addNonIncrementalStuffToCacheManifest(
24752475
try addModuleTableToCacheHash(gpa, arena, &man.hash, mod.root_mod, mod.main_mod, .{ .files = man });
24762476

24772477
// Synchronize with other matching comments: ZigOnlyHashStuff
2478-
man.hash.addOptionalBytes(comp.test_filter);
2478+
man.hash.addListOfBytes(comp.test_filters);
24792479
man.hash.addOptionalBytes(comp.test_name_prefix);
24802480
man.hash.add(comp.skip_linker_dependencies);
24812481
man.hash.add(comp.formatted_panics);

src/InternPool.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7904,7 +7904,7 @@ pub fn destroyNamespace(ip: *InternPool, gpa: Allocator, index: NamespaceIndex)
79047904
ip.namespacePtr(index).* = .{
79057905
.parent = undefined,
79067906
.file_scope = undefined,
7907-
.ty = undefined,
7907+
.decl_index = undefined,
79087908
};
79097909
ip.namespaces_free_list.append(gpa, index) catch {
79107910
// In order to keep `destroyNamespace` a non-fallible function, we ignore memory

0 commit comments

Comments
 (0)