diff options
| author | Johan Bolmsjö <dev@johan.bitmaster.se> | 2019-11-14 23:29:21 +0100 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-11-19 06:22:34 +0000 |
| commit | ad77e93415add43d1c259ea462d6653b1f16a5e2 (patch) | |
| tree | 3142701d76c8cc57b11e0b52b1176c3d9135a0ef /lib/std/testing.zig | |
| parent | b3539b40a6fc98978b820a74c348b6272bfbc027 (diff) | |
| download | zig-ad77e93415add43d1c259ea462d6653b1f16a5e2.tar.gz zig-ad77e93415add43d1c259ea462d6653b1f16a5e2.zip | |
std.testing.expectEqual: show differing pointer values
Show differing pointer values when comparing pointers instead of the
content they point to.
It's confusing for a test to say "expected S{.x = 1}, found S{.x = 1}"
as illustrated below when it was the pointers that differed.
There seems to be different rules for when a pointer is dereferenced by
the printing routine depending on its type. I don't fully grok this but
it's also illustrated below.
const std = @import("std");
const S = struct { x: u32 };
// before: ...expected S{ .x = 1 }, found S{ .x = 1 }
// after: ...expected S@7ffcd20b7798, found S@7ffcd20b7790
test "compare_ptr_to_struct" {
var a = S{.x = 1};
var b = S{.x = 1};
std.testing.expectEqual(&a, &b);
}
// before: ...expected u32@7fff316ba31c, found u32@7fff316ba318
// after: ...expected u32@7ffecec622dc, found u32@7ffecec622d8
test "compare_ptr_to_scalar" {
var a: u32 = 1;
var b: u32 = 1;
std.testing.expectEqual(&a, &b);
}
Diffstat (limited to 'lib/std/testing.zig')
| -rw-r--r-- | lib/std/testing.zig | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/std/testing.zig b/lib/std/testing.zig index 7f347b0c24..09ab6e406d 100644 --- a/lib/std/testing.zig +++ b/lib/std/testing.zig @@ -62,7 +62,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { builtin.TypeInfo.Pointer.Size.C, => { if (actual != expected) { - std.debug.panic("expected {}, found {}", expected, actual); + std.debug.panic("expected {*}, found {*}", expected, actual); } }, |
