Skip to content

Commit 42fe78d

Browse files
hbirlerhorenmar
authored andcommitted
Handle active Sections for fatal errors
Closes #1210 When a signal is caught, the destructors of Sections will not be called. Thus, we must call `sectionEndedEarly` manually for those Sections. Example test case: ``` TEST_CASE("broken") { SECTION("section") { /// Use illegal cpu instruction __asm__ __volatile__("ud2" : : : "memory"); } } ```
1 parent 2bce3e2 commit 42fe78d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/catch2/internal/catch_run_context.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,13 @@ namespace Catch {
450450
assertionEnded(CATCH_MOVE(result) );
451451
resetAssertionInfo();
452452

453+
// Best effort cleanup for sections that have not been destructed yet
454+
// Since this is a fatal error, we have not had and won't have the opportunity to destruct them properly
455+
while (!m_activeSections.empty()) {
456+
auto nl = m_activeSections.back()->nameAndLocation();
457+
SectionEndInfo endInfo{ SectionInfo(CATCH_MOVE(nl.location), CATCH_MOVE(nl.name)), {}, 0.0 };
458+
sectionEndedEarly(CATCH_MOVE(endInfo));
459+
}
453460
handleUnfinishedSections();
454461

455462
// Recreate section for test case (as we will lose the one that was in scope)

0 commit comments

Comments
 (0)