Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Add test for handleFatalErrorCondition within JUnit reporter

Commit
efb39689d94e43132e4e48f01e676ae6a56d8df6
Author
Martin Hořeňovský ·
Parents
42fe78d0ba0e

Files · Download .tar.gz

Changes

 tests/ExtraTests/CMakeLists.txt                    | 12 ++++++++
 .../X36-ReportingCrashWithJunitReporter.cpp        | 32 ++++++++++++++++++++++
 tools/misc/appveyorTestRunScript.bat               |  2 +-
 3 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/tests/ExtraTests/CMakeLists.txt b/tests/ExtraTests/CMakeLists.txt
index 8eaf3a56..9f6d8173 100644
--- a/tests/ExtraTests/CMakeLists.txt
+++ b/tests/ExtraTests/CMakeLists.txt
@@ -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
diff --git a/tests/ExtraTests/X36-ReportingCrashWithJunitReporter.cpp b/tests/ExtraTests/X36-ReportingCrashWithJunitReporter.cpp
new file mode 100644
index 00000000..34f4cd85
--- /dev/null
+++ b/tests/ExtraTests/X36-ReportingCrashWithJunitReporter.cpp
@@ -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
+    }
+}
diff --git a/tools/misc/appveyorTestRunScript.bat b/tools/misc/appveyorTestRunScript.bat
index 5982fc92..661bae24 100644
--- a/tools/misc/appveyorTestRunScript.bat
+++ b/tools/misc/appveyorTestRunScript.bat
@@ -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 (