The test framework will generate an exception if any googletest assertion fails.
However, if there already is an ongoing exception, we do not want to throw
another one. Thus, we check if std::current_exception() is nullptr, and only
throw our own exception if it is nullptr.
class ThrowListener : public testing::EmptyTestEventListener {
void OnTestPartResult(const testing::TestPartResult& result) override {
if (result.type() == testing::TestPartResult::kFatalFailure) {
+ // We need to make sure an exception wasn't already thrown so we dont throw another exception at the same time
+ std::exception_ptr ex = std::current_exception();
+ if (ex) {
+ return;
+ }
throw testing::AssertionException(result);
}
}