Defines | |
#define | U_TEST_MODULE(name) int u_test_run_ ## name (void) |
Define a test module. | |
#define | U_TEST_RUN(f) |
Define a test function. | |
#define | U_TEST_MODULE_USE(name) |
Import a test module in the test program. | |
Typedefs | |
typedef int(* | test_runner_t )(void) |
Functions | |
int | u_test_run (int argc, char **argv) |
Run tests. | |
Variables | |
test_runner_t | _mods [] |
test_runner_t * | _top |
char * | _mods_nm [] |
char ** | _top_nm |
int | _test_cnt |
int | _test_ok |
int | _test_fail |
int | _verbose |
Example: mymodule.c
int test_feature_1(void) { dbg_err_if(...) return 0; err: return ~0; } int test_feature_2(void) { dbg_err_if( return 0; err: return ~0; } U_TEST_MODULE( mymodule ) { U_TEST_RUN( test_feature_1 ); U_TEST_RUN( test_feature_2 ); return 0; }
To build the 'runtest' executable define a main() function like the example below and import your test modules using the U_TEST_USE_MODULE macro.
Example: main.c
#include <u/libu.h> int facility = LOG_LOCAL0; int main(int argc, char **argv) { U_TEST_USE_MODULE( mymodule ); U_TEST_USE_MODULE( mymodule2 ); return u_test_run(argc, argv); }
To run all tests call the built executable with no arguments. At the end of execution it will print the number of tests run and the number ot tests failed.
* ./runtest # runs all modules' test *
If you want to run just selected modules add their name to the 'runtest' command line:
* ./runtest mymodule # runs just 'mymodule' tests * ./runtest mymodule othermod # runs 'mymodule' and 'othermod' tests *
|
Defines a test module named
|
|
Value: do { \ int u_test_run_ ## name (void); \ *_top = u_test_run_ ## name; ++_top; *_top = NULL; \ *_top_nm = u_strdup( #name ); ++_top_nm; *_top_nm = NULL; \ } while(0)
|
|
Value: if( f () ) { _test_cnt++; _test_fail++; con("%s: failed", #f); } \ else { _test_cnt++; _test_ok++; if(_verbose) con("%s: ok", #f); }
|
|
Run tests. Must be called by the main() function. Returns when all tests have been run.
Definition at line 83 of file test.c. References _mods, _test_cnt, _test_fail, and _top. |