mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
Implemented more reporter methods and started to fill out Section impl
This commit is contained in:
@@ -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,
|
||||
|
||||
FailureBit = 0x10,
|
||||
|
||||
Info = 2,
|
||||
Warning = 3,
|
||||
ExplicitFailure = 4,
|
||||
ExpressionFailed = FailureBit | 1,
|
||||
ExplicitFailure = FailureBit | 2,
|
||||
|
||||
Exception = 0x100,
|
||||
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()
|
||||
@@ -134,6 +135,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;
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user