zt_visit_test_case(3)

under their macro from and are used to implement discovery for test suites and test cases

Section 3 libzt-doc bookworm source

Description

UNTITLED() LOCAL UNTITLED()

NAME

zt_visit_test_case, ZT_VISIT_TEST_CASE, zt_visit_test_suite, ZT_VISIT_TEST_SUITE — discover test cases and their 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

zt_visit_test_case() and zt_visit_test_suite(), or more usually - under their macro from ZT_VISIT_TEST_CASE() and ZT_VISIT_TEST_SUITE(), 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 zt_main() which handles the rest of the discovery, and if necessary, execution.

RETURN VALUES

Visit functions do not return any value.

EXAMPLES

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

SEE ALSO

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

HISTORY

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

AUTHORS

Zygmunt Krynicki <me@zygoon.pl> libzt 0.3.1 January 12, 2020 ZT_VISIT_TEST_CASE(3)