summaryrefslogtreecommitdiff
path: root/lily-test.h
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2021-12-22 00:27:43 -0600
committersanine <sanine.not@pm.me>2021-12-22 00:27:43 -0600
commitedb8c6114a20b806c56dd0225dd39e333ffb3ac3 (patch)
tree00ac174b41c0979a9c482e0cf68879341d4b7de0 /lily-test.h
parent7634dd65ac55a0fe4e7ed69cee7e3957f574a03e (diff)
re-implement basic lily_assert_msg() macro
Diffstat (limited to 'lily-test.h')
-rw-r--r--lily-test.h25
1 files changed, 23 insertions, 2 deletions
diff --git a/lily-test.h b/lily-test.h
index a94f292..1894127 100644
--- a/lily-test.h
+++ b/lily-test.h
@@ -1,12 +1,33 @@
#ifndef LILY_TEST_H
#define LILY_TEST_H
+#include <stddef.h>
+
+/* gives a string like 'some/filename:xxx' */
+#define STR_IMP(x) #x
+#define STR(x) STR_IMP(x)
/* define SOURCE_PATH_SIZE to strip away the
leading parts of the full compilation path */
#ifndef SOURCE_PATH_SIZE
-#define LILY_FILENAME __FILE__
+#define LILY_LOCATION "" __FILE__ ":" STR(__LINE__)
#else
-#define LILY_FILENAME (__FILE__ + SOURCE_PATH_SIZE)
+#define LILY_LOCATION (("" __FILE__ ":" STR(__LINE__)) + SOURCE_PATH_SIZE)
#endif
+struct lily_test_result_t {
+ int error;
+ const char *message;
+ const char *location;
+};
+
+typedef struct lily_test_result_t lily_test;
+#define LILY_SUCCESS (struct lily_test_result_t){ 0, NULL, NULL }
+
+// assertions
+#define lily_assert_msg(statement, message) do { \
+ if(!(statement)) { \
+ return (struct lily_test_result_t){1, (message), LILY_LOCATION}; \
+ } \
+ } while(0)
+
#endif