Now fully switched over to Clara-based command line with modified args

This commit is contained in:
Phil Nash 2013-06-04 08:37:28 +01:00
parent 130ec986c7
commit aee9b75e37
7 changed files with 105 additions and 329 deletions

View file

@ -71,8 +71,8 @@ TEST_CASE( "meta/Misc/Sections", "looped tests" ) {
template<size_t size>
void parseIntoConfig( const char * (&argv)[size], Catch::ConfigData& config ) {
static Catch::AllOptions options;
options.parseIntoConfig( Catch::CommandParser( size, argv ), config );
Clara::CommandLine<Catch::ConfigData> parser = Catch::makeCommandLineParser();
parser.parseInto( size, argv, config );
}
template<size_t size>
@ -89,11 +89,11 @@ std::string parseIntoConfigAndReturnError( const char * (&argv)[size], Catch::Co
inline Catch::TestCase fakeTestCase( const char* name ){ return Catch::makeTestCase( NULL, "", name, "", CATCH_INTERNAL_LINEINFO ); }
TEST_CASE( "selftest/parser/2", "ConfigData" ) {
TEST_CASE( "Process can be configured on command line", "[config][command-line]" ) {
Catch::ConfigData config;
SECTION( "default", "" ) {
SECTION( "default - no arguments", "" ) {
const char* argv[] = { "test" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
@ -104,8 +104,8 @@ TEST_CASE( "selftest/parser/2", "ConfigData" ) {
}
SECTION( "test lists", "" ) {
SECTION( "-t/1", "Specify one test case using -t" ) {
const char* argv[] = { "test", "-t", "test1" };
SECTION( "1 test", "Specify one test case using" ) {
const char* argv[] = { "test", "test1" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
Catch::Config cfg( config );
@ -113,8 +113,8 @@ TEST_CASE( "selftest/parser/2", "ConfigData" ) {
REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "notIncluded" ) ) == false );
REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "test1" ) ) );
}
SECTION( "-t/exclude:1", "Specify one test case exclusion using -t exclude:" ) {
const char* argv[] = { "test", "-t", "exclude:test1" };
SECTION( "Specify one test case exclusion using exclude:", "" ) {
const char* argv[] = { "test", "exclude:test1" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
Catch::Config cfg( config );
@ -123,28 +123,8 @@ TEST_CASE( "selftest/parser/2", "ConfigData" ) {
REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "alwaysIncluded" ) ) );
}
SECTION( "--test/1", "Specify one test case using --test" ) {
const char* argv[] = { "test", "--test", "test1" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
Catch::Config cfg( config );
REQUIRE( cfg.filters().size() == 1 );
REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "notIncluded" ) ) == false );
REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "test1" ) ) );
}
SECTION( "--test/exclude:1", "Specify one test case exclusion using --test exclude:" ) {
const char* argv[] = { "test", "--test", "exclude:test1" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
Catch::Config cfg( config );
REQUIRE( cfg.filters().size() == 1 );
REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "test1" ) ) == false );
REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "alwaysIncluded" ) ) );
}
SECTION( "--test/exclude:2", "Specify one test case exclusion using --test ~" ) {
const char* argv[] = { "test", "--test", "~test1" };
SECTION( "Specify one test case exclusion using ~", "" ) {
const char* argv[] = { "test", "~test1" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
Catch::Config cfg( config );
@ -153,7 +133,7 @@ TEST_CASE( "selftest/parser/2", "ConfigData" ) {
REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "alwaysIncluded" ) ) );
}
SECTION( "-t/2", "Specify two test cases using -t" ) {
SECTION( "Specify two test cases using -t", "" ) {
const char* argv[] = { "test", "-t", "test1", "test2" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
@ -163,11 +143,6 @@ TEST_CASE( "selftest/parser/2", "ConfigData" ) {
REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "test1" ) ) );
REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "test2" ) ) );
}
SECTION( "-t/0", "When no test names are supplied it is an error" ) {
const char* argv[] = { "test", "-t" };
REQUIRE_THAT( parseIntoConfigAndReturnError( argv, config ), Contains( "at least 1" ) );
}
}
SECTION( "reporter", "" ) {
@ -189,10 +164,6 @@ TEST_CASE( "selftest/parser/2", "ConfigData" ) {
REQUIRE( config.reporterName == "junit" );
}
SECTION( "-r/error", "reporter config only accepts one argument" ) {
const char* argv[] = { "test", "-r", "one", "two" };
REQUIRE_THAT( parseIntoConfigAndReturnError( argv, config ), Contains( "1 argument" ) );
}
}
SECTION( "debugger", "" ) {
@ -208,42 +179,34 @@ TEST_CASE( "selftest/parser/2", "ConfigData" ) {
REQUIRE( config.shouldDebugBreak );
}
SECTION( "-b", "break option has no arguments" ) {
const char* argv[] = { "test", "-b", "unexpected" };
REQUIRE_THAT( parseIntoConfigAndReturnError( argv, config ), Contains( "0 arguments" ) );
}
}
SECTION( "abort", "" ) {
SECTION( "-a", "" ) {
SECTION( "-a aborts after first failure", "" ) {
const char* argv[] = { "test", "-a" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
REQUIRE( config.abortAfter == 1 );
}
SECTION( "-a/2", "" ) {
const char* argv[] = { "test", "-a", "2" };
SECTION( "-x 2 aborts after two failures", "" ) {
const char* argv[] = { "test", "-x", "2" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
REQUIRE( config.abortAfter == 2 );
}
SECTION( "-a/error/0", "" ) {
const char* argv[] = { "test", "-a", "0" };
SECTION( "-x must be greater than zero", "" ) {
const char* argv[] = { "test", "-x", "0" };
REQUIRE_THAT( parseIntoConfigAndReturnError( argv, config ), Contains( "greater than zero" ) );
}
SECTION( "-a/error/non numeric", "" ) {
const char* argv[] = { "test", "-a", "oops" };
REQUIRE_THAT( parseIntoConfigAndReturnError( argv, config ), Contains( "greater than zero" ) );
}
SECTION( "-a/error/two args", "abortAfter only takes one argument" ) {
const char* argv[] = { "test", "-a", "1", "2" };
REQUIRE_THAT( parseIntoConfigAndReturnError( argv, config ), Contains( "0 and 1 argument" ) );
SECTION( "-x must be numeric", "" ) {
const char* argv[] = { "test", "-x", "oops" };
REQUIRE_THAT( parseIntoConfigAndReturnError( argv, config ), Contains( "-x" ) );
}
}
SECTION( "nothrow", "" ) {
SECTION( "-nt", "" ) {
const char* argv[] = { "test", "-nt" };
SECTION( "-e", "" ) {
const char* argv[] = { "test", "-e" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
REQUIRE( config.noThrow == true );
@ -272,8 +235,8 @@ TEST_CASE( "selftest/parser/2", "ConfigData" ) {
}
SECTION( "combinations", "" ) {
SECTION( "-a -b", "" ) {
const char* argv[] = { "test", "-a", "-b", "-nt" };
SECTION( "Single character flags can be combined", "" ) {
const char* argv[] = { "test", "-abe" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
CHECK( config.abortAfter == 1 );