Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle active Sections for fatal errors #2855

Merged
merged 2 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/catch2/internal/catch_run_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,13 @@ namespace Catch {
assertionEnded(CATCH_MOVE(result) );
resetAssertionInfo();

// Best effort cleanup for sections that have not been destructed yet
// Since this is a fatal error, we have not had and won't have the opportunity to destruct them properly
while (!m_activeSections.empty()) {
auto nl = m_activeSections.back()->nameAndLocation();
SectionEndInfo endInfo{ SectionInfo(CATCH_MOVE(nl.location), CATCH_MOVE(nl.name)), {}, 0.0 };
sectionEndedEarly(CATCH_MOVE(endInfo));
}
horenmar marked this conversation as resolved.
Show resolved Hide resolved
handleUnfinishedSections();

// Recreate section for test case (as we will lose the one that was in scope)
Expand Down
12 changes: 12 additions & 0 deletions tests/ExtraTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,18 @@ 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>"
LABELS "uses-signals"
)

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
}
}
2 changes: 1 addition & 1 deletion tools/misc/appveyorTestRunScript.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug\AutoExclusion
cd Build
if "%CONFIGURATION%"=="Debug" (
if "%coverage%"=="1" (
ctest -j 2 -C %CONFIGURATION% -D ExperimentalMemCheck || exit /b !ERRORLEVEL!
ctest -j 2 -C %CONFIGURATION% -D ExperimentalMemCheck -LE uses-signals || exit /b !ERRORLEVEL!
python ..\tools\misc\appveyorMergeCoverageScript.py || exit /b !ERRORLEVEL!
codecov --root .. --no-color --disable gcov -f cobertura.xml -t %CODECOV_TOKEN% || exit /b !ERRORLEVEL!
) else (
Expand Down
Loading