From 37b057187d0a224c4f8752135cf5809e04768920 Mon Sep 17 00:00:00 2001 From: Malcolm Noyes Date: Mon, 9 Dec 2013 15:14:47 +0000 Subject: [PATCH] Make merge easier --- projects/SelfTest/ClassTests.cpp | 40 +- projects/SelfTest/ConditionTests.cpp | 479 +++++++------- projects/SelfTest/ExceptionTests.cpp | 220 +++---- projects/SelfTest/MessageTests.cpp | 142 ++-- projects/SelfTest/MiscTests.cpp | 614 +++++++++--------- projects/SelfTest/TrickyTests.cpp | 154 +++-- .../TestCatch/TestCatch/TestCatch.vcxproj | 62 +- .../TestCatch/TestCatch.vcxproj.filters | 152 +---- 8 files changed, 827 insertions(+), 1036 deletions(-) diff --git a/projects/SelfTest/ClassTests.cpp b/projects/SelfTest/ClassTests.cpp index 78cbda61..61f0796f 100644 --- a/projects/SelfTest/ClassTests.cpp +++ b/projects/SelfTest/ClassTests.cpp @@ -8,32 +8,28 @@ #include "catch.hpp" -namespace ClassTests +class TestClass { - class TestClass - { - std::string s; + std::string s; - public: - TestClass() - : s( "hello" ) - {} +public: + TestClass() + : s( "hello" ) + {} - void succeedingCase() - { - REQUIRE( s == "hello" ); - } - void failingCase() - { - REQUIRE( s == "world" ); - } - }; + void succeedingCase() + { + REQUIRE( s == "hello" ); + } + void failingCase() + { + REQUIRE( s == "world" ); + } +}; - // Note: TestClass conflicts with template class with same name in VS2012 native tests - METHOD_AS_TEST_CASE( ClassTests::TestClass::succeedingCase, "./succeeding/TestClass/succeedingCase", "A method based test run that succeeds [class]" ) - METHOD_AS_TEST_CASE( ClassTests::TestClass::failingCase, "./failing/TestClass/failingCase", "A method based test run that fails [class]" ) - -} +// Note: TestClass conflicts with template class with same name in VS2012 native tests +METHOD_AS_TEST_CASE( TestClass::succeedingCase, "./succeeding/TestClass/succeedingCase", "A method based test run that succeeds [class]" ) +METHOD_AS_TEST_CASE( TestClass::failingCase, "./failing/TestClass/failingCase", "A method based test run that fails [class]" ) struct Fixture { diff --git a/projects/SelfTest/ConditionTests.cpp b/projects/SelfTest/ConditionTests.cpp index 93fc3b4e..93340871 100644 --- a/projects/SelfTest/ConditionTests.cpp +++ b/projects/SelfTest/ConditionTests.cpp @@ -42,167 +42,165 @@ struct TestDef { // 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 -namespace ConditionTests { +// Equality tests +TEST_CASE( "./succeeding/conditions/equality", + "Equality checks that should succeed" ) +{ - // Equality tests - TEST_CASE( "./succeeding/conditions/equality", - "Equality checks that should succeed" ) - { - - TestDef td; - td + "hello" + "hello"; + TestDef td; + td + "hello" + "hello"; - TestData data; + TestData data; - 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( "hello" == data.str_hello ); - REQUIRE( 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( "hello" == data.str_hello ); + REQUIRE( data.str_hello.size() == 5 ); - double x = 1.1 + 0.1 + 0.1; - REQUIRE( x == Approx( 1.3 ) ); - } + double x = 1.1 + 0.1 + 0.1; + REQUIRE( x == Approx( 1.3 ) ); +} - TEST_CASE( "./failing/conditions/equality", - "Equality checks that should fail" ) - { - TestData data; +TEST_CASE( "./failing/conditions/equality", + "Equality checks that should fail" ) +{ + TestData data; - CHECK( data.int_seven == 6 ); - CHECK( data.int_seven == 8 ); - CHECK( data.int_seven == 0 ); - CHECK( data.float_nine_point_one == Approx( 9.11f ) ); - CHECK( data.float_nine_point_one == Approx( 9.0f ) ); - CHECK( data.float_nine_point_one == Approx( 1 ) ); - CHECK( data.float_nine_point_one == Approx( 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 ); + CHECK( data.int_seven == 6 ); + CHECK( data.int_seven == 8 ); + CHECK( data.int_seven == 0 ); + CHECK( data.float_nine_point_one == Approx( 9.11f ) ); + CHECK( data.float_nine_point_one == Approx( 9.0f ) ); + CHECK( data.float_nine_point_one == Approx( 1 ) ); + CHECK( data.float_nine_point_one == Approx( 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 ); - double x = 1.1 + 0.1 + 0.1; - CHECK( x == Approx( 1.301 ) ); - } + double x = 1.1 + 0.1 + 0.1; + CHECK( x == Approx( 1.301 ) ); +} - TEST_CASE( "./succeeding/conditions/inequality", - "Inequality checks that should succeed" ) - { - TestData data; +TEST_CASE( "./succeeding/conditions/inequality", + "Inequality checks that should succeed" ) +{ + TestData data; - 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 != Approx( 1 ) ); - REQUIRE( data.float_nine_point_one != Approx( 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 ); - } + 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 != Approx( 1 ) ); + REQUIRE( data.float_nine_point_one != Approx( 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" ) - { - TestData data; +TEST_CASE( "./failing/conditions/inequality", + "Inequality checks that should fails" ) +{ + 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 ); - } + 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 ); +} - // Ordering comparison tests - TEST_CASE( "./succeeding/conditions/ordered", - "Ordering comparison checks that should succeed" ) - { - TestData data; +// Ordering comparison tests +TEST_CASE( "./succeeding/conditions/ordered", + "Ordering comparison checks that should succeed" ) +{ + TestData data; - REQUIRE( data.int_seven < 8 ); - REQUIRE( data.int_seven > 6 ); - REQUIRE( data.int_seven > 0 ); - REQUIRE( data.int_seven > -1 ); + REQUIRE( data.int_seven < 8 ); + REQUIRE( data.int_seven > 6 ); + REQUIRE( data.int_seven > 0 ); + REQUIRE( data.int_seven > -1 ); - REQUIRE( data.int_seven >= 7 ); - REQUIRE( data.int_seven >= 6 ); - REQUIRE( data.int_seven <= 7 ); - REQUIRE( data.int_seven <= 8 ); + REQUIRE( data.int_seven >= 7 ); + REQUIRE( data.int_seven >= 6 ); + REQUIRE( data.int_seven <= 7 ); + REQUIRE( data.int_seven <= 8 ); - REQUIRE( data.float_nine_point_one > 9 ); - REQUIRE( data.float_nine_point_one < 10 ); - REQUIRE( 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 ); - REQUIRE( data.str_hello <= "hello" ); - REQUIRE( data.str_hello >= "hello" ); + REQUIRE( data.str_hello <= "hello" ); + REQUIRE( data.str_hello >= "hello" ); - REQUIRE( data.str_hello < "hellp" ); - REQUIRE( data.str_hello < "zebra" ); - REQUIRE( data.str_hello > "hellm" ); - REQUIRE( 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" ) - { - TestData data; +TEST_CASE( "./failing/conditions/ordered", + "Ordering comparison checks that should fail" ) +{ + TestData data; - CHECK( data.int_seven > 7 ); - CHECK( data.int_seven < 7 ); - CHECK( data.int_seven > 8 ); - CHECK( data.int_seven < 6 ); - CHECK( data.int_seven < 0 ); - CHECK( data.int_seven < -1 ); + CHECK( data.int_seven > 7 ); + CHECK( data.int_seven < 7 ); + CHECK( data.int_seven > 8 ); + CHECK( data.int_seven < 6 ); + CHECK( data.int_seven < 0 ); + CHECK( data.int_seven < -1 ); - CHECK( data.int_seven >= 8 ); - CHECK( data.int_seven <= 6 ); + CHECK( data.int_seven >= 8 ); + CHECK( data.int_seven <= 6 ); - CHECK( data.float_nine_point_one < 9 ); - CHECK( data.float_nine_point_one > 10 ); - CHECK( data.float_nine_point_one > 9.2 ); + CHECK( data.float_nine_point_one < 9 ); + CHECK( data.float_nine_point_one > 10 ); + CHECK( data.float_nine_point_one > 9.2 ); - CHECK( data.str_hello > "hello" ); - CHECK( data.str_hello < "hello" ); - CHECK( data.str_hello > "hellp" ); - CHECK( data.str_hello > "z" ); - CHECK( data.str_hello < "hellm" ); - CHECK( data.str_hello < "a" ); + CHECK( data.str_hello > "hello" ); + CHECK( data.str_hello < "hello" ); + CHECK( data.str_hello > "hellp" ); + CHECK( data.str_hello > "z" ); + CHECK( data.str_hello < "hellm" ); + CHECK( data.str_hello < "a" ); - CHECK( data.str_hello >= "z" ); - CHECK( data.str_hello <= "a" ); - } + CHECK( data.str_hello >= "z" ); + CHECK( data.str_hello <= "a" ); +} - // Comparisons with int literals - TEST_CASE( "./succeeding/conditions/int literals", - "Comparisons with int literals don't warn when mixing signed/ unsigned" ) - { - int i = 1; - unsigned int ui = 2; - long l = 3; - unsigned long ul = 4; - char c = 5; - unsigned char uc = 6; +// Comparisons with int literals +TEST_CASE( "./succeeding/conditions/int literals", + "Comparisons with int literals don't warn when mixing signed/ unsigned" ) +{ + int i = 1; + unsigned int ui = 2; + long l = 3; + unsigned long ul = 4; + char c = 5; + unsigned char uc = 6; - REQUIRE( i == 1 ); - REQUIRE( ui == 2 ); - REQUIRE( l == 3 ); - REQUIRE( ul == 4 ); - REQUIRE( c == 5 ); - REQUIRE( uc == 6 ); + REQUIRE( i == 1 ); + REQUIRE( ui == 2 ); + REQUIRE( l == 3 ); + REQUIRE( ul == 4 ); + REQUIRE( c == 5 ); + REQUIRE( uc == 6 ); - REQUIRE( 1 == i ); - REQUIRE( 2 == ui ); - REQUIRE( 3 == l ); - REQUIRE( 4 == ul ); - REQUIRE( 5 == c ); - REQUIRE( 6 == uc ); + REQUIRE( 1 == i ); + REQUIRE( 2 == ui ); + REQUIRE( 3 == l ); + REQUIRE( 4 == ul ); + REQUIRE( 5 == c ); + REQUIRE( 6 == uc ); - REQUIRE( (std::numeric_limits::max)() > ul ); - } + REQUIRE( (std::numeric_limits::max)() > ul ); +} // Disable warnings about sign conversions for the next two tests // (as we are deliberately invoking them) @@ -216,63 +214,63 @@ namespace ConditionTests { #pragma warning(disable:4389) // '==' : signed/unsigned mismatch #endif - TEST_CASE( "./succeeding/conditions//long_to_unsigned_x", - "comparisons between int variables" ) - { - long long_var = 1L; - unsigned char unsigned_char_var = 1; - unsigned short unsigned_short_var = 1; - unsigned int unsigned_int_var = 1; - unsigned long unsigned_long_var = 1L; +TEST_CASE( "./succeeding/conditions//long_to_unsigned_x", + "comparisons between int variables" ) +{ + long long_var = 1L; + unsigned char unsigned_char_var = 1; + unsigned short unsigned_short_var = 1; + unsigned int unsigned_int_var = 1; + unsigned long unsigned_long_var = 1L; - REQUIRE( long_var == unsigned_char_var ); - REQUIRE( long_var == unsigned_short_var ); - REQUIRE( long_var == unsigned_int_var ); - REQUIRE( long_var == unsigned_long_var ); - } + REQUIRE( long_var == unsigned_char_var ); + REQUIRE( long_var == unsigned_short_var ); + REQUIRE( long_var == unsigned_int_var ); + REQUIRE( long_var == unsigned_long_var ); +} - TEST_CASE( "./succeeding/conditions/const ints to int literal", - "comparisons between const int variables" ) - { - const unsigned char unsigned_char_var = 1; - const unsigned short unsigned_short_var = 1; - const unsigned int unsigned_int_var = 1; - const unsigned long unsigned_long_var = 1L; +TEST_CASE( "./succeeding/conditions/const ints to int literal", + "comparisons between const int variables" ) +{ + const unsigned char unsigned_char_var = 1; + const unsigned short unsigned_short_var = 1; + const unsigned int unsigned_int_var = 1; + const unsigned long unsigned_long_var = 1L; - REQUIRE( unsigned_char_var == 1 ); - REQUIRE( unsigned_short_var == 1 ); - REQUIRE( unsigned_int_var == 1 ); - REQUIRE( unsigned_long_var == 1 ); - } + REQUIRE( unsigned_char_var == 1 ); + REQUIRE( unsigned_short_var == 1 ); + REQUIRE( unsigned_int_var == 1 ); + REQUIRE( unsigned_long_var == 1 ); +} - TEST_CASE( "./succeeding/conditions/negative ints", - "Comparisons between unsigned ints and negative signed ints match c++ standard behaviour" ) - { - CHECK( ( -1 > 2u ) ); - CHECK( -1 > 2u ); +TEST_CASE( "./succeeding/conditions/negative ints", + "Comparisons between unsigned ints and negative signed ints match c++ standard behaviour" ) +{ + CHECK( ( -1 > 2u ) ); + CHECK( -1 > 2u ); - CHECK( ( 2u < -1 ) ); - CHECK( 2u < -1 ); + CHECK( ( 2u < -1 ) ); + CHECK( 2u < -1 ); - const int minInt = (std::numeric_limits::min)(); - CHECK( ( minInt > 2u ) ); - CHECK( minInt > 2u ); - } + const int minInt = (std::numeric_limits::min)(); + CHECK( ( minInt > 2u ) ); + CHECK( minInt > 2u ); +} - template - struct Ex - { - Ex( T ){} +template +struct Ex +{ + Ex( T ){} - bool operator == ( const T& ) const { return true; } - T operator * ( const T& ) const { return T(); } - }; + bool operator == ( const T& ) const { return true; } + T operator * ( const T& ) const { return T(); } +}; - TEST_CASE( "./succeeding/conditions/computed ints", - "Comparisons between ints where one side is computed" ) - { - CHECK( 54 == 6*9 ); - } +TEST_CASE( "./succeeding/conditions/computed ints", + "Comparisons between ints where one side is computed" ) +{ + CHECK( 54 == 6*9 ); +} #ifdef __GNUC__ #pragma GCC diagnostic pop @@ -281,70 +279,69 @@ namespace ConditionTests { inline const char* returnsConstNull(){ return NULL; } inline char* returnsNull(){ return NULL; } - TEST_CASE( "./succeeding/conditions/ptr", - "Pointers can be compared to null" ) - { - TestData* p = NULL; - TestData* pNULL = NULL; +TEST_CASE( "./succeeding/conditions/ptr", + "Pointers can be compared to null" ) +{ + TestData* p = NULL; + TestData* pNULL = NULL; - REQUIRE( p == NULL ); - REQUIRE( p == pNULL ); + REQUIRE( p == NULL ); + REQUIRE( p == pNULL ); - TestData data; - p = &data; + TestData data; + p = &data; - REQUIRE( p != NULL ); + REQUIRE( p != NULL ); - const TestData* cp = p; - REQUIRE( cp != NULL ); + const TestData* cp = p; + REQUIRE( cp != NULL ); - const TestData* const cpc = p; - REQUIRE( cpc != NULL ); + const TestData* const cpc = p; + REQUIRE( cpc != NULL ); - REQUIRE( returnsNull() == NULL ); - REQUIRE( returnsConstNull() == NULL ); + REQUIRE( returnsNull() == NULL ); + REQUIRE( returnsConstNull() == NULL ); - REQUIRE( NULL != p ); - } - - // Not (!) tests - // The problem with the ! operator is that it has right-to-left associativity. - // This means we can't isolate it when we decompose. The simple REQUIRE( !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_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; - - REQUIRE( false == false ); - REQUIRE( true == true ); - REQUIRE( !false ); - REQUIRE_FALSE( false ); - - REQUIRE( !falseValue ); - REQUIRE_FALSE( falseValue ); - - REQUIRE( !(1 == 2) ); - REQUIRE_FALSE( 1 == 2 ); - } - - TEST_CASE( "./failing/conditions/not", - "'Not' checks that should fail" ) - { - bool trueValue = true; - - CHECK( false != false ); - CHECK( true != true ); - CHECK( !true ); - CHECK_FALSE( true ); - - CHECK( !trueValue ); - CHECK_FALSE( trueValue ); - - CHECK( !(1 == 1) ); - CHECK_FALSE( 1 == 1 ); - } + REQUIRE( NULL != p ); +} + +// Not (!) tests +// The problem with the ! operator is that it has right-to-left associativity. +// This means we can't isolate it when we decompose. The simple REQUIRE( !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_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; + + REQUIRE( false == false ); + REQUIRE( true == true ); + REQUIRE( !false ); + REQUIRE_FALSE( false ); + + REQUIRE( !falseValue ); + REQUIRE_FALSE( falseValue ); + + REQUIRE( !(1 == 2) ); + REQUIRE_FALSE( 1 == 2 ); +} + +TEST_CASE( "./failing/conditions/not", + "'Not' checks that should fail" ) +{ + bool trueValue = true; + + CHECK( false != false ); + CHECK( true != true ); + CHECK( !true ); + CHECK_FALSE( true ); + + CHECK( !trueValue ); + CHECK_FALSE( trueValue ); + + CHECK( !(1 == 1) ); + CHECK_FALSE( 1 == 1 ); } diff --git a/projects/SelfTest/ExceptionTests.cpp b/projects/SelfTest/ExceptionTests.cpp index a175df4d..123e8cef 100644 --- a/projects/SelfTest/ExceptionTests.cpp +++ b/projects/SelfTest/ExceptionTests.cpp @@ -28,120 +28,116 @@ namespace } } -namespace ExceptionTests +TEST_CASE( "./succeeding/exceptions/explicit", "When checked exceptions are thrown they can be expected or unexpected" ) { + REQUIRE_THROWS_AS( thisThrows(), std::domain_error ); + REQUIRE_NOTHROW( thisDoesntThrow() ); + REQUIRE_THROWS( thisThrows() ); +} - TEST_CASE( "./succeeding/exceptions/explicit", "When checked exceptions are thrown they can be expected or unexpected" ) +TEST_CASE( "./failing/exceptions/explicit", "When checked exceptions are thrown they can be expected or unexpected" ) +{ + CHECK_THROWS_AS( thisThrows(), std::string ); + CHECK_THROWS_AS( thisDoesntThrow(), std::domain_error ); + CHECK_NOTHROW( thisThrows() ); +} + +TEST_CASE( "./failing/exceptions/implicit", "When unchecked exceptions are thrown they are always failures" ) +{ + if( Catch::isTrue( true ) ) + throw std::domain_error( "unexpected exception" ); +} + +TEST_CASE( "./failing/exceptions/implicit/2", "An unchecked exception reports the line of the last assertion" ) +{ + CHECK( 1 == 1 ); + if( Catch::isTrue( true ) ) + throw std::domain_error( "unexpected exception" ); +} +TEST_CASE( "./failing/exceptions/implicit/3", "When unchecked exceptions are thrown they are always failures" ) +{ + SECTION( "section name", "" ) { - 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" ) - { - CHECK_THROWS_AS( thisThrows(), std::string ); - CHECK_THROWS_AS( thisDoesntThrow(), std::domain_error ); - CHECK_NOTHROW( thisThrows() ); - } - - TEST_CASE( "./failing/exceptions/implicit", "When unchecked exceptions are thrown they are always failures" ) - { - if( Catch::isTrue( true ) ) - throw std::domain_error( "unexpected exception" ); - } - - TEST_CASE( "./failing/exceptions/implicit/2", "An unchecked exception reports the line of the last assertion" ) - { - CHECK( 1 == 1 ); - if( Catch::isTrue( true ) ) - throw std::domain_error( "unexpected exception" ); - } - TEST_CASE( "./failing/exceptions/implicit/3", "When unchecked exceptions are thrown they are always failures" ) - { - SECTION( "section name", "" ) - { - if( Catch::isTrue( true ) ) - throw std::domain_error( "unexpected exception" ); - } - } - - TEST_CASE( "./failing/exceptions/implicit/4", "When unchecked exceptions are thrown they are always failures" ) - { - CHECK( thisThrows() == 0 ); - } - - TEST_CASE( "./succeeding/exceptions/implicit", "When unchecked exceptions are thrown, but caught, they do not affect the test" ) - { - try - { - throw std::domain_error( "unexpected exception" ); - } - catch(...) - { - } - } - - class CustomException - { - public: - CustomException( const std::string& msg ) - : m_msg( msg ) - {} - - std::string getMessage() const - { - return m_msg; - } - - private: - std::string m_msg; - }; - - CATCH_TRANSLATE_EXCEPTION( CustomException& ex ) - { - return ex.getMessage(); - } - - CATCH_TRANSLATE_EXCEPTION( double& ex ) - { - return Catch::toString( ex ); - } - - TEST_CASE( "./failing/exceptions/custom", "Unexpected custom exceptions can be translated" ) - { - if( Catch::isTrue( true ) ) - throw CustomException( "custom exception" ); - } - - inline void throwCustom() { - if( Catch::isTrue( true ) ) - throw CustomException( "custom exception - not std" ); - } - - TEST_CASE( "./failing/exceptions/custom/nothrow", "Custom exceptions can be translated when testing for nothrow" ) - { - REQUIRE_NOTHROW( throwCustom() ); - } - - TEST_CASE( "./failing/exceptions/custom/throw", "Custom exceptions can be translated when testing for throwing as something else" ) - { - REQUIRE_THROWS_AS( throwCustom(), std::exception ); - } - - - TEST_CASE( "./failing/exceptions/custom/double", "Unexpected custom exceptions can be translated" ) - { - if( Catch::isTrue( true ) ) - throw double( 3.14 ); - } - - inline int thisFunctionNotImplemented( int ) { - CATCH_NOT_IMPLEMENTED; - } - - TEST_CASE( "./succeeding/exceptions/notimplemented", "" ) - { - REQUIRE_THROWS( thisFunctionNotImplemented( 7 ) ); + if( Catch::isTrue( true ) ) + throw std::domain_error( "unexpected exception" ); } } + +TEST_CASE( "./failing/exceptions/implicit/4", "When unchecked exceptions are thrown they are always failures" ) +{ + CHECK( thisThrows() == 0 ); +} + +TEST_CASE( "./succeeding/exceptions/implicit", "When unchecked exceptions are thrown, but caught, they do not affect the test" ) +{ + try + { + throw std::domain_error( "unexpected exception" ); + } + catch(...) + { + } +} + +class CustomException +{ +public: + CustomException( const std::string& msg ) + : m_msg( msg ) + {} + + std::string getMessage() const + { + return m_msg; + } + +private: + std::string m_msg; +}; + +CATCH_TRANSLATE_EXCEPTION( CustomException& ex ) +{ + return ex.getMessage(); +} + +CATCH_TRANSLATE_EXCEPTION( double& ex ) +{ + return Catch::toString( ex ); +} + +TEST_CASE( "./failing/exceptions/custom", "Unexpected custom exceptions can be translated" ) +{ + if( Catch::isTrue( true ) ) + throw CustomException( "custom exception" ); +} + +inline void throwCustom() { + if( Catch::isTrue( true ) ) + throw CustomException( "custom exception - not std" ); +} + +TEST_CASE( "./failing/exceptions/custom/nothrow", "Custom exceptions can be translated when testing for nothrow" ) +{ + REQUIRE_NOTHROW( throwCustom() ); +} + +TEST_CASE( "./failing/exceptions/custom/throw", "Custom exceptions can be translated when testing for throwing as something else" ) +{ + REQUIRE_THROWS_AS( throwCustom(), std::exception ); +} + + +TEST_CASE( "./failing/exceptions/custom/double", "Unexpected custom exceptions can be translated" ) +{ + if( Catch::isTrue( true ) ) + throw double( 3.14 ); +} + +inline int thisFunctionNotImplemented( int ) { + CATCH_NOT_IMPLEMENTED; +} + +TEST_CASE( "./succeeding/exceptions/notimplemented", "" ) +{ + REQUIRE_THROWS( thisFunctionNotImplemented( 7 ) ); +} diff --git a/projects/SelfTest/MessageTests.cpp b/projects/SelfTest/MessageTests.cpp index 0a02bb24..9ba6eaec 100644 --- a/projects/SelfTest/MessageTests.cpp +++ b/projects/SelfTest/MessageTests.cpp @@ -8,99 +8,95 @@ #include "catch.hpp" -namespace MessageTests +TEST_CASE( "./succeeding/message", "INFO and WARN do not abort tests" ) { + INFO( "this is a " << "message" ); // This should output the message if a failure occurs + WARN( "this is a " << "warning" ); // This should always output the message but then continue +} +TEST_CASE( "./succeeding/succeed", "SUCCEED counts as a test pass" ) +{ + SUCCEED( "this is a " << "success" ); +} - TEST_CASE( "./succeeding/message", "INFO and WARN do not abort tests" ) - { - INFO( "this is a " << "message" ); // This should output the message if a failure occurs - WARN( "this is a " << "warning" ); // This should always output the message but then continue - } - TEST_CASE( "./succeeding/succeed", "SUCCEED counts as a test pass" ) - { - SUCCEED( "this is a " << "success" ); - } +TEST_CASE( "./failing/message/info/1", "INFO gets logged on failure" ) +{ + INFO( "this message should be logged" ); + INFO( "so should this" ); + int a = 2; + REQUIRE( a == 1 ); +} - TEST_CASE( "./failing/message/info/1", "INFO gets logged on failure" ) - { - INFO( "this message should be logged" ); - INFO( "so should this" ); - int a = 2; - REQUIRE( a == 1 ); - } +TEST_CASE( "./mixed/message/info/2", "INFO gets logged on failure" ) +{ + INFO( "this message may be logged later" ); + int a = 2; + CHECK( a == 2 ); - TEST_CASE( "./mixed/message/info/2", "INFO gets logged on failure" ) - { - INFO( "this message may be logged later" ); - int a = 2; - CHECK( a == 2 ); - - INFO( "this message should be logged" ); + INFO( "this message should be logged" ); - CHECK( a == 1 ); + CHECK( a == 1 ); - INFO( "and this, but later" ); + INFO( "and this, but later" ); - CHECK( a == 0 ); + CHECK( a == 0 ); - INFO( "but not this" ); + INFO( "but not this" ); - CHECK( a == 2 ); + CHECK( a == 2 ); +} + +TEST_CASE( "./failing/message/fail", "FAIL aborts the test" ) +{ + if( Catch::isTrue( true ) ) + FAIL( "This is a " << "failure" ); // This should output the message and abort +} + +TEST_CASE( "./failing/message/sections", "Output from all sections is reported" ) +{ + SECTION( "one", "" ) + { + FAIL( "Message from section one" ); } - TEST_CASE( "./failing/message/fail", "FAIL aborts the test" ) + SECTION( "two", "" ) { - if( Catch::isTrue( true ) ) - FAIL( "This is a " << "failure" ); // This should output the message and abort + FAIL( "Message from section two" ); } +} - TEST_CASE( "./failing/message/sections", "Output from all sections is reported" ) +TEST_CASE( "./succeeding/message/sections/stdout", "Output from all sections is reported" ) +{ + SECTION( "one", "" ) { - SECTION( "one", "" ) - { - FAIL( "Message from section one" ); - } - - SECTION( "two", "" ) - { - FAIL( "Message from section two" ); - } + std::cout << "Message from section one" << std::endl; } - - TEST_CASE( "./succeeding/message/sections/stdout", "Output from all sections is reported" ) - { - SECTION( "one", "" ) - { - std::cout << "Message from section one" << std::endl; - } - SECTION( "two", "" ) - { - std::cout << "Message from section two" << std::endl; - } + SECTION( "two", "" ) + { + std::cout << "Message from section two" << std::endl; } +} - TEST_CASE( "./mixed/message/scoped", "" ) +TEST_CASE( "./mixed/message/scoped", "" ) +{ + for( int i=0; i<100; i++ ) { - for( int i=0; i<100; i++ ) - { - SCOPED_INFO( "current counter " << i ); - SCOPED_CAPTURE( i ); - REQUIRE( i < 10 ); - } + SCOPED_INFO( "current counter " << i ); + SCOPED_CAPTURE( i ); + REQUIRE( i < 10 ); } +} - TEST_CASE( "./succeeding/nofail", "The NO_FAIL macro reports a failure but does not fail the test" ) - { - CHECK_NOFAIL( 1 == 2 ); - } +TEST_CASE( "./succeeding/nofail", "The NO_FAIL macro reports a failure but does not fail the test" ) +{ + CHECK_NOFAIL( 1 == 2 ); +} - TEST_CASE( "just info", "[info][isolated info][.]" ) - { - INFO( "this should never be seen" ); - } - TEST_CASE( "just failure", "[fail][isolated info][.]" ) - { - FAIL( "Previous info should not be seen" ); - } - } +TEST_CASE( "just info", "[info][isolated info][.]" ) +{ + INFO( "this should never be seen" ); +} +TEST_CASE( "just failure", "[fail][isolated info][.]" ) +{ + FAIL( "Previous info should not be seen" ); +} diff --git a/projects/SelfTest/MiscTests.cpp b/projects/SelfTest/MiscTests.cpp index e980fb84..5de04c56 100644 --- a/projects/SelfTest/MiscTests.cpp +++ b/projects/SelfTest/MiscTests.cpp @@ -11,360 +11,356 @@ #include -namespace MiscTests +TEST_CASE( "./succeeding/Misc/Sections", "random SECTION tests" ) { - - TEST_CASE( "./succeeding/Misc/Sections", "random SECTION tests" ) - { - int a = 1; - int b = 2; + int a = 1; + int b = 2; - SECTION( "s1", "doesn't equal" ) - { - REQUIRE( a != b ); - REQUIRE( b != a ); - } + SECTION( "s1", "doesn't equal" ) + { + REQUIRE( a != b ); + REQUIRE( b != a ); + } + + SECTION( "s2", "not equal" ) + { + REQUIRE( a != b); + } +} + +TEST_CASE( "./succeeding/Misc/Sections/nested", "nested SECTION tests" ) +{ + int a = 1; + int b = 2; + + SECTION( "s1", "doesn't equal" ) + { + REQUIRE( a != b ); + REQUIRE( b != a ); SECTION( "s2", "not equal" ) { REQUIRE( a != b); } } +} - TEST_CASE( "./succeeding/Misc/Sections/nested", "nested SECTION tests" ) - { - int a = 1; - int b = 2; +TEST_CASE( "./mixed/Misc/Sections/nested2", "nested SECTION tests" ) +{ + int a = 1; + int b = 2; - SECTION( "s1", "doesn't equal" ) + SECTION( "s1", "doesn't equal" ) + { + SECTION( "s2", "equal" ) + { + REQUIRE( a == b ); + } + + SECTION( "s3", "not equal" ) { REQUIRE( a != b ); - REQUIRE( b != a ); - - SECTION( "s2", "not equal" ) - { - REQUIRE( a != b); - } + } + SECTION( "s4", "less than" ) + { + REQUIRE( a < b ); } } +} - TEST_CASE( "./mixed/Misc/Sections/nested2", "nested SECTION tests" ) +TEST_CASE( "./Sections/nested/a/b", "nested SECTION tests" ) +{ + SECTION( "c", "" ) { - int a = 1; - int b = 2; - - SECTION( "s1", "doesn't equal" ) + SECTION( "d (leaf)", "" ) { - SECTION( "s2", "equal" ) - { - REQUIRE( a == b ); - } - - SECTION( "s3", "not equal" ) - { - REQUIRE( a != b ); - } - SECTION( "s4", "less than" ) - { - REQUIRE( a < b ); - } } - } - - TEST_CASE( "./Sections/nested/a/b", "nested SECTION tests" ) - { - SECTION( "c", "" ) - { - SECTION( "d (leaf)", "" ) - { - } - SECTION( "e (leaf)", "" ) - { - } - } - - SECTION( "f (leaf)", "" ) + SECTION( "e (leaf)", "" ) { } } - TEST_CASE( "./mixed/Misc/Sections/loops", "looped SECTION tests" ) + SECTION( "f (leaf)", "" ) { - int a = 1; + } +} + +TEST_CASE( "./mixed/Misc/Sections/loops", "looped SECTION tests" ) +{ + int a = 1; - for( int b = 0; b < 10; ++b ) + for( int b = 0; b < 10; ++b ) + { + std::ostringstream oss; + oss << "b is currently: " << b; + SECTION( "s1", oss.str() ) { - std::ostringstream oss; - oss << "b is currently: " << b; - SECTION( "s1", oss.str() ) - { - CHECK( b > a ); - } + CHECK( b > a ); } } +} - TEST_CASE( "./mixed/Misc/loops", "looped tests" ) - { - static const int fib[] = { 1, 1, 2, 3, 5, 8, 13, 21 }; +TEST_CASE( "./mixed/Misc/loops", "looped tests" ) +{ + static const int fib[] = { 1, 1, 2, 3, 5, 8, 13, 21 }; - for( size_t i=0; i < sizeof(fib)/sizeof(int); ++i ) - { - INFO( "Testing if fib[" << i << "] (" << fib[i] << ") is even" ); - CHECK( ( fib[i] % 2 ) == 0 ); - } - } - - TEST_CASE( "./succeeding/Misc/stdout,stderr", "Sends stuff to stdout and stderr" ) + for( size_t i=0; i < sizeof(fib)/sizeof(int); ++i ) { - std::cout << "Some information" << std::endl; + INFO( "Testing if fib[" << i << "] (" << fib[i] << ") is even" ); + CHECK( ( fib[i] % 2 ) == 0 ); + } +} + +TEST_CASE( "./succeeding/Misc/stdout,stderr", "Sends stuff to stdout and stderr" ) +{ + std::cout << "Some information" << std::endl; - std::cerr << "An error" << std::endl; - } + std::cerr << "An error" << std::endl; +} - inline const char* makeString( bool makeNull ) - { - return makeNull ? NULL : "valid string"; - } +inline const char* makeString( bool makeNull ) +{ + return makeNull ? NULL : "valid string"; +} - TEST_CASE( "./succeeding/Misc/null strings", "" ) - { - REQUIRE( makeString( false ) != static_cast(NULL)); - REQUIRE( makeString( true ) == static_cast(NULL)); - } +TEST_CASE( "./succeeding/Misc/null strings", "" ) +{ + REQUIRE( makeString( false ) != static_cast(NULL)); + REQUIRE( makeString( true ) == static_cast(NULL)); +} - TEST_CASE( "./failing/info", "sends information to INFO" ) - { - INFO( "hi" ); - int i = 7; - CAPTURE( i ); - REQUIRE( false ); - } +TEST_CASE( "./failing/info", "sends information to INFO" ) +{ + INFO( "hi" ); + int i = 7; + CAPTURE( i ); + REQUIRE( false ); +} - inline bool testCheckedIf( bool flag ) - { - CHECKED_IF( flag ) - return true; - else - return false; - } - - TEST_CASE( "./succeeding/checkedif", "" ) - { - REQUIRE( testCheckedIf( true ) ); - } - - TEST_CASE( "./failing/checkedif", "" ) - { - REQUIRE( testCheckedIf( false ) ); - } - - inline bool testCheckedElse( bool flag ) - { - CHECKED_ELSE( flag ) - return false; - +inline bool testCheckedIf( bool flag ) +{ + CHECKED_IF( flag ) return true; - } + else + return false; +} - TEST_CASE( "./succeeding/checkedelse", "" ) - { - REQUIRE( testCheckedElse( true ) ); - } +TEST_CASE( "./succeeding/checkedif", "" ) +{ + REQUIRE( testCheckedIf( true ) ); +} - TEST_CASE( "./failing/checkedelse", "" ) - { - REQUIRE( testCheckedElse( false ) ); - } +TEST_CASE( "./failing/checkedif", "" ) +{ + REQUIRE( testCheckedIf( false ) ); +} - TEST_CASE( "./misc/xmlentitycheck", "" ) +inline bool testCheckedElse( bool flag ) +{ + CHECKED_ELSE( flag ) + return false; + + return true; +} + +TEST_CASE( "./succeeding/checkedelse", "" ) +{ + REQUIRE( testCheckedElse( true ) ); +} + +TEST_CASE( "./failing/checkedelse", "" ) +{ + REQUIRE( testCheckedElse( false ) ); +} + +TEST_CASE( "./misc/xmlentitycheck", "" ) +{ + SECTION( "embedded xml", "it should be possible to embed xml characters, such as <, \" or &, or even whole documents within an attribute" ) { - SECTION( "embedded xml", "it should be possible to embed xml characters, such as <, \" or &, or even whole documents within an attribute" ) - { - // No test - } - SECTION( "encoded chars", "these should all be encoded: &&&\"\"\"<<<&\"<<&\"" ) - { - // No test + // No test + } + SECTION( "encoded chars", "these should all be encoded: &&&\"\"\"<<<&\"<<&\"" ) + { + // No test + } +} + +TEST_CASE( "./manual/onechar", "send a single char to INFO" ) +{ + INFO(3); + REQUIRE(false); +} + +TEST_CASE("./succeeding/atomic if", "") +{ + size_t x = 0; + + if( x ) + REQUIRE(x > 0); + else + REQUIRE(x == 0); +} + +inline const char* testStringForMatching() +{ + return "this string contains 'abc' as a substring"; +} + +TEST_CASE("./succeeding/matchers", "") +{ + REQUIRE_THAT( testStringForMatching(), Contains( "string" ) ); + CHECK_THAT( testStringForMatching(), Contains( "abc" ) ); + + CHECK_THAT( testStringForMatching(), StartsWith( "this" ) ); + CHECK_THAT( testStringForMatching(), EndsWith( "substring" ) ); +} + +TEST_CASE("./failing/matchers/Contains", "") +{ + CHECK_THAT( testStringForMatching(), Contains( "not there" ) ); +} + +TEST_CASE("./failing/matchers/StartsWith", "") +{ + CHECK_THAT( testStringForMatching(), StartsWith( "string" ) ); +} + +TEST_CASE("./failing/matchers/EndsWith", "") +{ + CHECK_THAT( testStringForMatching(), EndsWith( "this" ) ); +} + +TEST_CASE("./failing/matchers/Equals", "") +{ + CHECK_THAT( testStringForMatching(), Equals( "something else" ) ); +} +TEST_CASE("string", "Equals with NULL") +{ + REQUIRE_THAT("", Equals(NULL)); +} +TEST_CASE("./succeeding/matchers/AllOf", "") +{ + CHECK_THAT( testStringForMatching(), AllOf( Catch::Contains( "string" ), Catch::Contains( "abc" ) ) ); +} +TEST_CASE("./succeeding/matchers/AnyOf", "") +{ + CHECK_THAT( testStringForMatching(), AnyOf( Catch::Contains( "string" ), Catch::Contains( "not there" ) ) ); + CHECK_THAT( testStringForMatching(), AnyOf( Catch::Contains( "not there" ), Catch::Contains( "string" ) ) ); +} + +TEST_CASE("./succeeding/matchers/Equals", "") +{ + CHECK_THAT( testStringForMatching(), Equals( "this string contains 'abc' as a substring" ) ); +} + +inline unsigned int Factorial( unsigned int number ) +{ +// return number <= 1 ? number : Factorial(number-1)*number; + return number > 1 ? Factorial(number-1)*number : 1; +} + +TEST_CASE( "Factorials are computed", "[factorial]" ) { + REQUIRE( Factorial(0) == 1 ); + REQUIRE( Factorial(1) == 1 ); + REQUIRE( Factorial(2) == 2 ); + REQUIRE( Factorial(3) == 6 ); + REQUIRE( Factorial(10) == 3628800 ); +} + +TEST_CASE( "empty", "An empty test with no assertions" ) +{ +} + +TEST_CASE( "Nice descriptive name", "[tag1][tag2][tag3][.]" ) +{ + WARN( "This one ran" ); +} +TEST_CASE( "first tag", "[tag1]" ) +{ +} +TEST_CASE( "second tag", "[tag2]" ) +{ +} +// +//TEST_CASE( "spawn a new process", "[.]" ) +//{ +// // !TBD Work in progress +// char line[200]; +// FILE* output = popen("./CatchSelfTest ./failing/matchers/StartsWith", "r"); +// while ( fgets(line, 199, output) ) +// std::cout << line; +//} + +TEST_CASE( "vectors can be sized and resized", "[vector]" ) { + + std::vector v( 5 ); + + REQUIRE( v.size() == 5 ); + REQUIRE( v.capacity() >= 5 ); + + SECTION( "resizing bigger changes size and capacity", "" ) { + v.resize( 10 ); + + REQUIRE( v.size() == 10 ); + REQUIRE( v.capacity() >= 10 ); + } + SECTION( "resizing smaller changes size but not capacity", "" ) { + v.resize( 0 ); + + REQUIRE( v.size() == 0 ); + REQUIRE( v.capacity() >= 5 ); + + SECTION( "We can use the 'swap trick' to reset the capacity", "" ) { + std::vector empty; + empty.swap( v ); + + REQUIRE( v.capacity() == 0 ); } } - - TEST_CASE( "./manual/onechar", "send a single char to INFO" ) - { - INFO(3); - REQUIRE(false); + SECTION( "reserving bigger changes capacity but not size", "" ) { + v.reserve( 10 ); + + REQUIRE( v.size() == 5 ); + REQUIRE( v.capacity() >= 10 ); } - - TEST_CASE("./succeeding/atomic if", "") - { - size_t x = 0; - - if( x ) - REQUIRE(x > 0); - else - REQUIRE(x == 0); - } - - inline const char* testStringForMatching() - { - return "this string contains 'abc' as a substring"; - } - - TEST_CASE("./succeeding/matchers", "") - { - REQUIRE_THAT( testStringForMatching(), Contains( "string" ) ); - CHECK_THAT( testStringForMatching(), Contains( "abc" ) ); - - CHECK_THAT( testStringForMatching(), StartsWith( "this" ) ); - CHECK_THAT( testStringForMatching(), EndsWith( "substring" ) ); - } - - TEST_CASE("./failing/matchers/Contains", "") - { - CHECK_THAT( testStringForMatching(), Contains( "not there" ) ); - } - - TEST_CASE("./failing/matchers/StartsWith", "") - { - CHECK_THAT( testStringForMatching(), StartsWith( "string" ) ); - } - - TEST_CASE("./failing/matchers/EndsWith", "") - { - CHECK_THAT( testStringForMatching(), EndsWith( "this" ) ); - } - - TEST_CASE("./failing/matchers/Equals", "") - { - CHECK_THAT( testStringForMatching(), Equals( "something else" ) ); - } - TEST_CASE("string", "Equals with NULL") - { - REQUIRE_THAT("", Equals(NULL)); - } - TEST_CASE("./succeeding/matchers/AllOf", "") - { - CHECK_THAT( testStringForMatching(), AllOf( Catch::Contains( "string" ), Catch::Contains( "abc" ) ) ); - } - TEST_CASE("./succeeding/matchers/AnyOf", "") - { - CHECK_THAT( testStringForMatching(), AnyOf( Catch::Contains( "string" ), Catch::Contains( "not there" ) ) ); - CHECK_THAT( testStringForMatching(), AnyOf( Catch::Contains( "not there" ), Catch::Contains( "string" ) ) ); - } - - TEST_CASE("./succeeding/matchers/Equals", "") - { - CHECK_THAT( testStringForMatching(), Equals( "this string contains 'abc' as a substring" ) ); - } - - inline unsigned int Factorial( unsigned int number ) - { - // return number <= 1 ? number : Factorial(number-1)*number; - return number > 1 ? Factorial(number-1)*number : 1; - } - - TEST_CASE( "Factorials are computed", "[factorial]" ) { - REQUIRE( Factorial(0) == 1 ); - REQUIRE( Factorial(1) == 1 ); - REQUIRE( Factorial(2) == 2 ); - REQUIRE( Factorial(3) == 6 ); - REQUIRE( Factorial(10) == 3628800 ); - } - - TEST_CASE( "empty", "An empty test with no assertions" ) - { - } - - TEST_CASE( "Nice descriptive name", "[tag1][tag2][tag3][.]" ) - { - WARN( "This one ran" ); - } - TEST_CASE( "first tag", "[tag1]" ) - { - } - TEST_CASE( "second tag", "[tag2]" ) - { - } - // - //TEST_CASE( "spawn a new process", "[.]" ) - //{ - // // !TBD Work in progress - // char line[200]; - // FILE* output = popen("./CatchSelfTest ./failing/matchers/StartsWith", "r"); - // while ( fgets(line, 199, output) ) - // std::cout << line; - //} - - TEST_CASE( "vectors can be sized and resized", "[vector]" ) { - - std::vector v( 5 ); - + SECTION( "reserving smaller does not change size or capacity", "" ) { + v.reserve( 0 ); + REQUIRE( v.size() == 5 ); REQUIRE( v.capacity() >= 5 ); - - SECTION( "resizing bigger changes size and capacity", "" ) { - v.resize( 10 ); - - REQUIRE( v.size() == 10 ); - REQUIRE( v.capacity() >= 10 ); - } - SECTION( "resizing smaller changes size but not capacity", "" ) { - v.resize( 0 ); - - REQUIRE( v.size() == 0 ); - REQUIRE( v.capacity() >= 5 ); - - SECTION( "We can use the 'swap trick' to reset the capacity", "" ) { - std::vector empty; - empty.swap( v ); - - REQUIRE( v.capacity() == 0 ); - } - } - SECTION( "reserving bigger changes capacity but not size", "" ) { - v.reserve( 10 ); - - REQUIRE( v.size() == 5 ); - REQUIRE( v.capacity() >= 10 ); - } - SECTION( "reserving smaller does not change size or capacity", "" ) { - v.reserve( 0 ); - - REQUIRE( v.size() == 5 ); - REQUIRE( v.capacity() >= 5 ); - } } - - // https://github.com/philsquared/Catch/issues/166 - TEST_CASE("./failing/CatchSectionInfiniteLoop", "") - { - SECTION("Outer", "") - SECTION("Inner", "") - SUCCEED("that's not flying - that's failing in style"); - - FAIL("to infinity and beyond"); - } - - - //#include "internal/catch_timer.h" - // - //TEST_CASE( "Timer", "[work-in-progress]" ) - //{ - // Catch::Timer t; - // t.start(); - // - // std::cout << "starting..." << std::endl; - // - // double d = 0; - // for( int i = 0; i < 100000; ++i ) - // for( int j = 0; j < 1000; ++j ) - // d += (double)i*(double)j; - // - // double duration = t.getElapsedSeconds(); - // - // std::cout << "finished in " << duration << std::endl; - // - // SUCCEED("yay"); - // - //} } + +// https://github.com/philsquared/Catch/issues/166 +TEST_CASE("./failing/CatchSectionInfiniteLoop", "") +{ + SECTION("Outer", "") + SECTION("Inner", "") + SUCCEED("that's not flying - that's failing in style"); + + FAIL("to infinity and beyond"); +} + + +//#include "internal/catch_timer.h" +// +//TEST_CASE( "Timer", "[work-in-progress]" ) +//{ +// Catch::Timer t; +// t.start(); +// +// std::cout << "starting..." << std::endl; +// +// double d = 0; +// for( int i = 0; i < 100000; ++i ) +// for( int j = 0; j < 1000; ++j ) +// d += (double)i*(double)j; +// +// double duration = t.getElapsedSeconds(); +// +// std::cout << "finished in " << duration << std::endl; +// +// SUCCEED("yay"); +// +//} diff --git a/projects/SelfTest/TrickyTests.cpp b/projects/SelfTest/TrickyTests.cpp index 6d07d56f..27e1b8fd 100644 --- a/projects/SelfTest/TrickyTests.cpp +++ b/projects/SelfTest/TrickyTests.cpp @@ -24,98 +24,94 @@ namespace Catch } } -namespace TrickTests +/////////////////////////////////////////////////////////////////////////////// +TEST_CASE +( + "./succeeding/Tricky/std::pair", + "Parsing a std::pair" +) { + std::pair aNicePair( 1, 2 ); - /////////////////////////////////////////////////////////////////////////////// - TEST_CASE - ( - "./succeeding/Tricky/std::pair", - "Parsing a std::pair" - ) - { - std::pair aNicePair( 1, 2 ); + REQUIRE( (std::pair( 1, 2 )) == aNicePair ); +} - REQUIRE( (std::pair( 1, 2 )) == aNicePair ); - } - - /////////////////////////////////////////////////////////////////////////////// - TEST_CASE - ( - "./inprogress/failing/Tricky/trailing expression", - "Where the is more to the expression after the RHS" - ) - { - // int a = 1, b = 2; - // REQUIRE( a == 2 || b == 2 ); - WARN( "Uncomment the code in this test to check that it gives a sensible compiler error" ); - } - /////////////////////////////////////////////////////////////////////////////// - TEST_CASE - ( - "./inprogress/failing/Tricky/compound lhs", - "Where the LHS is not a simple value" - ) - { - /* - int a = 1; - int b = 2; +/////////////////////////////////////////////////////////////////////////////// +TEST_CASE +( + "./inprogress/failing/Tricky/trailing expression", + "Where the is more to the expression after the RHS" +) +{ +// int a = 1, b = 2; +// REQUIRE( a == 2 || b == 2 ); + WARN( "Uncomment the code in this test to check that it gives a sensible compiler error" ); +} +/////////////////////////////////////////////////////////////////////////////// +TEST_CASE +( + "./inprogress/failing/Tricky/compound lhs", + "Where the LHS is not a simple value" +) +{ + /* + int a = 1; + int b = 2; - // This only captures part of the expression, but issues a warning about the rest - REQUIRE( a+1 == b-1 ); - */ - WARN( "Uncomment the code in this test to check that it gives a sensible compiler error" ); + // This only captures part of the expression, but issues a warning about the rest + REQUIRE( a+1 == b-1 ); + */ + WARN( "Uncomment the code in this test to check that it gives a sensible compiler error" ); +} + +struct Opaque +{ + int val; + bool operator ==( const Opaque& o ) const + { + return val == o.val; } +}; - struct Opaque - { - int val; - bool operator ==( const Opaque& o ) const - { - return val == o.val; - } - }; - - /////////////////////////////////////////////////////////////////////////////// - TEST_CASE - ( - "./failing/Tricky/non streamable type", - "A failing expression with a non streamable type is still captured" - ) - { +/////////////////////////////////////////////////////////////////////////////// +TEST_CASE +( + "./failing/Tricky/non streamable type", + "A failing expression with a non streamable type is still captured" +) +{ - Opaque o1, o2; - o1.val = 7; - o2.val = 8; + Opaque o1, o2; + o1.val = 7; + o2.val = 8; - CHECK( &o1 == &o2 ); - CHECK( o1 == o2 ); - } + CHECK( &o1 == &o2 ); + CHECK( o1 == o2 ); +} - /////////////////////////////////////////////////////////////////////////////// - TEST_CASE - ( - "./failing/string literals", - "string literals of different sizes can be compared" - ) - { - REQUIRE( std::string( "first" ) == "second" ); +/////////////////////////////////////////////////////////////////////////////// +TEST_CASE +( + "./failing/string literals", + "string literals of different sizes can be compared" +) +{ + REQUIRE( std::string( "first" ) == "second" ); - } +} - /////////////////////////////////////////////////////////////////////////////// - TEST_CASE - ( - "./succeeding/side-effects", - "An expression with side-effects should only be evaluated once" - ) - { - int i = 7; +/////////////////////////////////////////////////////////////////////////////// +TEST_CASE +( + "./succeeding/side-effects", + "An expression with side-effects should only be evaluated once" +) +{ + int i = 7; - REQUIRE( i++ == 7 ); - REQUIRE( i++ == 8 ); + REQUIRE( i++ == 7 ); + REQUIRE( i++ == 8 ); - } } namespace A { diff --git a/projects/VS2010/TestCatch/TestCatch/TestCatch.vcxproj b/projects/VS2010/TestCatch/TestCatch/TestCatch.vcxproj index d9105496..a8f60653 100644 --- a/projects/VS2010/TestCatch/TestCatch/TestCatch.vcxproj +++ b/projects/VS2010/TestCatch/TestCatch/TestCatch.vcxproj @@ -94,11 +94,8 @@ - - - @@ -110,86 +107,41 @@ + + - - - + - - - - - - - - - - - + + - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - + - - - - diff --git a/projects/VS2010/TestCatch/TestCatch/TestCatch.vcxproj.filters b/projects/VS2010/TestCatch/TestCatch/TestCatch.vcxproj.filters index b358c13d..9742aa2a 100644 --- a/projects/VS2010/TestCatch/TestCatch/TestCatch.vcxproj.filters +++ b/projects/VS2010/TestCatch/TestCatch/TestCatch.vcxproj.filters @@ -7,9 +7,6 @@ Sources - - Sources - Sources @@ -28,12 +25,6 @@ Sources - - Sources - - - Sources - Sources @@ -51,24 +42,9 @@ - - Sources - Headers - - Headers - - - Headers - - - Headers - - - Headers - Headers @@ -78,48 +54,18 @@ Headers - - Headers - Headers - - Headers - - - Headers - - - Headers - - - Headers - Headers - - Headers - Headers Headers - - Headers - - - Headers - - - Headers - - - Headers - Headers @@ -132,18 +78,9 @@ Headers - - Headers - Headers - - Headers - - - Headers - Headers @@ -153,51 +90,9 @@ Headers - - Headers - - - Headers - Headers - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - - - Headers - Headers @@ -222,72 +117,39 @@ Headers - - Headers - - - Headers - Headers - - Headers - - - Headers - - - Headers - Headers - - Headers - Headers Headers - + Headers - + Headers - + Headers - + Headers - + Headers - + Headers - + Headers - - Headers - - - Headers - - - Headers - - - Headers - - - -