Fairly major reworking of console reporter (still in progress).

Changed reporter interface a bit.
This commit is contained in:
Phil Nash
2013-01-13 21:51:44 +00:00
parent e9305ecd65
commit 42aef1d99c
17 changed files with 306 additions and 259 deletions

View File

@@ -26,3 +26,17 @@ CATCH_TEST_CASE( "./succeeding/generators/1", "Generators over two ranges" )
CATCH_REQUIRE( multiply( i, 2 ) == i*2 );
CATCH_REQUIRE( multiply( j, 2 ) == j*2 );
}
struct IntPair { int first, second; };
CATCH_TEST_CASE( "./succeeding/generators/2", "Generator over a range of pairs" )
{
using namespace Catch::Generators;
IntPair p[] = { { 0, 1 }, { 2, 3 } };
IntPair* i = CATCH_GENERATE( between( p, &p[1] ) );
CATCH_REQUIRE( i->first == i->second-1 );
}

View File

@@ -20,12 +20,12 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results"
SECTION( "selftest/expected result/failing tests",
"Tests in the 'failing' branch fail" ) {
MetaTestRunner::runMatching( "./failing/*", MetaTestRunner::Expected::ToFail );
MetaTestRunner::runMatching( "./failing/*", MetaTestRunner::Expected::ToFail, 0, 2 );
}
SECTION( "selftest/expected result/succeeding tests",
"Tests in the 'succeeding' branch succeed" ) {
MetaTestRunner::runMatching( "./succeeding/*", MetaTestRunner::Expected::ToSucceed );
MetaTestRunner::runMatching( "./succeeding/*", MetaTestRunner::Expected::ToSucceed, 1, 2 );
}
}
@@ -36,14 +36,14 @@ 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" ) {
Totals totals = runner.runMatching( "./succeeding/*" );
Totals totals = runner.runMatching( "./succeeding/*", 0, 2 );
CHECK( totals.assertions.passed == 291 );
CHECK( totals.assertions.failed == 0 );
}
SECTION( "selftest/test counts/failing tests",
"Number of 'failing' tests is fixed" ) {
Totals totals = runner.runMatching( "./failing/*" );
Totals totals = runner.runMatching( "./failing/*", 1, 2 );
CHECK( totals.assertions.passed == 1 );
CHECK( totals.assertions.failed == 72 );
}
@@ -53,7 +53,7 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results"
TEST_CASE( "meta/Misc/Sections", "looped tests" ) {
Catch::EmbeddedRunner runner;
Catch::Totals totals = runner.runMatching( "./mixed/Misc/Sections/nested2" );
Catch::Totals totals = runner.runMatching( "./mixed/Misc/Sections/nested2", 0, 1 );
CHECK( totals.assertions.passed == 2 );
CHECK( totals.assertions.failed == 1 );
}

View File

