2010-11-10 00:24:00 +01:00
|
|
|
/*
|
|
|
|
* Created by Phil on 02/11/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_COMMANDLINE_HPP_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED
|
|
|
|
|
2011-01-01 01:29:58 +01:00
|
|
|
#include "catch_config.hpp"
|
2012-08-23 21:08:50 +02:00
|
|
|
#include "catch_common.h"
|
2014-02-10 18:20:30 +01:00
|
|
|
#include "catch_clara.h"
|
2010-11-10 00:24:00 +01:00
|
|
|
|
2013-11-26 21:57:34 +01:00
|
|
|
#include <fstream>
|
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
namespace Catch {
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-05-31 19:48:31 +02:00
|
|
|
inline void abortAfterFirst( ConfigData& config ) { config.abortAfter = 1; }
|
2013-06-04 09:37:28 +02:00
|
|
|
inline void abortAfterX( ConfigData& config, int x ) {
|
|
|
|
if( x < 1 )
|
|
|
|
throw std::runtime_error( "Value after -x or --abortAfter must be greater than zero" );
|
|
|
|
config.abortAfter = x;
|
|
|
|
}
|
2013-05-31 19:48:31 +02:00
|
|
|
inline void addTestOrTags( ConfigData& config, std::string const& _testSpec ) { config.testsOrTags.push_back( _testSpec ); }
|
|
|
|
|
|
|
|
inline void addWarning( ConfigData& config, std::string const& _warning ) {
|
|
|
|
if( _warning == "NoAssertions" )
|
2013-08-07 19:56:35 +02:00
|
|
|
config.warnings = (WarnAbout::What)( config.warnings | WarnAbout::NoAssertions );
|
2013-05-31 19:48:31 +02:00
|
|
|
else
|
|
|
|
throw std::runtime_error( "Unrecognised warning: '" + _warning + "'" );
|
|
|
|
|
|
|
|
}
|
|
|
|
inline void setVerbosity( ConfigData& config, int level ) {
|
|
|
|
// !TBD: accept strings?
|
2013-08-07 19:56:35 +02:00
|
|
|
config.verbosity = (Verbosity::Level)level;
|
2013-05-31 19:48:31 +02:00
|
|
|
}
|
2013-08-07 19:56:35 +02:00
|
|
|
inline void setShowDurations( ConfigData& config, bool _showDurations ) {
|
|
|
|
config.showDurations = _showDurations
|
|
|
|
? ShowDurations::Always
|
|
|
|
: ShowDurations::Never;
|
|
|
|
}
|
2013-11-26 21:57:34 +01:00
|
|
|
inline void loadTestNamesFromFile( ConfigData& config, std::string const& _filename ) {
|
|
|
|
std::ifstream f( _filename.c_str() );
|
|
|
|
if( !f.is_open() )
|
|
|
|
throw std::domain_error( "Unable to load input file: " + _filename );
|
|
|
|
|
|
|
|
std::string line;
|
|
|
|
while( std::getline( f, line ) ) {
|
|
|
|
line = trim(line);
|
|
|
|
if( !line.empty() && !startsWith( line, "#" ) )
|
|
|
|
addTestOrTags( config, line );
|
|
|
|
}
|
|
|
|
}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-06-04 09:37:28 +02:00
|
|
|
inline Clara::CommandLine<ConfigData> makeCommandLineParser() {
|
2013-05-31 19:48:31 +02:00
|
|
|
|
2014-03-06 09:16:06 +01:00
|
|
|
using namespace Clara;
|
|
|
|
CommandLine<ConfigData> cli;
|
2013-05-31 19:48:31 +02:00
|
|
|
|
2013-06-04 09:37:28 +02:00
|
|
|
cli.bindProcessName( &ConfigData::processName );
|
|
|
|
|
2014-03-06 09:16:06 +01:00
|
|
|
cli["-?"]["-h"]["--help"]
|
2013-05-31 19:48:31 +02:00
|
|
|
.describe( "display usage information" )
|
2014-03-06 09:16:06 +01:00
|
|
|
.into( &ConfigData::showHelp );
|
2013-05-31 19:48:31 +02:00
|
|
|
|
2014-03-06 09:16:06 +01:00
|
|
|
cli["-l"]["--list-tests"]
|
2013-11-26 21:57:34 +01:00
|
|
|
.describe( "list all/matching test cases" )
|
2014-03-06 09:16:06 +01:00
|
|
|
.into( &ConfigData::listTests );
|
2013-05-31 19:48:31 +02:00
|
|
|
|
2014-03-06 09:16:06 +01:00
|
|
|
cli["-t"]["--list-tags"]
|
2013-11-26 21:57:34 +01:00
|
|
|
.describe( "list all/matching tags" )
|
2014-03-06 09:16:06 +01:00
|
|
|
.into( &ConfigData::listTags );
|
2013-05-31 19:48:31 +02:00
|
|
|
|
2014-03-06 09:16:06 +01:00
|
|
|
cli["-s"]["--success"]
|
2013-05-31 19:48:31 +02:00
|
|
|
.describe( "include successful tests in output" )
|
2014-03-06 09:16:06 +01:00
|
|
|
.into( &ConfigData::showSuccessfulTests );
|
2013-05-31 19:48:31 +02:00
|
|
|
|
2014-03-06 09:16:06 +01:00
|
|
|
cli["-b"]["--break"]
|
2013-05-31 19:48:31 +02:00
|
|
|
.describe( "break into debugger on failure" )
|
2014-03-06 09:16:06 +01:00
|
|
|
.into( &ConfigData::shouldDebugBreak );
|
2013-05-31 19:48:31 +02:00
|
|
|
|
2014-03-06 09:16:06 +01:00
|
|
|
cli["-e"]["--nothrow"]
|
2013-06-07 22:15:25 +02:00
|
|
|
.describe( "skip exception tests" )
|
2014-03-06 09:16:06 +01:00
|
|
|
.into( &ConfigData::noThrow );
|
2013-05-31 19:48:31 +02:00
|
|
|
|
2014-03-06 09:16:06 +01:00
|
|
|
cli["-o"]["--out"]
|
|
|
|
.placeholder( "filename" )
|
2013-05-31 19:48:31 +02:00
|
|
|
.describe( "output filename" )
|
2014-03-06 09:16:06 +01:00
|
|
|
.into( &ConfigData::outputFilename );
|
2013-05-31 19:48:31 +02:00
|
|
|
|
2014-03-06 09:16:06 +01:00
|
|
|
cli["-r"]["--reporter"]
|
|
|
|
// .placeholder( "name[:filename]" )
|
|
|
|
.placeholder( "name" )
|
2013-11-26 21:57:34 +01:00
|
|
|
.describe( "reporter to use (defaults to console)" )
|
2014-03-06 09:16:06 +01:00
|
|
|
.into( &ConfigData::reporterName );
|
2013-05-31 19:48:31 +02:00
|
|
|
|
2014-03-06 09:16:06 +01:00
|
|
|
cli["-n"]["--name"]
|
|
|
|
.placeholder( "name" )
|
2013-05-31 19:48:31 +02:00
|
|
|
.describe( "suite name" )
|
2014-03-06 09:16:06 +01:00
|
|
|
.into( &ConfigData::name );
|
2013-05-31 19:48:31 +02:00
|
|
|
|
2014-03-06 09:16:06 +01:00
|
|
|
cli["-a"]["--abort"]
|
2013-05-31 19:48:31 +02:00
|
|
|
.describe( "abort at first failure" )
|
2014-03-06 09:16:06 +01:00
|
|
|
.into( &abortAfterFirst );
|
2013-05-31 19:48:31 +02:00
|
|
|
|
2014-03-06 09:16:06 +01:00
|
|
|
cli["-x"]["--abortx"]
|
|
|
|
.placeholder( "number of failures" )
|
2013-05-31 19:48:31 +02:00
|
|
|
.describe( "abort after x failures" )
|
2014-03-06 09:16:06 +01:00
|
|
|
.into( &abortAfterX );
|
2013-05-31 19:48:31 +02:00
|
|
|
|
2014-03-06 09:16:06 +01:00
|
|
|
cli["-w"]["--warn"]
|
|
|
|
.placeholder( "warning name" )
|
2013-05-31 19:48:31 +02:00
|
|
|
.describe( "enable warnings" )
|
2014-03-06 09:16:06 +01:00
|
|
|
.into( &addWarning );
|
2013-05-31 19:48:31 +02:00
|
|
|
|
2014-03-06 09:16:06 +01:00
|
|
|
// - needs updating if reinstated
|
|
|
|
// cli.into( &setVerbosity )
|
2013-06-06 19:56:43 +02:00
|
|
|
// .describe( "level of verbosity (0=no output)" )
|
|
|
|
// .shortOpt( "v")
|
|
|
|
// .longOpt( "verbosity" )
|
2014-03-06 09:16:06 +01:00
|
|
|
// .placeholder( "level" );
|
2013-05-31 19:48:31 +02:00
|
|
|
|
2014-03-06 09:16:06 +01:00
|
|
|
cli[_]
|
|
|
|
.placeholder( "test name, pattern or tags" )
|
2013-05-31 19:48:31 +02:00
|
|
|
.describe( "which test or tests to use" )
|
2014-03-06 09:16:06 +01:00
|
|
|
.into( &addTestOrTags );
|
2013-05-31 19:48:31 +02:00
|
|
|
|
2014-03-06 09:16:06 +01:00
|
|
|
cli["-d"]["--durations"]
|
|
|
|
.placeholder( "yes/no" )
|
2013-08-07 19:56:35 +02:00
|
|
|
.describe( "show test durations" )
|
2014-03-06 09:16:06 +01:00
|
|
|
.into( &setShowDurations );
|
2013-08-07 19:56:35 +02:00
|
|
|
|
2014-03-06 09:16:06 +01:00
|
|
|
cli["-f"]["--input-file"]
|
|
|
|
.placeholder( "filename" )
|
2013-11-26 21:57:34 +01:00
|
|
|
.describe( "load test names to run from a file" )
|
2014-03-06 09:16:06 +01:00
|
|
|
.into( &loadTestNamesFromFile );
|
2013-11-26 21:57:34 +01:00
|
|
|
|
|
|
|
// Less common commands which don't have a short form
|
2014-03-06 09:16:06 +01:00
|
|
|
cli["--list-test-names-only"]
|
2013-11-26 21:57:34 +01:00
|
|
|
.describe( "list all/matching test cases names only" )
|
2014-03-06 09:16:06 +01:00
|
|
|
.into( &ConfigData::listTestNamesOnly );
|
2013-11-26 21:57:34 +01:00
|
|
|
|
2014-03-06 09:16:06 +01:00
|
|
|
cli["--list-reporters"]
|
2013-11-26 21:57:34 +01:00
|
|
|
.describe( "list all reporters" )
|
2014-03-06 09:16:06 +01:00
|
|
|
.into( &ConfigData::listReporters );
|
2013-11-26 21:57:34 +01:00
|
|
|
|
2013-06-04 09:37:28 +02:00
|
|
|
return cli;
|
2013-05-31 19:48:31 +02:00
|
|
|
}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2010-11-10 00:24:00 +01:00
|
|
|
} // end namespace Catch
|
|
|
|
|
2010-12-28 15:42:46 +01:00
|
|
|
#endif // TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED
|