You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a test fails as a result of std.debug.assert recieving false, it produces a rather large error message:
thread 11119 panic: reached unreachable codezig/lib/std/debug.zig:412:14: 0x103eb9d in assert (test) if (!ok) unreachable; // assertion failure ^zig-string/zig-string-tests.zig:24:21: 0x103e25f in test.Basic Usage (test) std.debug.assert(myString.cmp("🔥 Hello, World ")); ^zig/lib/compiler/test_runner.zig:155:25: 0x1057a99 in mainTerminal (test) if (test_fn.func()) |_| { ^zig/lib/compiler/test_runner.zig:35:28: 0x104c7db in main (test) return mainTerminal(); ^zig/lib/std/start.zig:505:22: 0x10479f9 in posixCallMainAndExit (test) root.main(); ^zig/lib/std/start.zig:258:5: 0x1047561 in _start (test) asm volatile (switch (native_arch) { ^???:?:?: 0x0 in ??? (???)error: the following test command crashed:zig-string/.zig-cache/o/eb36f7fdef19d5a1c7c2da449e45015e/test
But when try std.testing.expect is used instead, the error message looks like this:
1/7 zig-string-tests.test.Basic Usage...FAIL (TestUnexpectedResult)zig/lib/std/testing.zig:542:14: 0x103e15f in expect (test) if (!ok) return error.TestUnexpectedResult; ^Zig Projects/zig-string/zig-string-tests.zig:24:5: 0x103e3c4 in test.Basic Usage (test) try expect(myString.cmp("🔥 Hello, World ")); ^6 passed; 0 skipped; 1 failed.error: the following test command failed with exit code 1:zig-string/.zig-cache/o/eb36f7fdef19d5a1c7c2da449e45015e/test
Not only is the message shorter, but it's also clearer that a test failed, and where it failed.
std.debug.assert should not be used in testing, as it's meant for debugging programs. Always use std.testing.expect in tests to assert that a condition is true.
The text was updated successfully, but these errors were encountered:
MorganMcmillan
changed the title
Replace std.debug.assert with std.testing.expect
Replace std.debug.assert with std.testing.expect in tests
Jul 4, 2024
When a test fails as a result of
std.debug.assert
recievingfalse
, it produces a rather large error message:But when
try std.testing.expect
is used instead, the error message looks like this:Not only is the message shorter, but it's also clearer that a test failed, and where it failed.
std.debug.assert
should not be used in testing, as it's meant for debugging programs. Always usestd.testing.expect
in tests to assert that a condition is true.The text was updated successfully, but these errors were encountered: