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");
   }
}
```
This commit is contained in:
Altan Birler 2024-04-15 13:25:08 +02:00 committed by Martin Hořeňovský
parent 2bce3e276b
commit 42fe78d0ba

View File

@ -450,6 +450,13 @@ namespace Catch {
assertionEnded(CATCH_MOVE(result) ); assertionEnded(CATCH_MOVE(result) );
resetAssertionInfo(); 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));
}
handleUnfinishedSections(); handleUnfinishedSections();
// Recreate section for test case (as we will lose the one that was in scope) // Recreate section for test case (as we will lose the one that was in scope)