mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Refactored internal interfaces to use Totals instead of success/ fail
This commit is contained in:
parent
8d93949b19
commit
9bbaeba3ae
@ -57,7 +57,7 @@ namespace Catch
|
|||||||
{
|
{
|
||||||
config.getReporter()->StartGroup( "" );
|
config.getReporter()->StartGroup( "" );
|
||||||
runner.runAll();
|
runner.runAll();
|
||||||
config.getReporter()->EndGroup( "", runner.getSuccessCount(), runner.getFailureCount() );
|
config.getReporter()->EndGroup( "", runner.getTotals().assertions.passed, runner.getTotals().assertions.failed );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -67,19 +67,19 @@ namespace Catch
|
|||||||
std::vector<std::string>::const_iterator itEnd = config.getTestSpecs().end();
|
std::vector<std::string>::const_iterator itEnd = config.getTestSpecs().end();
|
||||||
for(; it != itEnd; ++it )
|
for(; it != itEnd; ++it )
|
||||||
{
|
{
|
||||||
size_t prevSuccess = runner.getSuccessCount();
|
Totals prevTotals = runner.getTotals();
|
||||||
size_t prevFail = runner.getFailureCount();
|
|
||||||
config.getReporter()->StartGroup( *it );
|
config.getReporter()->StartGroup( *it );
|
||||||
if( runner.runMatching( *it ) == 0 )
|
if( runner.runMatching( *it ) == 0 )
|
||||||
{
|
{
|
||||||
// Use reporter?
|
// Use reporter?
|
||||||
// std::cerr << "\n[Unable to match any test cases with: " << *it << "]" << std::endl;
|
// std::cerr << "\n[Unable to match any test cases with: " << *it << "]" << std::endl;
|
||||||
}
|
}
|
||||||
config.getReporter()->EndGroup( *it, runner.getSuccessCount()-prevSuccess, runner.getFailureCount()-prevFail );
|
Totals diffTotals = runner.getTotals() - prevTotals;
|
||||||
|
config.getReporter()->EndGroup( *it, diffTotals.assertions.passed, diffTotals.assertions.failed );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return static_cast<int>( runner.getFailureCount() );
|
return static_cast<int>( runner.getTotals().assertions.failed );
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
#ifndef TWOBLUECUBES_INTERNAL_CATCH_INTERFACES_RUNNER_H_INCLUDED
|
#ifndef TWOBLUECUBES_INTERNAL_CATCH_INTERFACES_RUNNER_H_INCLUDED
|
||||||
#define TWOBLUECUBES_INTERNAL_CATCH_INTERFACES_RUNNER_H_INCLUDED
|
#define TWOBLUECUBES_INTERNAL_CATCH_INTERFACES_RUNNER_H_INCLUDED
|
||||||
|
|
||||||
|
#include "catch_totals.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Catch
|
namespace Catch
|
||||||
@ -32,10 +34,7 @@ namespace Catch
|
|||||||
( const std::string& rawTestSpec
|
( const std::string& rawTestSpec
|
||||||
) = 0;
|
) = 0;
|
||||||
|
|
||||||
virtual std::size_t getSuccessCount
|
virtual Totals getTotals
|
||||||
() const = 0;
|
|
||||||
|
|
||||||
virtual std:: size_t getFailureCount
|
|
||||||
() const = 0;
|
() const = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -391,19 +391,11 @@ namespace Catch
|
|||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
virtual std::size_t getSuccessCount
|
virtual Totals getTotals
|
||||||
()
|
()
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
return m_totals.assertions.passed;
|
return m_totals;
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
virtual std:: size_t getFailureCount
|
|
||||||
()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return m_totals.assertions.failed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private: // IResultCapture
|
private: // IResultCapture
|
||||||
|
@ -22,12 +22,28 @@ namespace Catch
|
|||||||
failed( 0 )
|
failed( 0 )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
Counts operator - ( const Counts& other ) const
|
||||||
|
{
|
||||||
|
Counts diff;
|
||||||
|
diff.passed = passed - other.passed;
|
||||||
|
diff.failed = failed - other.failed;
|
||||||
|
return diff;
|
||||||
|
}
|
||||||
|
|
||||||
std::size_t passed;
|
std::size_t passed;
|
||||||
std::size_t failed;
|
std::size_t failed;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Totals
|
struct Totals
|
||||||
{
|
{
|
||||||
|
Totals operator - ( const Totals& other ) const
|
||||||
|
{
|
||||||
|
Totals diff;
|
||||||
|
diff.assertions = assertions - other.assertions;
|
||||||
|
diff.testCases = testCases - other.testCases;
|
||||||
|
return diff;
|
||||||
|
}
|
||||||
|
|
||||||
Counts assertions;
|
Counts assertions;
|
||||||
Counts testCases;
|
Counts testCases;
|
||||||
};
|
};
|
||||||
|
@ -43,16 +43,16 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results"
|
|||||||
"Number of 'succeeding' tests is fixed" )
|
"Number of 'succeeding' tests is fixed" )
|
||||||
{
|
{
|
||||||
runner.runMatching( "./succeeding/*" );
|
runner.runMatching( "./succeeding/*" );
|
||||||
CHECK( runner.getSuccessCount() == 267 );
|
CHECK( runner.getTotals().assertions.passed == 267 );
|
||||||
CHECK( runner.getFailureCount() == 0 );
|
CHECK( runner.getTotals().assertions.failed == 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION( "selftest/test counts/failing tests",
|
SECTION( "selftest/test counts/failing tests",
|
||||||
"Number of 'failing' tests is fixed" )
|
"Number of 'failing' tests is fixed" )
|
||||||
{
|
{
|
||||||
runner.runMatching( "./failing/*" );
|
runner.runMatching( "./failing/*" );
|
||||||
CHECK( runner.getSuccessCount() == 0 );
|
CHECK( runner.getTotals().assertions.passed == 0 );
|
||||||
CHECK( runner.getFailureCount() == 68 );
|
CHECK( runner.getTotals().assertions.failed == 68 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ TEST_CASE( "meta/Misc/Sections", "looped tests" )
|
|||||||
Catch::EmbeddedRunner runner;
|
Catch::EmbeddedRunner runner;
|
||||||
|
|
||||||
runner.runMatching( "./mixed/Misc/Sections/nested2" );
|
runner.runMatching( "./mixed/Misc/Sections/nested2" );
|
||||||
CHECK( runner.getSuccessCount() == 2 );
|
CHECK( runner.getTotals().assertions.passed == 2 );
|
||||||
CHECK( runner.getFailureCount() == 1 );
|
CHECK( runner.getTotals().assertions.failed == 1 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,8 @@ namespace Catch
|
|||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
std::size_t EmbeddedRunner::runMatching
|
std::size_t EmbeddedRunner::runMatching
|
||||||
(
|
(
|
||||||
const std::string& rawTestSpec
|
const std::string& rawTestSpec
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
Config config;
|
Config config;
|
||||||
@ -32,8 +32,7 @@ namespace Catch
|
|||||||
{
|
{
|
||||||
Runner runner( config );
|
Runner runner( config );
|
||||||
result = runner.runMatching( rawTestSpec );
|
result = runner.runMatching( rawTestSpec );
|
||||||
m_successes = runner.getSuccessCount();
|
m_totals = runner.getTotals();
|
||||||
m_failures = runner.getFailureCount();
|
|
||||||
}
|
}
|
||||||
m_output = oss.str();
|
m_output = oss.str();
|
||||||
return result;
|
return result;
|
||||||
|
@ -36,24 +36,15 @@ namespace Catch
|
|||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
std::size_t getSuccessCount
|
const Totals& getTotals
|
||||||
()
|
()
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
return m_successes;
|
return m_totals;
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
std:: size_t getFailureCount
|
|
||||||
()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return m_failures;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::size_t m_successes;
|
Totals m_totals;
|
||||||
std::size_t m_failures;
|
|
||||||
std::string m_output;
|
std::string m_output;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -97,26 +88,27 @@ namespace Catch
|
|||||||
{
|
{
|
||||||
EmbeddedRunner runner;
|
EmbeddedRunner runner;
|
||||||
runner.runMatching( testCase.getName() );
|
runner.runMatching( testCase.getName() );
|
||||||
|
Totals totals = runner.getTotals();
|
||||||
switch( m_expectedResult )
|
switch( m_expectedResult )
|
||||||
{
|
{
|
||||||
case Expected::ToSucceed:
|
case Expected::ToSucceed:
|
||||||
if( runner.getFailureCount() > 0 )
|
if( totals.assertions.failed > 0 )
|
||||||
{
|
{
|
||||||
INFO( runner.getOutput() );
|
INFO( runner.getOutput() );
|
||||||
FAIL( "Expected test case '"
|
FAIL( "Expected test case '"
|
||||||
<< testCase.getName()
|
<< testCase.getName()
|
||||||
<< "' to succeed but there was/ were "
|
<< "' to succeed but there was/ were "
|
||||||
<< runner.getFailureCount() << " failure(s)" );
|
<< totals.assertions.failed << " failure(s)" );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Expected::ToFail:
|
case Expected::ToFail:
|
||||||
if( runner.getSuccessCount() > 0 )
|
if( totals.assertions.passed > 0 )
|
||||||
{
|
{
|
||||||
INFO( runner.getOutput() );
|
INFO( runner.getOutput() );
|
||||||
FAIL( "Expected test case '"
|
FAIL( "Expected test case '"
|
||||||
<< testCase.getName()
|
<< testCase.getName()
|
||||||
<< "' to fail but there was/ were "
|
<< "' to fail but there was/ were "
|
||||||
<< runner.getSuccessCount() << " success(es)" );
|
<< totals.assertions.passed << " success(es)" );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user