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.
pull/14948/head
Jaeden Amero 2021-07-21 16:26:46 +01:00
parent f0d7e24066
commit 51b81e0629
2 changed files with 8 additions and 0 deletions

View File

@ -35,4 +35,5 @@ target_link_libraries(mbed-stubs-platform
mbed-headers-base
mbed-headers-hal
mbed-headers-platform
gmock_main
)

View File

@ -16,6 +16,7 @@
*/
#include "platform/mbed_assert.h"
#include "gtest/gtest.h"
#include <stdio.h>
#include <stdbool.h>
@ -27,4 +28,10 @@ extern "C" void mbed_assert_internal(const char *expr, const char *file, int lin
if (mbed_assert_throw_errors) {
throw 1;
}
/* Ensure we fail the unit test if the Mbed assertion fails. Without this,
* we might not notice the assertion failure as it wouldn't be bubbled up
* to googletest. Note that this is after the above throw, as some tests
* check that an exception is thrown (i.e. negative tests). */
FAIL();
}