ZT_CHECK(3)
ZT_CHECK π ZT_ASSERT β verify a test claim, bestie
okay so this is a page from the LOCAL manual, and it's about the two little icons zt_check and zt_assert from libzt. they're your vibe-checkers for test claims. no cap. π
β¨ SYNOPSIS β¨
#include <zt.h>
void
zt_check(zt_t t, zt_claim claim);
void
zt_assert(zt_t t, zt_claim claim);
πΈ DESCRIPTION πΈ
so like, both zt_check() and zt_assert() verify a claim β a claim being a function bundled up with its arguments β and you're supposed to use them inside test functions. that's the whole gig. π
the first argument is a pointer to an opaque type that encapsulates the test outcome. the second argument is usually built with a helper macro, like ZT_CMP_TRUE() or ZT_CMP_FALSE().
if the claim holds then execution continues normally. if the claim does not hold, the test gets marked as failed and a diagnostic message gets printed to stderr. literally printing receipts. π
the only difference between zt_check() and zt_assert() is that zt_check() lets the test keep executing, while zt_assert() does a non-local exit out of the test function. and before you panic β only the currently executing test function is affected. the other test cases and test suites still run normally, they're unbothered, they're thriving. π
- use
zt_check()when it's safe to run the rest of the test even if the claim isn't true. this is the move because it lets every failure come with as much diagnostic output as possible, without yeeting the whole test program into a crash. - use
zt_assert()when running the rest of the test after a failure would be unsafe or just straight up meaningless.
it's giving "check everything you can, assert only what you must." iykyk π«Ά
π§ IMPLEMENTATION NOTES π§
the non-local exit from zt_assert() is implemented with siglongjump(). so do not count on C++ destructors or the GCC cleanup function extension to manage your resources correctly. like, do not. fr fr. π
β RETURN VALUES β
neither function returns anything. failures get remembered inside the opaque zt_test structure that's passed by pointer (aka zt_t) as the first argument. the receipts live in the struct, not in a return value. periodt. β¨
π¦ EXAMPLES π¦
a minimal test program that looks up the UNIX user root and measures several properties of the returned record:
#include <sys/types.h>
#include <pwd.h>
#include <zt.h>
static void test_root_user(zt_t t) {
struct passwd *p = getpwnam("root");
zt_assert(t, ZT_NOT_NULL(p));
zt_check(t, ZT_CMP_CSTR(p->pw_name, ==, "root"));
zt_check(t, ZT_CMP_INT(p->pw_uid, ==, 0));
zt_check(t, ZT_CMP_INT(p->pw_gid, ==, 0));
}
static void test_suite(zt_visitor v) {
ZT_VISIT_TEST_CASE(v, test_root_user);
}
int main(int argc, char** argv, char** envp) {
return zt_main(argc, argv, envp, test_suite);
}
π SEE ALSO π
ZT_CMP_BOOL(3)ZT_CMP_CSTR(3)ZT_CMP_INT(3)ZT_CMP_PTR(3)ZT_CMP_UINT(3)ZT_FALSE(3)ZT_NOT_NULL(3)ZT_NULL(3)ZT_TRUE(3)
π HISTORY π
the zt_check() and the zt_assert() functions first appeared in libzt 0.1. og behavior, honestly.
π AUTHORS π
Zygmunt Krynicki <me@zygoon.pl> β the icon who wrote this. π
and that's the whole page, bestie!! this beauty is from libzt 0.3.1, dated January 12, 2020, and it lives in section ZT_CHECK(3). go forth and assert responsibly πβ¨πΈπ¦
π¦ where this page comes from
- debian bookworm: libzt-doc 0.3.1-4 Β· LGPL-3.0-only
- debian trixie: libzt-doc 0.3.1-4 Β· LGPL-3.0-only
- ubuntu jammy: libzt-doc 0.3.1-4 Β· LGPL-3.0-only
- ubuntu noble: libzt-doc 0.3.1-4build1 Β· LGPL-3.0-only
- ubuntu questing: libzt-doc 0.3.1-4build1
- ubuntu resolute: libzt-doc 0.3.1-4build2 Β· LGPL-3.0-only
- ubuntu stonking: libzt-doc 0.3.1-4build2 Β· LGPL-3.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms