zt_visit_test_case(3)

zt_visit_test_case3

Discover test cases and their structure

Usage

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

Overview

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

Releases

Unchanged in 3 releases since Debian 11 (Bullseye).

  1. 11–13

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 ⟨[email protected]⟩

From libzt-doc 0.3.1-4 in Debian 13 (Trixie). Parsed by carta from the page's mdoc source.