Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2/internal
diff options
context:
space:
mode:
authorAltan Birler2024-04-15 13:25:08 +0200
committerMartin Hořeňovský2024-04-21 21:52:33 +0200
commit42fe78d0ba0eb33096a705e8f9c4814fd619eebd (patch)
treeb821fcd577522a7d9da67e17b5f31725cef7f0c4 /src/catch2/internal
parent2bce3e276b5f859ac45c43f011ffed98d0325115 (diff)
downloadcatch3-42fe78d0ba0eb33096a705e8f9c4814fd619eebd.tar.gz
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"); } } ```
Diffstat (limited to 'src/catch2/internal')
-rw-r--r--src/catch2/internal/catch_run_context.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/catch2/internal/catch_run_context.cpp b/src/catch2/internal/catch_run_context.cpp
index 77b476d8..07691788 100644
--- a/src/catch2/internal/catch_run_context.cpp
+++ b/src/catch2/internal/catch_run_context.cpp
@@ -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)