Support for reporting skipped tests

- implemented by TeamCity reporter
This commit is contained in:
Phil Nash 2014-12-22 20:10:33 +00:00
parent 58dcb5ea92
commit 7619920f86
8 changed files with 45 additions and 12 deletions

View File

@ -60,6 +60,14 @@ namespace Catch {
m_testsAlreadyRun.insert( *it ); m_testsAlreadyRun.insert( *it );
} }
} }
std::vector<TestCase> skippedTestCases;
getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, *m_config, skippedTestCases, true );
for( std::vector<TestCase>::const_iterator it = skippedTestCases.begin(), itEnd = skippedTestCases.end();
it != itEnd;
++it )
m_reporter->skipTest( *it );
context.testGroupEnded( "all tests", totals, 1, 1 ); context.testGroupEnded( "all tests", totals, 1, 1 );
return totals; return totals;
} }

View File

@ -244,6 +244,8 @@ namespace Catch
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0; virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;
virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0; virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0;
virtual void testRunEnded( TestRunStats const& testRunStats ) = 0; virtual void testRunEnded( TestRunStats const& testRunStats ) = 0;
virtual void skipTest( TestCaseInfo const& testInfo ) = 0;
}; };

View File

@ -28,7 +28,7 @@ namespace Catch {
struct ITestCaseRegistry { struct ITestCaseRegistry {
virtual ~ITestCaseRegistry(); virtual ~ITestCaseRegistry();
virtual std::vector<TestCase> const& getAllTests() const = 0; virtual std::vector<TestCase> const& getAllTests() const = 0;
virtual void getFilteredTests( TestSpec const& testSpec, IConfig const& config, std::vector<TestCase>& matchingTestCases ) const = 0; virtual void getFilteredTests( TestSpec const& testSpec, IConfig const& config, std::vector<TestCase>& matchingTestCases, bool negated = false ) const = 0;
}; };
} }

View File

@ -50,6 +50,7 @@ namespace Catch
virtual void testCaseEnded( TestCaseStats const& testCaseStats ); virtual void testCaseEnded( TestCaseStats const& testCaseStats );
virtual void testGroupEnded( TestGroupStats const& testGroupStats ); virtual void testGroupEnded( TestGroupStats const& testGroupStats );
virtual void testRunEnded( TestRunStats const& testRunStats ); virtual void testRunEnded( TestRunStats const& testRunStats );
virtual void skipTest( TestCaseInfo const& );
private: private:
Ptr<IReporter> m_legacyReporter; Ptr<IReporter> m_legacyReporter;

View File

@ -77,6 +77,8 @@ namespace Catch
void LegacyReporterAdapter::testRunEnded( TestRunStats const& testRunStats ) { void LegacyReporterAdapter::testRunEnded( TestRunStats const& testRunStats ) {
m_legacyReporter->EndTesting( testRunStats.totals ); m_legacyReporter->EndTesting( testRunStats.totals );
} }
void LegacyReporterAdapter::skipTest( TestCaseInfo const& ) {
}
} }
#endif // TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_H_INCLUDED #endif // TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_H_INCLUDED

View File

@ -67,33 +67,38 @@ namespace Catch {
return m_nonHiddenFunctions; return m_nonHiddenFunctions;
} }
virtual void getFilteredTests( TestSpec const& testSpec, IConfig const& config, std::vector<TestCase>& matchingTestCases ) const { 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(), for( std::vector<TestCase>::const_iterator it = m_functionsInOrder.begin(),
itEnd = m_functionsInOrder.end(); itEnd = m_functionsInOrder.end();
it != itEnd; it != itEnd;
++it ) { ++it ) {
if( testSpec.matches( *it ) && ( config.allowThrows() || !it->throws() ) ) bool includeTest = testSpec.matches( *it ) && ( config.allowThrows() || !it->throws() );
if( includeTest != negated )
matchingTestCases.push_back( *it ); matchingTestCases.push_back( *it );
} }
sortTests( config, matchingTestCases );
}
private:
static void sortTests( IConfig const& config, std::vector<TestCase>& matchingTestCases ) {
switch( config.runOrder() ) { switch( config.runOrder() ) {
case RunTests::InLexicographicalOrder: case RunTests::InLexicographicalOrder:
std::sort( matchingTestCases.begin(), matchingTestCases.end(), LexSort() ); std::sort( matchingTestCases.begin(), matchingTestCases.end(), LexSort() );
break; break;
case RunTests::InRandomOrder: case RunTests::InRandomOrder:
{ {
RandomNumberGenerator rng; RandomNumberGenerator rng;
std::random_shuffle( matchingTestCases.begin(), matchingTestCases.end(), rng ); std::random_shuffle( matchingTestCases.begin(), matchingTestCases.end(), rng );
} }
break; break;
case RunTests::InDeclarationOrder: case RunTests::InDeclarationOrder:
// already in declaration order // already in declaration order
break; break;
} }
} }
private:
std::set<TestCase> m_functions; std::set<TestCase> m_functions;
std::vector<TestCase> m_functionsInOrder; std::vector<TestCase> m_functionsInOrder;
std::vector<TestCase> m_nonHiddenFunctions; std::vector<TestCase> m_nonHiddenFunctions;

View File

@ -55,6 +55,11 @@ namespace Catch {
currentTestRunInfo.reset(); currentTestRunInfo.reset();
} }
virtual void skipTest( TestCaseInfo const& ) {
// Don't do anything with this by default.
// It can optionally be overridden in the derived class.
}
Ptr<IConfig> m_config; Ptr<IConfig> m_config;
std::ostream& stream; std::ostream& stream;
@ -185,6 +190,8 @@ namespace Catch {
} }
virtual void testRunEndedCumulative() = 0; virtual void testRunEndedCumulative() = 0;
virtual void skipTest( TestCaseInfo const& ) {}
Ptr<IConfig> m_config; Ptr<IConfig> m_config;
std::ostream& stream; std::ostream& stream;
std::vector<AssertionStats> m_assertions; std::vector<AssertionStats> m_assertions;

View File

@ -49,8 +49,16 @@ namespace Catch {
prefs.shouldRedirectStdOut = true; prefs.shouldRedirectStdOut = true;
return prefs; return prefs;
} }
// !TBD: ignored tests virtual void skipTest( TestCaseInfo const& testInfo ) {
stream << "##teamcity[testIgnored name='"
<< escape( testInfo.name ) << "'";
if( testInfo.isHidden() )
stream << " message='hidden test'";
else
stream << " message='test skipped because it didn't match the test spec'";
stream << "]\n";
}
virtual void noMatchingTestCases( std::string const& /* spec */ ) {} virtual void noMatchingTestCases( std::string const& /* spec */ ) {}