ReviewOS

also looking at this

zig-utils/zig-test-framework

Unify discovery and programmatic test execution

#23
Merged glennmichael123 wants to merge codex/issue-5-unified-test-pipeline into main
12 files +656 -169
src/parallel.zigmodified+15-1
Changes to src/parallel.zig
@@ -1,6 +1,7 @@
11const std = ;
22const suite = ;
33const reporter = ;
4const pipeline = ;
45const compat = ;
56
67/// Options for bounded parallel test execution.
@@ -10,6 +11,7 @@ pub const ParallelOptions = struct {
1011 n_jobs: ?usize = null,
1112 enabled: bool = false,
1213 filter: ?[]const u8 = null,
14 timeout_ms: ?u64 = null,
1315};
1416
1517pub const ParallelError = error{
@@ -31,6 +33,7 @@ const WorkerContext = struct {
3133 tests: []const *suite.TestCase,
3234 next_index: std.atomic.Value(usize) = std.atomic.Value(usize).init(0),
3335 error_mutex: compat.Mutex = .{},
36 policy: pipeline.ExecutionPolicy,
3437
3538 fn worker(self: *WorkerContext) void {
3639 while (true) {
@@ -90,8 +93,15 @@ const WorkerContext = struct {
9093 test_case.error_message = std.fmt.allocPrint(self.allocator, format, args) catch "Out of memory";
9194 }
9295
93 fn finishTiming(_: *WorkerContext, test_case: *suite.TestCase, start_time: i128) void {
96 fn finishTiming(self: *WorkerContext, test_case: *suite.TestCase, start_time: i128) void {
9497 test_case.execution_time_ns = @intCast(compat.nanoTimestamp() - start_time);
98 if (test_case.status == .passed and self.policy.timedOut(test_case.execution_time_ns)) {
99 self.fail(
100 test_case,
101 "Test exceeded timeout of {d}ms",
102 .{self.policy.timeout_ms.?},
103 );
104 }
95105 }
96106};
97107
@@ -167,6 +177,10 @@ const RunContext = struct {
167177 .allocator = self.allocator,
168178 .test_suite = test_suite,
169179 .tests = tests,
180 .policy = .{
181 .filter = self.options.filter,
182 .timeout_ms = self.options.timeout_ms,
183 },
170184 };
171185 const count = @min(self.worker_limit, tests.len);
172186 var threads: std.ArrayList(std.Thread) = .empty;