diff options
Diffstat (limited to 'libmisc')
-rw-r--r-- | libmisc/CMakeLists.txt | 1 | ||||
-rw-r--r-- | libmisc/include/libmisc/assert.h | 2 | ||||
-rw-r--r-- | libmisc/tests/test_assert_min.c | 17 |
3 files changed, 19 insertions, 1 deletions
diff --git a/libmisc/CMakeLists.txt b/libmisc/CMakeLists.txt index 83e91fe..5052f29 100644 --- a/libmisc/CMakeLists.txt +++ b/libmisc/CMakeLists.txt @@ -12,6 +12,7 @@ target_sources(libmisc INTERFACE target_compile_options(libmisc INTERFACE "$<$<COMPILE_LANGUAGE:C>:-fplan9-extensions>") add_lib_test(libmisc test_assert) +add_lib_test(libmisc test_assert_min) add_lib_test(libmisc test_endian) add_lib_test(libmisc test_hash) add_lib_test(libmisc test_log) diff --git a/libmisc/include/libmisc/assert.h b/libmisc/include/libmisc/assert.h index da2ba2b..8cf0735 100644 --- a/libmisc/include/libmisc/assert.h +++ b/libmisc/include/libmisc/assert.h @@ -17,7 +17,7 @@ #endif #define assert_msg(expr, msg) __assert_msg(expr, #expr, msg) /* libmisc */ -#define assert(expr) __assert_msg(expr, #expr, NULL) /* C89, POSIX-2001 */ +#define assert(expr) __assert_msg(expr, #expr, 0) /* C89, POSIX-2001 */ #define assert_notreached(msg) do { __assert_msg(0, "notreached", msg); __builtin_unreachable(); } while (0) /* libmisc */ #define static_assert _Static_assert /* C11 */ diff --git a/libmisc/tests/test_assert_min.c b/libmisc/tests/test_assert_min.c new file mode 100644 index 0000000..9c0394b --- /dev/null +++ b/libmisc/tests/test_assert_min.c @@ -0,0 +1,17 @@ +/* libmisc/tests/test_assert_min.c - Tests for minimal <libmisc/assert.h> + * + * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +/* Don't include *anything* else. */ +#include <libmisc/assert.h> + +static_assert(1 == 1); + +int main() { + assert_msg(1, "foo"); + assert(1); + return 0; + assert_notreached("ret"); +} |