mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 15:26:11 +01:00
Renamed SectionInfo -> RunningSection.
Added SectionInfo (that now corresponds to TestCaseInfo) and SectionStats Switched some const T&'s to T const&'s
This commit is contained in:
parent
3d6be037e9
commit
95df676a27
@ -21,9 +21,8 @@
|
|||||||
|
|
||||||
namespace Catch
|
namespace Catch
|
||||||
{
|
{
|
||||||
struct ReporterConfig
|
struct ReporterConfig {
|
||||||
{
|
ReporterConfig( std::ostream& _stream, ConfigData const& _fullConfig )
|
||||||
ReporterConfig( std::ostream& _stream, const ConfigData& _fullConfig )
|
|
||||||
: m_stream( &_stream ), m_fullConfig( _fullConfig ) {}
|
: m_stream( &_stream ), m_fullConfig( _fullConfig ) {}
|
||||||
|
|
||||||
std::ostream& stream() { return *m_stream; }
|
std::ostream& stream() { return *m_stream; }
|
||||||
@ -36,8 +35,7 @@ namespace Catch
|
|||||||
ConfigData m_fullConfig;
|
ConfigData m_fullConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ReporterPreferences
|
struct ReporterPreferences {
|
||||||
{
|
|
||||||
ReporterPreferences()
|
ReporterPreferences()
|
||||||
: shouldRedirectStdOut( false )
|
: shouldRedirectStdOut( false )
|
||||||
{}
|
{}
|
||||||
@ -45,9 +43,23 @@ namespace Catch
|
|||||||
bool shouldRedirectStdOut;
|
bool shouldRedirectStdOut;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SectionInfo {
|
||||||
|
SectionInfo( std::string const& _name,
|
||||||
|
std::string const& _description,
|
||||||
|
SourceLineInfo const& _lineInfo )
|
||||||
|
: name( _name ),
|
||||||
|
description( _description ),
|
||||||
|
sourceLineInfo( _lineInfo )
|
||||||
|
{}
|
||||||
|
|
||||||
|
std::string name;
|
||||||
|
std::string description;
|
||||||
|
SourceLineInfo sourceLineInfo;
|
||||||
|
};
|
||||||
|
|
||||||
struct AssertionStats {
|
struct AssertionStats {
|
||||||
AssertionStats( const AssertionResult& _assertionResult,
|
AssertionStats( AssertionResult const& _assertionResult,
|
||||||
const Totals& _totals )
|
Totals const& _totals )
|
||||||
: assertionResult( _assertionResult ),
|
: assertionResult( _assertionResult ),
|
||||||
totals( _totals )
|
totals( _totals )
|
||||||
{}
|
{}
|
||||||
@ -57,11 +69,16 @@ namespace Catch
|
|||||||
Totals totals;
|
Totals totals;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SectionStats {
|
||||||
|
SectionInfo sectionInfo;
|
||||||
|
Totals totals;
|
||||||
|
};
|
||||||
|
|
||||||
struct TestCaseStats {
|
struct TestCaseStats {
|
||||||
TestCaseStats( const TestCaseInfo& _testInfo,
|
TestCaseStats( TestCaseInfo const& _testInfo,
|
||||||
const Totals& _totals,
|
Totals const& _totals,
|
||||||
const std::string& _stdOut,
|
std::string const& _stdOut,
|
||||||
const std::string& _stdErr,
|
std::string const& _stdErr,
|
||||||
bool _missingAssertions,
|
bool _missingAssertions,
|
||||||
bool _aborting )
|
bool _aborting )
|
||||||
: testInfo( _testInfo ),
|
: testInfo( _testInfo ),
|
||||||
@ -81,8 +98,8 @@ namespace Catch
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct TestGroupStats {
|
struct TestGroupStats {
|
||||||
TestGroupStats( const std::string& _groupName,
|
TestGroupStats( std::string const& _groupName,
|
||||||
const Totals& _totals,
|
Totals const& _totals,
|
||||||
bool _aborting )
|
bool _aborting )
|
||||||
: groupName( _groupName ),
|
: groupName( _groupName ),
|
||||||
totals( _totals ),
|
totals( _totals ),
|
||||||
@ -95,8 +112,8 @@ namespace Catch
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct TestRunStats {
|
struct TestRunStats {
|
||||||
TestRunStats( const std::string& _runName,
|
TestRunStats( std::string const& _runName,
|
||||||
const Totals& _totals,
|
Totals const& _totals,
|
||||||
bool _aborting )
|
bool _aborting )
|
||||||
: runName( _runName ),
|
: runName( _runName ),
|
||||||
totals( _totals ),
|
totals( _totals ),
|
||||||
@ -113,17 +130,17 @@ namespace Catch
|
|||||||
virtual ~IStreamingReporter();
|
virtual ~IStreamingReporter();
|
||||||
virtual ReporterPreferences getPreferences() const = 0;
|
virtual ReporterPreferences getPreferences() const = 0;
|
||||||
|
|
||||||
virtual void testRunStarting( const std::string& runName ) = 0;
|
virtual void testRunStarting( std::string const& runName ) = 0;
|
||||||
virtual void testGroupStarting( const std::string& groupName ) = 0;
|
virtual void testGroupStarting( std::string const& groupName ) = 0;
|
||||||
|
|
||||||
// !TBD: include section info (perhaps TestCase has an isSection flag and/ or a parent pointer
|
// !TBD: include section info (perhaps TestCase has an isSection flag and/ or a parent pointer
|
||||||
virtual void testCaseStarting( const TestCaseInfo& testInfo ) = 0;
|
virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0;
|
||||||
virtual void assertionStarting( const AssertionInfo& assertionInfo ) = 0;
|
virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
|
||||||
|
|
||||||
virtual void assertionEnding( const AssertionStats& assertionStats ) = 0;
|
virtual void assertionEnding( AssertionStats const& assertionStats ) = 0;
|
||||||
virtual void testCaseEnding( const TestCaseStats& testCaseStats ) = 0;
|
virtual void testCaseEnding( TestCaseStats const& testCaseStats ) = 0;
|
||||||
virtual void testGroupEnding( const TestGroupStats& testGroupStats ) = 0;
|
virtual void testGroupEnding( TestGroupStats const& testGroupStats ) = 0;
|
||||||
virtual void testRunEnding( const TestRunStats& testRunStats ) = 0;
|
virtual void testRunEnding( TestRunStats const& testRunStats ) = 0;
|
||||||
};
|
};
|
||||||
// !TBD: Derived helper that implements the streaming interface but holds the stats
|
// !TBD: Derived helper that implements the streaming interface but holds the stats
|
||||||
// - declares a new interface where methods are called at the end of each event
|
// - declares a new interface where methods are called at the end of each event
|
||||||
@ -138,23 +155,23 @@ namespace Catch
|
|||||||
virtual bool shouldRedirectStdout() const = 0;
|
virtual bool shouldRedirectStdout() const = 0;
|
||||||
|
|
||||||
virtual void StartTesting() = 0;
|
virtual void StartTesting() = 0;
|
||||||
virtual void EndTesting( const Totals& totals ) = 0;
|
virtual void EndTesting( Totals const& totals ) = 0;
|
||||||
|
|
||||||
virtual void StartGroup( const std::string& groupName ) = 0;
|
virtual void StartGroup( std::string const& groupName ) = 0;
|
||||||
virtual void EndGroup( const std::string& groupName, const Totals& totals ) = 0;
|
virtual void EndGroup( std::string const& groupName, Totals const& totals ) = 0;
|
||||||
|
|
||||||
virtual void StartTestCase( const TestCaseInfo& testInfo ) = 0;
|
virtual void StartTestCase( TestCaseInfo const& testInfo ) = 0;
|
||||||
// TestCaseResult
|
// TestCaseResult
|
||||||
virtual void EndTestCase( const TestCaseInfo& testInfo, const Totals& totals, const std::string& stdOut, const std::string& stdErr ) = 0;
|
virtual void EndTestCase( TestCaseInfo const& testInfo, Totals const& totals, std::string const& stdOut, std::string const& stdErr ) = 0;
|
||||||
|
|
||||||
// SectionInfo
|
// SectionInfo
|
||||||
virtual void StartSection( const std::string& sectionName, const std::string& description ) = 0;
|
virtual void StartSection( std::string const& sectionName, std::string const& description ) = 0;
|
||||||
// Section Result
|
// Section Result
|
||||||
virtual void EndSection( const std::string& sectionName, const Counts& assertions ) = 0;
|
virtual void EndSection( std::string const& sectionName, const Counts& assertions ) = 0;
|
||||||
|
|
||||||
// - merge into SectionResult ?
|
// - merge into SectionResult ?
|
||||||
virtual void NoAssertionsInSection( const std::string& sectionName ) = 0;
|
virtual void NoAssertionsInSection( std::string const& sectionName ) = 0;
|
||||||
virtual void NoAssertionsInTestCase( const std::string& testName ) = 0;
|
virtual void NoAssertionsInTestCase( std::string const& testName ) = 0;
|
||||||
|
|
||||||
// - merge into SectionResult, TestCaseResult, GroupResult & TestRunResult
|
// - merge into SectionResult, TestCaseResult, GroupResult & TestRunResult
|
||||||
virtual void Aborted() = 0;
|
virtual void Aborted() = 0;
|
||||||
@ -166,7 +183,7 @@ namespace Catch
|
|||||||
class LegacyReporterAdapter : public SharedImpl<IStreamingReporter>
|
class LegacyReporterAdapter : public SharedImpl<IStreamingReporter>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LegacyReporterAdapter( const Ptr<IReporter>& legacyReporter, const ReporterConfig& config )
|
LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter, ReporterConfig const& config )
|
||||||
: m_legacyReporter( legacyReporter ),
|
: m_legacyReporter( legacyReporter ),
|
||||||
m_config( config )
|
m_config( config )
|
||||||
{}
|
{}
|
||||||
@ -178,33 +195,33 @@ namespace Catch
|
|||||||
return prefs;
|
return prefs;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void testRunStarting( const std::string& ) {
|
virtual void testRunStarting( std::string const& ) {
|
||||||
m_legacyReporter->StartTesting();
|
m_legacyReporter->StartTesting();
|
||||||
}
|
}
|
||||||
virtual void testGroupStarting( const std::string& groupName ) {
|
virtual void testGroupStarting( std::string const& groupName ) {
|
||||||
m_legacyReporter->StartGroup( groupName );
|
m_legacyReporter->StartGroup( groupName );
|
||||||
}
|
}
|
||||||
virtual void testCaseStarting( const TestCaseInfo& testInfo ) {
|
virtual void testCaseStarting( TestCaseInfo const& testInfo ) {
|
||||||
m_legacyReporter->StartTestCase( testInfo );
|
m_legacyReporter->StartTestCase( testInfo );
|
||||||
}
|
}
|
||||||
virtual void assertionStarting( const AssertionInfo& ) {
|
virtual void assertionStarting( AssertionInfo const& ) {
|
||||||
// Not on legacy interface
|
// Not on legacy interface
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void assertionEnding( const AssertionStats& assertionStats ) {
|
virtual void assertionEnding( AssertionStats const& assertionStats ) {
|
||||||
m_legacyReporter->Result( assertionStats.assertionResult );
|
m_legacyReporter->Result( assertionStats.assertionResult );
|
||||||
}
|
}
|
||||||
virtual void testCaseEnding( const TestCaseStats& testCaseStats ) {
|
virtual void testCaseEnding( TestCaseStats const& testCaseStats ) {
|
||||||
if( testCaseStats.missingAssertions )
|
if( testCaseStats.missingAssertions )
|
||||||
m_legacyReporter->NoAssertionsInTestCase( testCaseStats.testInfo.name );
|
m_legacyReporter->NoAssertionsInTestCase( testCaseStats.testInfo.name );
|
||||||
m_legacyReporter->EndTestCase( testCaseStats.testInfo, testCaseStats.totals, testCaseStats.stdOut, testCaseStats.stdErr );
|
m_legacyReporter->EndTestCase( testCaseStats.testInfo, testCaseStats.totals, testCaseStats.stdOut, testCaseStats.stdErr );
|
||||||
}
|
}
|
||||||
virtual void testGroupEnding( const TestGroupStats& testGroupStats ) {
|
virtual void testGroupEnding( TestGroupStats const& testGroupStats ) {
|
||||||
if( testGroupStats.aborting )
|
if( testGroupStats.aborting )
|
||||||
m_legacyReporter->Aborted();
|
m_legacyReporter->Aborted();
|
||||||
m_legacyReporter->EndGroup( testGroupStats.groupName, testGroupStats.totals );
|
m_legacyReporter->EndGroup( testGroupStats.groupName, testGroupStats.totals );
|
||||||
}
|
}
|
||||||
virtual void testRunEnding( const TestRunStats& testRunStats ) {
|
virtual void testRunEnding( TestRunStats const& testRunStats ) {
|
||||||
m_legacyReporter->EndTesting( testRunStats.totals );
|
m_legacyReporter->EndTesting( testRunStats.totals );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,7 +233,7 @@ namespace Catch
|
|||||||
|
|
||||||
struct IReporterFactory {
|
struct IReporterFactory {
|
||||||
virtual ~IReporterFactory();
|
virtual ~IReporterFactory();
|
||||||
virtual IReporter* create( const ReporterConfig& config ) const = 0;
|
virtual IReporter* create( ReporterConfig const& config ) const = 0;
|
||||||
virtual std::string getDescription() const = 0;
|
virtual std::string getDescription() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -224,11 +241,11 @@ namespace Catch
|
|||||||
typedef std::map<std::string, IReporterFactory*> FactoryMap;
|
typedef std::map<std::string, IReporterFactory*> FactoryMap;
|
||||||
|
|
||||||
virtual ~IReporterRegistry();
|
virtual ~IReporterRegistry();
|
||||||
virtual IReporter* create( const std::string& name, const ReporterConfig& config ) const = 0;
|
virtual IReporter* create( std::string const& name, ReporterConfig const& config ) const = 0;
|
||||||
virtual const FactoryMap& getFactories() const = 0;
|
virtual const FactoryMap& getFactories() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::string trim( const std::string& str ) {
|
inline std::string trim( std::string const& str ) {
|
||||||
std::string::size_type start = str.find_first_not_of( "\n\r\t " );
|
std::string::size_type start = str.find_first_not_of( "\n\r\t " );
|
||||||
std::string::size_type end = str.find_last_not_of( "\n\r\t " );
|
std::string::size_type end = str.find_last_not_of( "\n\r\t " );
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ namespace Catch {
|
|||||||
if( m_runStatus == NothingRun )
|
if( m_runStatus == NothingRun )
|
||||||
m_runStatus = EncounteredASection;
|
m_runStatus = EncounteredASection;
|
||||||
|
|
||||||
SectionInfo* thisSection = m_currentSection->findOrAddSubSection( name, m_changed );
|
RunningSection* thisSection = m_currentSection->findOrAddSubSection( name, m_changed );
|
||||||
|
|
||||||
if( !wasSectionSeen() && thisSection->shouldRun() ) {
|
if( !wasSectionSeen() && thisSection->shouldRun() ) {
|
||||||
m_currentSection = thisSection;
|
m_currentSection = thisSection;
|
||||||
@ -102,9 +102,9 @@ namespace Catch {
|
|||||||
private:
|
private:
|
||||||
const TestCase& m_info;
|
const TestCase& m_info;
|
||||||
RunStatus m_runStatus;
|
RunStatus m_runStatus;
|
||||||
SectionInfo m_rootSection;
|
RunningSection m_rootSection;
|
||||||
SectionInfo* m_currentSection;
|
RunningSection* m_currentSection;
|
||||||
SectionInfo* m_lastSectionToRun;
|
RunningSection* m_lastSectionToRun;
|
||||||
bool m_changed;
|
bool m_changed;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -15,17 +15,10 @@
|
|||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
struct ISectionInfo {
|
class RunningSection {
|
||||||
virtual ~ISectionInfo() {}
|
|
||||||
|
|
||||||
virtual std::string getName() const = 0;
|
|
||||||
virtual const ISectionInfo* getParent() const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class SectionInfo : public ISectionInfo {
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef std::vector<SectionInfo*> SubSections;
|
typedef std::vector<RunningSection*> SubSections;
|
||||||
|
|
||||||
enum State {
|
enum State {
|
||||||
Root,
|
Root,
|
||||||
@ -35,23 +28,23 @@ namespace Catch {
|
|||||||
TestedLeaf
|
TestedLeaf
|
||||||
};
|
};
|
||||||
|
|
||||||
SectionInfo( SectionInfo* parent, const std::string& name )
|
RunningSection( RunningSection* parent, const std::string& name )
|
||||||
: m_state( Unknown ),
|
: m_state( Unknown ),
|
||||||
m_parent( parent ),
|
m_parent( parent ),
|
||||||
m_name( name )
|
m_name( name )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
SectionInfo( const std::string& name )
|
RunningSection( const std::string& name )
|
||||||
: m_state( Root ),
|
: m_state( Root ),
|
||||||
m_parent( NULL ),
|
m_parent( NULL ),
|
||||||
m_name( name )
|
m_name( name )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
~SectionInfo() {
|
~RunningSection() {
|
||||||
deleteAll( m_subSections );
|
deleteAll( m_subSections );
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string getName() const {
|
std::string getName() const {
|
||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +56,7 @@ namespace Catch {
|
|||||||
return m_state == Branch;
|
return m_state == Branch;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SectionInfo* getParent() const {
|
const RunningSection* getParent() const {
|
||||||
return m_parent;
|
return m_parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,17 +73,17 @@ namespace Catch {
|
|||||||
|
|
||||||
// Mutable methods:
|
// Mutable methods:
|
||||||
|
|
||||||
SectionInfo* getParent() {
|
RunningSection* getParent() {
|
||||||
return m_parent;
|
return m_parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
SectionInfo* findOrAddSubSection( const std::string& name, bool& changed ) {
|
RunningSection* findOrAddSubSection( const std::string& name, bool& changed ) {
|
||||||
for( SubSections::const_iterator it = m_subSections.begin();
|
for( SubSections::const_iterator it = m_subSections.begin();
|
||||||
it != m_subSections.end();
|
it != m_subSections.end();
|
||||||
++it)
|
++it)
|
||||||
if( (*it)->getName() == name )
|
if( (*it)->getName() == name )
|
||||||
return *it;
|
return *it;
|
||||||
SectionInfo* subSection = new SectionInfo( this, name );
|
RunningSection* subSection = new RunningSection( this, name );
|
||||||
m_subSections.push_back( subSection );
|
m_subSections.push_back( subSection );
|
||||||
m_state = Branch;
|
m_state = Branch;
|
||||||
changed = true;
|
changed = true;
|
||||||
@ -111,7 +104,7 @@ namespace Catch {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
State m_state;
|
State m_state;
|
||||||
SectionInfo* m_parent;
|
RunningSection* m_parent;
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
SubSections m_subSections;
|
SubSections m_subSections;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user