diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2025-03-03 16:57:28 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2025-03-04 11:46:00 -0500 |
commit | 5c5ae3962c46cf4051bcd6d4e2355422e63de42b (patch) | |
tree | 6552fb22344d8385fc1b253448d5a29982488f3a /tests | |
parent | 1aefb830360e43b6e5ddee96791eb83cdad766cc (diff) | |
download | bfs-5c5ae3962c46cf4051bcd6d4e2355422e63de42b.tar.xz |
diag: Get rid of struct bfs_location
Just add the standard prefix to the passed format string in the
diagnostic macros themselves. This lets us write the whole message with
one dprintf() call, minimizing interleaving.
It's also a net win for binary size.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tests.h | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/tests/tests.h b/tests/tests.h index 4c6b3d2..8b7d691 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -45,26 +45,30 @@ bool bfs_check_impl(bool result); * Check a condition, logging a message on failure but continuing. */ #define bfs_check(...) \ - bfs_check_impl(bfs_check_(#__VA_ARGS__, __VA_ARGS__, "", "")) + 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)) + bfs_check_impl((cond) || (bfs_check__(str, format, __VA_ARGS__), false)) + +#define bfs_check__(str, format, ...) \ + bfs_diagf(sizeof(format) > 1 \ + ? BFS_DIAG_FORMAT_("%.0s" format "%s") \ + : BFS_DIAG_FORMAT_("Check failed: `%s`"), \ + BFS_DIAG_ARGS_(str, __VA_ARGS__)) /** * Check a condition, logging the current error string on failure. */ #define bfs_echeck(...) \ - bfs_check_impl(bfs_echeck_(#__VA_ARGS__, __VA_ARGS__, "", errstr())) + bfs_echeck_(#__VA_ARGS__, __VA_ARGS__, "", ) #define bfs_echeck_(str, cond, format, ...) \ - ((cond) ? true : (bfs_diag( \ - sizeof(format) > 1 \ - ? "%.0s" format "%s: %s" \ - : "Check failed: `%s`: %s", \ - str, __VA_ARGS__), false)) + bfs_check_impl((cond) || (bfs_echeck__(str, format, __VA_ARGS__), false)) + +#define bfs_echeck__(str, format, ...) \ + bfs_diagf(sizeof(format) > 1 \ + ? BFS_DIAG_FORMAT_("%.0s" format "%s: %s") \ + : BFS_DIAG_FORMAT_("Check failed: `%s`: %s"), \ + BFS_DIAG_ARGS_(str, __VA_ARGS__ errstr(), )) #endif // BFS_TESTS_H |