changed macro names: EXPECT -> REQUIRE, *_NOT -> *_FALSE

This commit is contained in:
Phil Nash 2010-12-14 09:00:09 +00:00
parent de77ff3b29
commit a2d20951a2
7 changed files with 67 additions and 67 deletions

View File

@ -25,11 +25,11 @@ namespace
void succeedingCase()
{
EXPECT( s == "hello" );
REQUIRE( s == "hello" );
}
void failingCase()
{
EXPECT( s == "world" );
REQUIRE( s == "world" );
}
};
}

View File

@ -29,23 +29,22 @@ struct TestData
double double_pi;
};
// These tests all use the CHECK macro, which continues if the specific test fails.
// This allows us to see all results, even if an earlier check fails - which is
// particularly important for the "should fail" checks
// The "failing" tests all use the CHECK macro, which continues if the specific test fails.
// This allows us to see all results, even if an earlier check fails
// Equality tests
TEST_CASE( "succeeding/conditions/equality", "Equality checks that should succeed" )
{
TestData data;
CHECK( data.int_seven == 7 );
CHECK( data.float_nine_point_one == Approx( 9.1f ) );
CHECK( data.double_pi == Approx( 3.1415926535 ) );
CHECK( data.str_hello == "hello" );
CHECK( data.str_hello.size() == 5 );
REQUIRE( data.int_seven == 7 );
REQUIRE( data.float_nine_point_one == Approx( 9.1f ) );
REQUIRE( data.double_pi == Approx( 3.1415926535 ) );
REQUIRE( data.str_hello == "hello" );
REQUIRE( data.str_hello.size() == 5 );
double x = 1.1 + 0.1 + 0.1;
CHECK( x == Approx( 1.3 ) );
REQUIRE( x == Approx( 1.3 ) );
}
TEST_CASE( "failing/conditions/equality", "Equality checks that should fail" )
@ -73,17 +72,17 @@ TEST_CASE( "succeeding/conditions/inequality", "Inequality checks that should su
{
TestData data;
CHECK( data.int_seven != 6 );
CHECK( data.int_seven != 8 );
CHECK( data.float_nine_point_one != Approx( 9.11f ) );
CHECK( data.float_nine_point_one != Approx( 9.0f ) );
CHECK( data.float_nine_point_one != 1 );
CHECK( data.float_nine_point_one != 0 );
CHECK( data.double_pi != Approx( 3.1415 ) );
CHECK( data.str_hello != "goodbye" );
CHECK( data.str_hello != "hell" );
CHECK( data.str_hello != "hello1" );
CHECK( data.str_hello.size() != 6 );
REQUIRE( data.int_seven != 6 );
REQUIRE( data.int_seven != 8 );
REQUIRE( data.float_nine_point_one != Approx( 9.11f ) );
REQUIRE( data.float_nine_point_one != Approx( 9.0f ) );
REQUIRE( data.float_nine_point_one != 1 );
REQUIRE( data.float_nine_point_one != 0 );
REQUIRE( data.double_pi != Approx( 3.1415 ) );
REQUIRE( data.str_hello != "goodbye" );
REQUIRE( data.str_hello != "hell" );
REQUIRE( data.str_hello != "hello1" );
REQUIRE( data.str_hello.size() != 6 );
}
TEST_CASE( "failing/conditions/inequality", "Inequality checks that should fails" )
@ -102,27 +101,27 @@ TEST_CASE( "succeeding/conditions/ordered", "Ordering comparison checks that sho
{
TestData data;
CHECK( data.int_seven < 8 );
CHECK( data.int_seven > 6 );
CHECK( data.int_seven > 0 );
CHECK( data.int_seven > -1 );
REQUIRE( data.int_seven < 8 );
REQUIRE( data.int_seven > 6 );
REQUIRE( data.int_seven > 0 );
REQUIRE( data.int_seven > -1 );
CHECK( data.int_seven >= 7 );
CHECK( data.int_seven >= 6 );
CHECK( data.int_seven <= 7 );
CHECK( data.int_seven <= 8 );
REQUIRE( data.int_seven >= 7 );
REQUIRE( data.int_seven >= 6 );
REQUIRE( data.int_seven <= 7 );
REQUIRE( data.int_seven <= 8 );
CHECK( data.float_nine_point_one > 9 );
CHECK( data.float_nine_point_one < 10 );
CHECK( data.float_nine_point_one < 9.2 );
REQUIRE( data.float_nine_point_one > 9 );
REQUIRE( data.float_nine_point_one < 10 );
REQUIRE( data.float_nine_point_one < 9.2 );
CHECK( data.str_hello <= "hello" );
CHECK( data.str_hello >= "hello" );
REQUIRE( data.str_hello <= "hello" );
REQUIRE( data.str_hello >= "hello" );
CHECK( data.str_hello < "hellp" );
CHECK( data.str_hello < "zebra" );
CHECK( data.str_hello > "hellm" );
CHECK( data.str_hello > "a" );
REQUIRE( data.str_hello < "hellp" );
REQUIRE( data.str_hello < "zebra" );
REQUIRE( data.str_hello > "hellm" );
REQUIRE( data.str_hello > "a" );
}
TEST_CASE( "failing/conditions/ordered", "Ordering comparison checks that should fail" )
@ -159,20 +158,20 @@ TEST_CASE( "failing/conditions/ordered", "Ordering comparison checks that should
// This means we can't isolate it when we decompose. The simple CHECK( !false ) form, therefore,
// cannot have the operand value extracted. The test will work correctly, and the situation
// is detected and a warning issued.
// An alternative form of the macros (CHECK_NOT and EXPECT_NOT) can be used instead to capture
// An alternative form of the macros (CHECK_FALSE and REQUIRE_FALSE) can be used instead to capture
// the operand value.
TEST_CASE( "succeeding/conditions/not", "'Not' checks that should succeed" )
{
bool falseValue = false;
CHECK( !false );
CHECK_NOT( false );
REQUIRE( !false );
REQUIRE_FALSE( false );
CHECK( !falseValue );
CHECK_NOT( falseValue );
REQUIRE( !falseValue );
REQUIRE_FALSE( falseValue );
CHECK( !(1 == 2) );
CHECK_NOT( 1 == 2 );
REQUIRE( !(1 == 2) );
REQUIRE_FALSE( 1 == 2 );
}
TEST_CASE( "failing/conditions/not", "'Not' checks that should fail" )
@ -180,12 +179,12 @@ TEST_CASE( "failing/conditions/not", "'Not' checks that should fail" )
bool trueValue = true;
CHECK( !true );
CHECK_NOT( true );
CHECK_FALSE( true );
CHECK( !trueValue );
CHECK_NOT( trueValue );
CHECK_FALSE( trueValue );
CHECK( !(1 == 1) );
CHECK_NOT( 1 == 1 );
CHECK_FALSE( 1 == 1 );
}

View File

@ -29,9 +29,9 @@ namespace
TEST_CASE( "succeeding/exceptions/explicit", "When checked exceptions are thrown they can be expected or unexpected" )
{
CHECK_THROWS_AS( thisThrows(), std::domain_error );
CHECK_NOTHROW( thisDoesntThrow() );
EXPECT_THROWS( thisThrows() );
REQUIRE_THROWS_AS( thisThrows(), std::domain_error );
REQUIRE_NOTHROW( thisDoesntThrow() );
REQUIRE_THROWS( thisThrows() );
}
TEST_CASE( "failing/exceptions/explicit", "When checked exceptions are thrown they can be expected or unexpected" )

View File

@ -19,13 +19,13 @@ TEST_CASE( "succeeding/Misc/Sections", "random SECTION tests" )
SECTION( "s1", "doesn't equal" )
{
EXPECT( a != b );
EXPECT( b != a );
REQUIRE( a != b );
REQUIRE( b != a );
}
SECTION( "s2", "not equal" )
{
EXPECT_NOT( a == b);
REQUIRE_FALSE( a == b);
}
}

View File

@ -14,7 +14,7 @@
#include "../catch_runner.hpp"
// This code runs the meta tests and verifies that the failing ones failed and the successful ones succeeded
/*
///*
int main (int argc, char * const argv[])
{
using namespace Catch;
@ -61,13 +61,13 @@ int main (int argc, char * const argv[])
if( result == 0 )
{
const size_t expectedTestCaseCount = 99; // !TBD factor this out
const size_t expectedTestCaseCount = 102; // !TBD factor this out
size_t testCaseCount = runner.getSuccessCount() + runner.getFailureCount();
std::cout << "All " << testCaseCount << " tests completed successfully" << std::endl;
if( testCaseCount != expectedTestCaseCount )
{
std::cerr << "- but we were expecting " << expectedTestCaseCount
<< " test to run. Where some added or removed, or were they not compiled in?"
<< " test to run. Were some added or removed, or were they not compiled in?"
<< std::endl;
return 1;
}
@ -75,5 +75,5 @@ int main (int argc, char * const argv[])
}
return result;
}
*/
#include "catch_default_main.hpp"
//*/
//#include "catch_default_main.hpp"

View File

@ -29,7 +29,7 @@ TEST_CASE( "succeeding/Tricky/std::pair", "Parsing a std::pair" )
std::pair<int, int> aNicePair( 1, 2 );
// !TBD: would be nice if this could compile without the extra parentheses
EXPECT( (std::pair<int, int>( 1, 2 )) == aNicePair );
REQUIRE( (std::pair<int, int>( 1, 2 )) == aNicePair );
}
@ -39,7 +39,7 @@ TEST_CASE( "succeeding/Tricky/complex lhs", "Where the LHS is not a simple value
int b = 2;
// This only captures part of the expression, but issues a warning about the rest
EXPECT( a == 2 || b == 2 );
REQUIRE( a == 2 || b == 2 );
}
struct Opaque

