Some clean-ups

This commit is contained in:
Phil Nash 2017-07-13 08:29:12 +01:00
parent d2d5910479
commit e4456aa243
1 changed files with 14 additions and 22 deletions

View File

@ -15,17 +15,10 @@
#include <limits> #include <limits>
struct TestData { struct TestData {
TestData() int int_seven = 7;
: int_seven( 7 ), std::string str_hello = "hello";
str_hello( "hello" ), float float_nine_point_one = 9.1f;
float_nine_point_one( 9.1f ), double double_pi = 3.1415926535;
double_pi( 3.1415926535 )
{}
int int_seven;
std::string str_hello;
float float_nine_point_one;
double double_pi;
}; };
@ -36,14 +29,13 @@ struct TestDef {
TestDef& operator[]( const std::string& ) { TestDef& operator[]( const std::string& ) {
return *this; return *this;
} }
}; };
// The "failing" tests all use the CHECK macro, which continues if the specific test fails. // 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 // This allows us to see all results, even if an earlier check fails
// Equality tests // Equality tests
TEST_CASE( "Equality checks that should succeed", "" ) TEST_CASE( "Equality checks that should succeed" )
{ {
TestDef td; TestDef td;
@ -83,7 +75,7 @@ TEST_CASE( "Equality checks that should fail", "[.][failing][!mayfail]" )
CHECK( x == Approx( 1.301 ) ); CHECK( x == Approx( 1.301 ) );
} }
TEST_CASE( "Inequality checks that should succeed", "" ) TEST_CASE( "Inequality checks that should succeed" )
{ {
TestData data; TestData data;
@ -112,7 +104,7 @@ TEST_CASE( "Inequality checks that should fail", "[.][failing][!shouldfail]" )
} }
// Ordering comparison tests // Ordering comparison tests
TEST_CASE( "Ordering comparison checks that should succeed", "" ) TEST_CASE( "Ordering comparison checks that should succeed" )
{ {
TestData data; TestData data;
@ -169,7 +161,7 @@ TEST_CASE( "Ordering comparison checks that should fail", "[.][failing]" )
} }
// Comparisons with int literals // Comparisons with int literals
TEST_CASE( "Comparisons with int literals don't warn when mixing signed/ unsigned", "" ) TEST_CASE( "Comparisons with int literals don't warn when mixing signed/ unsigned" )
{ {
int i = 1; int i = 1;
unsigned int ui = 2; unsigned int ui = 2;
@ -207,7 +199,7 @@ TEST_CASE( "Comparisons with int literals don't warn when mixing signed/ unsigne
#pragma warning(disable:4389) // '==' : signed/unsigned mismatch #pragma warning(disable:4389) // '==' : signed/unsigned mismatch
#endif #endif
TEST_CASE( "comparisons between int variables", "" ) TEST_CASE( "comparisons between int variables" )
{ {
long long_var = 1L; long long_var = 1L;
unsigned char unsigned_char_var = 1; unsigned char unsigned_char_var = 1;
@ -221,7 +213,7 @@ TEST_CASE( "comparisons between int variables", "" )
REQUIRE( long_var == unsigned_long_var ); REQUIRE( long_var == unsigned_long_var );
} }
TEST_CASE( "comparisons between const int variables", "" ) TEST_CASE( "comparisons between const int variables" )
{ {
const unsigned char unsigned_char_var = 1; const unsigned char unsigned_char_var = 1;
const unsigned short unsigned_short_var = 1; const unsigned short unsigned_short_var = 1;
@ -234,7 +226,7 @@ TEST_CASE( "comparisons between const int variables", "" )
REQUIRE( unsigned_long_var == 1 ); REQUIRE( unsigned_long_var == 1 );
} }
TEST_CASE( "Comparisons between unsigned ints and negative signed ints match c++ standard behaviour", "" ) TEST_CASE( "Comparisons between unsigned ints and negative signed ints match c++ standard behaviour" )
{ {
CHECK( ( -1 > 2u ) ); CHECK( ( -1 > 2u ) );
CHECK( -1 > 2u ); CHECK( -1 > 2u );
@ -247,7 +239,7 @@ TEST_CASE( "Comparisons between unsigned ints and negative signed ints match c++
CHECK( minInt > 2u ); CHECK( minInt > 2u );
} }
TEST_CASE( "Comparisons between ints where one side is computed", "" ) TEST_CASE( "Comparisons between ints where one side is computed" )
{ {
CHECK( 54 == 6*9 ); CHECK( 54 == 6*9 );
} }
@ -259,7 +251,7 @@ TEST_CASE( "Comparisons between ints where one side is computed", "" )
inline const char* returnsConstNull(){ return nullptr; } inline const char* returnsConstNull(){ return nullptr; }
inline char* returnsNull(){ return nullptr; } inline char* returnsNull(){ return nullptr; }
TEST_CASE( "Pointers can be compared to null", "" ) TEST_CASE( "Pointers can be compared to null" )
{ {
TestData* p = nullptr; TestData* p = nullptr;
TestData* pNULL = nullptr; TestData* pNULL = nullptr;
@ -291,7 +283,7 @@ TEST_CASE( "Pointers can be compared to null", "" )
// is detected and a warning issued. // is detected and a warning issued.
// An alternative form of the macros (CHECK_FALSE and REQUIRE_FALSE) 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. // the operand value.
TEST_CASE( "'Not' checks that should succeed", "" ) TEST_CASE( "'Not' checks that should succeed" )
{ {
bool falseValue = false; bool falseValue = false;