ordeal - minimalistic C Unit Testing framework.
Main features include:
* simple deployment in existent project (just copy and use)
* every test run in it's own process, so signal's can easly be processed
* possible to define own test processing routines for reports creation
* minimal api
Screenshot
Test definition
All ordeal tests associated with groups can be defined as:
OR_TEST(group1, test1) { OR_ASSERT_TRUE(1 == 0); return OR_OK; }
Test function must return OR_OK on success or OR_FAIL on failure. If assert function fail it also returns OR_FAIL.
Test asserts
ordeal has minimal usable set of asserts:
OR_ASSERT_TRUE(EXPR) OR_ASSERT_FALSE(EXPR) OR_ASSERT_EQ(A, B) OR_ASSERT_NOT_EQ(A, B) OR_ASSERT_EQ_STR(A, B) OR_ASSERT_NOT_EQ_STR(A, B)
Test environments
There are three way to define testing enveronment:
1. Initializing ordeal library, adding group's and tests:
ordeal_t ct; ordeal_group_t * group1; ordeal_init(&ct, OR_OPT_COLOR, NULL); group1 = ordeal_group_add(&ct, "group1"); ordeal_add(group1, OR_NAME(group1, test1), "test1"); ordeal_run(&ct); ordeal_free(&ct);
2. Using ordeal_execute function with ordeal_test_t table:
ordeal_test_t ordeal_tests[] = { OR_TEST_DEF(group1, test1), OR_TEST_END }; ordeal_execute(ordeal_tests);
3. Defining global tests with OR_TESTS macro and linking against -lordeal_main:
OR_TESTS { OR_TEST_DEF(group1, test1), OR_TEST_END }; // gcc test.c -lordeal_main -o test
Generating user-defined reports
It is possible to define own callback for processing tests information and it's status.
See ordeal_cb_t and ordeal_callback()
interface
#include < ordeal.h >
/* ordeal initialization function. * * opts argument specifies testing suite options: * OR_OPT_NONE - default behaviour * OR_OPT_COLOR - for color output support * OR_OPT_FSTOP - stop testing on first error * * fd is log output file descriptor, if NULL, then * stdout is used. */ void ordeal_init(ordeal_t * ordeal, unsigned long opts, FILE * fd); /* ordeal freeing function. */ void ordeal_free(ordeal_t * ordeal); /* ordeal callback setter. * * callback function can be used for processing tests and * deploying own report generators, etc. */ void ordeal_callback(ordeal_t * ordeal, ordeal_cbf_t cb); /* ordeal silent function sets callback function for * silent testing process. */ void ordeal_silent(ordeal_t * ordeal); /* ordeal testing group add/delete and matching functions. */ ordeal_group_t* ordeal_group_add(ordeal_t * ordeal, char * name); int ordeal_group_del(ordeal_t * ordeal, char * name); ordeal_group_t* ordeal_group_match(ordeal_t * ordeal, char * name); /* ordeal test add/del and matching functions. */ ordeal_func_t* ordeal_add(ordeal_group_t * group, ordealf_t test, char * name); int ordeal_del(ordeal_group_t * group, char * name); ordeal_func_t* ordeal_match(ordeal_group_t * group, char * name); /* ordeal_run run's main testing process. * * returns ordeal_result_t value OR_OK if all tests passed OK, * otherwise something failed. */ int ordeal_run(ordeal_t * ordeal); /* ordeal_run_execute function adds groups and tests from * test describing table ordeal_test_t and run's main * testing process * * returns ordeal_run() result. */ int ordeal_run_execute(ordeal_t * ordeal, ordeal_test_t * tests); /* ordeal_execute is stand alone function for defining whole * testing process according to test describing table * ordeal_test_t. * * For ease deployment test progra can be linked with * -lordeal_main, in that case testing table must be defined * globally with OR_TESTS macro. * * returns ordeal_run() result. */ int ordeal_execute(ordeal_test_t * tests);