mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
Added ReporterPreferences and started some SectionInfo refactoring
This commit is contained in:
parent
994e64c217
commit
c4ba6757d9
@ -36,6 +36,15 @@ namespace Catch
|
||||
ConfigData m_fullConfig;
|
||||
};
|
||||
|
||||
struct ReporterPreferences
|
||||
{
|
||||
ReporterPreferences()
|
||||
: shouldRedirectStdOut( false )
|
||||
{}
|
||||
|
||||
bool shouldRedirectStdOut;
|
||||
};
|
||||
|
||||
struct AssertionStats {
|
||||
AssertionStats( const AssertionResult& _assertionResult,
|
||||
const Totals& _totals )
|
||||
@ -102,6 +111,8 @@ namespace Catch
|
||||
// !Work In progress
|
||||
struct IStreamingReporter : IShared {
|
||||
virtual ~IStreamingReporter();
|
||||
virtual ReporterPreferences getPreferences() const = 0;
|
||||
|
||||
virtual void testRunStarting( const std::string& runName ) = 0;
|
||||
virtual void testGroupStarting( const std::string& groupName ) = 0;
|
||||
|
||||
@ -160,8 +171,13 @@ namespace Catch
|
||||
m_config( config )
|
||||
{}
|
||||
virtual ~LegacyReporterAdapter();
|
||||
|
||||
|
||||
|
||||
virtual ReporterPreferences getPreferences() const {
|
||||
ReporterPreferences prefs;
|
||||
prefs.shouldRedirectStdOut = m_legacyReporter->shouldRedirectStdout();
|
||||
return prefs;
|
||||
}
|
||||
|
||||
virtual void testRunStarting( const std::string& ) {
|
||||
m_legacyReporter->StartTesting();
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ namespace Catch {
|
||||
LegacyReporterAdapter reporter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) );
|
||||
reporter.testCaseStarting( testInfo );
|
||||
|
||||
m_runningTest = new RunningTest( &testCase );
|
||||
m_runningTest = new RunningTest( testCase );
|
||||
|
||||
do {
|
||||
do {
|
||||
@ -202,6 +202,10 @@ namespace Catch {
|
||||
|
||||
m_lastAssertionInfo.lineInfo = lineInfo;
|
||||
|
||||
// !TBD: ------------
|
||||
std::string className = m_runningTest->getTestCase().getTestCaseInfo().className;
|
||||
TestCaseInfo sectionInfo( name, className, description, std::set<std::string>(), false, lineInfo );
|
||||
|
||||
m_reporter->StartSection( name, description );
|
||||
assertions = m_totals.assertions;
|
||||
|
||||
@ -272,7 +276,8 @@ namespace Catch {
|
||||
try {
|
||||
m_lastAssertionInfo = AssertionInfo( "TEST_CASE", m_runningTest->getTestCase().getTestCaseInfo().lineInfo, "", ResultDisposition::Normal );
|
||||
m_runningTest->reset();
|
||||
if( m_reporter->shouldRedirectStdout() ) {
|
||||
LegacyReporterAdapter reporter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) );
|
||||
if( reporter.getPreferences().shouldRedirectStdOut ) {
|
||||
StreamRedirect coutRedir( std::cout, redirectedCout );
|
||||
StreamRedirect cerrRedir( std::cerr, redirectedCerr );
|
||||
m_runningTest->getTestCase().invoke();
|
||||
|
@ -24,9 +24,10 @@ namespace Catch {
|
||||
};
|
||||
|
||||
public:
|
||||
explicit RunningTest( const TestCase* info = NULL )
|
||||
explicit RunningTest( const TestCase& info )
|
||||
: m_info( info ),
|
||||
m_runStatus( RanAtLeastOneSection ),
|
||||
m_rootSection( info.getTestCaseInfo().name ),
|
||||
m_currentSection( &m_rootSection ),
|
||||
m_changed( false )
|
||||
{}
|
||||
@ -71,12 +72,8 @@ namespace Catch {
|
||||
if( m_runStatus == NothingRun )
|
||||
m_runStatus = EncounteredASection;
|
||||
|
||||
SectionInfo* thisSection = m_currentSection->findSubSection( name );
|
||||
if( !thisSection ) {
|
||||
thisSection = m_currentSection->addSubSection( name );
|
||||
m_changed = true;
|
||||
}
|
||||
|
||||
SectionInfo* thisSection = m_currentSection->findOrAddSubSection( name, m_changed );
|
||||
|
||||
if( !wasSectionSeen() && thisSection->shouldRun() ) {
|
||||
m_currentSection = thisSection;
|
||||
m_lastSectionToRun = NULL;
|
||||
@ -98,16 +95,16 @@ namespace Catch {
|
||||
}
|
||||
|
||||
const TestCase& getTestCase() const {
|
||||
return *m_info;
|
||||
return m_info;
|
||||
}
|
||||
|
||||
|
||||
bool hasUntestedSections() const {
|
||||
return m_runStatus == RanAtLeastOneSection ||
|
||||
( m_rootSection.hasUntestedSections() && m_changed );
|
||||
}
|
||||
|
||||
private:
|
||||
const TestCase* m_info;
|
||||
const TestCase& m_info;
|
||||
RunStatus m_runStatus;
|
||||
SectionInfo m_rootSection;
|
||||
SectionInfo* m_currentSection;
|
||||
|
@ -15,10 +15,17 @@
|
||||
|
||||
namespace Catch {
|
||||
|
||||
class SectionInfo {
|
||||
struct ISectionInfo {
|
||||
virtual ~ISectionInfo() {}
|
||||
|
||||
virtual std::string getName() const = 0;
|
||||
virtual const ISectionInfo* getParent() const = 0;
|
||||
};
|
||||
|
||||
class SectionInfo : ISectionInfo {
|
||||
public:
|
||||
|
||||
enum Status {
|
||||
enum State {
|
||||
Root,
|
||||
Unknown,
|
||||
Branch,
|
||||
@ -26,61 +33,40 @@ namespace Catch {
|
||||
TestedLeaf
|
||||
};
|
||||
|
||||
SectionInfo( SectionInfo* parent )
|
||||
: m_status( Unknown ),
|
||||
m_parent( parent )
|
||||
SectionInfo( SectionInfo* parent, const std::string& name )
|
||||
: m_state( Unknown ),
|
||||
m_parent( parent ),
|
||||
m_name( name )
|
||||
{}
|
||||
|
||||
SectionInfo()
|
||||
: m_status( Root ),
|
||||
m_parent( NULL )
|
||||
SectionInfo( const std::string& name )
|
||||
: m_state( Root ),
|
||||
m_parent( NULL ),
|
||||
m_name( name )
|
||||
{}
|
||||
|
||||
~SectionInfo() {
|
||||
deleteAllValues( m_subSections );
|
||||
}
|
||||
|
||||
|
||||
virtual std::string getName() const {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
bool shouldRun() const {
|
||||
return m_status < TestedBranch;
|
||||
return m_state < TestedBranch;
|
||||
}
|
||||
|
||||
bool ran() {
|
||||
if( m_status < Branch ) {
|
||||
m_status = TestedLeaf;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isBranch() const {
|
||||
return m_status == Branch;
|
||||
return m_state == Branch;
|
||||
}
|
||||
|
||||
void ranToCompletion() {
|
||||
if( m_status == Branch && !hasUntestedSections() )
|
||||
m_status = TestedBranch;
|
||||
}
|
||||
|
||||
SectionInfo* findSubSection( const std::string& name ) {
|
||||
std::map<std::string, SectionInfo*>::const_iterator it = m_subSections.find( name );
|
||||
return it != m_subSections.end()
|
||||
? it->second
|
||||
: NULL;
|
||||
}
|
||||
|
||||
SectionInfo* addSubSection( const std::string& name ) {
|
||||
SectionInfo* subSection = new SectionInfo( this );
|
||||
m_subSections.insert( std::make_pair( name, subSection ) );
|
||||
m_status = Branch;
|
||||
return subSection;
|
||||
}
|
||||
|
||||
SectionInfo* getParent() {
|
||||
const SectionInfo* getParent() const {
|
||||
return m_parent;
|
||||
}
|
||||
|
||||
|
||||
bool hasUntestedSections() const {
|
||||
if( m_status == Unknown )
|
||||
if( m_state == Unknown )
|
||||
return true;
|
||||
|
||||
std::map<std::string, SectionInfo*>::const_iterator it = m_subSections.begin();
|
||||
@ -91,11 +77,42 @@ namespace Catch {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Mutable methods:
|
||||
|
||||
SectionInfo* getParent() {
|
||||
return m_parent;
|
||||
}
|
||||
|
||||
SectionInfo* findOrAddSubSection( const std::string& name, bool& changed ) {
|
||||
std::map<std::string, SectionInfo*>::const_iterator it = m_subSections.find( name );
|
||||
if( it != m_subSections.end() )
|
||||
return it->second;
|
||||
SectionInfo* subSection = new SectionInfo( this, name );
|
||||
m_subSections.insert( std::make_pair( name, subSection ) );
|
||||
m_state = Branch;
|
||||
changed = true;
|
||||
return subSection;
|
||||
}
|
||||
|
||||
bool ran() {
|
||||
if( m_state < Branch ) {
|
||||
m_state = TestedLeaf;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ranToCompletion() {
|
||||
if( m_state == Branch && !hasUntestedSections() )
|
||||
m_state = TestedBranch;
|
||||
}
|
||||
|
||||
private:
|
||||
Status m_status;
|
||||
std::map<std::string, SectionInfo*> m_subSections;
|
||||
State m_state;
|
||||
SectionInfo* m_parent;
|
||||
std::string m_name;
|
||||
std::map<std::string, SectionInfo*> m_subSections;
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user