Skip to content

Instantly share code, notes, and snippets.

@catb0t
Forked from sam159/minunit.h
Created February 12, 2016 02:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catb0t/040750d7ac4063d1bf48 to your computer and use it in GitHub Desktop.
Save catb0t/040750d7ac4063d1bf48 to your computer and use it in GitHub Desktop.
minunit header for unit testing c code
/*
* File: minunit.h
* Author: Zed. A. Shaw, Sam
*
* @see http://c.learncodethehardway.org/book/ex30.html
*
* Created on 27 August 2014, 22:14
*/
#ifndef MINUNIT_H
#define MINUNIT_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdlib.h>
#define log_err(message) printf("\tError: %s\n", message)
#define mu_suite_start() char *message = NULL
#define mu_assert(test, message) \
do { \
if (!(test)) { \
log_err(message); \
return message; \
} \
} while(0)
#define mu_run_test(test) \
do { \
printf("\n-----%s", " " #test); \
message = test(); \
tests_run++; \
if (message) { return message; } \
while(0)
#define RUN_TESTS(name) \
int main(int argc, char *argv[]) { \
tests_run = 0; \
argc = 1; \
printf("----\nRUNNING: %s\n", argv[0]); \
char *result = name(); \
if (result != 0) { \
printf("FAILED: %s\n", result); \
} \
else { \
printf("ALL TESTS PASSED\n"); \
} \
printf("Tests run: %d\n", tests_run); \
exit(result == 0 ? EXIT_SUCCESS : EXIT_FAILURE);\
}
int tests_run;
#ifdef __cplusplus
}
#endif
#endif /* MINUNIT_H */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment