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

Read the death-test child's output with LF line endings

On Windows the standard error of the child is in text mode, so each LF it
wrote reached the parent as CR LF: the parent did not find the marker
"\n[catch3-death:reached]\n" and reported every statement as not reached,
and a matcher would not have seen the text as written. Interpret now reads
the output with every CR LF turned into LF before it looks for the markers
or hands the text to a matcher.

Also merges devel. basic-tests with clang pass 42/42; Death.cpp compiles
with -fno-exceptions.
Commit
849db10738c8aaeba8071542a3df90f78054bfca
Author
Leitwolf11 ·
Parents
fec7b8175d47

Files · Download .tar.gz

Changes

 extras/catch_amalgamated.cpp | 24 +++++++++++++++++++++---
 src/Progmasoft/Death.cpp     | 24 +++++++++++++++++++++---
 2 files changed, 42 insertions(+), 6 deletions(-)

diff --git a/extras/catch_amalgamated.cpp b/extras/catch_amalgamated.cpp
index a77857d7..c45d7b27 100644
--- a/extras/catch_amalgamated.cpp
+++ b/extras/catch_amalgamated.cpp
@@ -9082,16 +9082,34 @@ namespace Progmasoft::Catch3 {
             return DeathResult::Ending::kExited;
         }
 
+        /// What the child wrote, with every CR LF as LF: on Windows the
+        /// standard error of the child is in text mode, so each LF it wrote
+        /// arrives as CR LF, and neither the markers nor a matcher would
+        /// find the text the statement wrote.
+        std::string WithLineFeeds( const std::string& text ) {
+            std::string result;
+            result.reserve( text.size() );
+            for ( std::size_t i = 0; i < text.size(); ++i ) {
+                if ( text[i] == '\r' && i + 1 < text.size() &&
+                     text[i + 1] == '\n' ) {
+                    continue;
+                }
+                result.push_back( text[i] );
+            }
+            return result;
+        }
+
         /// The parent's side: read what the child wrote and how it ended.
         DeathResult Interpret( const Runner::CapturedRun& run ) {
             DeathResult result;
-            const std::size_t reached = run.errors.find( kReached );
+            const std::string errors = WithLineFeeds( run.errors );
+            const std::size_t reached = errors.find( kReached );
             if ( reached == std::string::npos ) {
                 result.kind = DeathResult::Kind::kNotReached;
-                result.errors = run.errors;
+                result.errors = errors;
                 return result;
             }
-            std::string after = run.errors.substr( reached + kReached.size() );
+            std::string after = errors.substr( reached + kReached.size() );
             const auto endsWith = [&after]( std::string_view marker ) {
                 return after.size() >= marker.size() &&
                        std::string_view( after ).substr(
diff --git a/src/Progmasoft/Death.cpp b/src/Progmasoft/Death.cpp
index d6aa7a8b..8dcf29f7 100644
--- a/src/Progmasoft/Death.cpp
+++ b/src/Progmasoft/Death.cpp
@@ -143,16 +143,34 @@ namespace Progmasoft::Catch3 {
             return DeathResult::Ending::kExited;
         }
 
+        /// What the child wrote, with every CR LF as LF: on Windows the
+        /// standard error of the child is in text mode, so each LF it wrote
+        /// arrives as CR LF, and neither the markers nor a matcher would
+        /// find the text the statement wrote.
+        std::string WithLineFeeds( const std::string& text ) {
+            std::string result;
+            result.reserve( text.size() );
+            for ( std::size_t i = 0; i < text.size(); ++i ) {
+                if ( text[i] == '\r' && i + 1 < text.size() &&
+                     text[i + 1] == '\n' ) {
+                    continue;
+                }
+                result.push_back( text[i] );
+            }
+            return result;
+        }
+
         /// The parent's side: read what the child wrote and how it ended.
         DeathResult Interpret( const Runner::CapturedRun& run ) {
             DeathResult result;
-            const std::size_t reached = run.errors.find( kReached );
+            const std::string errors = WithLineFeeds( run.errors );
+            const std::size_t reached = errors.find( kReached );
             if ( reached == std::string::npos ) {
                 result.kind = DeathResult::Kind::kNotReached;
-                result.errors = run.errors;
+                result.errors = errors;
                 return result;
             }
-            std::string after = run.errors.substr( reached + kReached.size() );
+            std::string after = errors.substr( reached + kReached.size() );
             const auto endsWith = [&after]( std::string_view marker ) {
                 return after.size() >= marker.size() &&
                        std::string_view( after ).substr(