Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1032 Make 'IOX_EXPECT_FATAL_FAILURE' aware of vio…
Browse files Browse the repository at this point in the history
…lations
  • Loading branch information
elBoberido committed Feb 3, 2024
1 parent 312d93a commit f0137a9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ class Violation
};

} // namespace er

const char* asStringLiteral(const er::ViolationErrorCode error) noexcept;

} // namespace iox

#endif // IOX_HOOFS_ERROR_REPORTING_VIOLATION_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,25 @@ inline bool IOX_EXPECT_FATAL_FAILURE(const function_ref<void()> testFunction,
{
iox::testing::ErrorHandler::instance().reset();
runInTestThread([&] { testFunction(); });
IOX_TESTING_EXPECT_PANIC();

/// @todo iox-#1032 'hasViolation' should not be necessary
auto hasExpectedError =
iox::testing::hasError(expectedError) || iox::testing::hasViolation() || iox::testing::hasPanicked();
auto hasExpectedError{false};
if constexpr (std::is_same_v<ErrorType, iox::er::FatalKind>)
{
hasExpectedError = iox::testing::hasPanicked();
}
else if constexpr (std::is_same_v<ErrorType, iox::er::EnforceViolationKind>)
{
hasExpectedError = iox::testing::hasEnforceViolation() && iox::testing::hasPanicked();
}
else if constexpr (std::is_same_v<ErrorType, iox::er::AssertViolationKind>)
{
hasExpectedError = iox::testing::hasAssertViolation() && iox::testing::hasPanicked();
}
else
{
hasExpectedError = iox::testing::hasError(expectedError) && iox::testing::hasPanicked();
}

EXPECT_TRUE(hasExpectedError);
return hasExpectedError;
}
Expand Down

0 comments on commit f0137a9

Please sign in to comment.