=head1 Unit testing Ermyth provides a simple yet powerful and specialised unit testing framework. Tests are grouped by putting them in files. For example all tests regarding metadata go into F. Tests are compiled to .t files, which are simple executables that get run by make test. =head2 Test boilerplate The very first line each testgroup should be #include "unit/test.h" and the very last line should be #include "unit/runtest.h" =head2 Defining tests Defining tests is very simple: test () { // do something here } =head2 Assertions Ermyth's unit test framework provides five assertions: =over =item ensure (expr) Writes an error if C does not evaluate to a true value. =item ensure_streq (str, expected) Checks with strcmp whether C and C are equal. Both C and C need to be one of C, C, C or an C variant of one. =item ensure_null (expr) Checks whether expr is NULL or 0. This check requires C to be L. =item ensure_equals (actual, expected) Checks whether C evaluates to C. This check requires C and C to be L. =item ensure_distance (actual, expected, tolerance) Checks whether C is at most C away from C. To allow this comparison, C and C need to be L and their sum together with C needs to be L. =head2 Example The following example can be found in F: #include "unit/test.h" test<1> () { metadata *md; myuser_t *mu = myuser_add ("name", "pass", "email", 0); mu->add_metadata ("cow", "moo"); ensure_streq (md->value, "moo"); mu->del_metadata ("cow"); mu->add_metadata ("cow2", "moo2"); mu->clear_metadata (); ensure_null (md); } #include "unit/runtest.h"