pw_assert: Only extern "C" in C++
- Use PW_EXTERN_C_* for the pw_assert_HandleFailure function.
- Specify a void parameter since this is a C function.
- Add C tests for PW_ASSERT.
Change-Id: Ica24e8f4e358381e95b3c95daab8dfc3a8669d43
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/19200
Reviewed-by: Ewout van Bekkum <ewout@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
diff --git a/pw_assert/assert_backend_compile_test_c.c b/pw_assert/assert_backend_compile_test_c.c
index 6743554..c602f37 100644
--- a/pw_assert/assert_backend_compile_test_c.c
+++ b/pw_assert/assert_backend_compile_test_c.c
@@ -32,6 +32,9 @@
PW_CHECK_NOTNULL(0x0);
}
+#include <stdbool.h>
+
+#include "pw_assert/light.h"
#include "pw_status/status.h"
#ifdef __cplusplus
@@ -196,7 +199,7 @@
CHECK_INT_LE(x_int, y_int, "INT: " FAIL_IF_DISPLAYED_ARGS, z);
}
- { // Compile tests for PW_ASSERT_OK().
+ { // Compile tests for PW_CHECK_OK().
PW_CHECK_OK(PW_STATUS_OK);
PW_CHECK_OK(PW_STATUS_OK, "msg");
PW_CHECK_OK(PW_STATUS_OK, "msg: %d", 5);
@@ -205,5 +208,19 @@
PW_DCHECK_OK(PW_STATUS_OK, "msg: %d", 5);
}
+ { // TEST(Assert, Basic)
+ MAYBE_SKIP_TEST;
+ PW_ASSERT(false);
+ PW_ASSERT(123 == 456);
+ }
+
+ { // Compile tests for PW_ASSERT().
+ PW_ASSERT(true);
+ PW_ASSERT(123 != 456);
+
+ PW_DASSERT(true);
+ PW_DASSERT(123 != 456);
+ }
+
EnsureNullIsIncluded();
}