Add a TAP test program in C
This commit is contained in:
20
tests/add.c
20
tests/add.c
@@ -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 */
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user