ZT_VISIT_TEST_CASE(3)

πŸ’– zt_visit_test_case β€” bestie's guide to finding your tests πŸ’–

okay so. this is the manual page for zt_visit_test_case(3) (yes that's the manual name, it lives in the LOCAL section, don't @ me). it's all about discovering test cases and their structure. let's get into it πŸ¦‹


✨ NAME ✨

zt_visit_test_case, ZT_VISIT_TEST_CASE, zt_visit_test_suite, ZT_VISIT_TEST_SUITE β€” the way you discover test cases and their whole little structure 🌸


✨ SYNOPSIS ✨

#include <zt.h>

void
zt_visit_test_case(zt_visitor v, zt_test_case_func func,
    const char *name);

#define ZT_VISIT_TEST_CASE(v, tcase) zt_visit_test_case(v, tcase,
#tcase)

void
zt_visit_test_case(zt_visitor v, zt_test_suite_func func,
    const char *name);

#define ZT_VISIT_TEST_SUITE(v, tsuite) zt_visit_test_suite(v, tsuite,
#tsuite)

✨ DESCRIPTION ✨

so zt_visit_test_case() and zt_visit_test_suite() β€” or, like, usually their macro glow-ups ZT_VISIT_TEST_CASE() and ZT_VISIT_TEST_SUITE() β€” are literally the whole discovery mechanism for test suites and test cases. that's their job. their entire personality πŸ’…

here's the tea: test suites are just functions that go visit other test suites and test cases. test cases are functions that actually run the real test code. it's giving recursive tree energy, fr fr 🌈

and the macros? they exist purely as a convenience so you don't have to sit there inventing names like a Victorian poet. iconic behavior honestly πŸ‘‘

usually the main test suite gets passed as an argument to zt_main(), which then handles all the rest of the discovery and, if it needs to, the execution. main character energy πŸŽ€


✨ RETURN VALUES ✨

visit functions do not return any value. nothing. nada. they're void, they said "not my problem" πŸ’€


✨ EXAMPLES ✨

okay here's a whole example showing how to build a test suite with two test cases. and heads up bestie β€” a suite can contain any number of nested suites and test cases, go wild πŸ¦‹

#include <zt.h>

static void test_foo(zt_t t) {
    printf("foo invoked\n");
}

static void suite_inner(zt_visitor v) {
    ZT_VISIT_TEST_CASE(v, test_foo);
}

static void test_bar(zt_t t) {
    printf("bar invoked\n");
}

static void main_suite(zt_visitor v) {
    ZT_VISIT_TEST_SUITE(v, suite_inner);
    ZT_VISIT_TEST_CASE(v, test_bar);
}

int main(int argc, char** argv, char** envp) {
    return zt_main(argc, argv, envp, main_suite);
}

look at that nesting. a suite inside a suite. it's giving matryoshka doll 😭 ate, no crumbs ✨


✨ SEE ALSO ✨

(yeah the original list ends in a comma, i'm not touching it, that's just how it is πŸ’œ)


✨ HISTORY ✨

zt_visit_test_case() and zt_visit_test_suite() β€” plus their corresponding macros β€” first appeared in libzt 0.1. a humble origin story. we love a glow-up arc πŸŒ±βž‘οΈπŸ‘‘


✨ AUTHORS ✨

Zygmunt Krynicki <me@zygoon.pl> β€” thank you for your service, king 🫢


and that's the whole page bestie!! this was libzt 0.3.1, dated January 12, 2020, and it's the ZT_VISIT_TEST_CASE(3) page πŸ’– go forth and discover ur tests, ily, periodt ✨🌸πŸ’