Starting to add tests for bstrlib
plus reporting assertion count via minunit
This commit is contained in:
parent
8f91cf3d0c
commit
5bf745f51d
55
lcthw-remnants-2/liblcthw/tests/lcthw/bstrlib_tests.c
Normal file
55
lcthw-remnants-2/liblcthw/tests/lcthw/bstrlib_tests.c
Normal file
@ -0,0 +1,55 @@
|
||||
#include "../minunit.h"
|
||||
#include <lcthw/bstrlib.h>
|
||||
|
||||
char *test_bfromcstr()
|
||||
{
|
||||
bstring b = bfromcstr("oh hai");
|
||||
mu_assert(b != NULL, "bstring is NULL.");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *test_blk2bstr()
|
||||
{
|
||||
bstring b = blk2bstr("hats", 5);
|
||||
mu_assert(b != NULL, "bstring is NULL.");
|
||||
|
||||
b = blk2bstr(NULL, 42);
|
||||
mu_assert(b == NULL, "bstring is not NULL.");
|
||||
|
||||
b = blk2bstr("bats", -17);
|
||||
mu_assert(b == NULL, "bstring is not NULL.");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *test_bstrcpy()
|
||||
{
|
||||
bstring b = bfromcstr("mats");
|
||||
mu_assert(bstrcpy(b) != NULL, "bstring is NULL.");
|
||||
|
||||
mu_assert(bstrcpy(NULL) == NULL, "bstring is not NULL.");
|
||||
|
||||
int orig_len = b->slen;
|
||||
b->slen = -1;
|
||||
mu_assert(bstrcpy(b) == NULL, "bstring is not NULL.");
|
||||
b->slen = orig_len;
|
||||
|
||||
b->data = NULL;
|
||||
mu_assert(bstrcpy(b) == NULL, "bstring is not NULL.");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *all_tests()
|
||||
{
|
||||
mu_suite_start();
|
||||
|
||||
mu_run_test(test_bfromcstr);
|
||||
mu_run_test(test_blk2bstr);
|
||||
mu_run_test(test_bstrcpy);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RUN_TESTS(all_tests);
|
@ -8,7 +8,10 @@
|
||||
|
||||
#define mu_suite_start() char *message = NULL
|
||||
|
||||
#define mu_assert(test, message) if (!(test)) { log_err(message); return message; }
|
||||
#define mu_assert(test, message) if (!(test)) {\
|
||||
log_err(message); return message;\
|
||||
}\
|
||||
assertions_made++;
|
||||
#define mu_run_test(test) debug("\n-----%s", " " #test); \
|
||||
message = test(); tests_run++; if (message) return message;
|
||||
|
||||
@ -25,9 +28,11 @@
|
||||
printf("ALL TESTS PASSED\n");\
|
||||
}\
|
||||
printf("Tests run: %d\n", tests_run);\
|
||||
printf("Assertions made: %d\n", assertions_made);\
|
||||
exit(result != 0);\
|
||||
}
|
||||
|
||||
int tests_run;
|
||||
int assertions_made;
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user