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"
|
2013-05-31 19:48:31 +02:00
|
|
|
#include "clara.h"
|
2010-11-10 00:24:00 +01:00
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
namespace Catch {
|
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" )
|
|
|
|
config.warnings = (ConfigData::WarnAbout::What)( config.warnings | ConfigData::WarnAbout::NoAssertions );
|
|
|
|
else
|
|
|
|
throw std::runtime_error( "Unrecognised warning: '" + _warning + "'" );
|
|
|
|
|
|
|
|
}
|
|
|
|
inline void setVerbosity( ConfigData& config, int level ) {
|
|
|
|
// !TBD: accept strings?
|
|
|
|
config.verbosity = (ConfigData::Verbosity::Level)level;
|
|
|
|
}
|
|
|
|
|
2013-06-04 09:37:28 +02:00
|
|
|
inline Clara::CommandLine<ConfigData> makeCommandLineParser() {
|
2013-05-31 19:48:31 +02:00
|
|
|
|
|
|
|
Clara::CommandLine<ConfigData> cli;
|
|
|
|
|
2013-06-04 09:37:28 +02:00
|
|
|
cli.bindProcessName( &ConfigData::processName );
|
|
|
|
|
2013-05-31 19:48:31 +02:00
|
|
|
cli.bind( &ConfigData::showHelp )
|
|
|
|
.describe( "display usage information" )
|
|
|
|
.shortOpt( "?")
|
|
|
|
.shortOpt( "h")
|
|
|
|
.longOpt( "help" );
|
|
|
|
|
|
|
|
cli.bind( &ConfigData::listTests )
|
|
|
|
.describe( "list all (or matching) test cases" )
|
|
|
|
.shortOpt( "l")
|
|
|
|
.longOpt( "list-tests" );
|
|
|
|
|
|
|
|
cli.bind( &ConfigData::listTags )
|
|
|
|
.describe( "list all (or matching) tags" )
|
|
|
|
.shortOpt( "t")
|
|
|
|
.longOpt( "list-tags" );
|
|
|
|
|
2013-06-04 09:37:28 +02:00
|
|
|
cli.bind( &ConfigData::listReporters )
|
2013-05-31 19:48:31 +02:00
|
|
|
.describe( "list all reporters" )
|
|
|
|
.longOpt( "list-reporters" );
|
|
|
|
|
|
|
|
cli.bind( &ConfigData::showSuccessfulTests )
|
|
|
|
.describe( "include successful tests in output" )
|
|
|
|
.shortOpt( "s")
|
|
|
|
.longOpt( "success" );
|
|
|
|
|
|
|
|
cli.bind( &ConfigData::shouldDebugBreak )
|
|
|
|
.describe( "break into debugger on failure" )
|
|
|
|
.shortOpt( "b")
|
|
|
|
.longOpt( "break" );
|
|
|
|
|
|
|
|
cli.bind( &ConfigData::noThrow )
|
2013-06-07 22:15:25 +02:00
|
|
|
.describe( "skip exception tests" )
|
2013-05-31 19:48:31 +02:00
|
|
|
.shortOpt( "e")
|
|
|
|
.longOpt( "nothrow" );
|
|
|
|
|
|
|
|
cli.bind( &ConfigData::outputFilename )
|
|
|
|
.describe( "output filename" )
|
|
|
|
.shortOpt( "o")
|
|
|
|
.longOpt( "out" )
|
|
|
|
.argName( "filename" );
|
|
|
|
|
|
|
|
cli.bind( &ConfigData::reporterName )
|
|
|
|
.describe( "reporter to use - defaults to console" )
|
|
|
|
.shortOpt( "r")
|
|
|
|
.longOpt( "reporter" )
|
|
|
|
.argName( "name[:filename]" );
|
|
|
|
|
|
|
|
cli.bind( &ConfigData::name )
|
|
|
|
.describe( "suite name" )
|
|
|
|
.shortOpt( "n")
|
|
|
|
.longOpt( "name" )
|
|
|
|
.argName( "name" );
|
|
|
|
|
2013-07-23 17:11:43 +02:00
|
|
|
cli.bind( &ConfigData::showTimings )
|
|
|
|
.describe( "print out performance timings per test case and group" )
|
|
|
|
.shortOpt( "p")
|
|
|
|
.longOpt( "performance-timings" );
|
|
|
|
|
|
|
|
cli.bind( &ConfigData::timingsThreshold )
|
|
|
|
.describe( "print out only the timings exceeding this given threshold value [in seconds]" )
|
|
|
|
.shortOpt( "q")
|
|
|
|
.longOpt( "performance-timings-theshold" )
|
|
|
|
.argName( "threshold" );
|
|
|
|
|
2013-05-31 19:48:31 +02:00
|
|
|
cli.bind( &abortAfterFirst )
|
|
|
|
.describe( "abort at first failure" )
|
|
|
|
.shortOpt( "a")
|
|
|
|
.longOpt( "abort" );
|
|
|
|
|
|
|
|
cli.bind( &abortAfterX )
|
|
|
|
.describe( "abort after x failures" )
|
|
|
|
.shortOpt( "x")
|
|
|
|
.longOpt( "abortx" )
|
|
|
|
.argName( "number of failures" );
|
|
|
|
|
|
|
|
cli.bind( &addWarning )
|
|
|
|
.describe( "enable warnings" )
|
|
|
|
.shortOpt( "w")
|
|
|
|
.longOpt( "warn" )
|
|
|
|
.argName( "warning name" );
|
|
|
|
|
2013-06-06 19:56:43 +02:00
|
|
|
// cli.bind( &setVerbosity )
|
|
|
|
// .describe( "level of verbosity (0=no output)" )
|
|
|
|
// .shortOpt( "v")
|
|
|
|
// .longOpt( "verbosity" )
|
|
|
|
// .argName( "level" );
|
2013-05-31 19:48:31 +02:00
|
|
|
|
|
|
|
cli.bind( &addTestOrTags )
|
|
|
|
.describe( "which test or tests to use" )
|
|
|
|
.argName( "test name, pattern or tags" );
|
|
|
|
|
2013-06-04 09:37:28 +02:00
|
|
|
return cli;
|
2013-05-31 19:48:31 +02:00
|
|
|
}
|
2012-06-08 09:22:56 +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
|