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
1 changed files with 7 additions and 0 deletions

View File

@ -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));
}
handleUnfinishedSections();
// Recreate section for test case (as we will lose the one that was in scope)