Starting to add tests for bstrlib

plus reporting assertion count via minunit
cat-town
Dan Buch 9 years ago
parent 8f91cf3d0c
commit 5bf745f51d
No known key found for this signature in database
GPG Key ID: FAEF12936DD3E3EC

@ -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_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); \ #define mu_run_test(test) debug("\n-----%s", " " #test); \
message = test(); tests_run++; if (message) return message; message = test(); tests_run++; if (message) return message;
@ -25,9 +28,11 @@
printf("ALL TESTS PASSED\n");\ printf("ALL TESTS PASSED\n");\
}\ }\
printf("Tests run: %d\n", tests_run);\ printf("Tests run: %d\n", tests_run);\
printf("Assertions made: %d\n", assertions_made);\
exit(result != 0);\ exit(result != 0);\
} }
int tests_run; int tests_run;
int assertions_made;
#endif #endif

Loading…
Cancel
Save