Skip to content

Commit

Permalink
test: Make MBED_ASSERT failures fail
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Patater authored and rwalton-arm committed Jul 26, 2021
1 parent c06b478 commit ccb9271
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions platform/tests/UNITTESTS/doubles/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ target_link_libraries(mbed-stubs-platform
mbed-headers-base
mbed-headers-hal
mbed-headers-platform
gmock_main
)
7 changes: 7 additions & 0 deletions platform/tests/UNITTESTS/doubles/mbed_assert_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "platform/mbed_assert.h"
#include "gtest/gtest.h"
#include <stdio.h>
#include <stdbool.h>

Expand All @@ -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();
}

0 comments on commit ccb9271

Please sign in to comment.