diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2024-03-27 11:20:20 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2024-03-27 13:13:23 -0400 |
commit | 25769288f62816d733004c9e8347c35dd0e4ce2a (patch) | |
tree | 9f4face40989e824c24cea08e02bd01c384d1778 /tests/tests.h | |
parent | 0ad5c7edda2de25e47077d138d7c371f94590a22 (diff) | |
download | bfs-25769288f62816d733004c9e8347c35dd0e4ce2a.tar.xz |
tests: New bfs_pcheck() macro to report xstrerror(errno)
Diffstat (limited to 'tests/tests.h')
-rw-r--r-- | tests/tests.h | 16 |
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 |