diff options
| author | alichraghi <alichraghi@pm.me> | 2022-07-13 18:46:10 +0430 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-07-16 12:33:25 +0300 |
| commit | 9c66fdadc709ca4c00b08aa8fa4dc6312cb559c3 (patch) | |
| tree | 26abeca76f7b54eb02a0efd65c043b4aa25b49f3 /lib/std/testing.zig | |
| parent | 43770c010321d965aba716d717e8470ae0ae966d (diff) | |
| download | zig-9c66fdadc709ca4c00b08aa8fa4dc6312cb559c3.tar.gz zig-9c66fdadc709ca4c00b08aa8fa4dc6312cb559c3.zip | |
std.testing: add `refAllDeclsRecursive` function
Diffstat (limited to 'lib/std/testing.zig')
| -rw-r--r-- | lib/std/testing.zig | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/std/testing.zig b/lib/std/testing.zig index 1deccce68b..f8155d413d 100644 --- a/lib/std/testing.zig +++ b/lib/std/testing.zig @@ -723,3 +723,19 @@ pub fn refAllDecls(comptime T: type) void { if (decl.is_pub) _ = @field(T, decl.name); } } + +/// Given a type, and Recursively reference all the declarations inside, so that the semantic analyzer sees them. +/// For deep types, you may use `@setEvalBranchQuota` +pub fn refAllDeclsRecursive(comptime T: type) void { + inline for (comptime std.meta.declarations(T)) |decl| { + if (decl.is_pub) { + if (@TypeOf(@field(T, decl.name)) == type) { + switch (@typeInfo(@field(T, decl.name))) { + .Struct, .Enum, .Union, .Opaque => refAllDeclsRecursive(@field(T, decl.name)), + else => {}, + } + } + _ = @field(T, decl.name); + } + } +} |
