mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Reformatting
This commit is contained in:
parent
6acb36a996
commit
2efc1146bf
@ -1,13 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* catch_approx.hpp
|
|
||||||
* Catch
|
|
||||||
*
|
|
||||||
* Created by Phil on 28/04/2011.
|
* Created by Phil on 28/04/2011.
|
||||||
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
||||||
*
|
*
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
* 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)
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
#ifndef TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED
|
||||||
@ -17,140 +13,78 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
namespace Catch
|
namespace Catch {
|
||||||
{
|
namespace Detail {
|
||||||
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 )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
class Approx {
|
||||||
static Approx custom
|
public:
|
||||||
()
|
explicit Approx ( double value )
|
||||||
{
|
: m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
|
||||||
return Approx( 0 );
|
m_scale( 1.0 ),
|
||||||
}
|
m_value( value )
|
||||||
|
{}
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
Approx operator()
|
Approx( const Approx& other )
|
||||||
(
|
: m_epsilon( other.m_epsilon ),
|
||||||
double value
|
m_scale( other.m_scale ),
|
||||||
)
|
m_value( other.m_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 );
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
static Approx custom() {
|
||||||
friend bool operator !=
|
return Approx( 0 );
|
||||||
(
|
}
|
||||||
const Approx& lhs,
|
|
||||||
double rhs
|
Approx operator()( double value ) {
|
||||||
)
|
Approx approx( value );
|
||||||
{
|
approx.epsilon( m_epsilon );
|
||||||
return !operator==( rhs, lhs );
|
approx.scale( m_scale );
|
||||||
}
|
return approx;
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
friend bool operator == ( double lhs, const Approx& rhs ) {
|
||||||
Approx& epsilon
|
// 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) ) );
|
||||||
double newEpsilon
|
}
|
||||||
)
|
|
||||||
{
|
friend bool operator == ( const Approx& lhs, double rhs ) {
|
||||||
m_epsilon = newEpsilon;
|
return operator==( rhs, lhs );
|
||||||
return *this;
|
}
|
||||||
}
|
|
||||||
|
friend bool operator != ( double lhs, const Approx& rhs ) {
|
||||||
///////////////////////////////////////////////////////////////////////////
|
return !operator==( lhs, rhs );
|
||||||
Approx& scale
|
}
|
||||||
(
|
|
||||||
double newScale
|
friend bool operator != ( const Approx& lhs, double rhs ) {
|
||||||
)
|
return !operator==( rhs, lhs );
|
||||||
{
|
}
|
||||||
m_scale = newScale;
|
|
||||||
return *this;
|
Approx& epsilon( double newEpsilon ) {
|
||||||
}
|
m_epsilon = newEpsilon;
|
||||||
|
return *this;
|
||||||
///////////////////////////////////////////////////////////////////////////
|
}
|
||||||
std::string toString() const
|
|
||||||
{
|
Approx& scale( double newScale ) {
|
||||||
std::ostringstream oss;
|
m_scale = newScale;
|
||||||
oss << "Approx( " << m_value << ")";
|
return *this;
|
||||||
return oss.str();
|
}
|
||||||
}
|
|
||||||
|
std::string toString() const {
|
||||||
private:
|
std::ostringstream oss;
|
||||||
double m_epsilon;
|
oss << "Approx( " << m_value << ")";
|
||||||
double m_scale;
|
return oss.str();
|
||||||
double m_value;
|
}
|
||||||
};
|
|
||||||
}
|
private:
|
||||||
|
double m_epsilon;
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
double m_scale;
|
||||||
template<>
|
double m_value;
|
||||||
inline std::string toString<Detail::Approx>
|
};
|
||||||
(
|
}
|
||||||
const Detail::Approx& value
|
|
||||||
)
|
template<>
|
||||||
{
|
inline std::string toString<Detail::Approx>( const Detail::Approx& value ) {
|
||||||
return value.toString();
|
return value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
|
||||||
|
@ -15,13 +15,11 @@
|
|||||||
#include "catch_common.h"
|
#include "catch_common.h"
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
namespace Catch
|
namespace Catch {
|
||||||
{
|
|
||||||
|
|
||||||
struct TestFailureException{};
|
struct TestFailureException{};
|
||||||
|
|
||||||
class ScopedInfo
|
class ScopedInfo {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
ScopedInfo() : m_oss() {
|
ScopedInfo() : m_oss() {
|
||||||
Context::getResultCapture().pushScopedInfo( this );
|
Context::getResultCapture().pushScopedInfo( this );
|
||||||
|
@ -1,24 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
* catch_evaluate.hpp
|
|
||||||
* Catch
|
|
||||||
*
|
|
||||||
* Created by Phil on 04/03/2011.
|
* Created by Phil on 04/03/2011.
|
||||||
* Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
|
* Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
|
||||||
*
|
*
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
* 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)
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TWOBLUECUBES_CATCH_EVALUATE_HPP_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_EVALUATE_HPP_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_EVALUATE_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_EVALUATE_HPP_INCLUDED
|
||||||
|
|
||||||
namespace Catch
|
namespace Catch {
|
||||||
{
|
namespace Internal {
|
||||||
namespace Internal
|
|
||||||
{
|
enum Operator {
|
||||||
enum Operator
|
|
||||||
{
|
|
||||||
IsEqualTo,
|
IsEqualTo,
|
||||||
IsNotEqualTo,
|
IsNotEqualTo,
|
||||||
IsLessThan,
|
IsLessThan,
|
||||||
@ -54,146 +47,116 @@ namespace Internal
|
|||||||
class Evaluator{};
|
class Evaluator{};
|
||||||
|
|
||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
struct Evaluator<T1, T2, IsEqualTo>
|
struct Evaluator<T1, T2, IsEqualTo> {
|
||||||
{
|
static bool evaluate( const T1& lhs, const T2& rhs) {
|
||||||
static bool evaluate( const T1& lhs, const T2& rhs)
|
|
||||||
{
|
|
||||||
return const_cast<T1&>( lhs ) == const_cast<T2&>( rhs );
|
return const_cast<T1&>( lhs ) == const_cast<T2&>( rhs );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
struct Evaluator<T1, T2, IsNotEqualTo>
|
struct Evaluator<T1, T2, IsNotEqualTo> {
|
||||||
{
|
static bool evaluate( const T1& lhs, const T2& rhs ) {
|
||||||
static bool evaluate( const T1& lhs, const T2& rhs )
|
|
||||||
{
|
|
||||||
return const_cast<T1&>( lhs ) != const_cast<T2&>( rhs );
|
return const_cast<T1&>( lhs ) != const_cast<T2&>( rhs );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
struct Evaluator<T1, T2, IsLessThan>
|
struct Evaluator<T1, T2, IsLessThan> {
|
||||||
{
|
static bool evaluate( const T1& lhs, const T2& rhs ) {
|
||||||
static bool evaluate( const T1& lhs, const T2& rhs )
|
|
||||||
{
|
|
||||||
return const_cast<T1&>( lhs ) < const_cast<T2&>( rhs );
|
return const_cast<T1&>( lhs ) < const_cast<T2&>( rhs );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
struct Evaluator<T1, T2, IsGreaterThan>
|
struct Evaluator<T1, T2, IsGreaterThan> {
|
||||||
{
|
static bool evaluate( const T1& lhs, const T2& rhs ) {
|
||||||
static bool evaluate( const T1& lhs, const T2& rhs )
|
|
||||||
{
|
|
||||||
return const_cast<T1&>( lhs ) > const_cast<T2&>( rhs );
|
return const_cast<T1&>( lhs ) > const_cast<T2&>( rhs );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
struct Evaluator<T1, T2, IsGreaterThanOrEqualTo>
|
struct Evaluator<T1, T2, IsGreaterThanOrEqualTo> {
|
||||||
{
|
static bool evaluate( const T1& lhs, const T2& rhs ) {
|
||||||
static bool evaluate( const T1& lhs, const T2& rhs )
|
|
||||||
{
|
|
||||||
return const_cast<T1&>( lhs ) >= const_cast<T2&>( rhs );
|
return const_cast<T1&>( lhs ) >= const_cast<T2&>( rhs );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
struct Evaluator<T1, T2, IsLessThanOrEqualTo>
|
struct Evaluator<T1, T2, IsLessThanOrEqualTo> {
|
||||||
{
|
static bool evaluate( const T1& lhs, const T2& rhs ) {
|
||||||
static bool evaluate( const T1& lhs, const T2& rhs )
|
|
||||||
{
|
|
||||||
return const_cast<T1&>( lhs ) <= const_cast<T2&>( rhs );
|
return const_cast<T1&>( lhs ) <= const_cast<T2&>( rhs );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<Operator Op, typename T1, typename T2>
|
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 );
|
return Evaluator<T1, T2, Op>::evaluate( lhs, rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
// "base" overload
|
// "base" overload
|
||||||
template<Operator Op, typename T1, typename T2>
|
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 );
|
return Evaluator<T1, T2, Op>::evaluate( lhs, rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
// unsigned X to int
|
// 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 ) );
|
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 ) );
|
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 ) );
|
return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// unsigned X to long
|
// 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 ) );
|
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 ) );
|
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 ) );
|
return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// int to unsigned X
|
// 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 );
|
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 );
|
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 );
|
return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
// long to unsigned X
|
// 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 );
|
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 );
|
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 );
|
return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Operator Op, typename T>
|
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 );
|
return Evaluator<const T*, const T*, Op>::evaluate( reinterpret_cast<const T*>( lhs ), rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Operator Op, typename T>
|
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 );
|
return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Operator Op, typename T>
|
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 ) );
|
return Evaluator<const T*, const T*, Op>::evaluate( lhs, reinterpret_cast<const T*>( rhs ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Operator Op, typename T>
|
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 ) );
|
return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end of namespace Internal
|
} // end of namespace Internal
|
||||||
} // end of namespace Catch
|
} // end of namespace Catch
|
||||||
|
@ -11,12 +11,10 @@
|
|||||||
#include "catch_resultinfo_builder.hpp"
|
#include "catch_resultinfo_builder.hpp"
|
||||||
#include "catch_evaluate.hpp"
|
#include "catch_evaluate.hpp"
|
||||||
|
|
||||||
namespace Catch
|
namespace Catch {
|
||||||
{
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class Expression
|
class Expression {
|
||||||
{
|
|
||||||
void operator = ( const Expression& );
|
void operator = ( const Expression& );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -79,8 +77,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename LhsT>
|
template<typename LhsT>
|
||||||
class PtrExpression
|
class PtrExpression {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PtrExpression ( ResultInfoBuilder& result, const LhsT* lhs )
|
PtrExpression ( ResultInfoBuilder& result, const LhsT* lhs )
|
||||||
|
@ -1,15 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* catch_generators.hpp
|
|
||||||
* Catch
|
|
||||||
*
|
|
||||||
* Created by Phil on 27/01/2011.
|
* Created by Phil on 27/01/2011.
|
||||||
* Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
|
* Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
|
||||||
*
|
*
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
* 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)
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED
|
||||||
|
|
||||||
@ -20,54 +15,25 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
namespace Catch
|
namespace Catch {
|
||||||
{
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct IGenerator
|
struct IGenerator {
|
||||||
{
|
virtual ~IGenerator() {}
|
||||||
virtual ~IGenerator
|
virtual T getValue( std::size_t index ) const = 0;
|
||||||
()
|
virtual std::size_t size () const = 0;
|
||||||
{}
|
|
||||||
|
|
||||||
virtual T getValue
|
|
||||||
( std::size_t index
|
|
||||||
) const = 0;
|
|
||||||
|
|
||||||
virtual std::size_t size
|
|
||||||
() const = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class BetweenGenerator : public IGenerator<T>
|
class BetweenGenerator : public IGenerator<T> {
|
||||||
{
|
|
||||||
public:
|
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 );
|
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 );
|
return static_cast<std::size_t>( 1+m_to-m_from );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,88 +44,49 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class ValuesGenerator : public IGenerator<T>
|
class ValuesGenerator : public IGenerator<T> {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
///////////////////////////////////////////////////////////////////////////
|
ValuesGenerator(){}
|
||||||
ValuesGenerator
|
|
||||||
()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
void add( T value ) {
|
||||||
void add
|
|
||||||
(
|
|
||||||
T value
|
|
||||||
)
|
|
||||||
{
|
|
||||||
m_values.push_back( 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];
|
return m_values[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
virtual std::size_t size() const {
|
||||||
virtual std::size_t size
|
|
||||||
()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return m_values.size();
|
return m_values.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::vector<T> m_values;
|
std::vector<T> m_values;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class CompositeGenerator
|
class CompositeGenerator {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
///////////////////////////////////////////////////////////////////////////
|
CompositeGenerator() : m_totalSize( 0 ) {}
|
||||||
CompositeGenerator()
|
|
||||||
: m_totalSize( 0 )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
// *** Move semantics, similar to auto_ptr ***
|
// *** Move semantics, similar to auto_ptr ***
|
||||||
CompositeGenerator( CompositeGenerator& other )
|
CompositeGenerator( CompositeGenerator& other )
|
||||||
: m_fileInfo( other.m_fileInfo ),
|
: m_fileInfo( other.m_fileInfo ),
|
||||||
m_totalSize( 0 )
|
m_totalSize( 0 )
|
||||||
{
|
{
|
||||||
move( other );
|
move( other );
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
CompositeGenerator& setFileInfo( const char* fileInfo ) {
|
||||||
CompositeGenerator& setFileInfo
|
|
||||||
(
|
|
||||||
const char* fileInfo
|
|
||||||
)
|
|
||||||
{
|
|
||||||
m_fileInfo = fileInfo;
|
m_fileInfo = fileInfo;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
~CompositeGenerator() {
|
||||||
~CompositeGenerator
|
|
||||||
()
|
|
||||||
{
|
|
||||||
deleteAll( m_composed );
|
deleteAll( m_composed );
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
operator T () const {
|
||||||
operator T
|
|
||||||
()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
size_t overallIndex = Context::getGeneratorIndex( m_fileInfo, m_totalSize );
|
size_t overallIndex = Context::getGeneratorIndex( m_fileInfo, m_totalSize );
|
||||||
|
|
||||||
typename std::vector<const IGenerator<T>*>::const_iterator it = m_composed.begin();
|
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
|
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_totalSize += generator->size();
|
||||||
m_composed.push_back( generator );
|
m_composed.push_back( generator );
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
CompositeGenerator& then( CompositeGenerator& other ) {
|
||||||
CompositeGenerator& then
|
|
||||||
(
|
|
||||||
CompositeGenerator& other
|
|
||||||
)
|
|
||||||
{
|
|
||||||
move( other );
|
move( other );
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
CompositeGenerator& then( T value ) {
|
||||||
CompositeGenerator& then
|
|
||||||
(
|
|
||||||
T value
|
|
||||||
)
|
|
||||||
{
|
|
||||||
ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
|
ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
|
||||||
valuesGen->add( value );
|
valuesGen->add( value );
|
||||||
add( valuesGen );
|
add( valuesGen );
|
||||||
@ -211,12 +123,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
void move( CompositeGenerator& other ) {
|
||||||
void move
|
|
||||||
(
|
|
||||||
CompositeGenerator& other
|
|
||||||
)
|
|
||||||
{
|
|
||||||
std::copy( other.m_composed.begin(), other.m_composed.end(), std::back_inserter( m_composed ) );
|
std::copy( other.m_composed.begin(), other.m_composed.end(), std::back_inserter( m_composed ) );
|
||||||
m_totalSize += other.m_totalSize;
|
m_totalSize += other.m_totalSize;
|
||||||
other.m_composed.clear();
|
other.m_composed.clear();
|
||||||
@ -229,27 +136,15 @@ private:
|
|||||||
|
|
||||||
namespace Generators
|
namespace Generators
|
||||||
{
|
{
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
CompositeGenerator<T> between
|
CompositeGenerator<T> between( T from, T to ) {
|
||||||
(
|
|
||||||
T from,
|
|
||||||
T to
|
|
||||||
)
|
|
||||||
{
|
|
||||||
CompositeGenerator<T> generators;
|
CompositeGenerator<T> generators;
|
||||||
generators.add( new BetweenGenerator<T>( from, to ) );
|
generators.add( new BetweenGenerator<T>( from, to ) );
|
||||||
return generators;
|
return generators;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
CompositeGenerator<T> values
|
CompositeGenerator<T> values( T val1, T val2 ) {
|
||||||
(
|
|
||||||
T val1,
|
|
||||||
T val2
|
|
||||||
)
|
|
||||||
{
|
|
||||||
CompositeGenerator<T> generators;
|
CompositeGenerator<T> generators;
|
||||||
ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
|
ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
|
||||||
valuesGen->add( val1 );
|
valuesGen->add( val1 );
|
||||||
@ -258,15 +153,8 @@ namespace Generators
|
|||||||
return generators;
|
return generators;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
CompositeGenerator<T> values
|
CompositeGenerator<T> values( T val1, T val2, T val3 ){
|
||||||
(
|
|
||||||
T val1,
|
|
||||||
T val2,
|
|
||||||
T val3
|
|
||||||
)
|
|
||||||
{
|
|
||||||
CompositeGenerator<T> generators;
|
CompositeGenerator<T> generators;
|
||||||
ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
|
ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
|
||||||
valuesGen->add( val1 );
|
valuesGen->add( val1 );
|
||||||
@ -276,16 +164,8 @@ namespace Generators
|
|||||||
return generators;
|
return generators;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
CompositeGenerator<T> values
|
CompositeGenerator<T> values( T val1, T val2, T val3, T val4 ) {
|
||||||
(
|
|
||||||
T val1,
|
|
||||||
T val2,
|
|
||||||
T val3,
|
|
||||||
T val4
|
|
||||||
)
|
|
||||||
{
|
|
||||||
CompositeGenerator<T> generators;
|
CompositeGenerator<T> generators;
|
||||||
ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
|
ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
|
||||||
valuesGen->add( val1 );
|
valuesGen->add( val1 );
|
||||||
|
@ -8,16 +8,12 @@
|
|||||||
#ifndef TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED
|
||||||
|
|
||||||
namespace Catch
|
namespace Catch {
|
||||||
{
|
namespace Matchers {
|
||||||
namespace Matchers
|
namespace Impl {
|
||||||
{
|
namespace StdString {
|
||||||
namespace Impl
|
|
||||||
{
|
struct Contains {
|
||||||
namespace StdString
|
|
||||||
{
|
|
||||||
struct Contains
|
|
||||||
{
|
|
||||||
Contains( const std::string& substr ) : m_substr( substr ){}
|
Contains( const std::string& substr ) : m_substr( substr ){}
|
||||||
|
|
||||||
bool operator()( const std::string& str ) const
|
bool operator()( const std::string& str ) const
|
||||||
@ -33,8 +29,7 @@ namespace Matchers
|
|||||||
std::string m_substr;
|
std::string m_substr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct StartsWith
|
struct StartsWith {
|
||||||
{
|
|
||||||
StartsWith( const std::string& substr ) : m_substr( substr ){}
|
StartsWith( const std::string& substr ) : m_substr( substr ){}
|
||||||
|
|
||||||
bool operator()( const std::string& str ) const
|
bool operator()( const std::string& str ) const
|
||||||
@ -50,8 +45,7 @@ namespace Matchers
|
|||||||
std::string m_substr;
|
std::string m_substr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct EndsWith
|
struct EndsWith {
|
||||||
{
|
|
||||||
EndsWith( const std::string& substr ) : m_substr( substr ){}
|
EndsWith( const std::string& substr ) : m_substr( substr ){}
|
||||||
|
|
||||||
bool operator()( const std::string& str ) const
|
bool operator()( const std::string& str ) const
|
||||||
|
@ -1,51 +1,40 @@
|
|||||||
/*
|
/*
|
||||||
* catch_result_type.h
|
|
||||||
* Catch
|
|
||||||
*
|
|
||||||
* Created by Phil on 07/01/2011.
|
* Created by Phil on 07/01/2011.
|
||||||
* Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
|
* Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
|
||||||
*
|
*
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
* 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)
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED
|
#define TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED
|
||||||
|
|
||||||
namespace Catch
|
namespace Catch {
|
||||||
{
|
|
||||||
|
|
||||||
struct ResultWas{ enum OfType
|
struct ResultWas { enum OfType {
|
||||||
{
|
Unknown = -1,
|
||||||
Unknown = -1,
|
Ok = 0,
|
||||||
Ok = 0,
|
Info = 1,
|
||||||
Info = 1,
|
Warning = 2,
|
||||||
Warning = 2,
|
|
||||||
|
FailureBit = 0x10,
|
||||||
FailureBit = 0x10,
|
|
||||||
|
ExpressionFailed = FailureBit | 1,
|
||||||
ExpressionFailed = FailureBit | 1,
|
ExplicitFailure = FailureBit | 2,
|
||||||
ExplicitFailure = FailureBit | 2,
|
|
||||||
|
Exception = 0x100 | FailureBit,
|
||||||
Exception = 0x100 | FailureBit,
|
|
||||||
|
ThrewException = Exception | 1,
|
||||||
ThrewException = Exception | 1,
|
DidntThrowException = Exception | 2
|
||||||
DidntThrowException = Exception | 2
|
|
||||||
|
}; };
|
||||||
}; };
|
|
||||||
|
|
||||||
struct ResultAction
|
struct ResultAction { enum Value {
|
||||||
{
|
None,
|
||||||
enum Value
|
Failed = 1, // Failure - but no debug break if Debug bit not set
|
||||||
{
|
DebugFailed = 3 // Indicates that the debugger should break, if possible
|
||||||
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
|
#endif // TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* catch_resultinfo.hpp
|
|
||||||
* Catch
|
|
||||||
*
|
|
||||||
* Created by Phil on 28/10/2010.
|
* Created by Phil on 28/10/2010.
|
||||||
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
||||||
*
|
*
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
* 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)
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
#ifndef TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED
|
||||||
@ -15,15 +11,11 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "catch_result_type.h"
|
#include "catch_result_type.h"
|
||||||
|
|
||||||
namespace Catch
|
namespace Catch {
|
||||||
{
|
|
||||||
class ResultInfo
|
class ResultInfo {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
|
ResultInfo()
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
ResultInfo
|
|
||||||
()
|
|
||||||
: m_macroName(),
|
: m_macroName(),
|
||||||
m_expr(),
|
m_expr(),
|
||||||
m_lhs(),
|
m_lhs(),
|
||||||
@ -34,16 +26,12 @@ namespace Catch
|
|||||||
m_isNot( false )
|
m_isNot( false )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
ResultInfo( const char* expr,
|
||||||
ResultInfo
|
ResultWas::OfType result,
|
||||||
(
|
bool isNot,
|
||||||
const char* expr,
|
const SourceLineInfo& lineInfo,
|
||||||
ResultWas::OfType result,
|
const char* macroName,
|
||||||
bool isNot,
|
const char* message )
|
||||||
const SourceLineInfo& lineInfo,
|
|
||||||
const char* macroName,
|
|
||||||
const char* message
|
|
||||||
)
|
|
||||||
: m_macroName( macroName ),
|
: m_macroName( macroName ),
|
||||||
m_lineInfo( lineInfo ),
|
m_lineInfo( lineInfo ),
|
||||||
m_expr( expr ),
|
m_expr( expr ),
|
||||||
@ -52,113 +40,61 @@ namespace Catch
|
|||||||
m_op( isNotExpression( expr ) ? "!" : "" ),
|
m_op( isNotExpression( expr ) ? "!" : "" ),
|
||||||
m_message( message ),
|
m_message( message ),
|
||||||
m_result( result ),
|
m_result( result ),
|
||||||
m_isNot( isNot )
|
m_isNot( isNot )
|
||||||
{
|
{
|
||||||
if( isNot )
|
if( isNot )
|
||||||
m_expr = "!" + m_expr;
|
m_expr = "!" + m_expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
virtual ~ResultInfo() {}
|
||||||
virtual ~ResultInfo
|
|
||||||
()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
bool ok() const {
|
||||||
bool ok
|
|
||||||
()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return ( m_result & ResultWas::FailureBit ) != ResultWas::FailureBit;
|
return ( m_result & ResultWas::FailureBit ) != ResultWas::FailureBit;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
ResultWas::OfType getResultType() const {
|
||||||
ResultWas::OfType getResultType
|
|
||||||
()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return m_result;
|
return m_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
bool hasExpression() const {
|
||||||
bool hasExpression
|
|
||||||
()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return !m_expr.empty();
|
return !m_expr.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
bool hasMessage() const {
|
||||||
bool hasMessage
|
|
||||||
()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return !m_message.empty();
|
return !m_message.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
std::string getExpression() const {
|
||||||
std::string getExpression
|
|
||||||
()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return m_expr;
|
return m_expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
bool hasExpandedExpression() const {
|
||||||
bool hasExpandedExpression
|
|
||||||
()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return hasExpression() && getExpandedExpressionInternal() != m_expr;
|
return hasExpression() && getExpandedExpressionInternal() != m_expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
std::string getExpandedExpression() const {
|
||||||
std::string getExpandedExpression
|
|
||||||
()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return hasExpression() ? getExpandedExpressionInternal() : "";
|
return hasExpression() ? getExpandedExpressionInternal() : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
std::string getMessage() const {
|
||||||
std::string getMessage
|
|
||||||
()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return m_message;
|
return m_message;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
std::string getFilename() const {
|
||||||
std::string getFilename
|
|
||||||
()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return m_lineInfo.file;
|
return m_lineInfo.file;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
std::size_t getLine() const {
|
||||||
std::size_t getLine
|
|
||||||
()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return m_lineInfo.line;
|
return m_lineInfo.line;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
std::string getTestMacroName() const {
|
||||||
std::string getTestMacroName
|
|
||||||
()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return m_macroName;
|
return m_macroName;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
std::string getExpandedExpressionInternal() const {
|
||||||
std::string getExpandedExpressionInternal
|
|
||||||
()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
if( m_op == "" || m_isNot )
|
if( m_op == "" || m_isNot )
|
||||||
return m_lhs.empty() ? m_expr : m_op + m_lhs;
|
return m_lhs.empty() ? m_expr : m_op + m_lhs;
|
||||||
else if( m_op == "matches" )
|
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}";
|
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] == '!';
|
return expr && expr[0] == '!';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,5 +127,4 @@ namespace Catch
|
|||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED
|
||||||
|
@ -14,8 +14,7 @@
|
|||||||
#include "catch_evaluate.hpp"
|
#include "catch_evaluate.hpp"
|
||||||
#include "catch_common.h"
|
#include "catch_common.h"
|
||||||
|
|
||||||
namespace Catch
|
namespace Catch {
|
||||||
{
|
|
||||||
|
|
||||||
struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
|
struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
|
||||||
|
|
||||||
|
@ -1,15 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* catch_section.hpp
|
|
||||||
* Catch
|
|
||||||
*
|
|
||||||
* Created by Phil on 03/11/2010.
|
* Created by Phil on 03/11/2010.
|
||||||
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
||||||
*
|
*
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
* 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)
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED
|
||||||
|
|
||||||
@ -18,36 +13,24 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Catch
|
namespace Catch{
|
||||||
{
|
|
||||||
class Section
|
class Section {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
///////////////////////////////////////////////////////////////////////
|
Section( const std::string& name,
|
||||||
Section
|
const std::string& description,
|
||||||
(
|
const SourceLineInfo& lineInfo )
|
||||||
const std::string& name,
|
|
||||||
const std::string& description,
|
|
||||||
const SourceLineInfo& lineInfo
|
|
||||||
)
|
|
||||||
: m_name( name ),
|
: m_name( name ),
|
||||||
m_sectionIncluded( Context::getResultCapture().sectionStarted( name, description, lineInfo, m_assertions ) )
|
m_sectionIncluded( Context::getResultCapture().sectionStarted( name, description, lineInfo, m_assertions ) )
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
~Section() {
|
||||||
~Section
|
|
||||||
()
|
|
||||||
{
|
|
||||||
if( m_sectionIncluded )
|
if( m_sectionIncluded )
|
||||||
Context::getResultCapture().sectionEnded( m_name, m_assertions );
|
Context::getResultCapture().sectionEnded( m_name, m_assertions );
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
|
||||||
// This indicates whether the section should be executed or not
|
// This indicates whether the section should be executed or not
|
||||||
operator bool
|
operator bool() {
|
||||||
()
|
|
||||||
{
|
|
||||||
return m_sectionIncluded;
|
return m_sectionIncluded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,10 +11,9 @@
|
|||||||
#include "catch_common.h"
|
#include "catch_common.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace Catch
|
namespace Catch {
|
||||||
{
|
namespace Detail {
|
||||||
namespace Detail
|
|
||||||
{
|
|
||||||
struct NonStreamable {
|
struct NonStreamable {
|
||||||
template<typename T> NonStreamable( const T& ){}
|
template<typename T> NonStreamable( const T& ){}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user