Created
November 17, 2014 12:42
-
-
Save larte/038628c82ea0a3c3572d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _UNIT_H_ | |
#define _UNIT_H_ | |
#define mu_assert(message, test) do { if (!(test)) return message; } while (0) | |
#define mu_run_test(test) do { char *message = test(); tests_run++; \ | |
if (message) {failed++; return message;} } while (0) | |
extern int tests_run; | |
extern int failed; | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "unit.h" | |
int tests_run = 0; | |
int failed = 0; | |
static char *the_test() { | |
int subject = 0; | |
mu_assert("test subject failed", subject == 0); | |
return NULL; | |
} | |
int main(int argc, char **argv) { | |
char *res = mu_run_test(the_test); | |
if (result) { | |
printf("\n%s\n", result); | |
} | |
else { | |
printf("\t\t\t\t...ALL TESTS PASSED\n"); | |
} | |
printf("Tests run: %d, failed tests %d\n", | |
tests_run, failed); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment