aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authors-over-42023-07-10 00:59:08 -0400
committers-over-42023-07-10 00:59:08 -0400
commitfa403b3fb6ff14dbed73d815684d6935c3c19717 (patch)
treed255f1a2ea4f27f1b2046e29f9811e52dbd4dee9 /src/include
parent979bf65d49a8d362be8ba370dc453362dca158cd (diff)
made a test framework (HLKT)
Diffstat (limited to 'src/include')
-rw-r--r--src/include/hlkt.h29
-rw-r--r--src/include/util.h1
2 files changed, 30 insertions, 0 deletions
diff --git a/src/include/hlkt.h b/src/include/hlkt.h
new file mode 100644
index 0000000..295e5f4
--- /dev/null
+++ b/src/include/hlkt.h
@@ -0,0 +1,29 @@
+#ifndef HLKT_H
+#define HLKT_H
+
+#include <time.h>
+
+#include "util.h"
+
+static int hlkt_run = 0; /* number of tests run */
+static int hlkt_failed = 0; /* number of tests that have failed */
+
+#define HLKT_HIDE(stuff) do { stuff } while (0)
+
+#define HLKT_LOG() HLKT_HIDE( \
+ if ((hlkt_run > 0) && (hlkt_failed > 0)) { \
+ log_war("HLKT: %d/%d tests failed", hlkt_failed, hlkt_run); \
+ } else { \
+ log_inf("HLKT: all %d tests passed", hlkt_run); \
+ } \
+)
+
+#define HLKT_ASS(pred) HLKT_HIDE( \
+ hlkt_run ++; \
+ if (! pred) { \
+ hlkt_failed ++; \
+ log_err("HLKT: test [%s] failed: %s:%s:%d", #pred, __FILE__, __func__, __LINE__);\
+ } \
+)
+
+#endif
diff --git a/src/include/util.h b/src/include/util.h
index 63ee8bb..a7879e9 100644
--- a/src/include/util.h
+++ b/src/include/util.h
@@ -8,6 +8,7 @@
void die(const char* fmt, ...);
+void log_err(const char* fmt, ...);
void log_inf(const char* fmt, ...);
void log_raw(const char* fmt, ...);
void log_war(const char* fmt, ...);