Reformatting

This commit is contained in:
Phil Nash 2012-05-15 07:42:26 +01:00
parent 6acb36a996
commit 2efc1146bf
11 changed files with 211 additions and 545 deletions

View File

@ -1,13 +1,9 @@
/*
* catch_approx.hpp
* Catch
*
* Created by Phil on 28/04/2011.
* 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)
*
*/
#ifndef TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED
@ -17,140 +13,78 @@
#include <cmath>
#include <limits>
namespace Catch
{
namespace Detail
{
class Approx
{
public:
///////////////////////////////////////////////////////////////////////////
explicit Approx
(
double value
)
: m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
m_scale( 1.0 ),
m_value( value )
{
}
///////////////////////////////////////////////////////////////////////////
Approx
(
const Approx& other
)
: m_epsilon( other.m_epsilon ),
m_scale( other.m_scale ),
m_value( other.m_value )
{
}
namespace Catch {
namespace Detail {
///////////////////////////////////////////////////////////////////////////
static Approx custom
()
{
return Approx( 0 );
}
///////////////////////////////////////////////////////////////////////////
Approx operator()
(
double value
)
{
Approx approx( value );
approx.epsilon( m_epsilon );
approx.scale( m_scale );
return approx;
}
///////////////////////////////////////////////////////////////////////////
friend bool operator ==
(
double lhs,
const Approx& rhs
)
{
// Thanks to Richard Harris for his help refining this formula
return fabs( lhs - rhs.m_value ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( fabs(lhs), fabs(rhs.m_value) ) );
}
///////////////////////////////////////////////////////////////////////////
friend bool operator ==
(
const Approx& lhs,
double rhs
)
{
return operator==( rhs, lhs );
}
///////////////////////////////////////////////////////////////////////////
friend bool operator !=
(
double lhs,
const Approx& rhs
)
{
return !operator==( lhs, rhs );
}
class Approx {
public:
explicit Approx ( double value )
: m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
m_scale( 1.0 ),
m_value( value )
{}
Approx( const Approx& other )
: m_epsilon( other.m_epsilon ),
m_scale( other.m_scale ),
m_value( other.m_value )
{}
///////////////////////////////////////////////////////////////////////////
friend bool operator !=
(
const Approx& lhs,
double rhs
)
{
return !operator==( rhs, lhs );
}
///////////////////////////////////////////////////////////////////////////
Approx& epsilon
(
double newEpsilon
)
{
m_epsilon = newEpsilon;
return *this;
}
///////////////////////////////////////////////////////////////////////////
Approx& scale
(
double newScale
)
{
m_scale = newScale;
return *this;
}
///////////////////////////////////////////////////////////////////////////
std::string toString() const
{
std::ostringstream oss;
oss << "Approx( " << m_value << ")";
return oss.str();
}
private:
double m_epsilon;
double m_scale;
double m_value;
};
}
///////////////////////////////////////////////////////////////////////////////
template<>
inline std::string toString<Detail::Approx>
(
const Detail::Approx& value
)
{
return value.toString();
}
static Approx custom() {
return Approx( 0 );
}
Approx operator()( double value ) {
Approx approx( value );
approx.epsilon( m_epsilon );
approx.scale( m_scale );
return approx;
}
friend bool operator == ( double lhs, const Approx& rhs ) {
// Thanks to Richard Harris for his help refining this formula
return fabs( lhs - rhs.m_value ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( fabs(lhs), fabs(rhs.m_value) ) );
}
friend bool operator == ( const Approx& lhs, double rhs ) {
return operator==( rhs, lhs );
}
friend bool operator != ( double lhs, const Approx& rhs ) {
return !operator==( lhs, rhs );
}
friend bool operator != ( const Approx& lhs, double rhs ) {
return !operator==( rhs, lhs );
}
Approx& epsilon( double newEpsilon ) {
m_epsilon = newEpsilon;
return *this;
}
Approx& scale( double newScale ) {
m_scale = newScale;
return *this;
}
std::string toString() const {
std::ostringstream oss;
oss << "Approx( " << m_value << ")";
return oss.str();
}
private:
double m_epsilon;
double m_scale;
double m_value;
};
}
template<>
inline std::string toString<Detail::Approx>( const Detail::Approx& value ) {
return value.toString();
}
} // end namespace Catch

View File

@ -15,13 +15,11 @@
#include "catch_common.h"
#include <ostream>
namespace Catch
{
namespace Catch {
struct TestFailureException{};
class ScopedInfo
{
class ScopedInfo {
public:
ScopedInfo() : m_oss() {
Context::getResultCapture().pushScopedInfo( this );

View File

@ -1,24 +1,17 @@
/*
* catch_evaluate.hpp
* Catch
*
* Created by Phil on 04/03/2011.
* Copyright 2011 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)
*
*/
#ifndef TWOBLUECUBES_CATCH_EVALUATE_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_EVALUATE_HPP_INCLUDED
namespace Catch
{
namespace Internal
{
enum Operator
{
namespace Catch {
namespace Internal {
enum Operator {
IsEqualTo,
IsNotEqualTo,
IsLessThan,
@ -54,146 +47,116 @@ namespace Internal
class Evaluator{};
template<typename T1, typename T2>
struct Evaluator<T1, T2, IsEqualTo>
{
static bool evaluate( const T1& lhs, const T2& rhs)
{
struct Evaluator<T1, T2, IsEqualTo> {
static bool evaluate( const T1& lhs, const T2& rhs) {
return const_cast<T1&>( lhs ) == const_cast<T2&>( rhs );
}
};
template<typename T1, typename T2>
struct Evaluator<T1, T2, IsNotEqualTo>
{
static bool evaluate( const T1& lhs, const T2& rhs )
{
struct Evaluator<T1, T2, IsNotEqualTo> {
static bool evaluate( const T1& lhs, const T2& rhs ) {
return const_cast<T1&>( lhs ) != const_cast<T2&>( rhs );
}
};
template<typename T1, typename T2>
struct Evaluator<T1, T2, IsLessThan>
{
static bool evaluate( const T1& lhs, const T2& rhs )
{
struct Evaluator<T1, T2, IsLessThan> {
static bool evaluate( const T1& lhs, const T2& rhs ) {
return const_cast<T1&>( lhs ) < const_cast<T2&>( rhs );
}
};
template<typename T1, typename T2>
struct Evaluator<T1, T2, IsGreaterThan>
{
static bool evaluate( const T1& lhs, const T2& rhs )
{
struct Evaluator<T1, T2, IsGreaterThan> {
static bool evaluate( const T1& lhs, const T2& rhs ) {
return const_cast<T1&>( lhs ) > const_cast<T2&>( rhs );
}
};
template<typename T1, typename T2>
struct Evaluator<T1, T2, IsGreaterThanOrEqualTo>
{
static bool evaluate( const T1& lhs, const T2& rhs )
{
struct Evaluator<T1, T2, IsGreaterThanOrEqualTo> {
static bool evaluate( const T1& lhs, const T2& rhs ) {
return const_cast<T1&>( lhs ) >= const_cast<T2&>( rhs );
}
};
template<typename T1, typename T2>
struct Evaluator<T1, T2, IsLessThanOrEqualTo>
{
static bool evaluate( const T1& lhs, const T2& rhs )
{
struct Evaluator<T1, T2, IsLessThanOrEqualTo> {
static bool evaluate( const T1& lhs, const T2& rhs ) {
return const_cast<T1&>( lhs ) <= const_cast<T2&>( rhs );
}
};
template<Operator Op, typename T1, typename T2>
bool applyEvaluator( const T1& lhs, const T2& rhs )
{
bool applyEvaluator( const T1& lhs, const T2& rhs ) {
return Evaluator<T1, T2, Op>::evaluate( lhs, rhs );
}
// "base" overload
template<Operator Op, typename T1, typename T2>
bool compare( const T1& lhs, const T2& rhs )
{
bool compare( const T1& lhs, const T2& rhs ) {
return Evaluator<T1, T2, Op>::evaluate( lhs, rhs );
}
// unsigned X to int
template<Operator Op> bool compare( unsigned int lhs, int rhs )
{
template<Operator Op> bool compare( unsigned int lhs, int rhs ) {
return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
}
template<Operator Op> bool compare( unsigned long lhs, int rhs )
{
template<Operator Op> bool compare( unsigned long lhs, int rhs ) {
return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
}
template<Operator Op> bool compare( unsigned char lhs, int rhs )
{
template<Operator Op> bool compare( unsigned char lhs, int rhs ) {
return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
}
// unsigned X to long
template<Operator Op> bool compare( unsigned int lhs, long rhs )
{
template<Operator Op> bool compare( unsigned int lhs, long rhs ) {
return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
}
template<Operator Op> bool compare( unsigned long lhs, long rhs )
{
template<Operator Op> bool compare( unsigned long lhs, long rhs ) {
return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
}
template<Operator Op> bool compare( unsigned char lhs, long rhs )
{
template<Operator Op> bool compare( unsigned char lhs, long rhs ) {
return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
}
// int to unsigned X
template<Operator Op> bool compare( int lhs, unsigned int rhs )
{
template<Operator Op> bool compare( int lhs, unsigned int rhs ) {
return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
}
template<Operator Op> bool compare( int lhs, unsigned long rhs )
{
template<Operator Op> bool compare( int lhs, unsigned long rhs ) {
return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
}
template<Operator Op> bool compare( int lhs, unsigned char rhs )
{
template<Operator Op> bool compare( int lhs, unsigned char rhs ) {
return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
}
// long to unsigned X
template<Operator Op> bool compare( long lhs, unsigned int rhs )
{
template<Operator Op> bool compare( long lhs, unsigned int rhs ) {
return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
}
template<Operator Op> bool compare( long lhs, unsigned long rhs )
{
template<Operator Op> bool compare( long lhs, unsigned long rhs ) {
return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
}
template<Operator Op> bool compare( long lhs, unsigned char rhs )
{
template<Operator Op> bool compare( long lhs, unsigned char rhs ) {
return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
}
template<Operator Op, typename T>
bool compare( long lhs, const T* rhs )
{
bool compare( long lhs, const T* rhs ) {
return Evaluator<const T*, const T*, Op>::evaluate( reinterpret_cast<const T*>( lhs ), rhs );
}
template<Operator Op, typename T>
bool compare( long lhs, T* rhs )
{
bool compare( long lhs, T* rhs ) {
return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
}
template<Operator Op, typename T>
bool compare( const T* lhs, long rhs )
{
bool compare( const T* lhs, long rhs ) {
return Evaluator<const T*, const T*, Op>::evaluate( lhs, reinterpret_cast<const T*>( rhs ) );
}
}
template<Operator Op, typename T>
bool compare( T* lhs, long rhs )
{
bool compare( T* lhs, long rhs ) {
return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) );
}
}
} // end of namespace Internal
} // end of namespace Catch

View File

@ -11,12 +11,10 @@
#include "catch_resultinfo_builder.hpp"
#include "catch_evaluate.hpp"
namespace Catch
{
namespace Catch {
template<typename T>
class Expression
{
class Expression {
void operator = ( const Expression& );
public:
@ -79,8 +77,7 @@ private:
};
template<typename LhsT>
class PtrExpression
{
class PtrExpression {
public:
PtrExpression ( ResultInfoBuilder& result, const LhsT* lhs )

View File

@ -1,15 +1,10 @@
/*
* catch_generators.hpp
* Catch
*
* Created by Phil on 27/01/2011.
* Copyright 2011 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)
*
*/
#ifndef TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED
@ -20,54 +15,25 @@
#include <string>
#include <stdlib.h>
namespace Catch
{
namespace Catch {
template<typename T>
struct IGenerator
{
virtual ~IGenerator
()
{}
virtual T getValue
( std::size_t index
) const = 0;
virtual std::size_t size
() const = 0;
struct IGenerator {
virtual ~IGenerator() {}
virtual T getValue( std::size_t index ) const = 0;
virtual std::size_t size () const = 0;
};
template<typename T>
class BetweenGenerator : public IGenerator<T>
{
class BetweenGenerator : public IGenerator<T> {
public:
///////////////////////////////////////////////////////////////////////////
BetweenGenerator
(
T from,
T to
)
: m_from( from ),
m_to( to )
{
}
BetweenGenerator( T from, T to ) : m_from( from ), m_to( to ){}
///////////////////////////////////////////////////////////////////////////
virtual T getValue
(
std::size_t index
)
const
{
virtual T getValue( std::size_t index ) const {
return m_from+static_cast<T>( index );
}
///////////////////////////////////////////////////////////////////////////
virtual std::size_t size
()
const
{
virtual std::size_t size() const {
return static_cast<std::size_t>( 1+m_to-m_from );
}
@ -78,88 +44,49 @@ private:
};
template<typename T>
class ValuesGenerator : public IGenerator<T>
{
class ValuesGenerator : public IGenerator<T> {
public:
///////////////////////////////////////////////////////////////////////////
ValuesGenerator
()
{
}
ValuesGenerator(){}
///////////////////////////////////////////////////////////////////////////
void add
(
T value
)
{
void add( T value ) {
m_values.push_back( value );
}
///////////////////////////////////////////////////////////////////////////
virtual T getValue
(
std::size_t index
)
const
{
virtual T getValue( std::size_t index ) const {
return m_values[index];
}
///////////////////////////////////////////////////////////////////////////
virtual std::size_t size
()
const
{
virtual std::size_t size() const {
return m_values.size();
}
private:
std::vector<T> m_values;
};
template<typename T>
class CompositeGenerator
{
class CompositeGenerator {
public:
///////////////////////////////////////////////////////////////////////////
CompositeGenerator()
: m_totalSize( 0 )
{
}
CompositeGenerator() : m_totalSize( 0 ) {}
///////////////////////////////////////////////////////////////////////////
// *** Move semantics, similar to auto_ptr ***
CompositeGenerator( CompositeGenerator& other )
: m_fileInfo( other.m_fileInfo ),
m_totalSize( 0 )
CompositeGenerator( CompositeGenerator& other )
: m_fileInfo( other.m_fileInfo ),
m_totalSize( 0 )
{
move( other );
}
///////////////////////////////////////////////////////////////////////////
CompositeGenerator& setFileInfo
(
const char* fileInfo
)
{
CompositeGenerator& setFileInfo( const char* fileInfo ) {
m_fileInfo = fileInfo;
return *this;
}
///////////////////////////////////////////////////////////////////////////
~CompositeGenerator
()
{
~CompositeGenerator() {
deleteAll( m_composed );
}
///////////////////////////////////////////////////////////////////////////
operator T
()
const
{
operator T () const {
size_t overallIndex = Context::getGeneratorIndex( m_fileInfo, m_totalSize );
typename std::vector<const IGenerator<T>*>::const_iterator it = m_composed.begin();
@ -177,32 +104,17 @@ public:
return T(); // Suppress spurious "not all control paths return a value" warning in Visual Studio - if you know how to fix this please do so
}
///////////////////////////////////////////////////////////////////////////
void add
(
const IGenerator<T>* generator
)
{
void add( const IGenerator<T>* generator ) {
m_totalSize += generator->size();
m_composed.push_back( generator );
}
///////////////////////////////////////////////////////////////////////////
CompositeGenerator& then
(
CompositeGenerator& other
)
{
CompositeGenerator& then( CompositeGenerator& other ) {
move( other );
return *this;
}
///////////////////////////////////////////////////////////////////////////
CompositeGenerator& then
(
T value
)
{
CompositeGenerator& then( T value ) {
ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
valuesGen->add( value );
add( valuesGen );
@ -211,12 +123,7 @@ public:
private:
///////////////////////////////////////////////////////////////////////////
void move
(
CompositeGenerator& other
)
{
void move( CompositeGenerator& other ) {
std::copy( other.m_composed.begin(), other.m_composed.end(), std::back_inserter( m_composed ) );
m_totalSize += other.m_totalSize;
other.m_composed.clear();
@ -229,27 +136,15 @@ private:
namespace Generators
{
///////////////////////////////////////////////////////////////////////////
template<typename T>
CompositeGenerator<T> between
(
T from,
T to
)
{
CompositeGenerator<T> between( T from, T to ) {
CompositeGenerator<T> generators;
generators.add( new BetweenGenerator<T>( from, to ) );
return generators;
}
///////////////////////////////////////////////////////////////////////////
template<typename T>
CompositeGenerator<T> values
(
T val1,
T val2
)
{
CompositeGenerator<T> values( T val1, T val2 ) {
CompositeGenerator<T> generators;
ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
valuesGen->add( val1 );
@ -258,15 +153,8 @@ namespace Generators
return generators;
}
///////////////////////////////////////////////////////////////////////////
template<typename T>
CompositeGenerator<T> values
(
T val1,
T val2,
T val3
)
{
CompositeGenerator<T> values( T val1, T val2, T val3 ){
CompositeGenerator<T> generators;
ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
valuesGen->add( val1 );
@ -276,16 +164,8 @@ namespace Generators
return generators;
}
///////////////////////////////////////////////////////////////////////////
template<typename T>
CompositeGenerator<T> values
(
T val1,
T val2,
T val3,
T val4
)
{
CompositeGenerator<T> values( T val1, T val2, T val3, T val4 ) {
CompositeGenerator<T> generators;
ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
valuesGen->add( val1 );

View File

@ -8,16 +8,12 @@
#ifndef TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED
namespace Catch
{
namespace Matchers
{
namespace Impl
{
namespace StdString
{
struct Contains
{
namespace Catch {
namespace Matchers {
namespace Impl {
namespace StdString {
struct Contains {
Contains( const std::string& substr ) : m_substr( substr ){}
bool operator()( const std::string& str ) const
@ -33,8 +29,7 @@ namespace Matchers
std::string m_substr;
};
struct StartsWith
{
struct StartsWith {
StartsWith( const std::string& substr ) : m_substr( substr ){}
bool operator()( const std::string& str ) const
@ -50,8 +45,7 @@ namespace Matchers
std::string m_substr;
};
struct EndsWith
{
struct EndsWith {
EndsWith( const std::string& substr ) : m_substr( substr ){}
bool operator()( const std::string& str ) const

View File

@ -1,51 +1,40 @@
/*
* catch_result_type.h
* Catch
*
* Created by Phil on 07/01/2011.
* Copyright 2011 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)
*
*/
#ifndef TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED
#define TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED
namespace Catch
{
namespace Catch {
struct ResultWas{ enum OfType
{
Unknown = -1,
Ok = 0,
Info = 1,
Warning = 2,
FailureBit = 0x10,
ExpressionFailed = FailureBit | 1,
ExplicitFailure = FailureBit | 2,
Exception = 0x100 | FailureBit,
ThrewException = Exception | 1,
DidntThrowException = Exception | 2
}; };
struct ResultWas { enum OfType {
Unknown = -1,
Ok = 0,
Info = 1,
Warning = 2,
FailureBit = 0x10,
ExpressionFailed = FailureBit | 1,
ExplicitFailure = FailureBit | 2,
Exception = 0x100 | FailureBit,
ThrewException = Exception | 1,
DidntThrowException = Exception | 2
}; };
struct ResultAction
{
enum Value
{
None,
Failed = 1, // Failure - but no debug break if Debug bit not set
DebugFailed = 3 // Indicates that the debugger should break, if possible
};
};
struct ResultAction { enum Value {
None,
Failed = 1, // Failure - but no debug break if Debug bit not set
DebugFailed = 3 // Indicates that the debugger should break, if possible
}; };
}
#endif // TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED

View File

@ -1,13 +1,9 @@
/*
* catch_resultinfo.hpp
* Catch
*
* Created by Phil on 28/10/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)
*
*/
#ifndef TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED
@ -15,15 +11,11 @@
#include <string>
#include "catch_result_type.h"
namespace Catch
{
class ResultInfo
{
namespace Catch {
class ResultInfo {
public:
///////////////////////////////////////////////////////////////////////////
ResultInfo
()
ResultInfo()
: m_macroName(),
m_expr(),
m_lhs(),
@ -34,16 +26,12 @@ namespace Catch
m_isNot( false )
{}
///////////////////////////////////////////////////////////////////////////
ResultInfo
(
const char* expr,
ResultWas::OfType result,
bool isNot,
const SourceLineInfo& lineInfo,
const char* macroName,
const char* message
)
ResultInfo( const char* expr,
ResultWas::OfType result,
bool isNot,
const SourceLineInfo& lineInfo,
const char* macroName,
const char* message )
: m_macroName( macroName ),
m_lineInfo( lineInfo ),
m_expr( expr ),
@ -52,113 +40,61 @@ namespace Catch
m_op( isNotExpression( expr ) ? "!" : "" ),
m_message( message ),
m_result( result ),
m_isNot( isNot )
m_isNot( isNot )
{
if( isNot )
m_expr = "!" + m_expr;
}
///////////////////////////////////////////////////////////////////////////
virtual ~ResultInfo
()
{
}
virtual ~ResultInfo() {}
///////////////////////////////////////////////////////////////////////////
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;
}
///////////////////////////////////////////////////////////////////////////
bool hasExpandedExpression
()
const
{
bool hasExpandedExpression() const {
return hasExpression() && getExpandedExpressionInternal() != m_expr;
}
///////////////////////////////////////////////////////////////////////////
std::string getExpandedExpression
()
const
{
std::string getExpandedExpression() const {
return hasExpression() ? getExpandedExpressionInternal() : "";
}
///////////////////////////////////////////////////////////////////////////
std::string getMessage
()
const
{
std::string getMessage() const {
return m_message;
}
///////////////////////////////////////////////////////////////////////////
std::string getFilename
()
const
{
std::string getFilename() const {
return m_lineInfo.file;
}
///////////////////////////////////////////////////////////////////////////
std::size_t getLine
()
const
{
std::size_t getLine() const {
return m_lineInfo.line;
}
///////////////////////////////////////////////////////////////////////////
std::string getTestMacroName
()
const
{
std::string getTestMacroName() const {
return m_macroName;
}
protected:
///////////////////////////////////////////////////////////////////////////
std::string getExpandedExpressionInternal
()
const
{
std::string getExpandedExpressionInternal() const {
if( m_op == "" || m_isNot )
return m_lhs.empty() ? m_expr : m_op + m_lhs;
else if( m_op == "matches" )
@ -176,12 +112,7 @@ namespace Catch
return "{can't expand - use " + m_macroName + "_FALSE( " + m_expr.substr(1) + " ) instead of " + m_macroName + "( " + m_expr + " ) for better diagnostics}";
}
///////////////////////////////////////////////////////////////////////////
bool isNotExpression
(
const char* expr
)
{
bool isNotExpression( const char* expr ) {
return expr && expr[0] == '!';
}
@ -196,5 +127,4 @@ namespace Catch
} // end namespace Catch
#endif // TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED

View File

@ -14,8 +14,7 @@
#include "catch_evaluate.hpp"
#include "catch_common.h"
namespace Catch
{
namespace Catch {
struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;

View File

@ -1,15 +1,10 @@
/*
* catch_section.hpp
* Catch
*
* Created by Phil on 03/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)
*
*/
#ifndef TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED
@ -18,36 +13,24 @@
#include <string>
namespace Catch
{
class Section
{
namespace Catch{
class Section {
public:
///////////////////////////////////////////////////////////////////////
Section
(
const std::string& name,
const std::string& description,
const SourceLineInfo& lineInfo
)
Section( const std::string& name,
const std::string& description,
const SourceLineInfo& lineInfo )
: m_name( name ),
m_sectionIncluded( Context::getResultCapture().sectionStarted( name, description, lineInfo, m_assertions ) )
{
}
{}
///////////////////////////////////////////////////////////////////////
~Section
()
{
~Section() {
if( m_sectionIncluded )
Context::getResultCapture().sectionEnded( m_name, m_assertions );
}
///////////////////////////////////////////////////////////////////////
// This indicates whether the section should be executed or not
operator bool
()
{
operator bool() {
return m_sectionIncluded;
}

View File

@ -11,10 +11,9 @@
#include "catch_common.h"
#include <sstream>
namespace Catch
{
namespace Detail
{
namespace Catch {
namespace Detail {
struct NonStreamable {
template<typename T> NonStreamable( const T& ){}
};