GenSVM
Macros | Variables
minunit.h File Reference

Minimal unit testing framework for C. More...

#include "dbg.h"
#include <stdlib.h>
Include dependency graph for minunit.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define mu_suite_start()   char *message = NULL
 
#define mu_assert(test, message)   if (!(test)) { log_err(message); return message; }
 
#define mu_run_test(test)
 
#define RUN_TESTS(name)
 
#define mu_test_missing()
 

Variables

int tests_run
 

Detailed Description

Minimal unit testing framework for C.

Author
Zed Shaw

This unit testing framework comes from Zed Shaw's book Learn C The Hard Way, and are evolved from the "minunit" code snippets by Jera Design. I've added a mu_test_missing() macro to deal with missing unit tests.

See also
dbg.h

Definition in file minunit.h.

Macro Definition Documentation

◆ mu_assert

#define mu_assert (   test,
  message 
)    if (!(test)) { log_err(message); return message; }

Check a condition and log the message as an error if it fails

Definition at line 29 of file minunit.h.

◆ mu_run_test

#define mu_run_test (   test)
Value:
debug("\n-----%s", " " #test); \
message = test(); tests_run++; if (message) return message;
int tests_run
Definition: minunit.h:66
#define debug(M,...)
Definition: dbg.h:29

Run a test function, return the message if there is one, increment tests_run

Definition at line 35 of file minunit.h.

◆ mu_suite_start

#define mu_suite_start ( )    char *message = NULL

Start the unit testing suite by creating an empty message

Definition at line 24 of file minunit.h.

◆ mu_test_missing

#define mu_test_missing ( )
Value:
printf("\033[33;1mWARNING: Test missing\033[0m\n");\
tests_run--;

Log a warning to stdout when a test is missing and reduce tests_run by 1.

Definition at line 60 of file minunit.h.

◆ RUN_TESTS

#define RUN_TESTS (   name)
Value:
int main(int argc, char *argv[]) {\
argc = 1; \
debug("\n-----\nRUNNING: %s", argv[0]);\
printf("----\nRUNNING: %s\n", argv[0]);\
char *result = name();\
if (result != 0) {\
printf("\033[91mFAILED:\033[0m %s\n", result);\
}\
else {\
printf("ALL TESTS \033[92mPASSED\033[0m\n");\
}\
printf("Tests run: %d\n", tests_run);\
exit(result != 0);\
}
int tests_run
Definition: minunit.h:66
int main(int argc, char **argv)
Main interface function for GenSVMgrid.
Definition: GenSVMgrid.c:102

Definition of main function for the test framework. Defines the output presented to stdout/stderr and runs all_tests function provided by "name"

Definition at line 42 of file minunit.h.

Variable Documentation

◆ tests_run

int tests_run

Global counter for the number of tests that have been run.

Definition at line 66 of file minunit.h.