pw_assert: Add new "light" PW_ASSERT macros
This introduces two new macros: PW_ASSERT() and PW_DASSERT(). These
exist to offer a lightweight assert that is safe to use in headers and
is safe for constexpr. Most of the time, these macros should not be
used, and instead the PW_CHECK() and PW_DCHECK() variants used instead.
Other changes:
- Renames PW_ASSERT_ENABLE_DCHECK to PW_ASSERT_ENABLE_DEBUG, to reflect
that the setting applies to both PW_CHECK and PW_ASSERT.
- Updates Roadamp & Status documentation sections
Testing: Since currently it is not possible to test the PW_ASSERT macros
due to needing to swap the backend, this is manually tested by flipping
the #if in pw_assert/light_test.cc to 1, and verifying that it crashes
as expected.
Change-Id: I6d2c68f772da4280e61a52576bfb6ab60e280bdf
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/17462
Reviewed-by: Wyatt Hepler <hepler@google.com>
Commit-Queue: Keir Mierle <keir@google.com>
diff --git a/pw_assert/assert_facade_test.cc b/pw_assert/assert_facade_test.cc
index 8621163..34faecb 100644
--- a/pw_assert/assert_facade_test.cc
+++ b/pw_assert/assert_facade_test.cc
@@ -384,7 +384,7 @@
// Verify side effects of debug checks work as expected.
// Only check a couple of cases, since the logic is all the same.
-#if PW_ASSERT_ENABLE_DCHECK
+#if PW_ASSERT_ENABLE_DEBUG
// When DCHECKs are enabled, they behave the same as normal checks.
TEST(AssertPass, DCheckEnabledSingleSideEffectingCall) {
global_state_for_multi_evaluate_test = 0;
@@ -417,7 +417,7 @@
EXPECT_EQ(global_state_for_multi_evaluate_test, 2);
}
-#else // PW_ASSERT_ENABLE_DCHECK
+#else // PW_ASSERT_ENABLE_DEBUG
// When DCHECKs are disabled, they should not trip, and their arguments
// shouldn't be evaluated.
@@ -451,7 +451,7 @@
PW_DCHECK_INT_EQ(IncrementsGlobal() + 10, IncrementsGlobal());
EXPECT_EQ(global_state_for_multi_evaluate_test, 0);
}
-#endif // PW_ASSERT_ENABLE_DCHECK
+#endif // PW_ASSERT_ENABLE_DEBUG
// Note: This requires enabling PW_ASSERT_USE_SHORT_NAMES 1 above.
TEST(Check, ShortNamesWork) {
@@ -512,7 +512,7 @@
TEST_F(AssertFail, Dynamic) { PW_CHECK_OK(MakeStatus(pw::Status::UNKNOWN)); }
TEST_F(AssertFail, Enum) { PW_CHECK_OK(PW_STATUS_UNKNOWN); }
-#if PW_ASSERT_ENABLE_DCHECK
+#if PW_ASSERT_ENABLE_DEBUG
// In debug mode, the asserts should check their arguments.
TEST_F(AssertPass, DCheckConstant) { PW_DCHECK_OK(pw::Status::OK); }
@@ -521,7 +521,7 @@
TEST_F(AssertFail, DCheckDynamic) {
PW_DCHECK_OK(MakeStatus(pw::Status::UNKNOWN));
}
-#else // PW_ASSERT_ENABLE_DCHECK
+#else // PW_ASSERT_ENABLE_DEBUG
// In release mode, all the asserts should pass.
TEST_F(AssertPass, DCheckConstant) { PW_DCHECK_OK(pw::Status::OK); }
@@ -530,7 +530,7 @@
TEST_F(AssertPass, DCheckDynamic) {
PW_DCHECK_OK(MakeStatus(pw::Status::UNKNOWN));
}
-#endif // PW_ASSERT_ENABLE_DCHECK
+#endif // PW_ASSERT_ENABLE_DEBUG
// TODO: Figure out how to run some of these tests is C.