Some formating clean-up

This commit is contained in:
Phil Nash 2011-01-28 18:56:26 +00:00
parent d944e69b18
commit 44488f6331
6 changed files with 160 additions and 41 deletions

View File

@ -21,9 +21,9 @@
namespace Catch
{
struct GeneratorInfo
{
///////////////////////////////////////////////////////////////////////
GeneratorInfo
(
std::size_t size
@ -33,6 +33,7 @@ namespace Catch
{
}
///////////////////////////////////////////////////////////////////////
bool moveNext
()
{
@ -44,6 +45,7 @@ namespace Catch
return true;
}
///////////////////////////////////////////////////////////////////////
std::size_t getCurrentIndex
()
const
@ -55,16 +57,21 @@ namespace Catch
std::size_t m_currentIndex;
};
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
class GeneratorsForTest
{
public:
///////////////////////////////////////////////////////////////////////
~GeneratorsForTest
()
{
deleteAll( m_generatorsInOrder );
}
///////////////////////////////////////////////////////////////////////
GeneratorInfo& getGeneratorInfo
(
const std::string& fileInfo,
@ -82,6 +89,7 @@ namespace Catch
return *it->second;
}
///////////////////////////////////////////////////////////////////////
bool moveNext
()
{

View File

@ -65,12 +65,14 @@ namespace Catch
( const std::string& fileInfo,
size_t totalSize
);
static bool advanceGeneratorsForCurrentTest
();
();
private:
GeneratorsForTest* findGeneratorsForCurrentTest
();
GeneratorsForTest& getGeneratorsForCurrentTest
();

View File

@ -22,7 +22,8 @@ namespace Catch
public:
///////////////////////////////////////////////////////////////////////////
ResultInfo()
ResultInfo
()
: m_line( 0 ),
m_result( ResultWas::Unknown ),
m_isNot( false ),
@ -53,37 +54,49 @@ namespace Catch
}
///////////////////////////////////////////////////////////////////////////
bool ok() const
bool ok
()
const
{
return ( m_result & ResultWas::FailureBit ) != ResultWas::FailureBit;
}
///////////////////////////////////////////////////////////////////////////
ResultWas::OfType getResultType() const
ResultWas::OfType getResultType
()
const
{
return m_result;
}
///////////////////////////////////////////////////////////////////////////
bool hasExpression() const
bool hasExpression
()
const
{
return !m_expr.empty();
}
///////////////////////////////////////////////////////////////////////////
bool hasMessage() const
bool hasMessage
()
const
{
return !m_message.empty();
}
///////////////////////////////////////////////////////////////////////////
std::string getExpression() const
std::string getExpression
()
const
{
return m_expr;
}
///////////////////////////////////////////////////////////////////////////
std::string getExpandedExpression() const
std::string getExpandedExpression
()
const
{
if( !hasExpression() )
return "";
@ -94,25 +107,33 @@ namespace Catch
}
///////////////////////////////////////////////////////////////////////////
std::string getMessage() const
std::string getMessage
()
const
{
return m_message;
}
///////////////////////////////////////////////////////////////////////////
std::string getFilename() const
std::string getFilename
()
const
{
return m_filename;
}
///////////////////////////////////////////////////////////////////////////
std::size_t getLine() const
std::size_t getLine
()
const
{
return m_line;
}
///////////////////////////////////////////////////////////////////////////
std::string getTestMacroName() const
std::string getTestMacroName
()
const
{
return m_macroName;
}
@ -120,7 +141,9 @@ namespace Catch
protected:
///////////////////////////////////////////////////////////////////////////
std::string getExpandedExpressionInternal() const
std::string getExpandedExpressionInternal
()
const
{
if( m_op == "" || m_isNot )
return m_lhs.empty() ? m_expr : m_op + m_lhs;

View File

@ -24,7 +24,11 @@ namespace Catch
class TestSpec
{
public:
TestSpec( const std::string& rawSpec )
///////////////////////////////////////////////////////////////////////
TestSpec
(
const std::string& rawSpec
)
: m_rawSpec( rawSpec ),
m_isWildcarded( false )
{
@ -35,7 +39,12 @@ namespace Catch
}
}
bool matches( const std::string& testName ) const
///////////////////////////////////////////////////////////////////////
bool matches
(
const std::string& testName
)
const
{
if( !m_isWildcarded )
return m_rawSpec == testName;
@ -48,37 +57,60 @@ namespace Catch
bool m_isWildcarded;
};
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
class RunningTest
{
public:
explicit RunningTest( const TestCaseInfo* info = NULL )
///////////////////////////////////////////////////////////////////////
explicit RunningTest
(
const TestCaseInfo* info = NULL
)
: m_info( info ),
m_sectionSeen( false )
{
}
size_t sectionsSeenCount() const
///////////////////////////////////////////////////////////////////////
size_t sectionsSeenCount
()
const
{
return m_sectionsSeen.size();
}
bool wasSectionSeen() const
///////////////////////////////////////////////////////////////////////
bool wasSectionSeen
()
const
{
return m_sectionSeen;
}
void resetSectionSeen()
///////////////////////////////////////////////////////////////////////
void resetSectionSeen
()
{
m_sectionSeen = false;
}
bool addSection( const std::string& name )
///////////////////////////////////////////////////////////////////////
bool addSection
(
const std::string& name
)
{
if( m_sectionsSeen.find( name ) != m_sectionsSeen.end() )
return false;
m_sectionsSeen.insert( name );
return m_sectionSeen = true;
}
const TestCaseInfo& getTestCaseInfo() const
///////////////////////////////////////////////////////////////////////
const TestCaseInfo& getTestCaseInfo
()
const
{
return *m_info;
}
@ -90,18 +122,28 @@ namespace Catch
};
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
class StreamRedirect
{
public:
StreamRedirect( std::ostream& stream, std::string& targetString )
///////////////////////////////////////////////////////////////////////
StreamRedirect
(
std::ostream& stream,
std::string& targetString
)
: m_stream( stream ),
m_prevBuf( stream.rdbuf() ),
m_targetString( targetString )
m_prevBuf( stream.rdbuf() ),
m_targetString( targetString )
{
stream.rdbuf( m_oss.rdbuf() );
}
~StreamRedirect()
///////////////////////////////////////////////////////////////////////
~StreamRedirect
()
{
m_targetString = m_oss.str();
m_stream.rdbuf( m_prevBuf );
@ -114,6 +156,8 @@ namespace Catch
std::string& m_targetString;
};
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
class Runner : public IResultCapture, public IRunner
{

View File

@ -22,20 +22,29 @@ namespace Catch
class Section
{
public:
Section( const std::string& name, const std::string& description )
///////////////////////////////////////////////////////////////////////
Section
(
const std::string& name,
const std::string& description
)
: m_name( name ),
m_sectionIncluded( Hub::getResultCapture().sectionStarted( name, description, m_successes, m_failures ) )
{
}
~Section()
///////////////////////////////////////////////////////////////////////
~Section
()
{
if( m_sectionIncluded )
Hub::getResultCapture().sectionEnded( m_name, m_successes, m_failures );
}
///////////////////////////////////////////////////////////////////////
// This indicates whether the section should be executed or not
operator bool()
operator bool
()
{
return m_sectionIncluded;
}

View File

@ -23,12 +23,18 @@ namespace Catch
class TestRegistry : public ITestCaseRegistry
{
public:
TestRegistry()
///////////////////////////////////////////////////////////////////////////
TestRegistry
()
: m_unnamedCount( 0 )
{
}
virtual void registerTest( const TestCaseInfo& testInfo )
///////////////////////////////////////////////////////////////////////////
virtual void registerTest
(
const TestCaseInfo& testInfo
)
{
if( testInfo.getName() == "" )
{
@ -43,7 +49,10 @@ namespace Catch
}
}
virtual const std::vector<TestCaseInfo>& getAllTests() const
///////////////////////////////////////////////////////////////////////////
virtual const std::vector<TestCaseInfo>& getAllTests
()
const
{
return m_functionsInOrder;
}
@ -54,30 +63,54 @@ namespace Catch
std::vector<TestCaseInfo> m_functionsInOrder;
size_t m_unnamedCount;
};
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
struct FreeFunctionTestCase : ITestCase
{
FreeFunctionTestCase( TestFunction fun )
///////////////////////////////////////////////////////////////////////////
FreeFunctionTestCase
(
TestFunction fun
)
: fun( fun )
{}
virtual void invoke() const
///////////////////////////////////////////////////////////////////////////
virtual void invoke
()
const
{
fun();
}
virtual ITestCase* clone() const
///////////////////////////////////////////////////////////////////////////
virtual ITestCase* clone
()
const
{
return new FreeFunctionTestCase( fun );
}
virtual bool operator == ( const ITestCase& other ) const
///////////////////////////////////////////////////////////////////////////
virtual bool operator ==
(
const ITestCase& other
)
const
{
const FreeFunctionTestCase* ffOther = dynamic_cast<const FreeFunctionTestCase*> ( &other );
return ffOther && fun == ffOther->fun;
}
virtual bool operator < ( const ITestCase& other ) const
///////////////////////////////////////////////////////////////////////////
virtual bool operator <
(
const ITestCase& other
)
const
{
const FreeFunctionTestCase* ffOther = dynamic_cast<const FreeFunctionTestCase*> ( &other );
return ffOther && fun < ffOther->fun;
@ -93,10 +126,10 @@ namespace Catch
///////////////////////////////////////////////////////////////////////////
AutoReg::AutoReg
(
TestFunction function,
const char* name,
const char* description
)
TestFunction function,
const char* name,
const char* description
)
{
registerTestCase( new FreeFunctionTestCase( function ), name, description );
}