Add a TAP test program in C

This commit is contained in:
Ruben Laguna
2015-06-23 21:43:51 +02:00
parent 844bdf6d3c
commit 924acf4748
4 changed files with 24 additions and 10 deletions

View File

@@ -6,13 +6,20 @@
int tests_run=0;
char * add_test() {
mu_assert("add(1,2) must produce 3", add(1,2) == 4);
char * test_add_fail() {
mu_assert("add(1,2) must produce 4", add(1,2) == 4);
return 0;
}
char * test_add_sucess() {
mu_assert("add(1,2) must produce 3", add(1,2) == 3);
return 0;
}
char * all_tests() {
mu_run_test(add_test);
printf("1..2\n");
mu_run_test("test_add_fail", test_add_fail);
mu_run_test("test_add_sucess", test_add_sucess);
return 0;
}
@@ -20,11 +27,10 @@ int main(int argc, char *argv[])
{
char *result = all_tests();
if (result) {
printf("FAILURE\n");
exit(1);
printf("# FAILURE\n");
}
printf("ALL TESTS PASSED");
printf("#ALL TESTS PASSED\n");
return 0;
return 0; /* tap tests report failures via stdout not exit code */
}

View File

@@ -3,6 +3,6 @@
extern int tests_run;
#define mu_assert(message,test) do { if (!(test)) return message; } while (0)
#define mu_run_test(test) do { char *result = test(); tests_run++; if (result) return result; } while (0)
#define mu_run_test(test_name, test) do { printf("# starting test %s\n", test_name); char *result = test(); tests_run++; if (result) {printf("not "); } printf("ok %d - %s\n", tests_run, test_name);} while (0)
#endif /* MINUNIT_H */