Skip to content

Commit

Permalink
iox-#1032 Adjust error detection condition in fatal failure test func…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
elBoberido committed Feb 5, 2024
1 parent d125bc3 commit 5866693
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,44 @@ inline bool IOX_EXPECT_FATAL_FAILURE(const function_ref<void()> testFunction,
iox::testing::ErrorHandler::instance().reset();
runInTestThread([&] { testFunction(); });
IOX_TESTING_EXPECT_PANIC();
auto hasPanicked = iox::testing::hasPanicked();

auto hasExpectedError{false};
if constexpr (std::is_same_v<ErrorType, iox::er::FatalKind>)
{
hasExpectedError = iox::testing::hasPanicked();
hasExpectedError = hasPanicked;
if (!hasExpectedError)
{
IOX_LOG(ERROR, "Expected '" << iox::er::FatalKind::name << "' but it did not happen!");
}
}
else if constexpr (std::is_same_v<ErrorType, iox::er::EnforceViolationKind>)
{
hasExpectedError = iox::testing::hasEnforceViolation() && iox::testing::hasPanicked();
hasExpectedError = iox::testing::hasEnforceViolation();
if (!hasExpectedError)
{
IOX_LOG(ERROR, "Expected '" << iox::er::EnforceViolationKind::name << "' but it did not happen!");
}
}
else if constexpr (std::is_same_v<ErrorType, iox::er::AssertViolationKind>)
{
hasExpectedError = iox::testing::hasAssertViolation() && iox::testing::hasPanicked();
hasExpectedError = iox::testing::hasAssertViolation();
if (!hasExpectedError)
{
IOX_LOG(ERROR, "Expected '" << iox::er::AssertViolationKind::name << "' but it did not happen!");
}
}
else
{
hasExpectedError = iox::testing::hasError(expectedError) && iox::testing::hasPanicked();
hasExpectedError = iox::testing::hasError(expectedError);
if (!hasExpectedError)
{
IOX_LOG(ERROR, "Expected an '" << expectedError << "' error but it did not happen!");
}
}

EXPECT_TRUE(hasExpectedError);
return hasExpectedError;
return hasExpectedError && hasPanicked;
}

inline bool IOX_EXPECT_NO_FATAL_FAILURE(const function_ref<void()> testFunction)
Expand Down

0 comments on commit 5866693

Please sign in to comment.