logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

zt_visit_test_case, ZT_VISIT_TEST_CASE, zt_visit_test_suite, ZT_VISIT_TEST_SUITE — discover test cases

Authors

       Zygmunt Krynicki <me@zygoon.pl>

libzt 0.3.1                                     January 12, 2020                           ZT_VISIT_TEST_CASE(3)

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.

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

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

Name

       zt_visit_test_case,  ZT_VISIT_TEST_CASE,  zt_visit_test_suite,  ZT_VISIT_TEST_SUITE — discover test cases
       and their structure

Return Values

       Visit functions do not return any value.

See Also

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

Synopsis

#include<zt.h>voidzt_visit_test_case(zt_visitorv, zt_test_case_funcfunc, constchar*name);

       #defineZT_VISIT_TEST_CASE(v,tcase)zt_visit_test_case(v,tcase,#tcase)voidzt_visit_test_case(zt_visitorv, zt_test_suite_funcfunc, constchar*name);

       #defineZT_VISIT_TEST_SUITE(v,tsuite)zt_visit_test_suite(v,tsuite,#tsuite)

See Also