Chadium is a lightweight C unit test library.
To install chadium, simply place and #include
chadium.h
in your project.
Additionally, you can make
(or make install
) to add the header to your include path (/usr/include/
).
Chadium consists of 7 macros:
CHADIUM_RAN_TESTS
: provides a read-only amount of ran tests up until this point;CHADIUM_PASSED_TESTS
: provides a read-only amount of passed tests up until this point;CHADIUM_FAILED_TESTS
: provides a read-only amount of failed tests up until this point;CHADIUM_SET_OUT_FILE
takes aFILE*
to which the messages will be printed to. TheFILE*
is evaluated only once. IfNULL
is given,stderr
will be used by default. This macro must be called at least once, before any call to CHADIUM_RUN_TEST_W_MSG and CHADIUM_PRINT_TEST_RESULTS(), with a validFILE*
to a writable file;CHADIUM_RUN_TEST
takes an expression that can be evaluated to a boolean, and checks if it's true. The expression is evaluated only once;CHADIUM_RUN_TEST_W_MSG
is the same asCHADIUM_RUN_TEST
, but takes an additional amount of printf-like arguments, which will be printed if the expression is false;CHADIUM_PRINT_TEST_RESULTS()
prints the total amount of ran tests, passed tests and failed tests executed up until this point.
There is an example file in the directory examples
illustrating the usage of these macros. The following block displays its output.
>>> ./example.out
Incorrect fibonacci value.
Expected value: 233
Actual value: 9786
Function: test_bad_fib_13
Line: 23
Ran tests: 2
Passed tests: 1
Failed tests: 1