ConfigData just keeps strings for test names/ specs/ tags (processed in Config actor)

This commit is contained in:
Phil Nash 2013-05-29 18:56:29 +01:00
parent c2ca80d9fb
commit 20ddb0055f
4 changed files with 679 additions and 677 deletions

View File

@ -255,20 +255,8 @@ namespace Catch {
} }
virtual void parseIntoConfig( Command const& cmd, ConfigData& config ) { virtual void parseIntoConfig( Command const& cmd, ConfigData& config ) {
std::string groupName; for( std::size_t i = 0; i < cmd.argsCount(); ++i )
for( std::size_t i = 0; i < cmd.argsCount(); ++i ) { config.testsOrTags.push_back( cmd[i] );
if( i != 0 )
groupName += " ";
groupName += cmd[i];
}
TestCaseFilters filters( groupName );
for( std::size_t i = 0; i < cmd.argsCount(); ++i ) {
if( startsWith( cmd[i], "[" ) || startsWith( cmd[i], "~[" ) )
filters.addTags( cmd[i] );
else
filters.addFilter( TestCaseFilter( cmd[i] ) );
}
config.filters.push_back( filters );
} }
}; };
@ -301,16 +289,8 @@ namespace Catch {
} }
virtual void parseIntoConfig( Command const& cmd, ConfigData& config ) { virtual void parseIntoConfig( Command const& cmd, ConfigData& config ) {
std::string groupName;
for( std::size_t i = 0; i < cmd.argsCount(); ++i ) {
if( i != 0 )
groupName += " ";
groupName += cmd[i];
}
TestCaseFilters filters( groupName );
for( std::size_t i = 0; i < cmd.argsCount(); ++i ) for( std::size_t i = 0; i < cmd.argsCount(); ++i )
filters.addTags( cmd[i] ); config.testsOrTags.push_back( cmd[i] );
config.filters.push_back( filters );
} }
}; };

View File

