summaryrefslogtreecommitdiffstats
path: root/tests/tests.h
diff options
context:
space:
mode:
Diffstat (limited to 'tests/tests.h')
-rw-r--r--tests/tests.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/tests.h b/tests/tests.h
index 6629dcf..b644450 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -51,4 +51,20 @@ static inline bool bfs_check(bool ret) {
: "Check failed: `%s`%s", \
str, __VA_ARGS__), false))
+/** Get a string description of the last error. */
+const char *bfs_errstr(void);
+
+/**
+ * Check a condition, logging the current error string on failure.
+ */
+#define bfs_pcheck(...) \
+ bfs_pcheck_(#__VA_ARGS__, __VA_ARGS__, "", "")
+
+#define bfs_pcheck_(str, cond, format, ...) \
+ ((cond) ? true : (bfs_diag( \
+ sizeof(format) > 1 \
+ ? "%.0s" format "%s%s: %s" \
+ : "Check failed: `%s`%s: %s", \
+ str, __VA_ARGS__, bfs_errstr()), false))
+
#endif // BFS_TESTS_H