diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2025-06-25 17:10:41 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2025-07-26 14:19:52 -0400 |
commit | 3e4787b7ac8cb28a1125ebc1e042d00bc58a91b5 (patch) | |
tree | b00fe8f666e54b4e2d637a9fedd3b1bfce8fbfdf /tests/tests.h | |
parent | bfc69fd326bd823c454c9fffa62748650a1a81dd (diff) | |
download | bfs-3e4787b7ac8cb28a1125ebc1e042d00bc58a91b5.tar.xz |
diag: Simplify macros with __VA_OPT__
Diffstat (limited to 'tests/tests.h')
-rw-r--r-- | tests/tests.h | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/tests/tests.h b/tests/tests.h index d395c7c..cd5715f 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -8,6 +8,7 @@ #ifndef BFS_TESTS_H #define BFS_TESTS_H +#include "bfs.h" #include "bfstd.h" #include "diag.h" @@ -44,31 +45,23 @@ bool bfs_check_impl(bool result); /** * Check a condition, logging a message on failure but continuing. */ -#define 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, ...) \ - bfs_check_impl((cond) || (bfs_check__(format, BFS_DIAG_MSG_(format, str), __VA_ARGS__), false)) - -#define bfs_check__(format, ...) \ - bfs_diagf(sizeof(format) > 1 \ - ? BFS_DIAG_FORMAT_("%s" format "%s") \ - : BFS_DIAG_FORMAT_("Check failed: `%s`"), \ - BFS_DIAG_ARGS_(__VA_ARGS__)) +#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_echeck(...) \ - bfs_echeck_(#__VA_ARGS__, __VA_ARGS__, "", ) - -#define bfs_echeck_(str, cond, format, ...) \ - bfs_check_impl((cond) || (bfs_echeck__(format, BFS_DIAG_MSG_(format, str), __VA_ARGS__), false)) +#define bfs_echeck(cond, ...) \ + bfs_check_impl((cond) || (bfs_echeck_(#cond, __VA_ARGS__), false)) -#define bfs_echeck__(format, ...) \ - bfs_diagf(sizeof(format) > 1 \ - ? BFS_DIAG_FORMAT_("%s" format "%s: %s") \ - : BFS_DIAG_FORMAT_("Check failed: `%s`: %s"), \ - BFS_DIAG_ARGS_(__VA_ARGS__ errstr(), )) +#define bfs_echeck_(str, ...) \ + BFS_VA_IF(__VA_ARGS__) \ + (bfs_ediag(__VA_ARGS__)) \ + (bfs_ediag("Check failed: `%s`", str)) #endif // BFS_TESTS_H |