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>
|
2017-02-12 13:34:55 +01:00
|
|
|
#include <ctime>
|
2013-11-26 21:57:34 +01:00
|
|
|
|
2012-05-16 00:58:23 +02:00
|
|
|
namespace Catch {
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2017-06-13 00:04:24 +02:00
|
|
|
inline clara::Parser makeCommandLineParser( ConfigData& config ) {
|
|
|
|
|
2017-06-21 09:54:34 +02:00
|
|
|
using namespace clara;
|
|
|
|
|
|
|
|
auto const setWarning = [&]( std::string const& warning ) {
|
|
|
|
if( warning != "NoAssertions" )
|
|
|
|
return ParserResult::runtimeError( "Unrecognised warning: '" + warning + "'" );
|
|
|
|
config.warnings = static_cast<WarnAbout::What>( config.warnings | WarnAbout::NoAssertions );
|
|
|
|
return ParserResult::ok( ParseResultType::Matched );
|
|
|
|
};
|
2017-06-13 00:04:24 +02:00
|
|
|
auto const loadTestNamesFromFile = [&]( std::string const& filename ) {
|
|
|
|
std::ifstream f( filename.c_str() );
|
|
|
|
if( !f.is_open() )
|
2017-06-21 09:54:34 +02:00
|
|
|
return ParserResult::runtimeError( "Unable to load input file: '" + filename + "'" );
|
2017-06-13 00:04:24 +02:00
|
|
|
|
|
|
|
std::string line;
|
|
|
|
while( std::getline( f, line ) ) {
|
|
|
|
line = trim(line);
|
|
|
|
if( !line.empty() && !startsWith( line, '#' ) ) {
|
|
|
|
if( !startsWith( line, '"' ) )
|
|
|
|
line = '"' + line + '"';
|
|
|
|
config.testsOrTags.push_back( line + ',' );
|
|
|
|
}
|
|
|
|
}
|
2017-06-21 09:54:34 +02:00
|
|
|
return ParserResult::ok( ParseResultType::Matched );
|
|
|
|
};
|
|
|
|
auto const setTestOrder = [&]( std::string const& order ) {
|
|
|
|
if( startsWith( "declared", order ) )
|
|
|
|
config.runOrder = RunTests::InDeclarationOrder;
|
|
|
|
else if( startsWith( "lexical", order ) )
|
|
|
|
config.runOrder = RunTests::InLexicographicalOrder;
|
|
|
|
else if( startsWith( "random", order ) )
|
|
|
|
config.runOrder = RunTests::InRandomOrder;
|
|
|
|
else
|
|
|
|
return clara::ParserResult::runtimeError( "Unrecognised ordering: '" + order + "'" );
|
|
|
|
return ParserResult::ok( ParseResultType::Matched );
|
2017-06-13 00:04:24 +02:00
|
|
|
};
|
2017-06-21 09:54:34 +02:00
|
|
|
auto const setRngSeed = [&]( std::string const& seed ) {
|
|
|
|
if( seed != "time" )
|
|
|
|
return clara::detail::convertInto( seed, config.rngSeed );
|
|
|
|
config.rngSeed = static_cast<unsigned int>( std::time(0) );
|
|
|
|
return ParserResult::ok( ParseResultType::Matched );
|
|
|
|
};
|
|
|
|
auto const setColourUsage = [&]( std::string const& useColour ) {
|
|
|
|
auto mode = toLower( useColour );
|
2017-06-13 00:04:24 +02:00
|
|
|
|
2017-06-21 09:54:34 +02:00
|
|
|
if( mode == "yes" )
|
|
|
|
config.useColour = UseColour::Yes;
|
|
|
|
else if( mode == "no" )
|
|
|
|
config.useColour = UseColour::No;
|
|
|
|
else if( mode == "auto" )
|
|
|
|
config.useColour = UseColour::Auto;
|
|
|
|
else
|
|
|
|
return ParserResult::runtimeError( "colour mode must be one of: auto, yes or no. '" + useColour + "' not recognised" );
|
|
|
|
return ParserResult::ok( ParseResultType::Matched );
|
|
|
|
};
|
2017-06-20 21:14:38 +02:00
|
|
|
auto const setVerbosity = [&]( std::string const& verbosity ) {
|
|
|
|
auto lcVerbosity = toLower( verbosity );
|
|
|
|
if( lcVerbosity == "quiet" )
|
|
|
|
config.verbosity = Verbosity::Quiet;
|
|
|
|
else if( lcVerbosity == "normal" )
|
|
|
|
config.verbosity = Verbosity::Normal;
|
|
|
|
else if( lcVerbosity == "high" )
|
|
|
|
config.verbosity = Verbosity::High;
|
|
|
|
else
|
|
|
|
return ParserResult::runtimeError( "Unrecognised verbosity, '" + verbosity + "'" );
|
|
|
|
return ParserResult::ok( ParseResultType::Matched );
|
|
|
|
};
|
2017-06-13 00:04:24 +02:00
|
|
|
|
2017-06-21 12:42:53 +02:00
|
|
|
auto cli
|
2017-06-13 00:04:24 +02:00
|
|
|
= ExeName( config.processName )
|
2017-06-22 16:52:01 +02:00
|
|
|
+ Help( config.showHelp )
|
|
|
|
+ Opt( config.listTests )
|
2017-06-13 00:04:24 +02:00
|
|
|
["-l"]["--list-tests"]
|
2017-06-22 16:52:01 +02:00
|
|
|
( "list all/matching test cases" )
|
|
|
|
+ Opt( config.listTags )
|
2017-06-13 00:04:24 +02:00
|
|
|
["-t"]["--list-tags"]
|
2017-06-22 16:52:01 +02:00
|
|
|
( "list all/matching tags" )
|
|
|
|
+ Opt( config.showSuccessfulTests )
|
2017-06-13 00:04:24 +02:00
|
|
|
["-s"]["--success"]
|
2017-06-22 16:52:01 +02:00
|
|
|
( "include successful tests in output" )
|
|
|
|
+ Opt( config.shouldDebugBreak )
|
2017-06-13 00:04:24 +02:00
|
|
|
["-b"]["--break"]
|
2017-06-22 16:52:01 +02:00
|
|
|
( "break into debugger on failure" )
|
|
|
|
+ Opt( config.noThrow )
|
2017-06-13 00:04:24 +02:00
|
|
|
["-e"]["--nothrow"]
|
2017-06-22 16:52:01 +02:00
|
|
|
( "skip exception tests" )
|
|
|
|
+ Opt( config.showInvisibles )
|
2017-06-13 00:04:24 +02:00
|
|
|
["-i"]["--invisibles"]
|
2017-06-22 16:52:01 +02:00
|
|
|
( "show invisibles (tabs, newlines)" )
|
|
|
|
+ Opt( config.outputFilename, "filename" )
|
2017-06-13 00:04:24 +02:00
|
|
|
["-o"]["--out"]
|
2017-06-22 16:52:01 +02:00
|
|
|
( "output filename" )
|
|
|
|
+ Opt( config.reporterNames, "name" )
|
2017-06-13 00:04:24 +02:00
|
|
|
["-r"]["--reporter"]
|
2017-06-22 16:52:01 +02:00
|
|
|
( "reporter to use (defaults to console)" )
|
|
|
|
+ Opt( config.name, "name" )
|
2017-06-13 00:04:24 +02:00
|
|
|
["-n"]["--name"]
|
2017-06-22 16:52:01 +02:00
|
|
|
( "suite name" )
|
|
|
|
+ Opt( [&]( bool ){ config.abortAfter = 1; } )
|
2017-06-13 00:04:24 +02:00
|
|
|
["-a"]["--abort"]
|
2017-06-22 16:52:01 +02:00
|
|
|
( "abort at first failure" )
|
|
|
|
+ Opt( [&]( int x ){ config.abortAfter = x; }, "no. failures" )
|
2017-06-13 00:04:24 +02:00
|
|
|
["-x"]["--abortx"]
|
2017-06-22 16:52:01 +02:00
|
|
|
( "abort after x failures" )
|
|
|
|
+ Opt( setWarning, "warning name" )
|
2017-06-13 00:04:24 +02:00
|
|
|
["-w"]["--warn"]
|
2017-06-22 16:52:01 +02:00
|
|
|
( "enable warnings" )
|
|
|
|
+ Opt( [&]( bool ) { config.showDurations = ShowDurations::Always; } )
|
2017-06-13 00:04:24 +02:00
|
|
|
["-d"]["--durations"]
|
2017-06-22 16:52:01 +02:00
|
|
|
( "show test durations" )
|
|
|
|
+ Opt( loadTestNamesFromFile, "filename" )
|
2017-06-13 00:04:24 +02:00
|
|
|
["-f"]["--input-file"]
|
2017-06-22 16:52:01 +02:00
|
|
|
( "load test names to run from a file" )
|
|
|
|
+ Opt( config.filenamesAsTags )
|
2017-06-13 00:04:24 +02:00
|
|
|
["-#"]["--filenames-as-tags"]
|
2017-06-22 16:52:01 +02:00
|
|
|
( "adds a tag for the filename" )
|
|
|
|
+ Opt( config.sectionsToRun, "section name" )
|
2017-06-13 00:04:24 +02:00
|
|
|
["-c"]["--section"]
|
2017-06-22 16:52:01 +02:00
|
|
|
( "specify section to run" )
|
2017-06-20 21:14:38 +02:00
|
|
|
+ Opt( setVerbosity, "quiet|normal|high" )
|
|
|
|
["-v"]["--verbosity"]
|
|
|
|
( "set output verbosity" )
|
2017-06-22 16:52:01 +02:00
|
|
|
+ Opt( config.listTestNamesOnly )
|
2017-06-13 00:04:24 +02:00
|
|
|
["--list-test-names-only"]
|
2017-06-22 16:52:01 +02:00
|
|
|
( "list all/matching test cases names only" )
|
|
|
|
+ Opt( config.listReporters )
|
2017-06-13 00:04:24 +02:00
|
|
|
["--list-reporters"]
|
2017-06-22 16:52:01 +02:00
|
|
|
( "list all reporters" )
|
|
|
|
+ Opt( setTestOrder, "decl|lex|rand" )
|
2017-06-13 00:04:24 +02:00
|
|
|
["--order"]
|
2017-06-22 16:52:01 +02:00
|
|
|
( "test case order (defaults to decl)" )
|
|
|
|
+ Opt( setRngSeed, "'time'|number" )
|
2017-06-13 00:04:24 +02:00
|
|
|
["--rng-seed"]
|
2017-06-22 16:52:01 +02:00
|
|
|
( "set a specific seed for random numbers" )
|
|
|
|
+ Opt( setColourUsage, "yes|no" )
|
2017-06-13 00:04:24 +02:00
|
|
|
["--use-colour"]
|
2017-06-22 16:52:01 +02:00
|
|
|
( "should output be colourised" )
|
|
|
|
|
|
|
|
+ Arg( config.testsOrTags, "test name|pattern|tags" )
|
2017-06-13 00:04:24 +02:00
|
|
|
( "which test or tests to use" );
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2017-06-21 12:42:53 +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
|