@@ -17,7 +17,7 @@ namespace Catch{
NullStreamingReporter::~NullStreamingReporter() {}
Totals EmbeddedRunner::runMatching( const std::string& rawTestSpec, const std::string& ) {
Totals EmbeddedRunner::runMatching( const std::string& rawTestSpec, std::size_t groupIndex, std::size_t groupsCount, const std::string& ) {
std::ostringstream oss;
Config config;
config.setStreamBuf( oss.rdbuf() );
@@ -27,7 +27,7 @@ namespace Catch{
// Scoped because Runner doesn't report EndTesting until its destructor
{
Runner runner( config, m_reporter.get() );
totals = runner.runMatching( rawTestSpec );
totals = runner.runMatching( rawTestSpec, groupIndex, groupsCount );
}
return totals;
}

View File

@@ -53,6 +53,8 @@ namespace Catch {
EmbeddedRunner() : m_reporter( new NullStreamingReporter() ) {}
Totals runMatching( const std::string& rawTestSpec,
std::size_t groupIndex,
std::size_t groupsCount,
const std::string& reporter = "console" );
private:
@@ -67,12 +69,18 @@ namespace Catch {
ToFail
}; };
MetaTestRunner( Expected::Result expectedResult ) : m_expectedResult( expectedResult ) {}
MetaTestRunner( Expected::Result expectedResult, std::size_t groupIndex, std::size_t groupsCount )
: m_expectedResult( expectedResult ),
m_groupIndex( groupIndex ),
m_groupsCount( groupsCount )
{}
static void runMatching( const std::string& testSpec,
Expected::Result expectedResult ) {
Expected::Result expectedResult,
std::size_t groupIndex,
std::size_t groupsCount ) {
forEach( getRegistryHub().getTestCaseRegistry().getMatchingTestCases( testSpec ),
MetaTestRunner( expectedResult ) );
MetaTestRunner( expectedResult, groupIndex, groupsCount ) );
}
void operator()( const TestCase& testCase ) {
@@ -81,7 +89,7 @@ namespace Catch {
{
EmbeddedRunner runner;
name = testCase.getTestCaseInfo().name;
totals = runner.runMatching( name );
totals = runner.runMatching( name, m_groupIndex, m_groupsCount );
}
switch( m_expectedResult ) {
case Expected::ToSucceed:
@@ -111,6 +119,8 @@ namespace Catch {
private:
Expected::Result m_expectedResult;
std::size_t m_groupIndex;
std::size_t m_groupsCount;
};

View File

@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
2694A1FD16A0000E004816E3 /* catch_line_wrap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2694A1FB16A0000E004816E3 /* catch_line_wrap.cpp */; };
4A45DA2416161EF9004F8D6B /* catch_console_colour.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A45DA2316161EF9004F8D6B /* catch_console_colour.cpp */; };
4A45DA2716161F1F004F8D6B /* catch_ptr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A45DA2616161F1F004F8D6B /* catch_ptr.cpp */; };
4A45DA2916161F3D004F8D6B /* catch_streambuf.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A45DA2816161F3D004F8D6B /* catch_streambuf.cpp */; };
@@ -52,6 +53,9 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
2694A1F8169FFF9B004816E3 /* catch_line_wrap.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_line_wrap.h; sourceTree = "<group>"; };
2694A1FA169FFFEC004816E3 /* catch_line_wrap.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_line_wrap.hpp; sourceTree = "<group>"; };
2694A1FB16A0000E004816E3 /* catch_line_wrap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = catch_line_wrap.cpp; sourceTree = "<group>"; };
4A084F1C15DACEEA0027E631 /* catch_test_case_info.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_test_case_info.hpp; sourceTree = "<group>"; };
4A084F1D15DAD15F0027E631 /* catch_test_spec.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_test_spec.h; sourceTree = "<group>"; };
4A3D7DD01503869D005F9203 /* catch_matchers.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_matchers.hpp; sourceTree = "<group>"; };
@@ -270,6 +274,7 @@
4AB3D99F1616219100C9A0F8 /* catch_interfaces_config.cpp */,
4AB3D9A1161621B500C9A0F8 /* catch_interfaces_generators.cpp */,
4ACE21CA166CA1B300FB5509 /* catch_option.cpp */,
2694A1FB16A0000E004816E3 /* catch_line_wrap.cpp */,
);
name = SurrogateCpps;
sourceTree = "<group>";
@@ -288,6 +293,7 @@
4A90B59D15D24FE900EF71BC /* catch_assertionresult.hpp */,
4A90B59E15D2521E00EF71BC /* catch_expressionresult_builder.hpp */,
4A084F1C15DACEEA0027E631 /* catch_test_case_info.hpp */,
2694A1FA169FFFEC004816E3 /* catch_line_wrap.hpp */,
);
name = impl;
sourceTree = "<group>";
@@ -374,6 +380,7 @@
4AB77CB51551AEA200857BF0 /* catch_ptr.hpp */,
4AEE0326161431070071E950 /* catch_streambuf.h */,
4ACE21C8166CA19700FB5509 /* catch_option.hpp */,
2694A1F8169FFF9B004816E3 /* catch_line_wrap.h */,
);
name = Infrastructure;
sourceTree = "<group>";
@@ -465,6 +472,7 @@
4AB3D9A01616219100C9A0F8 /* catch_interfaces_config.cpp in Sources */,
4AB3D9A2161621B500C9A0F8 /* catch_interfaces_generators.cpp in Sources */,
4ACE21CC166CA1B300FB5509 /* catch_option.cpp in Sources */,
2694A1FD16A0000E004816E3 /* catch_line_wrap.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -0,0 +1,2 @@
// This file is only here to verify (to the extent possible) the self sufficiency of the header
#include "catch_line_wrap.h"