2010-11-09 18:24:00 -05:00
|
|
|
/*
|
|
|
|
* catch_runner.hpp
|
|
|
|
* Catch
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
2011-01-07 05:22:24 -05:00
|
|
|
#include "internal/catch_hub_impl.hpp"
|
|
|
|
|
2010-11-09 18:24:00 -05:00
|
|
|
#include "internal/catch_commandline.hpp"
|
|
|
|
#include "internal/catch_list.hpp"
|
|
|
|
#include "catch_reporter_basic.hpp"
|
|
|
|
#include "catch_reporter_xml.hpp"
|
2010-11-29 14:40:44 -05:00
|
|
|
#include "catch_reporter_junit.hpp"
|
2010-11-09 18:24:00 -05:00
|
|
|
|
2010-12-31 17:07:47 -05:00
|
|
|
#include <fstream>
|
|
|
|
|
2010-11-09 18:24:00 -05:00
|
|
|
namespace Catch
|
|
|
|
{
|
|
|
|
inline int Main( int argc, char * const argv[] )
|
|
|
|
{
|
2010-12-31 19:20:14 -05:00
|
|
|
Config config;
|
2011-01-31 05:10:20 -05:00
|
|
|
ArgParser( argc, argv, config );
|
2010-11-09 18:24:00 -05:00
|
|
|
|
2011-01-18 14:49:00 -05:00
|
|
|
if( !config.getMessage().empty() )
|
2010-11-09 18:24:00 -05:00
|
|
|
{
|
2011-01-18 14:49:00 -05:00
|
|
|
std::cerr << config.getMessage() << std::endl;
|
2010-11-09 18:24:00 -05:00
|
|
|
return std::numeric_limits<int>::max();
|
|
|
|
}
|
|
|
|
|
2010-12-30 13:51:02 -05:00
|
|
|
// Handle help
|
|
|
|
if( config.showHelp() )
|
|
|
|
{
|
|
|
|
std::string exeName( argv[0] );
|
|
|
|
std::string::size_type pos = exeName.find_last_of( "/\\" );
|
|
|
|
if( pos != std::string::npos )
|
|
|
|
{
|
|
|
|
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"
|
2011-01-18 04:20:06 -05:00
|
|
|
<< "\t-o, --out <file name>|<%stream name>\n"
|
2010-12-30 13:51:02 -05:00
|
|
|
<< "\t-s, --success\n"
|
|
|
|
<< "\t-b, --break\n\n"
|
|
|
|
<< "For more detail usage please see: https://github.com/philsquared/Catch/wiki/Command-line" << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-09 18:24:00 -05:00
|
|
|
// Handle list request
|
2010-12-31 19:37:49 -05:00
|
|
|
if( config.listWhat() != Config::List::None )
|
2010-11-09 18:24:00 -05:00
|
|
|
return List( config );
|
|
|
|
|
|
|
|
// Open output file, if specified
|
|
|
|
std::ofstream ofs;
|
|
|
|
if( !config.getFilename().empty() )
|
|
|
|
{
|
|
|
|
ofs.open( config.getFilename().c_str() );
|
|
|
|
if( ofs.fail() )
|
|
|
|
{
|
|
|
|
std::cerr << "Unable to open file: '" << config.getFilename() << "'" << std::endl;
|
|
|
|
return std::numeric_limits<int>::max();
|
|
|
|
}
|
2010-12-31 19:18:35 -05:00
|
|
|
config.setStreamBuf( ofs.rdbuf() );
|
2010-11-09 18:24:00 -05:00
|
|
|
}
|
|
|
|
|
2010-12-27 15:49:19 -05:00
|
|
|
Runner runner( config );
|
2010-11-09 18:24:00 -05:00
|
|
|
|
|
|
|
// Run test specs specified on the command line - or default to all
|
2011-01-18 14:49:00 -05:00
|
|
|
if( !config.testsSpecified() )
|
2010-11-09 18:24:00 -05:00
|
|
|
{
|
2010-11-29 14:40:44 -05:00
|
|
|
config.getReporter()->StartGroup( "" );
|
2010-11-09 18:24:00 -05:00
|
|
|
runner.runAll();
|
2010-11-29 14:40:44 -05:00
|
|
|
config.getReporter()->EndGroup( "", runner.getSuccessCount(), runner.getFailureCount() );
|
2010-11-09 18:24:00 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// !TBD We should get all the testcases upfront, report any missing,
|
|
|
|
// then just run them
|
2011-01-18 14:49:00 -05:00
|
|
|
std::vector<std::string>::const_iterator it = config.getTestSpecs().begin();
|
|
|
|
std::vector<std::string>::const_iterator itEnd = config.getTestSpecs().end();
|
2010-11-09 18:24:00 -05:00
|
|
|
for(; it != itEnd; ++it )
|
|
|
|
{
|
2010-11-29 14:40:44 -05:00
|
|
|
size_t prevSuccess = runner.getSuccessCount();
|
|
|
|
size_t prevFail = runner.getFailureCount();
|
|
|
|
config.getReporter()->StartGroup( *it );
|
2010-11-09 18:24:00 -05:00
|
|
|
if( runner.runMatching( *it ) == 0 )
|
|
|
|
{
|
|
|
|
// Use reporter?
|
2010-12-27 06:09:34 -05:00
|
|
|
// std::cerr << "\n[Unable to match any test cases with: " << *it << "]" << std::endl;
|
2010-11-09 18:24:00 -05:00
|
|
|
}
|
2010-11-29 14:40:44 -05:00
|
|
|
config.getReporter()->EndGroup( *it, runner.getSuccessCount()-prevSuccess, runner.getFailureCount()-prevFail );
|
2010-11-09 18:24:00 -05:00
|
|
|
}
|
|
|
|
}
|
2010-11-12 14:32:13 -05:00
|
|
|
return runner.getFailureCount();
|
2010-11-09 18:24:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace Catch
|
|
|
|
|
|
|
|
#endif // TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED
|