mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-04 05:09:53 +01:00
Exception message assertions now work with matchers
This commit is contained in:
parent
8342ae8dfb
commit
72868920bb
@ -72,7 +72,7 @@
|
|||||||
|
|
||||||
#define CATCH_REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, "", "CATCH_REQUIRE_THROWS" )
|
#define CATCH_REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, "", "CATCH_REQUIRE_THROWS" )
|
||||||
#define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_THROWS_AS" )
|
#define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_THROWS_AS" )
|
||||||
#define CATCH_REQUIRE_THROWS_WITH( expr, expectedMessage ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, expectedMessage, "CATCH_REQUIRE_THROWS_WITH" )
|
#define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, matcher, "CATCH_REQUIRE_THROWS_WITH" )
|
||||||
#define CATCH_REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_NOTHROW" )
|
#define CATCH_REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_NOTHROW" )
|
||||||
|
|
||||||
#define CATCH_CHECK( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK" )
|
#define CATCH_CHECK( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK" )
|
||||||
@ -83,7 +83,7 @@
|
|||||||
|
|
||||||
#define CATCH_CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THROWS" )
|
#define CATCH_CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THROWS" )
|
||||||
#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THROWS_AS" )
|
#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THROWS_AS" )
|
||||||
#define CATCH_CHECK_THROWS_WITH( expr, expectedMessage ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, expectedMessage, "CATCH_CHECK_THROWS_WITH" )
|
#define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, matcher, "CATCH_CHECK_THROWS_WITH" )
|
||||||
#define CATCH_CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_NOTHROW" )
|
#define CATCH_CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_NOTHROW" )
|
||||||
|
|
||||||
#define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THAT" )
|
#define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THAT" )
|
||||||
@ -139,7 +139,7 @@
|
|||||||
|
|
||||||
#define REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, "", "REQUIRE_THROWS" )
|
#define REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, "", "REQUIRE_THROWS" )
|
||||||
#define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::Normal, "REQUIRE_THROWS_AS" )
|
#define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::Normal, "REQUIRE_THROWS_AS" )
|
||||||
#define REQUIRE_THROWS_WITH( expr, expectedMessage ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, expectedMessage, "REQUIRE_THROWS_WITH" )
|
#define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, matcher, "REQUIRE_THROWS_WITH" )
|
||||||
#define REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::Normal, "REQUIRE_NOTHROW" )
|
#define REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::Normal, "REQUIRE_NOTHROW" )
|
||||||
|
|
||||||
#define CHECK( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECK" )
|
#define CHECK( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECK" )
|
||||||
@ -150,7 +150,7 @@
|
|||||||
|
|
||||||
#define CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, "", "CHECK_THROWS" )
|
#define CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, "", "CHECK_THROWS" )
|
||||||
#define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::ContinueOnFailure, "CHECK_THROWS_AS" )
|
#define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::ContinueOnFailure, "CHECK_THROWS_AS" )
|
||||||
#define CHECK_THROWS_WITH( expr, expectedMessage ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, expectedMessage, "CHECK_THROWS_WITH" )
|
#define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, matcher, "CHECK_THROWS_WITH" )
|
||||||
#define CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECK_NOTHROW" )
|
#define CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECK_NOTHROW" )
|
||||||
|
|
||||||
#define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::ContinueOnFailure, "CHECK_THAT" )
|
#define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::ContinueOnFailure, "CHECK_THAT" )
|
||||||
|
@ -66,16 +66,16 @@
|
|||||||
} while( Catch::alwaysFalse() )
|
} while( Catch::alwaysFalse() )
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_THROWS( expr, resultDisposition, expectedMessage, macroName ) \
|
#define INTERNAL_CATCH_THROWS( expr, resultDisposition, matcher, macroName ) \
|
||||||
do { \
|
do { \
|
||||||
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition, expectedMessage ); \
|
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition, #matcher ); \
|
||||||
if( __catchResult.allowThrows() ) \
|
if( __catchResult.allowThrows() ) \
|
||||||
try { \
|
try { \
|
||||||
expr; \
|
expr; \
|
||||||
__catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \
|
__catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \
|
||||||
} \
|
} \
|
||||||
catch( ... ) { \
|
catch( ... ) { \
|
||||||
__catchResult.captureExpectedException( expectedMessage ); \
|
__catchResult.captureExpectedException( matcher ); \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
__catchResult.captureResult( Catch::ResultWas::Ok ); \
|
__catchResult.captureResult( Catch::ResultWas::Ok ); \
|
||||||
|
@ -25,6 +25,11 @@ namespace Catch {
|
|||||||
|
|
||||||
struct IConfig;
|
struct IConfig;
|
||||||
|
|
||||||
|
struct CaseSensitive { enum Choice {
|
||||||
|
Yes,
|
||||||
|
No
|
||||||
|
}; };
|
||||||
|
|
||||||
class NonCopyable {
|
class NonCopyable {
|
||||||
#ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
|
#ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
|
||||||
NonCopyable( NonCopyable const& ) = delete;
|
NonCopyable( NonCopyable const& ) = delete;
|
||||||
|
@ -108,68 +108,96 @@ namespace Matchers {
|
|||||||
inline std::string makeString( std::string const& str ) { return str; }
|
inline std::string makeString( std::string const& str ) { return str; }
|
||||||
inline std::string makeString( const char* str ) { return str ? std::string( str ) : std::string(); }
|
inline std::string makeString( const char* str ) { return str ? std::string( str ) : std::string(); }
|
||||||
|
|
||||||
|
struct CasedString
|
||||||
|
{
|
||||||
|
CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity )
|
||||||
|
: m_caseSensitivity( caseSensitivity ),
|
||||||
|
m_str( adjustString( str ) )
|
||||||
|
{}
|
||||||
|
std::string adjustString( std::string const& str ) const {
|
||||||
|
return m_caseSensitivity == CaseSensitive::No
|
||||||
|
? toLower( str )
|
||||||
|
: str;
|
||||||
|
|
||||||
|
}
|
||||||
|
std::string toStringSuffix() const
|
||||||
|
{
|
||||||
|
return m_caseSensitivity == CaseSensitive::No
|
||||||
|
? " (case insensitive)"
|
||||||
|
: "";
|
||||||
|
}
|
||||||
|
CaseSensitive::Choice m_caseSensitivity;
|
||||||
|
std::string m_str;
|
||||||
|
};
|
||||||
|
|
||||||
struct Equals : MatcherImpl<Equals, std::string> {
|
struct Equals : MatcherImpl<Equals, std::string> {
|
||||||
Equals( std::string const& str ) : m_str( str ){}
|
Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes )
|
||||||
Equals( Equals const& other ) : m_str( other.m_str ){}
|
: m_data( str, caseSensitivity )
|
||||||
|
{}
|
||||||
|
Equals( Equals const& other ) : m_data( other.m_data ){}
|
||||||
|
|
||||||
virtual ~Equals();
|
virtual ~Equals();
|
||||||
|
|
||||||
virtual bool match( std::string const& expr ) const {
|
virtual bool match( std::string const& expr ) const {
|
||||||
return m_str == expr;
|
return m_data.m_str == m_data.adjustString( expr );;
|
||||||
}
|
}
|
||||||
virtual std::string toString() const {
|
virtual std::string toString() const {
|
||||||
return "equals: \"" + m_str + "\"";
|
return "equals: \"" + m_data.m_str + "\"" + m_data.toStringSuffix();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string m_str;
|
CasedString m_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Contains : MatcherImpl<Contains, std::string> {
|
struct Contains : MatcherImpl<Contains, std::string> {
|
||||||
Contains( std::string const& substr ) : m_substr( substr ){}
|
Contains( std::string const& substr, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes )
|
||||||
Contains( Contains const& other ) : m_substr( other.m_substr ){}
|
: m_data( substr, caseSensitivity ){}
|
||||||
|
Contains( Contains const& other ) : m_data( other.m_data ){}
|
||||||
|
|
||||||
virtual ~Contains();
|
virtual ~Contains();
|
||||||
|
|
||||||
virtual bool match( std::string const& expr ) const {
|
virtual bool match( std::string const& expr ) const {
|
||||||
return expr.find( m_substr ) != std::string::npos;
|
return m_data.adjustString( expr ).find( m_data.m_str ) != std::string::npos;
|
||||||
}
|
}
|
||||||
virtual std::string toString() const {
|
virtual std::string toString() const {
|
||||||
return "contains: \"" + m_substr + "\"";
|
return "contains: \"" + m_data.m_str + "\"" + m_data.toStringSuffix();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string m_substr;
|
CasedString m_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct StartsWith : MatcherImpl<StartsWith, std::string> {
|
struct StartsWith : MatcherImpl<StartsWith, std::string> {
|
||||||
StartsWith( std::string const& substr ) : m_substr( substr ){}
|
StartsWith( std::string const& substr, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes )
|
||||||
StartsWith( StartsWith const& other ) : m_substr( other.m_substr ){}
|
: m_data( substr, caseSensitivity ){}
|
||||||
|
|
||||||
|
StartsWith( StartsWith const& other ) : m_data( other.m_data ){}
|
||||||
|
|
||||||
virtual ~StartsWith();
|
virtual ~StartsWith();
|
||||||
|
|
||||||
virtual bool match( std::string const& expr ) const {
|
virtual bool match( std::string const& expr ) const {
|
||||||
return expr.find( m_substr ) == 0;
|
return m_data.adjustString( expr ).find( m_data.m_str ) == 0;
|
||||||
}
|
}
|
||||||
virtual std::string toString() const {
|
virtual std::string toString() const {
|
||||||
return "starts with: \"" + m_substr + "\"";
|
return "starts with: \"" + m_data.m_str + "\"" + m_data.toStringSuffix();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string m_substr;
|
CasedString m_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct EndsWith : MatcherImpl<EndsWith, std::string> {
|
struct EndsWith : MatcherImpl<EndsWith, std::string> {
|
||||||
EndsWith( std::string const& substr ) : m_substr( substr ){}
|
EndsWith( std::string const& substr, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes )
|
||||||
EndsWith( EndsWith const& other ) : m_substr( other.m_substr ){}
|
: m_data( substr, caseSensitivity ){}
|
||||||
|
EndsWith( EndsWith const& other ) : m_data( other.m_data ){}
|
||||||
|
|
||||||
virtual ~EndsWith();
|
virtual ~EndsWith();
|
||||||
|
|
||||||
virtual bool match( std::string const& expr ) const {
|
virtual bool match( std::string const& expr ) const {
|
||||||
return expr.find( m_substr ) == expr.size() - m_substr.size();
|
return m_data.adjustString( expr ).find( m_data.m_str ) == expr.size() - m_data.m_str.size();
|
||||||
}
|
}
|
||||||
virtual std::string toString() const {
|
virtual std::string toString() const {
|
||||||
return "ends with: \"" + m_substr + "\"";
|
return "ends with: \"" + m_data.m_str + "\"" + m_data.toStringSuffix();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string m_substr;
|
CasedString m_data;
|
||||||
};
|
};
|
||||||
} // namespace StdString
|
} // namespace StdString
|
||||||
} // namespace Impl
|
} // namespace Impl
|
||||||
@ -199,17 +227,17 @@ namespace Matchers {
|
|||||||
return Impl::Generic::AnyOf<ExpressionT>().add( m1 ).add( m2 ).add( m3 );
|
return Impl::Generic::AnyOf<ExpressionT>().add( m1 ).add( m2 ).add( m3 );
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Impl::StdString::Equals Equals( std::string const& str ) {
|
inline Impl::StdString::Equals Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) {
|
||||||
return Impl::StdString::Equals( str );
|
return Impl::StdString::Equals( str, caseSensitivity );
|
||||||
}
|
}
|
||||||
inline Impl::StdString::Equals Equals( const char* str ) {
|
inline Impl::StdString::Equals Equals( const char* str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) {
|
||||||
return Impl::StdString::Equals( Impl::StdString::makeString( str ) );
|
return Impl::StdString::Equals( Impl::StdString::makeString( str ), caseSensitivity );
|
||||||
}
|
}
|
||||||
inline Impl::StdString::Contains Contains( std::string const& substr ) {
|
inline Impl::StdString::Contains Contains( std::string const& substr, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) {
|
||||||
return Impl::StdString::Contains( substr );
|
return Impl::StdString::Contains( substr, caseSensitivity );
|
||||||
}
|
}
|
||||||
inline Impl::StdString::Contains Contains( const char* substr ) {
|
inline Impl::StdString::Contains Contains( const char* substr, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) {
|
||||||
return Impl::StdString::Contains( Impl::StdString::makeString( substr ) );
|
return Impl::StdString::Contains( Impl::StdString::makeString( substr ), caseSensitivity );
|
||||||
}
|
}
|
||||||
inline Impl::StdString::StartsWith StartsWith( std::string const& substr ) {
|
inline Impl::StdString::StartsWith StartsWith( std::string const& substr ) {
|
||||||
return Impl::StdString::StartsWith( substr );
|
return Impl::StdString::StartsWith( substr );
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "catch_result_type.h"
|
#include "catch_result_type.h"
|
||||||
#include "catch_assertionresult.h"
|
#include "catch_assertionresult.h"
|
||||||
#include "catch_common.h"
|
#include "catch_common.h"
|
||||||
|
#include "catch_matchers.hpp"
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
@ -69,6 +70,7 @@ namespace Catch {
|
|||||||
void captureResult( ResultWas::OfType resultType );
|
void captureResult( ResultWas::OfType resultType );
|
||||||
void captureExpression();
|
void captureExpression();
|
||||||
void captureExpectedException( std::string const& expectedMessage );
|
void captureExpectedException( std::string const& expectedMessage );
|
||||||
|
void captureExpectedException( Matchers::Impl::Matcher<std::string> const& matcher );
|
||||||
void handleResult( AssertionResult const& result );
|
void handleResult( AssertionResult const& result );
|
||||||
void react();
|
void react();
|
||||||
bool shouldDebugBreak() const;
|
bool shouldDebugBreak() const;
|
||||||
|
@ -19,9 +19,9 @@
|
|||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
std::string capturedExpressionWithSecondArgument( std::string const& capturedExpression, std::string const& secondArg ) {
|
std::string capturedExpressionWithSecondArgument( std::string const& capturedExpression, std::string const& secondArg ) {
|
||||||
return secondArg.empty()
|
return secondArg.empty() || secondArg == "\"\""
|
||||||
? capturedExpression
|
? capturedExpression
|
||||||
: capturedExpression + ", \"" + secondArg + "\"";
|
: capturedExpression + ", " + secondArg;
|
||||||
}
|
}
|
||||||
ResultBuilder::ResultBuilder( char const* macroName,
|
ResultBuilder::ResultBuilder( char const* macroName,
|
||||||
SourceLineInfo const& lineInfo,
|
SourceLineInfo const& lineInfo,
|
||||||
@ -69,21 +69,25 @@ namespace Catch {
|
|||||||
setResultType( resultType );
|
setResultType( resultType );
|
||||||
captureExpression();
|
captureExpression();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResultBuilder::captureExpectedException( std::string const& expectedMessage ) {
|
void ResultBuilder::captureExpectedException( std::string const& expectedMessage ) {
|
||||||
|
if( expectedMessage.empty() )
|
||||||
|
captureExpectedException( Matchers::Impl::Generic::AllOf<std::string>() );
|
||||||
|
else
|
||||||
|
captureExpectedException( Matchers::Equals( expectedMessage ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResultBuilder::captureExpectedException( Matchers::Impl::Matcher<std::string> const& matcher ) {
|
||||||
|
|
||||||
assert( m_exprComponents.testFalse == false );
|
assert( m_exprComponents.testFalse == false );
|
||||||
AssertionResultData data = m_data;
|
AssertionResultData data = m_data;
|
||||||
data.resultType = ResultWas::Ok;
|
data.resultType = ResultWas::Ok;
|
||||||
data.reconstructedExpression = m_assertionInfo.capturedExpression;
|
data.reconstructedExpression = m_assertionInfo.capturedExpression;
|
||||||
if( expectedMessage != "" ) {
|
|
||||||
|
|
||||||
std::string actualMessage = Catch::translateActiveException();
|
std::string actualMessage = Catch::translateActiveException();
|
||||||
WildcardPattern pattern( expectedMessage, WildcardPattern::CaseInsensitive );
|
if( !matcher.match( actualMessage ) ) {
|
||||||
if( !pattern.matches( actualMessage ) ) {
|
|
||||||
data.resultType = ResultWas::ExpressionFailed;
|
data.resultType = ResultWas::ExpressionFailed;
|
||||||
data.reconstructedExpression = actualMessage;
|
data.reconstructedExpression = actualMessage;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
AssertionResult result( m_assertionInfo, data );
|
AssertionResult result( m_assertionInfo, data );
|
||||||
handleResult( result );
|
handleResult( result );
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ namespace Catch {
|
|||||||
class NamePattern : public Pattern {
|
class NamePattern : public Pattern {
|
||||||
public:
|
public:
|
||||||
NamePattern( std::string const& name )
|
NamePattern( std::string const& name )
|
||||||
: m_wildcardPattern( toLower( name ), WildcardPattern::CaseInsensitive )
|
: m_wildcardPattern( toLower( name ), CaseSensitive::No )
|
||||||
{}
|
{}
|
||||||
virtual ~NamePattern();
|
virtual ~NamePattern();
|
||||||
virtual bool matches( TestCaseInfo const& testCase ) const {
|
virtual bool matches( TestCaseInfo const& testCase ) const {
|
||||||
|
@ -22,11 +22,7 @@ namespace Catch
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum CaseSensitivity {
|
WildcardPattern( std::string const& pattern, CaseSensitive::Choice caseSensitivity )
|
||||||
CaseSensitive,
|
|
||||||
CaseInsensitive
|
|
||||||
};
|
|
||||||
WildcardPattern( std::string const& pattern, CaseSensitivity caseSensitivity )
|
|
||||||
: m_caseSensitivity( caseSensitivity ),
|
: m_caseSensitivity( caseSensitivity ),
|
||||||
m_wildcard( NoWildcard ),
|
m_wildcard( NoWildcard ),
|
||||||
m_pattern( adjustCase( pattern ) )
|
m_pattern( adjustCase( pattern ) )
|
||||||
@ -64,9 +60,9 @@ namespace Catch
|
|||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
std::string adjustCase( std::string const& str ) const {
|
std::string adjustCase( std::string const& str ) const {
|
||||||
return m_caseSensitivity == CaseInsensitive ? toLower( str ) : str;
|
return m_caseSensitivity == CaseSensitive::No ? toLower( str ) : str;
|
||||||
}
|
}
|
||||||
CaseSensitivity m_caseSensitivity;
|
CaseSensitive::Choice m_caseSensitivity;
|
||||||
WildcardPosition m_wildcard;
|
WildcardPosition m_wildcard;
|
||||||
std::string m_pattern;
|
std::string m_pattern;
|
||||||
};
|
};
|
||||||
|
@ -798,5 +798,5 @@ with expansion:
|
|||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
test cases: 157 | 117 passed | 39 failed | 1 failed as expected
|
test cases: 157 | 117 passed | 39 failed | 1 failed as expected
|
||||||
assertions: 774 | 681 passed | 80 failed | 13 failed as expected
|
assertions: 773 | 680 passed | 80 failed | 13 failed as expected
|
||||||
|
|
||||||
|
@ -1297,7 +1297,7 @@ ExceptionTests.cpp:<line number>
|
|||||||
|
|
||||||
ExceptionTests.cpp:<line number>:
|
ExceptionTests.cpp:<line number>:
|
||||||
PASSED:
|
PASSED:
|
||||||
REQUIRE_THROWS_WITH( thisThrows(), "expecteD Exception" )
|
REQUIRE_THROWS_WITH( thisThrows(), Equals( "expecteD Exception", Catch::CaseSensitive::No ) )
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Exception messages can be tested for
|
Exception messages can be tested for
|
||||||
@ -1308,19 +1308,19 @@ ExceptionTests.cpp:<line number>
|
|||||||
|
|
||||||
ExceptionTests.cpp:<line number>:
|
ExceptionTests.cpp:<line number>:
|
||||||
PASSED:
|
PASSED:
|
||||||
REQUIRE_THROWS_WITH( thisThrows(), "expected*" )
|
REQUIRE_THROWS_WITH( thisThrows(), StartsWith( "expected" ) )
|
||||||
|
|
||||||
ExceptionTests.cpp:<line number>:
|
ExceptionTests.cpp:<line number>:
|
||||||
PASSED:
|
PASSED:
|
||||||
REQUIRE_THROWS_WITH( thisThrows(), "*exception" )
|
REQUIRE_THROWS_WITH( thisThrows(), EndsWith( "exception" ) )
|
||||||
|
|
||||||
ExceptionTests.cpp:<line number>:
|
ExceptionTests.cpp:<line number>:
|
||||||
PASSED:
|
PASSED:
|
||||||
REQUIRE_THROWS_WITH( thisThrows(), "*except*" )
|
REQUIRE_THROWS_WITH( thisThrows(), Contains( "except" ) )
|
||||||
|
|
||||||
ExceptionTests.cpp:<line number>:
|
ExceptionTests.cpp:<line number>:
|
||||||
PASSED:
|
PASSED:
|
||||||
REQUIRE_THROWS_WITH( thisThrows(), "*exCept*" )
|
REQUIRE_THROWS_WITH( thisThrows(), Contains( "exCept", Catch::CaseSensitive::No ) )
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Mismatching exception messages failing the test
|
Mismatching exception messages failing the test
|
||||||
@ -1328,10 +1328,6 @@ Mismatching exception messages failing the test
|
|||||||
ExceptionTests.cpp:<line number>
|
ExceptionTests.cpp:<line number>
|
||||||
...............................................................................
|
...............................................................................
|
||||||
|
|
||||||
ExceptionTests.cpp:<line number>:
|
|
||||||
PASSED:
|
|
||||||
REQUIRE_THROWS_WITH( thisThrows(), "expected exception" )
|
|
||||||
|
|
||||||
ExceptionTests.cpp:<line number>:
|
ExceptionTests.cpp:<line number>:
|
||||||
PASSED:
|
PASSED:
|
||||||
REQUIRE_THROWS_WITH( thisThrows(), "expected exception" )
|
REQUIRE_THROWS_WITH( thisThrows(), "expected exception" )
|
||||||
@ -8009,5 +8005,5 @@ with expansion:
|
|||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
test cases: 157 | 101 passed | 55 failed | 1 failed as expected
|
test cases: 157 | 101 passed | 55 failed | 1 failed as expected
|
||||||
assertions: 794 | 681 passed | 100 failed | 13 failed as expected
|
assertions: 793 | 680 passed | 100 failed | 13 failed as expected
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="all tests" errors="12" failures="88" tests="794" hostname="tbd" time="{duration}" timestamp="tbd">
|
<testsuite name="all tests" errors="12" failures="88" tests="793" hostname="tbd" time="{duration}" timestamp="tbd">
|
||||||
<testcase classname="global" name="toString(enum)" time="{duration}"/>
|
<testcase classname="global" name="toString(enum)" time="{duration}"/>
|
||||||
<testcase classname="global" name="toString(enum w/operator<<)" time="{duration}"/>
|
<testcase classname="global" name="toString(enum w/operator<<)" time="{duration}"/>
|
||||||
<testcase classname="global" name="toString(enum class)" time="{duration}"/>
|
<testcase classname="global" name="toString(enum class)" time="{duration}"/>
|
||||||
|
@ -1611,10 +1611,10 @@
|
|||||||
<Section name="different case">
|
<Section name="different case">
|
||||||
<Expression success="true" type="REQUIRE_THROWS_WITH" filename="projects/SelfTest/ExceptionTests.cpp" >
|
<Expression success="true" type="REQUIRE_THROWS_WITH" filename="projects/SelfTest/ExceptionTests.cpp" >
|
||||||
<Original>
|
<Original>
|
||||||
thisThrows(), "expecteD Exception"
|
thisThrows(), Equals( "expecteD Exception", Catch::CaseSensitive::No )
|
||||||
</Original>
|
</Original>
|
||||||
<Expanded>
|
<Expanded>
|
||||||
thisThrows(), "expecteD Exception"
|
thisThrows(), Equals( "expecteD Exception", Catch::CaseSensitive::No )
|
||||||
</Expanded>
|
</Expanded>
|
||||||
</Expression>
|
</Expression>
|
||||||
<OverallResults successes="1" failures="0" expectedFailures="0"/>
|
<OverallResults successes="1" failures="0" expectedFailures="0"/>
|
||||||
@ -1622,34 +1622,34 @@
|
|||||||
<Section name="wildcarded">
|
<Section name="wildcarded">
|
||||||
<Expression success="true" type="REQUIRE_THROWS_WITH" filename="projects/SelfTest/ExceptionTests.cpp" >
|
<Expression success="true" type="REQUIRE_THROWS_WITH" filename="projects/SelfTest/ExceptionTests.cpp" >
|
||||||
<Original>
|
<Original>
|
||||||
thisThrows(), "expected*"
|
thisThrows(), StartsWith( "expected" )
|
||||||
</Original>
|
</Original>
|
||||||
<Expanded>
|
<Expanded>
|
||||||
thisThrows(), "expected*"
|
thisThrows(), StartsWith( "expected" )
|
||||||
</Expanded>
|
</Expanded>
|
||||||
</Expression>
|
</Expression>
|
||||||
<Expression success="true" type="REQUIRE_THROWS_WITH" filename="projects/SelfTest/ExceptionTests.cpp" >
|
<Expression success="true" type="REQUIRE_THROWS_WITH" filename="projects/SelfTest/ExceptionTests.cpp" >
|
||||||
<Original>
|
<Original>
|
||||||
thisThrows(), "*exception"
|
thisThrows(), EndsWith( "exception" )
|
||||||
</Original>
|
</Original>
|
||||||
<Expanded>
|
<Expanded>
|
||||||
thisThrows(), "*exception"
|
thisThrows(), EndsWith( "exception" )
|
||||||
</Expanded>
|
</Expanded>
|
||||||
</Expression>
|
</Expression>
|
||||||
<Expression success="true" type="REQUIRE_THROWS_WITH" filename="projects/SelfTest/ExceptionTests.cpp" >
|
<Expression success="true" type="REQUIRE_THROWS_WITH" filename="projects/SelfTest/ExceptionTests.cpp" >
|
||||||
<Original>
|
<Original>
|
||||||
thisThrows(), "*except*"
|
thisThrows(), Contains( "except" )
|
||||||
</Original>
|
</Original>
|
||||||
<Expanded>
|
<Expanded>
|
||||||
thisThrows(), "*except*"
|
thisThrows(), Contains( "except" )
|
||||||
</Expanded>
|
</Expanded>
|
||||||
</Expression>
|
</Expression>
|
||||||
<Expression success="true" type="REQUIRE_THROWS_WITH" filename="projects/SelfTest/ExceptionTests.cpp" >
|
<Expression success="true" type="REQUIRE_THROWS_WITH" filename="projects/SelfTest/ExceptionTests.cpp" >
|
||||||
<Original>
|
<Original>
|
||||||
thisThrows(), "*exCept*"
|
thisThrows(), Contains( "exCept", Catch::CaseSensitive::No )
|
||||||
</Original>
|
</Original>
|
||||||
<Expanded>
|
<Expanded>
|
||||||
thisThrows(), "*exCept*"
|
thisThrows(), Contains( "exCept", Catch::CaseSensitive::No )
|
||||||
</Expanded>
|
</Expanded>
|
||||||
</Expression>
|
</Expression>
|
||||||
<OverallResults successes="4" failures="0" expectedFailures="0"/>
|
<OverallResults successes="4" failures="0" expectedFailures="0"/>
|
||||||
@ -1657,14 +1657,6 @@
|
|||||||
<OverallResult success="true"/>
|
<OverallResult success="true"/>
|
||||||
</TestCase>
|
</TestCase>
|
||||||
<TestCase name="Mismatching exception messages failing the test">
|
<TestCase name="Mismatching exception messages failing the test">
|
||||||
<Expression success="true" type="REQUIRE_THROWS_WITH" filename="projects/SelfTest/ExceptionTests.cpp" >
|
|
||||||
<Original>
|
|
||||||
thisThrows(), "expected exception"
|
|
||||||
</Original>
|
|
||||||
<Expanded>
|
|
||||||
thisThrows(), "expected exception"
|
|
||||||
</Expanded>
|
|
||||||
</Expression>
|
|
||||||
<Expression success="true" type="REQUIRE_THROWS_WITH" filename="projects/SelfTest/ExceptionTests.cpp" >
|
<Expression success="true" type="REQUIRE_THROWS_WITH" filename="projects/SelfTest/ExceptionTests.cpp" >
|
||||||
<Original>
|
<Original>
|
||||||
thisThrows(), "expected exception"
|
thisThrows(), "expected exception"
|
||||||
@ -8307,7 +8299,7 @@ there"
|
|||||||
</Section>
|
</Section>
|
||||||
<OverallResult success="true"/>
|
<OverallResult success="true"/>
|
||||||
</TestCase>
|
</TestCase>
|
||||||
<OverallResults successes="681" failures="100" expectedFailures="13"/>
|
<OverallResults successes="680" failures="100" expectedFailures="13"/>
|
||||||
</Group>
|
</Group>
|
||||||
<OverallResults successes="681" failures="100" expectedFailures="13"/>
|
<OverallResults successes="680" failures="100" expectedFailures="13"/>
|
||||||
</Catch>
|
</Catch>
|
||||||
|
@ -154,20 +154,21 @@ TEST_CASE( "NotImplemented exception", "" )
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "Exception messages can be tested for", "" ) {
|
TEST_CASE( "Exception messages can be tested for", "" ) {
|
||||||
|
using namespace Catch::Matchers;
|
||||||
SECTION( "exact match" )
|
SECTION( "exact match" )
|
||||||
REQUIRE_THROWS_WITH( thisThrows(), "expected exception" );
|
REQUIRE_THROWS_WITH( thisThrows(), "expected exception" );
|
||||||
SECTION( "different case" )
|
SECTION( "different case" )
|
||||||
REQUIRE_THROWS_WITH( thisThrows(), "expecteD Exception" );
|
REQUIRE_THROWS_WITH( thisThrows(), Equals( "expecteD Exception", Catch::CaseSensitive::No ) );
|
||||||
SECTION( "wildcarded" ) {
|
SECTION( "wildcarded" ) {
|
||||||
REQUIRE_THROWS_WITH( thisThrows(), "expected*" );
|
REQUIRE_THROWS_WITH( thisThrows(), StartsWith( "expected" ) );
|
||||||
REQUIRE_THROWS_WITH( thisThrows(), "*exception" );
|
REQUIRE_THROWS_WITH( thisThrows(), EndsWith( "exception" ) );
|
||||||
REQUIRE_THROWS_WITH( thisThrows(), "*except*" );
|
REQUIRE_THROWS_WITH( thisThrows(), Contains( "except" ) );
|
||||||
REQUIRE_THROWS_WITH( thisThrows(), "*exCept*" );
|
REQUIRE_THROWS_WITH( thisThrows(), Contains( "exCept", Catch::CaseSensitive::No ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "Mismatching exception messages failing the test", "[.][failing]" ) {
|
TEST_CASE( "Mismatching exception messages failing the test", "[.][failing]" ) {
|
||||||
REQUIRE_THROWS_WITH( thisThrows(), "expected exception" );
|
|
||||||
REQUIRE_THROWS_WITH( thisThrows(), "expected exception" );
|
REQUIRE_THROWS_WITH( thisThrows(), "expected exception" );
|
||||||
REQUIRE_THROWS_WITH( thisThrows(), "should fail" );
|
REQUIRE_THROWS_WITH( thisThrows(), "should fail" );
|
||||||
|
REQUIRE_THROWS_WITH( thisThrows(), "expected exception" );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user