Matchers macro uses Catch::Matchers namespace internally - so it doesn't have to be declared with "using" first

This commit is contained in:
Phil Nash 2012-05-24 08:29:03 +01:00
parent 1c98fc98ef
commit 7035b55832
5 changed files with 13 additions and 7 deletions

View File

@ -126,7 +126,7 @@ inline bool isTrue( bool value ){ return value; }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CHECK_THAT( arg, matcher, stopOnFailure, macroName ) \ #define INTERNAL_CHECK_THAT( arg, matcher, stopOnFailure, macroName ) \
do{ try{ \ do{ try{ \
INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #arg " " #matcher, false ).acceptMatcher( matcher, arg, #matcher ) ), stopOnFailure, false ); \ INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #arg " " #matcher, false ).acceptMatcher( ::Catch::Matchers::matcher, arg, #matcher ) ), stopOnFailure, false ); \
}catch( Catch::TestFailureException& ){ \ }catch( Catch::TestFailureException& ){ \
throw; \ throw; \
} catch( ... ){ \ } catch( ... ){ \

View File

@ -178,7 +178,6 @@ namespace Catch {
mutable std::ostream m_os; mutable std::ostream m_os;
Include::What m_includeWhat; Include::What m_includeWhat;
std::string m_name; std::string m_name;
}; };
} // end namespace Catch } // end namespace Catch

View File

@ -247,8 +247,6 @@ inline const char* testStringForMatching()
return "this string contains 'abc' as a substring"; return "this string contains 'abc' as a substring";
} }
using namespace Catch::Matchers;
TEST_CASE("./succeeding/matchers", "") TEST_CASE("./succeeding/matchers", "")
{ {
REQUIRE_THAT( testStringForMatching(), Contains( "string" ) ); REQUIRE_THAT( testStringForMatching(), Contains( "string" ) );
@ -272,3 +270,13 @@ TEST_CASE("./failing/matchers/EndsWith", "")
{ {
CHECK_THAT( testStringForMatching(), EndsWith( "this" ) ); CHECK_THAT( testStringForMatching(), EndsWith( "this" ) );
} }
TEST_CASE("./failing/matchers/Equals", "")
{
CHECK_THAT( testStringForMatching(), Equals( "something else" ) );
}
TEST_CASE("./succeeding/matchers/Equals", "")
{
CHECK_THAT( testStringForMatching(), Equals( "this string contains 'abc' as a substring" ) );
}

View File

@ -33,7 +33,7 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results"
SECTION( "selftest/test counts/succeeding tests", SECTION( "selftest/test counts/succeeding tests",
"Number of 'succeeding' tests is fixed" ) { "Number of 'succeeding' tests is fixed" ) {
runner.runMatching( "./succeeding/*" ); runner.runMatching( "./succeeding/*" );
CHECK( runner.getTotals().assertions.passed == 276 ); CHECK( runner.getTotals().assertions.passed == 277 );
CHECK( runner.getTotals().assertions.failed == 0 ); CHECK( runner.getTotals().assertions.failed == 0 );
} }
@ -41,7 +41,7 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results"
"Number of 'failing' tests is fixed" ) { "Number of 'failing' tests is fixed" ) {
runner.runMatching( "./failing/*" ); runner.runMatching( "./failing/*" );
CHECK( runner.getTotals().assertions.passed == 0 ); CHECK( runner.getTotals().assertions.passed == 0 );
CHECK( runner.getTotals().assertions.failed == 71 ); CHECK( runner.getTotals().assertions.failed == 72 );
} }
} }
} }

View File

@ -60,7 +60,6 @@ void useObject( const T& object ){}
template<typename T> template<typename T>
void useObject( const T* object ){} void useObject( const T* object ){}
using namespace Catch::Matchers;
OC_TEST_CASE( "OCTest/matchers", "Matches work with OC types (NSString so far)" ) OC_TEST_CASE( "OCTest/matchers", "Matches work with OC types (NSString so far)" )
{ {
REQUIRE_THAT( @"This is a string", Equals( @"This is a string" ) ); REQUIRE_THAT( @"This is a string", Equals( @"This is a string" ) );