Skip to content

Instantly share code, notes, and snippets.

@larte
Created November 17, 2014 12:42
Show Gist options
  • Save larte/038628c82ea0a3c3572d to your computer and use it in GitHub Desktop.
Save larte/038628c82ea0a3c3572d to your computer and use it in GitHub Desktop.
#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
#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