DOKK / manpages / debian 11 / libzt-doc / zt_visit_test_case.3.en
ZT_VISIT_TEST_CASE(3) Library Functions Manual (prm) ZT_VISIT_TEST_CASE(3)

zt_visit_test_case, ZT_VISIT_TEST_CASE, zt_visit_test_suite, ZT_VISIT_TEST_SUITEdiscover test cases and their structure

#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)

() and (), or more usually - under their macro from () and (), are used to implement discovery for test suites and test cases. Test suites are represented as functions that visit other test suites and test cases. Test cases are represented as functions that execute actual test code.

The macros are provided as convenience to avoid having to invent names.

Typically the main test suite is passed as an argument to () which handles the rest of the discovery, and if necessary, execution.

Visit functions do not return any value.

The following example shows how to create a test suite with two test cases. A suite can contain any number of nested suites and test cases.

#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);
}

zt_main(3), zt_test_suite_func(3), zt_test_case_func(3),

The zt_visit_test_case() and the zt_visit_test_suite() functions, as well as the corresponding macros, first appeared in libzt 0.1

Zygmunt Krynicki <me@zygoon.pl>

January 12, 2020 libzt 0.3.1