Skip to content

Commit 51b81e0

Browse files
committed
test: Make MBED_ASSERT failures fail
Make MBED_ASSERT failures fail the unit test case. Without this, we might not notice the assertion failure as it wouldn't be bubbled up to googletest.
1 parent f0d7e24 commit 51b81e0

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

platform/tests/UNITTESTS/doubles/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ target_link_libraries(mbed-stubs-platform
3535
mbed-headers-base
3636
mbed-headers-hal
3737
mbed-headers-platform
38+
gmock_main
3839
)

platform/tests/UNITTESTS/doubles/mbed_assert_stub.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
#include "platform/mbed_assert.h"
19+
#include "gtest/gtest.h"
1920
#include <stdio.h>
2021
#include <stdbool.h>
2122

@@ -27,4 +28,10 @@ extern "C" void mbed_assert_internal(const char *expr, const char *file, int lin
2728
if (mbed_assert_throw_errors) {
2829
throw 1;
2930
}
31+
32+
/* Ensure we fail the unit test if the Mbed assertion fails. Without this,
33+
* we might not notice the assertion failure as it wouldn't be bubbled up
34+
* to googletest. Note that this is after the above throw, as some tests
35+
* check that an exception is thrown (i.e. negative tests). */
36+
FAIL();
3037
}

0 commit comments

Comments
 (0)