summaryrefslogtreecommitdiffstats
path: root/tests/tests.h
diff options
context:
space:
mode:
Diffstat (limited to 'tests/tests.h')
-rw-r--r--tests/tests.h68
1 files changed, 31 insertions, 37 deletions
diff --git a/tests/tests.h b/tests/tests.h
index 351badb..cd5715f 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -8,66 +8,60 @@
#ifndef BFS_TESTS_H
#define BFS_TESTS_H
-#include "../src/config.h"
-#include "../src/diag.h"
-
-/** Unit test function type. */
-typedef bool test_fn(void);
+#include "bfs.h"
+#include "bfstd.h"
+#include "diag.h"
/** Memory allocation tests. */
-bool check_alloc(void);
+void check_alloc(void);
/** Standard library wrapper tests. */
-bool check_bfstd(void);
+void check_bfstd(void);
/** Bit manipulation tests. */
-bool check_bit(void);
+void check_bit(void);
/** I/O queue tests. */
-bool check_ioq(void);
+void check_ioq(void);
+
+/** Linked list tests. */
+void check_list(void);
+
+/** Signal hook tests. */
+void check_sighook(void);
/** Trie tests. */
-bool check_trie(void);
+void check_trie(void);
/** Process spawning tests. */
-bool check_xspawn(void);
+void check_xspawn(void);
/** Time tests. */
-bool check_xtime(void);
+void check_xtime(void);
-/** Don't ignore the bfs_check() return value. */
-attr(nodiscard)
-static inline bool bfs_check(bool ret) {
- return ret;
-}
+/** Record a single check and return the result. */
+bool bfs_check_impl(bool result);
/**
* Check a condition, logging a message on failure but continuing.
*/
-#define bfs_check(...) \
- bfs_check(bfs_check_(#__VA_ARGS__, __VA_ARGS__, "", ""))
+#define bfs_check(cond, ...) \
+ bfs_check_impl((cond) || (bfs_check_(#cond, __VA_ARGS__), false))
-#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))
-
-/** Get a string description of the last error. */
-const char *bfs_errstr(void);
+#define bfs_check_(str, ...) \
+ BFS_VA_IF(__VA_ARGS__) \
+ (bfs_diag(__VA_ARGS__)) \
+ (bfs_diag("Check failed: `%s`", str))
/**
* 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))
+#define bfs_echeck(cond, ...) \
+ bfs_check_impl((cond) || (bfs_echeck_(#cond, __VA_ARGS__), false))
+
+#define bfs_echeck_(str, ...) \
+ BFS_VA_IF(__VA_ARGS__) \
+ (bfs_ediag(__VA_ARGS__)) \
+ (bfs_ediag("Check failed: `%s`", str))
#endif // BFS_TESTS_H