Skip to content

Commit 2caae02

Browse files
test: cover discovery filtering end to end
1 parent 4d50a92 commit 2caae02

4 files changed

Lines changed: 34 additions & 13 deletions

File tree

‎README.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,15 @@ This will automatically discover and run all `*.test.zig` files in the `tests` d
9494
- `--pattern <pattern>` - File pattern to match (default: `*.test.zig`)
9595
- `--no-recursive` - Disable recursive directory search
9696
- `--bail` - Stop on first failure
97+
- `--filter <text>` / `--grep <text>` - Run only Zig tests whose names contain the text
98+
- `--no-color` - Disable color in child Zig test processes
9799
- `--verbose` - Show detailed output
98100

101+
Discovery mode rejects options that it cannot honor yet instead of silently
102+
ignoring them. Reporter selection, quiet output, timeouts, parallel jobs,
103+
snapshot updates, memory profiling, configuration files, JUnit output, and the
104+
web UI require the shared execution pipeline planned for future releases.
105+
99106
**Examples:**
100107

101108
```bash

‎build.zig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ pub fn build(b: *std.Build) void {
130130
.target = target,
131131
.optimize = optimize,
132132
.link_libc = true,
133+
.imports = &.{
134+
.{ .name = "zig_test_framework", .module = lib_module },
135+
},
133136
}),
134137
});
135138
const run_filter_tests = b.addRunArtifact(filter_tests);

‎tests/filter_test.zig‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
const std = @import("std");
2+
const ztf = @import("zig_test_framework");
23

3-
// Placeholder tests for filter module
4-
// TODO: Implement comprehensive tests for test filtering
4+
test "discovery forwards test-name filters to zig test" {
5+
const allocator = std.testing.allocator;
6+
var discovered = ztf.DiscoveryResult.init(allocator);
7+
defer discovered.deinit();
58

6-
test "filter by test name" {
7-
// Test filtering tests by name
8-
try std.testing.expect(true);
9-
}
9+
try discovered.addFile(
10+
"tests/fixtures/filter_fixture.zig",
11+
"fixtures/filter_fixture.zig",
12+
"filter_fixture.zig",
13+
);
1014

11-
test "filter by pattern" {
12-
// Test filtering tests by pattern
13-
try std.testing.expect(true);
14-
}
15+
const passed = try ztf.runDiscoveredTests(allocator, &discovered, .{
16+
.filter = "selected test passes",
17+
.use_colors = false,
18+
});
1519

16-
test "filter combination" {
17-
// Test combined filters
18-
try std.testing.expect(true);
20+
try std.testing.expect(passed);
1921
}

‎tests/fixtures/filter_fixture.zig‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const std = @import("std");
2+
3+
test "selected test passes" {
4+
try std.testing.expect(true);
5+
}
6+
7+
test "unselected test fails" {
8+
return error.ShouldHaveBeenFiltered;
9+
}

0 commit comments

Comments
 (0)