diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-12-26 20:09:17 -0700 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-12-26 20:09:17 -0700 |
commit | e7e0cff1960fca598e0ba01be2bb56b65cbb9e2b (patch) | |
tree | 1e2c607ae9980b47917effe4203b4448a1dd4c5f /libmisc/tests/test_assert.c | |
parent | d0e9e9c4a178fe396f3ba255bc440a15b107a097 (diff) | |
parent | 1aecc70750ee6ce9c96ebf3e6b4a7fb322ff8ca3 (diff) |
Merge branch 'lukeshu/check-build'
Diffstat (limited to 'libmisc/tests/test_assert.c')
-rw-r--r-- | libmisc/tests/test_assert.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/libmisc/tests/test_assert.c b/libmisc/tests/test_assert.c index 189f6de..3c2d6b6 100644 --- a/libmisc/tests/test_assert.c +++ b/libmisc/tests/test_assert.c @@ -5,12 +5,14 @@ */ #include <setjmp.h> +#include <stdarg.h> /* for va_list, va_start(), va_end() */ #include <stdbool.h> -#include <string.h> #include <stdlib.h> +#include <string.h> #include <libmisc/macro.h> #include <libmisc/assert.h> +#include <libmisc/_intercept.h> #include "test.h" @@ -28,17 +30,21 @@ jmp_buf global_env; setjmp(global_env) == 0; \ }) -[[noreturn]] void abort(void) { +void __lm_abort(void) { global_failed = true; longjmp(global_env, 1); } -#define __builtin_unreachable() test_assert(0) - -int vprintf(const char *format, va_list ap) { - return vasprintf(&global_log, format, ap); +int __lm_printf(const char *format, ...) { + va_list va; + va_start(va, format); + int ret = vasprintf(&global_log, format, va); + va_end(va); + return ret; } +#define __builtin_unreachable() test_assert(0) + /* Utilities ******************************************************************/ #define test_should_succeed(test) do { \ @@ -68,6 +74,7 @@ int vprintf(const char *format, va_list ap) { static_assert(sizeof(char) == 1); int main() { +#ifndef NDEBUG test_should_succeed(assert(true)); test_should_fail(assert(false), "error: ASSERT: "__FILE__":"LM_STR_(__LINE__)":main(): assertion \"false\" failed\n"); @@ -82,5 +89,6 @@ int main() { free(global_log); global_log = NULL; } +#endif return 0; } |