mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
Separated getting test cases to run from running them
This commit is contained in:
@@ -34,16 +34,16 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results"
|
||||
|
||||
SECTION( "selftest/test counts/succeeding tests",
|
||||
"Number of 'succeeding' tests is fixed" ) {
|
||||
runner.runMatching( "./succeeding/*" );
|
||||
CHECK( runner.getTotals().assertions.passed == 285 );
|
||||
CHECK( runner.getTotals().assertions.failed == 0 );
|
||||
Totals totals = runner.runMatching( "./succeeding/*" );
|
||||
CHECK( totals.assertions.passed == 285 );
|
||||
CHECK( totals.assertions.failed == 0 );
|
||||
}
|
||||
|
||||
SECTION( "selftest/test counts/failing tests",
|
||||
"Number of 'failing' tests is fixed" ) {
|
||||
runner.runMatching( "./failing/*" );
|
||||
CHECK( runner.getTotals().assertions.passed == 0 );
|
||||
CHECK( runner.getTotals().assertions.failed == 72 );
|
||||
Totals totals = runner.runMatching( "./failing/*" );
|
||||
CHECK( totals.assertions.passed == 0 );
|
||||
CHECK( totals.assertions.failed == 72 );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,9 +51,9 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results"
|
||||
TEST_CASE( "meta/Misc/Sections", "looped tests" ) {
|
||||
Catch::EmbeddedRunner runner;
|
||||
|
||||
runner.runMatching( "./mixed/Misc/Sections/nested2" );
|
||||
CHECK( runner.getTotals().assertions.passed == 2 );
|
||||
CHECK( runner.getTotals().assertions.failed == 1 );
|
||||
Catch::Totals totals = runner.runMatching( "./mixed/Misc/Sections/nested2" );
|
||||
CHECK( totals.assertions.passed == 2 );
|
||||
CHECK( totals.assertions.failed == 1 );
|
||||
}
|
||||
|
||||
#pragma clang diagnostic ignored "-Wweak-vtables"
|
||||
|
@@ -13,21 +13,20 @@
|
||||
|
||||
namespace Catch{
|
||||
|
||||
std::size_t EmbeddedRunner::runMatching( const std::string& rawTestSpec, const std::string& ) {
|
||||
Totals EmbeddedRunner::runMatching( const std::string& rawTestSpec, const std::string& ) {
|
||||
std::ostringstream oss;
|
||||
Config config;
|
||||
config.setStreamBuf( oss.rdbuf() );
|
||||
|
||||
std::size_t result;
|
||||
|
||||
Totals totals;
|
||||
|
||||
// Scoped because Runner doesn't report EndTesting until its destructor
|
||||
{
|
||||
Runner runner( config, m_reporter.get() );
|
||||
result = runner.runMatching( rawTestSpec );
|
||||
m_totals = runner.getTotals();
|
||||
totals = runner.runMatching( rawTestSpec );
|
||||
}
|
||||
m_output = oss.str();
|
||||
return result;
|
||||
return totals;
|
||||
}
|
||||
|
||||
void MockReporter::Result( const ResultInfo& resultInfo ) {
|
||||
|
@@ -114,17 +114,13 @@ namespace Catch {
|
||||
public:
|
||||
EmbeddedRunner() : m_reporter( new MockReporter() ) {}
|
||||
|
||||
std::size_t runMatching( const std::string& rawTestSpec,
|
||||
const std::string& reporter = "basic" );
|
||||
Totals runMatching( const std::string& rawTestSpec,
|
||||
const std::string& reporter = "basic" );
|
||||
|
||||
std::string getOutput() {
|
||||
return m_output;
|
||||
}
|
||||
|
||||
const Totals& getTotals() const {
|
||||
return m_totals;
|
||||
}
|
||||
|
||||
void addRecorder( const std::string& recorder ) {
|
||||
m_reporter->addRecorder( recorder );
|
||||
}
|
||||
@@ -134,7 +130,6 @@ namespace Catch {
|
||||
}
|
||||
|
||||
private:
|
||||
Totals m_totals;
|
||||
std::string m_output;
|
||||
Ptr<MockReporter> m_reporter;
|
||||
};
|
||||
@@ -157,8 +152,7 @@ namespace Catch {
|
||||
|
||||
void operator()( const TestCaseInfo& testCase ) {
|
||||
EmbeddedRunner runner;
|
||||
runner.runMatching( testCase.getName() );
|
||||
Totals totals = runner.getTotals();
|
||||
Totals totals = runner.runMatching( testCase.getName() );
|
||||
switch( m_expectedResult ) {
|
||||
case Expected::ToSucceed:
|
||||
if( totals.assertions.failed > 0 ) {
|
||||
|
Reference in New Issue
Block a user