std: force refAllDecls to actually resolve all decls

Only about half of the tests in std were actually being run (918 vs 2144).
This commit is contained in:
Veikka Tuominen
2022-02-13 14:35:49 +02:00
parent 17822e4a05
commit 8937f18a6f
3 changed files with 14 additions and 10 deletions

View File

@@ -466,6 +466,8 @@ test {
pub fn refAllDecls(comptime T: type) void {
if (!builtin.is_test) return;
inline for (comptime std.meta.declarations(T)) |decl| {
if (decl.is_pub and @typeInfo(@TypeOf(@field(T, decl.name))) == .Struct)
_ = @hasDecl(@field(T, decl.name), "foo");
_ = decl;
}
}

View File

@@ -166,7 +166,7 @@ pub fn sizeof(target: anytype) usize {
const array_info = @typeInfo(ptr.child).Array;
if ((array_info.child == u8 or array_info.child == u16) and
array_info.sentinel != null and
array_info.sentinel.? == 0)
@ptrCast(*const array_info.child, array_info.sentinel.?).* == 0)
{
// length of the string plus one for the null terminator.
return (array_info.len + 1) * @sizeOf(array_info.child);

View File

@@ -585,15 +585,6 @@ test "zig fmt: asm expression with comptime content" {
);
}
test "zig fmt: anytype struct field" {
try testCanonical(
\\pub const Pointer = struct {
\\ sentinel: anytype,
\\};
\\
);
}
test "zig fmt: array types last token" {
try testCanonical(
\\test {
@@ -4148,6 +4139,17 @@ test "zig fmt: container doc comments" {
);
}
test "zig fmt: anytype struct field" {
try testError(
\\pub const Pointer = struct {
\\ sentinel: anytype,
\\};
\\
, &[_]Error{
.expected_type_expr,
});
}
test "zig fmt: extern without container keyword returns error" {
try testError(
\\const container = extern {};