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.
This commit is contained in:
Jan Včelák 2017-01-31 20:48:14 +01:00 committed by Martin Hořeňovský
parent 7dd4f2977a
commit 1e5176bd69
2 changed files with 9 additions and 4 deletions

View File

@ -24,7 +24,7 @@ int main( int argc, char* argv[] )
// global clean-up... // global clean-up...
return result; return ( result < 0xff ? result : 0xff );
} }
``` ```
@ -51,7 +51,11 @@ int main( int argc, char* argv[] )
// overrides command line args // overrides command line args
// only do this if you know you need to // 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 );
} }
``` ```

View File

@ -12,7 +12,8 @@
// Standard C/C++ main entry point // Standard C/C++ main entry point
int main (int argc, char * argv[]) { 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__ #else // __OBJC__
@ -30,7 +31,7 @@ int main (int argc, char * const argv[]) {
[pool drain]; [pool drain];
#endif #endif
return result; return ( result < 0xff ? result : 0xff );
} }
#endif // __OBJC__ #endif // __OBJC__