Skip to content

Commit

Permalink
Add test for handleFatalErrorCondition within JUnit reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
horenmar committed Apr 20, 2024
1 parent e1741f6 commit 0a8aa4a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/ExtraTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,17 @@ set_tests_properties(
PASS_REGULAR_EXPRESSION "Errors occurred during startup!"
)

add_executable(ReportingCrashWithJunitReporter ${TESTS_DIR}/X36-ReportingCrashWithJunitReporter.cpp)
target_link_libraries(ReportingCrashWithJunitReporter PRIVATE Catch2::Catch2WithMain)
add_test(
NAME Reporters::CrashInJunitReporter
COMMAND ${CMAKE_COMMAND} -E env $<TARGET_FILE:ReportingCrashWithJunitReporter> --reporter JUnit
)
set_tests_properties(
Reporters::CrashInJunitReporter
PROPERTIES
PASS_REGULAR_EXPRESSION "</testsuites>"
)

add_executable(AssertionStartingEventGoesBeforeAssertionIsEvaluated
X20-AssertionStartingEventGoesBeforeAssertionIsEvaluated.cpp
Expand Down
32 changes: 32 additions & 0 deletions tests/ExtraTests/X36-ReportingCrashWithJunitReporter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

// Copyright Catch2 Authors
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)

// SPDX-License-Identifier: BSL-1.0

/**\file
* Checks that signals/SEH within open section does not hard crash JUnit
* (or similar reporter) while we are trying to report fatal error.
*/

#include <catch2/catch_test_macros.hpp>

#include <csignal>

// On Windows we need to send SEH and not signal to test the
// RunContext::handleFatalErrorCondition code path
#if defined( _MSC_VER )
# include <windows.h>
#endif

TEST_CASE( "raises signal" ) {
SECTION( "section" ) {
#if defined( _MSC_VER )
RaiseException( 0xC0000005, 0, 0, NULL );
#else
std::raise( SIGILL );
#endif
}
}

0 comments on commit 0a8aa4a

Please sign in to comment.