View File

@ -32,14 +32,15 @@
//////
#define EXPECT( expr ) INTERNAL_CATCH_TEST( expr, false, true, "EXPECT" )
#define EXPECT_NOT( expr ) INTERNAL_CATCH_TEST( expr, true, true, "EXPECT_NOT" )
#define REQUIRE( expr ) INTERNAL_CATCH_TEST( expr, false, true, "REQUIRE" )
#define REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( expr, true, true, "REQUIRE_FALSE" )
#define EXPECT_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, ..., false, true, "EXPECT_THROWS" )
#define EXPECT_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, false, true, "EXPECT_THROWS_AS" )
#define REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, ..., false, true, "REQUIRE_THROWS" )
#define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, false, true, "REQUIRE_THROWS_AS" )
#define REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_THROWS_AS( expr, Catch::DummyExceptionType_DontUse, true, true, "REQUIRE_NOTHROW" )
#define CHECK( expr ) INTERNAL_CATCH_TEST( expr, false, false, "CHECK" )
#define CHECK_NOT( expr ) INTERNAL_CATCH_TEST( expr, true, false, "CHECK_NOT" )
#define CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( expr, true, false, "CHECK_FALSE" )
#define CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, ..., false. false, "CHECK_THROWS" )
#define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, false, false, "CHECK_THROWS_AS" )