From daed96802fcf01d0243c8ce6a5151bdc41baf352 Mon Sep 17 00:00:00 2001 From: "Peter A. Bigot" Date: Sat, 7 Sep 2019 07:21:27 -0500 Subject: [PATCH] subsys/testsuite: use bool for condition types Use of the test suite in C++ causes warnings because use of defined cast operators have the wrong target type. For example, many standard container APIs use operator bool() to test for empty containers. Code like zassert_true(v, "") fails to build when the test parameter is an int. Correct the argument type. This also causes any use of an assignment expression as a conditional in zassert to be diagnosed as a potential error. Signed-off-by: Peter A. Bigot --- subsys/testsuite/ztest/include/ztest_assert.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/subsys/testsuite/ztest/include/ztest_assert.h b/subsys/testsuite/ztest/include/ztest_assert.h index b1d7f163f07..54b33cf96c7 100644 --- a/subsys/testsuite/ztest/include/ztest_assert.h +++ b/subsys/testsuite/ztest/include/ztest_assert.h @@ -18,6 +18,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -26,9 +27,9 @@ extern "C" { void ztest_test_fail(void); #if CONFIG_ZTEST_ASSERT_VERBOSE == 0 -static inline void z_zassert_(int cond, const char *file, int line) +static inline void z_zassert_(bool cond, const char *file, int line) { - if (!(cond)) { + if (cond == false) { PRINT("\n Assertion failed at %s:%d\n", file, line); ztest_test_fail(); @@ -40,13 +41,13 @@ static inline void z_zassert_(int cond, const char *file, int line) #else /* CONFIG_ZTEST_ASSERT_VERBOSE != 0 */ -static inline void z_zassert(int cond, +static inline void z_zassert(bool cond, const char *default_msg, const char *file, int line, const char *func, const char *msg, ...) { - if (!(cond)) { + if (cond == false) { va_list vargs; va_start(vargs, msg);