mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
Implemented more reporter methods and started to fill out Section impl
This commit is contained in:
parent
3d6fa68970
commit
e6b2b0e656
31
Test/MiscTests.cpp
Normal file
31
Test/MiscTests.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* MiscTests.cpp
|
||||
* Catch - Test
|
||||
*
|
||||
* Created by Phil on 29/11/2010.
|
||||
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../catch.hpp"
|
||||
|
||||
TEST_CASE( "succeeding/Misc/Sections", "random SECTION tests" )
|
||||
{
|
||||
int a = 1;
|
||||
int b = 2;
|
||||
|
||||
SECTION( "s1", "doesn't equal" )
|
||||
{
|
||||
EXPECT( a != b );
|
||||
EXPECT( b != a );
|
||||
}
|
||||
|
||||
SECTION( "s2", "not equal" )
|
||||
{
|
||||
EXPECT_NOT( a == b);
|
||||
}
|
||||
|
||||
}
|
@ -8,6 +8,7 @@
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
4A3BFFB9128DCF06005609E3 /* TestMain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A3BFFB8128DCF06005609E3 /* TestMain.cpp */; };
|
||||
4AA7EA9212A438C7005A0B97 /* MiscTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4AA7EA9112A438C7005A0B97 /* MiscTests.cpp */; };
|
||||
4AFC38CD12887D80003A0C29 /* ConditionTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4AFC38CC12887D80003A0C29 /* ConditionTests.cpp */; };
|
||||
4AFC3A9912893C56003A0C29 /* ExceptionTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4AFC3A9812893C56003A0C29 /* ExceptionTests.cpp */; };
|
||||
4AFC3AA912893E54003A0C29 /* MessageTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4AFC3AA812893E54003A0C29 /* MessageTests.cpp */; };
|
||||
@ -32,6 +33,8 @@
|
||||
/* Begin PBXFileReference section */
|
||||
4A3BFFB8128DCF06005609E3 /* TestMain.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TestMain.cpp; sourceTree = "<group>"; };
|
||||
4A3BFFF0128DD23C005609E3 /* catch_runnerconfig.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_runnerconfig.hpp; path = ../internal/catch_runnerconfig.hpp; sourceTree = SOURCE_ROOT; };
|
||||
4AA7E968129FA1DF005A0B97 /* catch_reporter_junit.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_reporter_junit.hpp; path = ../../../Lib/Catch/catch_reporter_junit.hpp; sourceTree = SOURCE_ROOT; };
|
||||
4AA7EA9112A438C7005A0B97 /* MiscTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MiscTests.cpp; sourceTree = "<group>"; };
|
||||
4AFC341512809A36003A0C29 /* catch_capture.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_capture.hpp; path = ../internal/catch_capture.hpp; sourceTree = SOURCE_ROOT; };
|
||||
4AFC341612809A36003A0C29 /* catch_common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = catch_common.h; path = ../internal/catch_common.h; sourceTree = SOURCE_ROOT; };
|
||||
4AFC341712809A36003A0C29 /* catch_registry.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_registry.hpp; path = ../internal/catch_registry.hpp; sourceTree = SOURCE_ROOT; };
|
||||
@ -80,13 +83,9 @@
|
||||
08FB7795FE84155DC02AAC07 /* Source */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
4AA7E96C129FA2A0005A0B97 /* Tests */,
|
||||
4A3BFFB8128DCF06005609E3 /* TestMain.cpp */,
|
||||
4AFC341312809A12003A0C29 /* Catch */,
|
||||
4AFC38CC12887D80003A0C29 /* ConditionTests.cpp */,
|
||||
4AFC3A9812893C56003A0C29 /* ExceptionTests.cpp */,
|
||||
4AFC3AA812893E54003A0C29 /* MessageTests.cpp */,
|
||||
4AFC3B0A12894114003A0C29 /* ClassTests.cpp */,
|
||||
4AFC3B661289C7E3003A0C29 /* TrickyTests.cpp */,
|
||||
);
|
||||
name = Source;
|
||||
sourceTree = "<group>";
|
||||
@ -99,14 +98,36 @@
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
4AA7E96B129FA282005A0B97 /* Reporters */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
4AFC341D12809A45003A0C29 /* catch_reporter_basic.hpp */,
|
||||
4AFC341E12809A45003A0C29 /* catch_reporter_xml.hpp */,
|
||||
4AA7E968129FA1DF005A0B97 /* catch_reporter_junit.hpp */,
|
||||
);
|
||||
name = Reporters;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
4AA7E96C129FA2A0005A0B97 /* Tests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
4AA7EA9112A438C7005A0B97 /* MiscTests.cpp */,
|
||||
4AFC38CC12887D80003A0C29 /* ConditionTests.cpp */,
|
||||
4AFC3A9812893C56003A0C29 /* ExceptionTests.cpp */,
|
||||
4AFC3AA812893E54003A0C29 /* MessageTests.cpp */,
|
||||
4AFC3B0A12894114003A0C29 /* ClassTests.cpp */,
|
||||
4AFC3B661289C7E3003A0C29 /* TrickyTests.cpp */,
|
||||
);
|
||||
name = Tests;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
4AFC341312809A12003A0C29 /* Catch */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
4AFC342012809A45003A0C29 /* catch.hpp */,
|
||||
4AFC341C12809A45003A0C29 /* catch_default_main.hpp */,
|
||||
4AFC341D12809A45003A0C29 /* catch_reporter_basic.hpp */,
|
||||
4AFC341E12809A45003A0C29 /* catch_reporter_xml.hpp */,
|
||||
4AFC38161284B387003A0C29 /* catch_runner.hpp */,
|
||||
4AA7E96B129FA282005A0B97 /* Reporters */,
|
||||
4AFC341412809A1B003A0C29 /* Internal */,
|
||||
);
|
||||
name = Catch;
|
||||
@ -187,6 +208,7 @@
|
||||
4AFC3B0B12894114003A0C29 /* ClassTests.cpp in Sources */,
|
||||
4AFC3B671289C7E3003A0C29 /* TrickyTests.cpp in Sources */,
|
||||
4A3BFFB9128DCF06005609E3 /* TestMain.cpp in Sources */,
|
||||
4AA7EA9212A438C7005A0B97 /* MiscTests.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "../catch_runner.hpp"
|
||||
|
||||
// This code runs the meta tests and verifies that the failing ones failed and the successful ones succeeded
|
||||
/*
|
||||
int main (int argc, char * const argv[])
|
||||
{
|
||||
using namespace Catch;
|
||||
@ -22,17 +23,18 @@ int main (int argc, char * const argv[])
|
||||
if( argc > 1 && ( std::string( argv[1] ) == "-s" || std::string( argv[1] ) == "--success" ) )
|
||||
showAllResults = true;
|
||||
|
||||
std::ostringstream ossSucceeding;
|
||||
std::ostringstream ossFailing;
|
||||
|
||||
ReporterConfig reporterConfig( ReporterConfig::Include::SuccessfulResults );
|
||||
BasicReporter reporter (reporterConfig );
|
||||
Runner runner;
|
||||
runner.setReporter( &reporter );
|
||||
|
||||
std::ostringstream ossSucceeding;
|
||||
Runner runner( &reporter );
|
||||
|
||||
reporterConfig.setStreamBuf( ossSucceeding.rdbuf() );
|
||||
runner.runMatching( "succeeding/*" );
|
||||
std::string succeedingResults = ossSucceeding.str();
|
||||
|
||||
std::ostringstream ossFailing;
|
||||
reporterConfig.setStreamBuf( ossFailing.rdbuf() );
|
||||
runner.runMatching( "failing/*" );
|
||||
std::string failingResults = ossFailing.str();
|
||||
@ -63,3 +65,5 @@ int main (int argc, char * const argv[])
|
||||
}
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
#include "catch_default_main.hpp"
|
@ -41,3 +41,4 @@ TEST_CASE( "succeeding/Tricky/complex lhs", "Where the LHS is not a simple value
|
||||
// This only captures part of the expression, but issues a warning about the rest
|
||||
EXPECT( a == 2 || b == 2 );
|
||||
}
|
||||
|
||||
|
@ -32,12 +32,80 @@ namespace Catch
|
||||
return "Reports test results as lines of text";
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void ReportCounts( std::size_t succeeded, std::size_t failed )
|
||||
{
|
||||
if( failed + succeeded == 0 )
|
||||
m_config.stream() << "No tests ran";
|
||||
else if( failed == 0 )
|
||||
m_config.stream() << "All " << succeeded << " test(s) succeeded";
|
||||
else if( succeeded == 0 )
|
||||
m_config.stream() << "All " << failed << " test(s) failed";
|
||||
else
|
||||
m_config.stream() << succeeded << " test(s) passed but " << failed << " test(s) failed";
|
||||
}
|
||||
|
||||
private: // ITestReporter
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void StartTesting()
|
||||
{
|
||||
m_config.stream() << "[Started testing]" << std::endl;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void EndTesting( std::size_t succeeded, std::size_t failed )
|
||||
{
|
||||
m_config.stream() << "[Testing completed. ";
|
||||
ReportCounts( succeeded, failed );
|
||||
m_config.stream() << "]" << std::endl;
|
||||
(succeeded, failed);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void StartGroup( const std::string& groupName )
|
||||
{
|
||||
if( !groupName.empty() )
|
||||
m_config.stream() << "[Started group: '" << groupName << "']" << std::endl;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void EndGroup( const std::string& groupName, std::size_t succeeded, std::size_t failed )
|
||||
{
|
||||
if( !groupName.empty() )
|
||||
{
|
||||
m_config.stream() << "[End of group: '" << groupName << "'. ";
|
||||
ReportCounts( succeeded, failed );
|
||||
m_config.stream() << "]\n" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void StartTestCase( const TestCaseInfo& testInfo )
|
||||
{
|
||||
m_config.stream() << std::endl << "[Running: " << testInfo.getName() << "]" << std::endl;
|
||||
m_firstSectionInTestCase = true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void StartSection( const std::string& sectionName, const std::string /*description*/ )
|
||||
{
|
||||
if( m_firstSectionInTestCase )
|
||||
{
|
||||
m_config.stream() << "\n";
|
||||
m_firstSectionInTestCase = false;
|
||||
}
|
||||
m_config.stream() << "[Started section: '" << sectionName << "']" << std::endl;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void EndSection( const std::string& sectionName, std::size_t succeeded, std::size_t failed )
|
||||
{
|
||||
m_config.stream() << "[End of section: '" << sectionName << "'. ";
|
||||
ReportCounts( succeeded, failed );
|
||||
m_config.stream() << "]\n" << std::endl;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
@ -92,6 +160,7 @@ namespace Catch
|
||||
|
||||
private:
|
||||
const ReporterConfig& m_config;
|
||||
bool m_firstSectionInTestCase;
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
@ -35,6 +35,15 @@ namespace Catch
|
||||
|
||||
private: // ITestReporter
|
||||
|
||||
virtual void StartTesting(){}
|
||||
virtual void EndTesting( std::size_t succeeded, std::size_t failed ){(succeeded, failed);}
|
||||
|
||||
virtual void StartGroup( const std::string& groupName ){(groupName);}
|
||||
virtual void EndGroup( const std::string& groupName, std::size_t succeeded, std::size_t failed ){(groupName, succeeded, failed);}
|
||||
|
||||
virtual void StartSection( const std::string& sectionName, const std::string description ){(sectionName,description);}
|
||||
virtual void EndSection( const std::string& sectionName, std::size_t succeeded, std::size_t failed ){(sectionName, succeeded, failed);}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void StartTestCase( const Catch::TestCaseInfo& testInfo )
|
||||
{
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "internal/catch_list.hpp"
|
||||
#include "catch_reporter_basic.hpp"
|
||||
#include "catch_reporter_xml.hpp"
|
||||
#include "catch_reporter_junit.hpp"
|
||||
|
||||
namespace Catch
|
||||
{
|
||||
@ -24,6 +25,7 @@ namespace Catch
|
||||
{
|
||||
ReporterRegistry::instance().registerReporter<BasicReporter>( "basic" );
|
||||
ReporterRegistry::instance().registerReporter<XmlReporter>( "xml" );
|
||||
ReporterRegistry::instance().registerReporter<JunitReporter>( "junit" );
|
||||
|
||||
RunnerConfig config;
|
||||
ArgParser( argc, argv, config );
|
||||
@ -51,13 +53,14 @@ namespace Catch
|
||||
config.getReporterConfig().setStreamBuf( ofs.rdbuf() );
|
||||
}
|
||||
|
||||
Runner runner;
|
||||
runner.setReporter( config.getReporter() );
|
||||
Runner runner( config.getReporter() );
|
||||
|
||||
// Run test specs specified on the command line - or default to all
|
||||
if( config.m_testSpecs.size() == 0 )
|
||||
{
|
||||
config.getReporter()->StartGroup( "" );
|
||||
runner.runAll();
|
||||
config.getReporter()->EndGroup( "", runner.getSuccessCount(), runner.getFailureCount() );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -67,11 +70,15 @@ namespace Catch
|
||||
std::vector<std::string>::const_iterator itEnd = config.m_testSpecs.end();
|
||||
for(; it != itEnd; ++it )
|
||||
{
|
||||
size_t prevSuccess = runner.getSuccessCount();
|
||||
size_t prevFail = runner.getFailureCount();
|
||||
config.getReporter()->StartGroup( *it );
|
||||
if( runner.runMatching( *it ) == 0 )
|
||||
{
|
||||
// Use reporter?
|
||||
std::cerr << "\n[Unable to match any test cases with: " << *it << "]" << std::endl;
|
||||
}
|
||||
config.getReporter()->EndGroup( *it, runner.getSuccessCount()-prevSuccess, runner.getFailureCount()-prevFail );
|
||||
}
|
||||
}
|
||||
return runner.getFailureCount();
|
||||
|
@ -142,6 +142,8 @@ struct IResultListener
|
||||
{
|
||||
virtual ~IResultListener(){}
|
||||
virtual void testEnded( const ResultInfo& result ) = 0;
|
||||
virtual bool sectionStarted( const std::string& name, const std::string& description, std::size_t& successes, std::size_t& failures ) = 0;
|
||||
virtual void sectionEnded( const std::string& name, std::size_t successes, std::size_t failures ) = 0;
|
||||
};
|
||||
|
||||
class ResultsCapture
|
||||
@ -209,6 +211,16 @@ public:
|
||||
instance().currentResult.setMessage( msg );
|
||||
}
|
||||
|
||||
static bool acceptSectionStart( const std::string& name, const std::string& description, std::size_t& successes, std::size_t& failures )
|
||||
{
|
||||
return instance().m_listener->sectionStarted( name, description, successes, failures );
|
||||
}
|
||||
|
||||
static void acceptSectionEnd( const std::string& name, std::size_t successes, std::size_t failures )
|
||||
{
|
||||
instance().m_listener->sectionEnded( name, successes, failures );
|
||||
}
|
||||
|
||||
private:
|
||||
MutableResultInfo currentResult;
|
||||
IResultListener* m_listener;
|
||||
|
@ -79,16 +79,19 @@ namespace Catch
|
||||
{
|
||||
virtual ~ITestReporter(){}
|
||||
|
||||
// !TBD
|
||||
// StartTesting
|
||||
// EndTesting
|
||||
// StartGroup
|
||||
// EndGroup
|
||||
// StartSection
|
||||
// EndSection
|
||||
virtual void StartTesting() = 0;
|
||||
virtual void EndTesting( std::size_t succeeded, std::size_t failed ) = 0;
|
||||
|
||||
virtual void StartGroup( const std::string& groupName ) = 0;
|
||||
virtual void EndGroup( const std::string& groupName, std::size_t succeeded, std::size_t failed ) = 0;
|
||||
|
||||
virtual void StartSection( const std::string& sectionName, const std::string description ) = 0;
|
||||
virtual void EndSection( const std::string& sectionName, std::size_t succeeded, std::size_t failed ) = 0;
|
||||
|
||||
virtual void StartTestCase( const TestCaseInfo& testInfo ) = 0;
|
||||
virtual void Result( const ResultInfo& result ) = 0;
|
||||
virtual void EndTestCase( const TestCaseInfo& testInfo ) = 0;
|
||||
|
||||
virtual void Result( const ResultInfo& result ) = 0;
|
||||
};
|
||||
|
||||
struct IReporterFactory
|
||||
|
@ -20,13 +20,15 @@ namespace Catch
|
||||
{
|
||||
Unknown = -1,
|
||||
Ok = 0,
|
||||
ExpressionFailed = 1,
|
||||
Info = 1,
|
||||
Warning = 2,
|
||||
|
||||
Info = 2,
|
||||
Warning = 3,
|
||||
ExplicitFailure = 4,
|
||||
FailureBit = 0x10,
|
||||
|
||||
Exception = 0x100,
|
||||
ExpressionFailed = FailureBit | 1,
|
||||
ExplicitFailure = FailureBit | 2,
|
||||
|
||||
Exception = 0x110,
|
||||
|
||||
ThrewException = Exception | 1,
|
||||
DidntThrowException = Exception | 2
|
||||
@ -58,7 +60,7 @@ namespace Catch
|
||||
|
||||
bool ok() const
|
||||
{
|
||||
return m_result == ResultWas::Ok;
|
||||
return ( m_result & ResultWas::FailureBit ) != ResultWas::FailureBit;
|
||||
}
|
||||
|
||||
ResultWas::OfType getResultType() const
|
||||
|
@ -48,16 +48,17 @@ namespace Catch
|
||||
class Runner : public IResultListener
|
||||
{
|
||||
public:
|
||||
Runner()
|
||||
explicit Runner( ITestReporter* reporter )
|
||||
: m_successes( 0 ),
|
||||
m_failures( 0 ),
|
||||
m_reporter( 0 )
|
||||
m_reporter( reporter )
|
||||
{
|
||||
m_reporter->StartTesting();
|
||||
}
|
||||
|
||||
void setReporter( ITestReporter* reporter )
|
||||
~Runner()
|
||||
{
|
||||
m_reporter = reporter;
|
||||
m_reporter->EndTesting( m_successes, m_failures );
|
||||
}
|
||||
|
||||
void runAll()
|
||||
@ -135,6 +136,19 @@ namespace Catch
|
||||
m_reporter->Result( result );
|
||||
}
|
||||
|
||||
virtual bool sectionStarted( const std::string& name, const std::string& description, std::size_t& successes, std::size_t& failures )
|
||||
{
|
||||
m_reporter->StartSection( name, description );
|
||||
successes = m_successes;
|
||||
failures = m_failures;
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void sectionEnded( const std::string& name, std::size_t prevSuccesses, std::size_t prevFailures )
|
||||
{
|
||||
m_reporter->EndSection( name, m_successes - prevSuccesses, m_failures - prevFailures );
|
||||
}
|
||||
|
||||
private:
|
||||
std::size_t m_successes;
|
||||
std::size_t m_failures;
|
||||
|
@ -13,6 +13,8 @@
|
||||
#ifndef TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED
|
||||
|
||||
#include "catch_capture.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Catch
|
||||
@ -21,15 +23,27 @@ namespace Catch
|
||||
{
|
||||
public:
|
||||
Section( const std::string& name, const std::string& description )
|
||||
: m_name( name ),
|
||||
m_sectionIncluded( ResultsCapture::acceptSectionStart( name, description, m_successes, m_failures ) )
|
||||
{
|
||||
(name, description); // !TBD notify the runner
|
||||
}
|
||||
|
||||
~Section()
|
||||
{
|
||||
ResultsCapture::acceptSectionEnd( m_name, m_successes, m_failures );
|
||||
}
|
||||
|
||||
// This indicates whether the section should be executed or not
|
||||
operator bool()
|
||||
{
|
||||
// !TBD get this from runner
|
||||
return true;
|
||||
return m_sectionIncluded;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
std::size_t m_successes;
|
||||
std::size_t m_failures;
|
||||
bool m_sectionIncluded;
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
Loading…
Reference in New Issue
Block a user