mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-23 03:43:28 +01:00
Clamp exit code internally, so it doesn’t have to be done in every main() implies
This commit is contained in:
parent
fae0fa4ec1
commit
4c1880b35f
@ -23,7 +23,7 @@ int main( int argc, char* argv[] ) {
|
|||||||
|
|
||||||
// global clean-up...
|
// global clean-up...
|
||||||
|
|
||||||
return ( result < 0xff ? result : 0xff );
|
return result;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -66,10 +66,10 @@ int main( int argc, char* argv[] )
|
|||||||
// only do this if you know you need to
|
// only do this if you know you need to
|
||||||
|
|
||||||
int numFailed = session.run();
|
int numFailed = session.run();
|
||||||
// Note that on unices only the lower 8 bits are usually used, clamping
|
// numFailed is clamped to 255 as some unices only use the lower 8 bits.
|
||||||
// the return value to 255 prevents false negative when some multiple
|
// This clamping has already been applied, so just return it here
|
||||||
// of 256 tests has failed
|
// You can also do any post run clean-up here
|
||||||
return ( numFailed < 0xff ? numFailed : 0xff );
|
return numFailed;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -96,6 +96,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Session : NonCopyable {
|
class Session : NonCopyable {
|
||||||
|
static const int MaxExitCode;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Session() {
|
Session() {
|
||||||
@ -113,7 +114,7 @@ namespace Catch {
|
|||||||
Catch::cout() << "\nCatch v" << libraryVersion() << "\n";
|
Catch::cout() << "\nCatch v" << libraryVersion() << "\n";
|
||||||
|
|
||||||
Catch::cout() << m_cli << std::endl;
|
Catch::cout() << m_cli << std::endl;
|
||||||
Catch::cout() << "For more detail usage please see the project docs\n" << std::endl;
|
Catch::cout() << "For more detailed usage please see the project docs\n" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int applyCommandLine( int argc, char* argv[] ) {
|
int applyCommandLine( int argc, char* argv[] ) {
|
||||||
@ -127,7 +128,7 @@ namespace Catch {
|
|||||||
<< "\n\n";
|
<< "\n\n";
|
||||||
}
|
}
|
||||||
Catch::cerr() << m_cli << std::endl;
|
Catch::cerr() << m_cli << std::endl;
|
||||||
return (std::numeric_limits<int>::max)();
|
return MaxExitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( m_configData.showHelp )
|
if( m_configData.showHelp )
|
||||||
@ -174,9 +175,7 @@ namespace Catch {
|
|||||||
WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, utf8Argv[i], bufSize, NULL, NULL );
|
WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, utf8Argv[i], bufSize, NULL, NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
int returnCode = applyCommandLine( argc, utf8Argv );
|
int returnCode = run( argc, utf8Argv );
|
||||||
if( returnCode == 0 )
|
|
||||||
returnCode = run();
|
|
||||||
|
|
||||||
for ( int i = 0; i < argc; ++i )
|
for ( int i = 0; i < argc; ++i )
|
||||||
delete [] utf8Argv[ i ];
|
delete [] utf8Argv[ i ];
|
||||||
@ -204,11 +203,11 @@ namespace Catch {
|
|||||||
if( Option<std::size_t> listed = list( config() ) )
|
if( Option<std::size_t> listed = list( config() ) )
|
||||||
return static_cast<int>( *listed );
|
return static_cast<int>( *listed );
|
||||||
|
|
||||||
return static_cast<int>( runTests( m_config ).assertions.failed );
|
return (std::min)( MaxExitCode, static_cast<int>( runTests( m_config ).assertions.failed ) );
|
||||||
}
|
}
|
||||||
catch( std::exception& ex ) {
|
catch( std::exception& ex ) {
|
||||||
Catch::cerr() << ex.what() << std::endl;
|
Catch::cerr() << ex.what() << std::endl;
|
||||||
return (std::numeric_limits<int>::max)();
|
return MaxExitCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,6 +231,8 @@ namespace Catch {
|
|||||||
std::shared_ptr<Config> m_config;
|
std::shared_ptr<Config> m_config;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const int Session::MaxExitCode = 255;
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED
|
||||||
|
@ -18,8 +18,7 @@ extern "C" int wmain (int argc, wchar_t * argv[], wchar_t * []) {
|
|||||||
int main (int argc, char * argv[]) {
|
int main (int argc, char * argv[]) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int result = Catch::Session().run( argc, argv );
|
return Catch::Session().run( argc, argv );
|
||||||
return ( result < 0xff ? result : 0xff );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else // __OBJC__
|
#else // __OBJC__
|
||||||
@ -37,7 +36,7 @@ int main (int argc, char * const argv[]) {
|
|||||||
[pool drain];
|
[pool drain];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return ( result < 0xff ? result : 0xff );
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // __OBJC__
|
#endif // __OBJC__
|
||||||
|
Loading…
Reference in New Issue
Block a user