2010-11-10 00:24:00 +01:00
|
|
|
/*
|
|
|
|
* Created by Phil on 31/10/2010.
|
|
|
|
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
|
|
|
*
|
|
|
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
*/
|
|
|
|
#ifndef TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED
|
|
|
|
|
2012-05-10 08:58:48 +02:00
|
|
|
#include "internal/catch_context_impl.hpp"
|
2011-01-07 11:22:24 +01:00
|
|
|
|
2010-11-10 00:24:00 +01:00
|
|
|
#include "internal/catch_commandline.hpp"
|
|
|
|
#include "internal/catch_list.hpp"
|
2011-04-26 09:32:40 +02:00
|
|
|
#include "reporters/catch_reporter_basic.hpp"
|
|
|
|
#include "reporters/catch_reporter_xml.hpp"
|
|
|
|
#include "reporters/catch_reporter_junit.hpp"
|
2010-11-10 00:24:00 +01:00
|
|
|
|
2010-12-31 23:07:47 +01:00
|
|
|
#include <fstream>
|
2011-02-04 10:30:36 +01:00
|
|
|
#include <stdlib.h>
|
2011-03-15 23:41:27 +01:00
|
|
|
#include <limits>
|
2010-12-31 23:07:47 +01:00
|
|
|
|
2012-05-16 16:02:51 +02:00
|
|
|
namespace Catch {
|
|
|
|
|
|
|
|
inline int Main( Config& config ) {
|
|
|
|
|
2010-11-10 00:24:00 +01:00
|
|
|
// Handle list request
|
2011-01-01 01:37:49 +01:00
|
|
|
if( config.listWhat() != Config::List::None )
|
2010-11-10 00:24:00 +01:00
|
|
|
return List( config );
|
|
|
|
|
|
|
|
// Open output file, if specified
|
|
|
|
std::ofstream ofs;
|
2012-05-16 16:02:51 +02:00
|
|
|
if( !config.getFilename().empty() ) {
|
2010-11-10 00:24:00 +01:00
|
|
|
ofs.open( config.getFilename().c_str() );
|
2012-05-16 16:02:51 +02:00
|
|
|
if( ofs.fail() ) {
|
2010-11-10 00:24:00 +01:00
|
|
|
std::cerr << "Unable to open file: '" << config.getFilename() << "'" << std::endl;
|
2011-02-16 20:02:09 +01:00
|
|
|
return (std::numeric_limits<int>::max)();
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
2011-01-01 01:18:35 +01:00
|
|
|
config.setStreamBuf( ofs.rdbuf() );
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
|
|
|
|
2010-12-27 21:49:19 +01:00
|
|
|
Runner runner( config );
|
2010-11-10 00:24:00 +01:00
|
|
|
|
|
|
|
// Run test specs specified on the command line - or default to all
|
2012-05-16 16:02:51 +02:00
|
|
|
if( !config.testsSpecified() ) {
|
2010-11-29 20:40:44 +01:00
|
|
|
config.getReporter()->StartGroup( "" );
|
2010-11-10 00:24:00 +01:00
|
|
|
runner.runAll();
|
2012-02-24 09:59:35 +01:00
|
|
|
config.getReporter()->EndGroup( "", runner.getTotals() );
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
2012-05-16 16:02:51 +02:00
|
|
|
else {
|
2010-11-10 00:24:00 +01:00
|
|
|
// !TBD We should get all the testcases upfront, report any missing,
|
|
|
|
// then just run them
|
2011-01-18 20:49:00 +01:00
|
|
|
std::vector<std::string>::const_iterator it = config.getTestSpecs().begin();
|
|
|
|
std::vector<std::string>::const_iterator itEnd = config.getTestSpecs().end();
|
2012-05-16 16:02:51 +02:00
|
|
|
for(; it != itEnd; ++it ) {
|
2012-02-23 19:51:21 +01:00
|
|
|
Totals prevTotals = runner.getTotals();
|
2010-11-29 20:40:44 +01:00
|
|
|
config.getReporter()->StartGroup( *it );
|
2012-05-16 16:02:51 +02:00
|
|
|
if( runner.runMatching( *it ) == 0 ) {
|
2010-11-10 00:24:00 +01:00
|
|
|
// Use reporter?
|
2010-12-27 12:09:34 +01:00
|
|
|
// std::cerr << "\n[Unable to match any test cases with: " << *it << "]" << std::endl;
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
2012-02-24 09:59:35 +01:00
|
|
|
config.getReporter()->EndGroup( *it, runner.getTotals() - prevTotals );
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
|
|
|
}
|
2012-02-23 19:51:21 +01:00
|
|
|
return static_cast<int>( runner.getTotals().assertions.failed );
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
2011-03-21 13:36:21 +01:00
|
|
|
|
2012-05-16 16:02:51 +02:00
|
|
|
inline void showHelp( std::string exeName ) {
|
2011-03-21 13:36:21 +01:00
|
|
|
std::string::size_type pos = exeName.find_last_of( "/\\" );
|
2012-05-16 16:02:51 +02:00
|
|
|
if( pos != std::string::npos ) {
|
2011-03-21 13:36:21 +01:00
|
|
|
exeName = exeName.substr( pos+1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << exeName << " is a CATCH host application. Options are as follows:\n\n"
|
|
|
|
<< "\t-l, --list <tests | reporters> [xml]\n"
|
|
|
|
<< "\t-t, --test <testspec> [<testspec>...]\n"
|
|
|
|
<< "\t-r, --reporter <reporter name>\n"
|
|
|
|
<< "\t-o, --out <file name>|<%stream name>\n"
|
|
|
|
<< "\t-s, --success\n"
|
2011-04-19 19:53:48 +02:00
|
|
|
<< "\t-b, --break\n"
|
|
|
|
<< "\t-n, --name <name>\n\n"
|
2011-03-21 13:36:21 +01:00
|
|
|
<< "For more detail usage please see: https://github.com/philsquared/Catch/wiki/Command-line" << std::endl;
|
|
|
|
}
|
2010-11-10 00:24:00 +01:00
|
|
|
|
2012-05-16 16:02:51 +02:00
|
|
|
inline int Main( int argc, char* const argv[], Config& config ) {
|
2011-03-21 13:21:25 +01:00
|
|
|
ArgParser( argc, argv, config );
|
|
|
|
|
2012-05-16 16:02:51 +02:00
|
|
|
if( !config.getMessage().empty() ) {
|
2011-03-21 13:21:25 +01:00
|
|
|
std::cerr << config.getMessage() << std::endl;
|
|
|
|
return (std::numeric_limits<int>::max)();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle help
|
2012-05-16 16:02:51 +02:00
|
|
|
if( config.showHelp() ) {
|
2011-03-21 13:36:21 +01:00
|
|
|
showHelp( argv[0] );
|
2011-03-21 13:21:25 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Main( config );
|
|
|
|
}
|
|
|
|
|
2012-05-16 16:02:51 +02:00
|
|
|
inline int Main( int argc, char* const argv[] ) {
|
2011-03-21 13:21:25 +01:00
|
|
|
Config config;
|
2011-03-29 09:05:47 +02:00
|
|
|
// if( isDebuggerActive() )
|
|
|
|
// config.useStream( "debug" );
|
2012-05-10 09:17:06 +02:00
|
|
|
int result = Main( argc, argv, config );
|
|
|
|
Catch::Context::cleanUp();
|
|
|
|
return result;
|
2011-03-21 13:21:25 +01:00
|
|
|
}
|
|
|
|
|
2010-11-10 00:24:00 +01:00
|
|
|
} // end namespace Catch
|
|
|
|
|
2011-02-16 20:02:09 +01:00
|
|
|
#endif // TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED
|