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

Cap main exit code to 255 (#797)

Changed default main to clamp exit code to 8 bits because of POSIX limitations.

Updated documentation about declaring non-default main.
Commit
1e5176bd691b8549be51f1aa7c2e6f1cb8a6d033
Author
Jan Včelák ·
Committer
Martin Hořeňovský
Parents
7dd4f2977a3c

Files · Download .tar.gz

Changes

 docs/own-main.md                        | 8 ++++++--
 include/internal/catch_default_main.hpp | 5 +++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/docs/own-main.md b/docs/own-main.md
index 4330c8b4..67e551f3 100644
--- a/docs/own-main.md
+++ b/docs/own-main.md
@@ -24,7 +24,7 @@ int main( int argc, char* argv[] )
 
   // global clean-up...
 
-  return result;
+  return ( result < 0xff ? result : 0xff );
 }
 ```
 
@@ -51,7 +51,11 @@ int main( int argc, char* argv[] )
   // overrides command line args
   // only do this if you know you need to
 
-  return session.run();
+  int numFailed = session.run();
+  // Note that on unices only the lower 8 bits are usually used, clamping
+  // the return value to 255 prevents false negative when some multiple
+  // of 256 tests has failed
+  return ( numFailed < 0xff ? numFailed : 0xff );
 }
 ```
 
diff --git a/include/internal/catch_default_main.hpp b/include/internal/catch_default_main.hpp
index 54202fb3..12ca9024 100644
--- a/include/internal/catch_default_main.hpp
+++ b/include/internal/catch_default_main.hpp
@@ -12,7 +12,8 @@
 
 // Standard C/C++ main entry point
 int main (int argc, char * argv[]) {
-    return Catch::Session().run( argc, argv );
+    int result = Catch::Session().run( argc, argv );
+    return ( result < 0xff ? result : 0xff );
 }
 
 #else // __OBJC__
@@ -30,7 +31,7 @@ int main (int argc, char * const argv[]) {
     [pool drain];
 #endif
 
-    return result;
+    return ( result < 0xff ? result : 0xff );
 }
 
 #endif // __OBJC__