@ -65,7 +65,7 @@ namespace Catch {
std::string outputFilename; std::string outputFilename;
std::string name; std::string name;
std::vector<TestCaseFilters> filters; // !TBD strings std::vector<std::string> testsOrTags;
std::string stream; std::string stream;
}; };
@ -84,9 +84,24 @@ namespace Catch {
Config( ConfigData const& data ) Config( ConfigData const& data )
: m_data( data ), : m_data( data ),
m_os( std::cout.rdbuf() ), m_os( std::cout.rdbuf() )
m_filters( data.filters ) {
{} std::string groupName;
for( std::size_t i = 0; i < data.testsOrTags.size(); ++i ) {
if( i != 0 )
groupName += " ";
groupName += data.testsOrTags[i];
}
TestCaseFilters filters( groupName );
for( std::size_t i = 0; i < data.testsOrTags.size(); ++i ) {
std::string filter = data.testsOrTags[i];
if( startsWith( filter, "[" ) || startsWith( filter, "~[" ) )
filters.addTags( filter );
else
filters.addFilter( TestCaseFilter( filter ) );
}
m_filterSets.push_back( filters );
}
virtual ~Config() { virtual ~Config() {
m_os.rdbuf( std::cout.rdbuf() ); m_os.rdbuf( std::cout.rdbuf() );
@ -131,7 +146,7 @@ namespace Catch {
void addTestSpec( std::string const& testSpec ) { void addTestSpec( std::string const& testSpec ) {
TestCaseFilters filters( testSpec ); TestCaseFilters filters( testSpec );
filters.addFilter( TestCaseFilter( testSpec ) ); filters.addFilter( TestCaseFilter( testSpec ) );
m_data.filters.push_back( filters ); m_filterSets.push_back( filters );
} }
int abortAfter() const { int abortAfter() const {
@ -139,7 +154,7 @@ namespace Catch {
} }
std::vector<TestCaseFilters> const& filters() const { std::vector<TestCaseFilters> const& filters() const {
return m_filters; return m_filterSets;
} }
// IConfig interface // IConfig interface
@ -154,7 +169,7 @@ namespace Catch {
Stream m_stream; Stream m_stream;
mutable std::ostream m_os; mutable std::ostream m_os;
std::vector<TestCaseFilters> m_filters; std::vector<TestCaseFilters> m_filterSets;
}; };

File diff suppressed because it is too large Load Diff

View File

@ -108,54 +108,60 @@ TEST_CASE( "selftest/parser/2", "ConfigData" ) {
const char* argv[] = { "test", "-t", "test1" }; const char* argv[] = { "test", "-t", "test1" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) ); CHECK_NOTHROW( parseIntoConfig( argv, config ) );
REQUIRE( config.filters.size() == 1 ); Catch::Config cfg( config );
REQUIRE( config.filters[0].shouldInclude( fakeTestCase( "notIncluded" ) ) == false ); REQUIRE( cfg.filters().size() == 1 );
REQUIRE( config.filters[0].shouldInclude( fakeTestCase( "test1" ) ) ); 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:" ) { SECTION( "-t/exclude:1", "Specify one test case exclusion using -t exclude:" ) {
const char* argv[] = { "test", "-t", "exclude:test1" }; const char* argv[] = { "test", "-t", "exclude:test1" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) ); CHECK_NOTHROW( parseIntoConfig( argv, config ) );
REQUIRE( config.filters.size() == 1 ); Catch::Config cfg( config );
REQUIRE( config.filters[0].shouldInclude( fakeTestCase( "test1" ) ) == false ); REQUIRE( cfg.filters().size() == 1 );
REQUIRE( config.filters[0].shouldInclude( fakeTestCase( "alwaysIncluded" ) ) ); REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "test1" ) ) == false );
REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "alwaysIncluded" ) ) );
} }
SECTION( "--test/1", "Specify one test case using --test" ) { SECTION( "--test/1", "Specify one test case using --test" ) {
const char* argv[] = { "test", "--test", "test1" }; const char* argv[] = { "test", "--test", "test1" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) ); CHECK_NOTHROW( parseIntoConfig( argv, config ) );
REQUIRE( config.filters.size() == 1 ); Catch::Config cfg( config );
REQUIRE( config.filters[0].shouldInclude( fakeTestCase( "notIncluded" ) ) == false ); REQUIRE( cfg.filters().size() == 1 );
REQUIRE( config.filters[0].shouldInclude( fakeTestCase( "test1" ) ) ); 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:" ) { SECTION( "--test/exclude:1", "Specify one test case exclusion using --test exclude:" ) {
const char* argv[] = { "test", "--test", "exclude:test1" }; const char* argv[] = { "test", "--test", "exclude:test1" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) ); CHECK_NOTHROW( parseIntoConfig( argv, config ) );
REQUIRE( config.filters.size() == 1 ); Catch::Config cfg( config );
REQUIRE( config.filters[0].shouldInclude( fakeTestCase( "test1" ) ) == false ); REQUIRE( cfg.filters().size() == 1 );
REQUIRE( config.filters[0].shouldInclude( fakeTestCase( "alwaysIncluded" ) ) ); 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 ~" ) { SECTION( "--test/exclude:2", "Specify one test case exclusion using --test ~" ) {
const char* argv[] = { "test", "--test", "~test1" }; const char* argv[] = { "test", "--test", "~test1" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) ); CHECK_NOTHROW( parseIntoConfig( argv, config ) );
REQUIRE( config.filters.size() == 1 ); Catch::Config cfg( config );
REQUIRE( config.filters[0].shouldInclude( fakeTestCase( "test1" ) ) == false ); REQUIRE( cfg.filters().size() == 1 );
REQUIRE( config.filters[0].shouldInclude( fakeTestCase( "alwaysIncluded" ) ) ); REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "test1" ) ) == false );
REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "alwaysIncluded" ) ) );
} }
SECTION( "-t/2", "Specify two test cases using -t" ) { SECTION( "-t/2", "Specify two test cases using -t" ) {
const char* argv[] = { "test", "-t", "test1", "test2" }; const char* argv[] = { "test", "-t", "test1", "test2" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) ); CHECK_NOTHROW( parseIntoConfig( argv, config ) );
REQUIRE( config.filters.size() == 1 ); Catch::Config cfg( config );
REQUIRE( config.filters[0].shouldInclude( fakeTestCase( "notIncluded" ) ) == false ); REQUIRE( cfg.filters().size() == 1 );
REQUIRE( config.filters[0].shouldInclude( fakeTestCase( "test1" ) ) ); REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "notIncluded" ) ) == false );
REQUIRE( config.filters[0].shouldInclude( fakeTestCase( "test2" ) ) ); 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" ) { SECTION( "-t/0", "When no test names are supplied it is an error" ) {
@ -351,9 +357,10 @@ TEST_CASE( "selftest/option parsers", "" )
CHECK_NOTHROW( opt.parseIntoConfig( parser, config ) ); CHECK_NOTHROW( opt.parseIntoConfig( parser, config ) );
REQUIRE( config.filters.size() == 1 ); Catch::Config cfg( config );
REQUIRE( config.filters[0].shouldInclude( fakeTestCase( "notIncluded" ) ) == false ); REQUIRE( cfg.filters().size() == 1 );
REQUIRE( config.filters[0].shouldInclude( fakeTestCase( "test1" ) ) ); REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "notIncluded" ) ) == false );
REQUIRE( cfg.filters()[0].shouldInclude( fakeTestCase( "test1" ) ) );
} }
TEST_CASE( "selftest/tags", "" ) { TEST_CASE( "selftest/tags", "" ) {