Repository navigation
fix(tests): recursively collect nested zspec tests (#14) - #16
Conversation
…w run (#14) tests/root.zig used std.testing.refAllDecls, which is one level deep: it referenced the imported test files but NOT the doubly-nested `pub const FooSpec = struct { pub const group = struct { test ... } }` zspec groups. Under Zig 0.16 a test block is only collected once its container is analyzed, so every nested spec test was silently never compiled OR run — `zig build test` reported only the single root-level #13 regression test and passed even with failing assertions. Add a local refAllDeclsRecursive (Zig 0.16 dropped the std one) so every nested group is analyzed and its tests collected. This surfaced that the dead tests were masking 0.16-stale code in the library itself: * src/a_star.zig — PriorityQueue moved to the unmanaged API (init->initContext, add->push(allocator), removeOrNull->pop, deinit(allocator)) * src/z_index_buckets.zig — ArrayListUnmanaged init {} -> .empty * tests/floyd_warshall_optimized_test.zig — same ArrayListUnmanaged init Result: 1 -> 91 tests run, all green; force-failing any nested test now fails `zig build test`. version 0.7.2 -> 0.7.3.
PR SummaryMedium Risk Overview Once those tests actually ran, the PR updates Zig 0.16 std API usage: A*’s open set uses Reviewed by Cursor Bugbot for commit b627ac3. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
Code Review
This pull request updates the codebase for compatibility with Zig 0.16.0. Key changes include updating std.PriorityQueue API usage in src/a_star.zig, adopting .empty initializers for Bucket and ArrayListUnmanaged, and introducing a custom refAllDeclsRecursive helper in tests/root.zig to ensure nested tests are run. Feedback on the changes suggests checking decl.is_pub within refAllDeclsRecursive to avoid attempting to inspect private declarations, which can lead to compile-time errors or increased compilation times.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| inline for (comptime std.meta.declarations(T)) |decl| { | ||
| const field = @field(T, decl.name); | ||
| if (@TypeOf(field) == type) { | ||
| switch (@typeInfo(field)) { | ||
| .@"struct", .@"enum", .@"union", .@"opaque" => refAllDeclsRecursive(field), | ||
| else => {}, | ||
| } | ||
| } | ||
| _ = &@field(T, decl.name); | ||
| } |
There was a problem hiding this comment.
Checking decl.is_pub is highly recommended here. Without this check, refAllDeclsRecursive will attempt to inspect private declarations (such as private imports like const std = @import("std"); or other helper constants/functions). This can lead to compile-time errors (since private declarations of other files/structs cannot be accessed from outside) or cause the compiler to recursively traverse the entire standard library, significantly increasing compile times or hitting recursion limits.
inline for (comptime std.meta.declarations(T)) |decl| {
if (!decl.is_pub) continue;
const field = @field(T, decl.name);
if (@TypeOf(field) == type) {
switch (@typeInfo(field)) {
.@"struct", .@"enum", .@"union", .@"opaque" => refAllDeclsRecursive(field),
else => {},
}
}
_ = &@field(T, decl.name);
}
|
This suggestion is based on an older Zig — in 0.16 |
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_f7606078-da3c-49cb-93f7-ca613dd28211) |
Closes #14. One-level refAllDecls meant doubly-nested zspec tests (FooSpec → group → test) were never compiled or run under Zig 0.16 — zig build test ran only the root #13 test and passed even when broken. Added refAllDeclsRecursive; surfaced + fixed 0.16-stale library code it masked (a_star PriorityQueue → unmanaged initContext/push/pop/deinit(allocator); z_index_buckets + a floyd test ArrayListUnmanaged → .empty). 1 → 91 tests run, all green; force-failing a nested test now fails the build (verified). v0.7.2 → 0.7.3.