diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2016-05-17 23:02:04 +0200 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2016-05-17 23:02:04 +0200 |
| commit | 7d9f7e9341ab22599ea541959dbf9323661c777f (patch) | |
| tree | 93b9262f64b606089b6b85aceafc47fa631887e8 /tests/include | |
| parent | make blas and lapack calls more compact (diff) | |
| download | gensvm-7d9f7e9341ab22599ea541959dbf9323661c777f.tar.gz gensvm-7d9f7e9341ab22599ea541959dbf9323661c777f.zip | |
start adding unit tests
Diffstat (limited to 'tests/include')
| -rw-r--r-- | tests/include/dbg.h | 36 | ||||
| -rw-r--r-- | tests/include/minunit.h | 34 |
2 files changed, 70 insertions, 0 deletions
diff --git a/tests/include/dbg.h b/tests/include/dbg.h new file mode 100644 index 0000000..0401ea1 --- /dev/null +++ b/tests/include/dbg.h @@ -0,0 +1,36 @@ +#ifndef __dbg_h__ +#define __dbg_h__ + +#include <stdio.h> +#include <errno.h> +#include <string.h> + +#ifdef NDEBUG +#define debug(M, ...) +#else +#define debug(M, ...) fprintf(stderr, "DEBUG %s:%d: " M "\n", __FILE__, \ + __LINE__, ##__VA_ARGS__) +#endif + +#define clean_errno() (errno == 0 ? "None" : strerror(errno)) + +#define log_err(M, ...) fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " M "\n", \ + __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__) + +#define log_warn(M, ...) fprintf(stderr, "[WARN] (%s:%d: errno: %s) " M "\n", \ + __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__) + +#define log_info(M, ...) fprintf(stderr, "[INFO] (%s:%d) " M "\n", \ + __FILE__, __LINE__, ##__VA_ARGS__) + +#define check(A, M, ...) if(!(A)) { log_err(M, ##__VA_ARGS__); errno=0; \ + goto error; } + +#define sentinel(M, ...) { log_err(M, ##__VA_ARGS__); errno=0; goto error; } + +#define check_mem(A) check((A), "Out of memory."); + +#define check_debug(A, M, ...) if (!(A)) { debug(M, ##__VA_ARGS__); errno=0; \ + goto error; } + +#endif diff --git a/tests/include/minunit.h b/tests/include/minunit.h new file mode 100644 index 0000000..4197310 --- /dev/null +++ b/tests/include/minunit.h @@ -0,0 +1,34 @@ +#undef NDEBUG +#ifndef _minunit_h +#define _minunit_h + +#include "dbg.h" +#include <stdlib.h> + +#define mu_suite_start() char *message = NULL + +#define mu_assert(test, message) if (!(test)) { log_err(message); return message; } + +#define mu_run_test(test) debug("\n-----%s", " " #test); \ + message = test(); tests_run++; if (message) return message; + +#define RUN_TESTS(name) 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);\ +} + +#define mu_test_missing() printf("\033[33;1mWARNING: Test missing\033[0m\n"); + +int tests_run; + +#endif |
