summaryrefslogtreecommitdiffstats
path: root/tests/tests.h
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-02-29 13:23:02 -0500
committerTavian Barnes <tavianator@tavianator.com>2024-02-29 13:41:46 -0500
commit4e2f094d29ff8140f2b46a059128c780560db0f1 (patch)
treec492f871db65857f106b755d21c413ff74357f03 /tests/tests.h
parenta228788769d7e3c71154606609a13eafb03a5fc2 (diff)
downloadbfs-4e2f094d29ff8140f2b46a059128c780560db0f1.tar.xz
tests: New bfs_check() macro
We now report failures and continue, rather than aborting after the first failure.
Diffstat (limited to 'tests/tests.h')
-rw-r--r--tests/tests.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/tests.h b/tests/tests.h
index d8adbb9..6629dcf 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -9,6 +9,7 @@
#define BFS_TESTS_H
#include "../src/config.h"
+#include "../src/diag.h"
/** Unit test function type. */
typedef bool test_fn(void);
@@ -31,4 +32,23 @@ bool check_trie(void);
/** Time tests. */
bool check_xtime(void);
+/** Don't ignore the bfs_check() return value. */
+attr(nodiscard)
+static inline bool bfs_check(bool ret) {
+ return ret;
+}
+
+/**
+ * Check a condition, logging a message on failure but continuing.
+ */
+#define bfs_check(...) \
+ bfs_check(bfs_check_(#__VA_ARGS__, __VA_ARGS__, "", ""))
+
+#define bfs_check_(str, cond, format, ...) \
+ ((cond) ? true : (bfs_diag( \
+ sizeof(format) > 1 \
+ ? "%.0s" format "%s%s" \
+ : "Check failed: `%s`%s", \
+ str, __VA_ARGS__), false))
+
#endif // BFS_TESTS_H