Totals runTests() { RunContext context( m_config.get(), m_reporter ); Totals totals; context.testGroupStarting( "all tests", 1, 1 ); // deprecated? TestSpec testSpec = m_config->testSpec(); if( !testSpec.hasFilters() ) testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "~[.]" ).testSpec(); // All not hidden tests std::vector<TestCase> testCases; getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, *m_config, testCases ); int testsRunForGroup = 0; for( std::vector<TestCase>::const_iterator it = testCases.begin(), itEnd = testCases.end(); it != itEnd; ++it ) { testsRunForGroup++; if( m_testsAlreadyRun.find( *it ) == m_testsAlreadyRun.end() ) { if( context.aborting() ) break; totals += context.runTest( *it ); m_testsAlreadyRun.insert( *it ); } } context.testGroupEnded( "all tests", totals, 1, 1 ); return totals; }
Totals runTests( Ptr<Config> const& config ) { Ptr<IConfig const> iconfig = config.get(); Ptr<IStreamingReporter> reporter = makeReporter( config ); reporter = addListeners( iconfig, reporter ); RunContext context( iconfig, reporter ); Totals totals; context.testGroupStarting( config->name(), 1, 1 ); TestSpec testSpec = config->testSpec(); if( !testSpec.hasFilters() ) testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "~[.]" ).testSpec(); // All not hidden tests std::vector<TestCase> const& allTestCases = getAllTestCasesSorted( *iconfig ); for( std::vector<TestCase>::const_iterator it = allTestCases.begin(), itEnd = allTestCases.end(); it != itEnd; ++it ) { if( !context.aborting() && matchTest( *it, testSpec, *iconfig ) ) totals += context.runTest( *it ); else reporter->skipTest( *it ); } context.testGroupEnded( iconfig->name(), totals, 1, 1 ); return totals; }
virtual void getFilteredTests( TestSpec const& testSpec, IConfig const& config, std::vector<TestCase>& matchingTestCases ) const { for( std::vector<TestCase>::const_iterator it = m_functionsInOrder.begin(), itEnd = m_functionsInOrder.end(); it != itEnd; ++it ) { if( testSpec.matches( *it ) && ( config.allowThrows() || !it->throws() ) ) matchingTestCases.push_back( *it ); } }
virtual void getFilteredTests( TestSpec const& testSpec, IConfig const& config, std::vector<TestCase>& matchingTestCases, bool negated = false ) const { for( std::vector<TestCase>::const_iterator it = m_functionsInOrder.begin(), itEnd = m_functionsInOrder.end(); it != itEnd; ++it ) { bool includeTest = testSpec.matches( *it ) && ( config.allowThrows() || !it->throws() ); if( includeTest != negated ) matchingTestCases.push_back( *it ); } sortTests( config, matchingTestCases ); }
bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ) { return testSpec.matches( testCase ) && ( config.allowThrows() || !testCase.throws() ); }
inline Catch::TestCase fakeTestCase( const char* name, const char* desc = "" ){ return Catch::makeTestCase( NULL, "", name, desc, CATCH_INTERNAL_LINEINFO ); } TEST_CASE( "Parse test names and tags", "" ) { using Catch::parseTestSpec; using Catch::TestSpec; Catch::TestCase tcA = fakeTestCase( "a", "" ); Catch::TestCase tcB = fakeTestCase( "b", "[one][x]" ); Catch::TestCase tcC = fakeTestCase( "longer name with spaces", "[two][three][.][x]" ); Catch::TestCase tcD = fakeTestCase( "zlonger name with spacesz", "" ); SECTION( "Empty test spec should have no filters", "" ) { TestSpec spec; CHECK( spec.hasFilters() == false ); CHECK( spec.matches( tcA ) == false ); CHECK( spec.matches( tcB ) == false ); } SECTION( "Test spec from empty string should have no filters", "" ) { TestSpec spec = parseTestSpec( "" ); CHECK( spec.hasFilters() == false ); CHECK( spec.matches(tcA ) == false ); CHECK( spec.matches( tcB ) == false ); } SECTION( "Test spec from just a comma should have no filters", "" ) { TestSpec spec = parseTestSpec( "," ); CHECK( spec.hasFilters() == false );