From 587af6a408071812fede8a223bcbbd3100bd31ab Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Wed, 9 Jan 2019 23:23:04 +0100 Subject: [PATCH 01/33] README.md: Add C++11 note on major version 5 --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2ade74b..313b2c7 100644 --- a/README.md +++ b/README.md @@ -518,6 +518,8 @@ Compatibility-breaking changes since version 3.0.0: Booleans are now displayed as `true` or `false`. Strings are put into quotation marks for improved readability. + * Since version 5.0.0, the support for C++ versions prior to C++11 are dropped. + ## Contributing The development of Snowhouse takes place on [GitHub](//github.com/banditcpp/snowhouse). @@ -533,7 +535,7 @@ Please make sure to be consistent with the project's coding style. The `.clang-format` file allows easy checking and implementation of the coding style. -C++ code should comply to C++98, C++03- and C++11. +C++ code should comply to C++11. Please use `__cplusplus` guards if you want to use language features of a certain C++ version. From 95529d990eabc1c2c8c55da1f27592a8f1091b63 Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Fri, 27 Dec 2019 00:31:01 +0100 Subject: [PATCH 02/33] Drop C++98 and C++03 support from build scripts --- .appveyor.yml | 2 -- .github/workflows/ci.yml | 4 ++-- .travis.yml | 9 --------- CMakeLists.txt | 10 +++------- util/build-in-container.sh | 2 +- util/build.sh | 4 ++-- 6 files changed, 8 insertions(+), 23 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 1363e01..f915c36 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,7 +1,5 @@ environment: matrix: - - CXX_STANDARD: 98 - - CXX_STANDARD: 03 - CXX_STANDARD: 11 - CXX_STANDARD: 14 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 24cf50c..efaa53c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: image: docker://banditcpp/build-environments:debian-bullseye-compilers strategy: matrix: - cxx-standard: ["98", "03", "11", "14", "17"] + cxx-standard: ["11", "14", "17"] compiler-env: ["CC=gcc-9 CXX=g++-9", "CC=clang-9 CXX=clang++-9"] steps: - name: Clone and checkout commit @@ -22,7 +22,7 @@ jobs: runs-on: windows-2019 strategy: matrix: - # C++98, C++03 and C++11 is NOT supported by MSVC 2019 + # C++11 is NOT supported by MSVC 2019 cxx-standard: ["14", "17"] steps: - name: Clone and checkout commit diff --git a/.travis.yml b/.travis.yml index 5fed4b5..4c474dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,18 +6,9 @@ services: - docker env: - - DOCKER_TAG=snowhouse-minimum CXX_STANDARD=98 CC=gcc-4.4 CXX=g++-4.4 - - DOCKER_TAG=snowhouse-minimum CXX_STANDARD=98 CC=gcc-4.6 CXX=g++-4.6 - - DOCKER_TAG=snowhouse-minimum CXX_STANDARD=03 CC=gcc-4.6 CXX=g++-4.6 - - DOCKER_TAG=snowhouse-minimum CXX_STANDARD=98 CC=clang CXX=clang++ - - DOCKER_TAG=snowhouse-minimum CXX_STANDARD=03 CC=clang CXX=clang++ - DOCKER_TAG=snowhouse-minimum CXX_STANDARD=11 CC=clang CXX=clang++ - - DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=98 CC=gcc-4.8 CXX=g++-4.8 - - DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=03 CC=gcc-4.8 CXX=g++-4.8 - DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=11 CC=gcc-4.8 CXX=g++-4.8 - - DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=98 CC=gcc-4.9 CXX=g++-4.9 - DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=11 CC=gcc-4.9 CXX=g++-4.9 - - DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=98 CC=clang-3.5 CXX=clang++-3.5 - DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=11 CC=clang-3.5 CXX=clang++-3.5 - DOCKER_TAG=debian-stretch-compilers CXX_STANDARD=11 CC=gcc-6 CXX=g++-6 - DOCKER_TAG=debian-stretch-compilers CXX_STANDARD=11 CC=clang-3.9 CXX=clang++-3.9 diff --git a/CMakeLists.txt b/CMakeLists.txt index 9523a69..ebd0a43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,19 +4,15 @@ project(snowhouse) option(SNOWHOUSE_BUILD_TESTS "Build the Snowhouse tests" OFF) option(SNOWHOUSE_RUN_TESTS "Run the Snowhouse tests" OFF) -set(SNOWHOUSE_CXX_STANDARD "C++03" CACHE STRING "The C++ standard the examples are compiled with") -set_property(CACHE SNOWHOUSE_CXX_STANDARD PROPERTY STRINGS "C++98" "C++03" "C++11" "C++14" "C++17") +set(SNOWHOUSE_CXX_STANDARD "C++11" CACHE STRING "The C++ standard the examples are compiled with") +set_property(CACHE SNOWHOUSE_CXX_STANDARD PROPERTY STRINGS "C++11" "C++14" "C++17") if (NOT ${CMAKE_VERSION} VERSION_LESS "3.0.0") add_library(snowhouse INTERFACE) target_include_directories(snowhouse INTERFACE include) endif() -if(SNOWHOUSE_CXX_STANDARD STREQUAL "C++98") - set(std_name "c++98") -elseif(SNOWHOUSE_CXX_STANDARD STREQUAL "C++03") - set(std_name "c++03") -elseif(SNOWHOUSE_CXX_STANDARD STREQUAL "C++11") +if(SNOWHOUSE_CXX_STANDARD STREQUAL "C++11") set(std_name "c++11") elseif(SNOWHOUSE_CXX_STANDARD STREQUAL "C++14") set(std_name "c++14") diff --git a/util/build-in-container.sh b/util/build-in-container.sh index ca24b2c..9bd6a7d 100755 --- a/util/build-in-container.sh +++ b/util/build-in-container.sh @@ -2,7 +2,7 @@ if test "$#" -ne 2 then - echo "Usage: $0 (98|03|11|14) " >&2 + echo "Usage: $0 (11|14|17) " >&2 exit 2 fi diff --git a/util/build.sh b/util/build.sh index 23130ae..90c5e5f 100755 --- a/util/build.sh +++ b/util/build.sh @@ -6,10 +6,10 @@ test -n "$CXX" || CXX=c++ cxxstandard="$1" case "$cxxstandard" in -98|03|11|14|17) +11|14|17) ;; *) - echo "Usage: $0 (98|03|11|14|17) [image name]" >&2 + echo "Usage: $0 (11|14|17) [image name]" >&2 exit 1 esac From da16edc427de4201bf307bd7042ce3f3f504d69e Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Mon, 24 Feb 2020 18:59:41 +0100 Subject: [PATCH 03/33] Remove noexcept workaround for MSVC We require a C++11-compliant compiler now, so this is not necessary. --- include/snowhouse/macros.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/include/snowhouse/macros.h b/include/snowhouse/macros.h index 5247cb6..8224ab5 100644 --- a/include/snowhouse/macros.h +++ b/include/snowhouse/macros.h @@ -13,14 +13,6 @@ SNOWHOUSE_MACROTOSTRING(SNOWHOUSE_MINOR) "." \ SNOWHOUSE_MACROTOSTRING(SNOWHOUSE_PATCH) -#if __cplusplus > 199711L -// Visual Studio (including 2013) does not support the noexcept keyword -# if defined(_MSC_VER) && !defined(__clang__) -# define _ALLOW_KEYWORD_MACROS -# define noexcept -# endif -#endif - #if __cplusplus > 199711L || (defined(_MSC_VER) && _MSC_VER >= 1600) # include # define SNOWHOUSE_HAS_NULLPTR From 48db031f83caa49ba141d1a38caee8a6c3ceb0d4 Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Mon, 24 Feb 2020 19:02:22 +0100 Subject: [PATCH 04/33] Replace NULL by nullptr And remove inclusion of cstddef --- include/snowhouse/exceptions.h | 14 +++++++------- include/snowhouse/macros.h | 1 - 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/include/snowhouse/exceptions.h b/include/snowhouse/exceptions.h index 4518cd1..5cbd0f2 100644 --- a/include/snowhouse/exceptions.h +++ b/include/snowhouse/exceptions.h @@ -15,7 +15,7 @@ namespace snowhouse { static void last_exception(ExceptionType*** e, bool clear = false) { - static ExceptionType* last = NULL; + static ExceptionType* last = nullptr; if (clear && last) { delete last; @@ -33,12 +33,12 @@ namespace snowhouse static void store(const ExceptionType& e) { - ExceptionType** last = NULL; + ExceptionType** last = nullptr; last_exception(&last); if (*last) { delete *last; - *last = NULL; + *last = nullptr; } *last = new ExceptionType(e); @@ -50,12 +50,12 @@ namespace snowhouse ~ExceptionStorage() { - ExceptionType** e = NULL; + ExceptionType** e = nullptr; last_exception(&e); if (*e) { delete *e; - *e = NULL; + *e = nullptr; } } }; @@ -63,9 +63,9 @@ namespace snowhouse template inline ExceptionType& LastException() { - ExceptionType** e = NULL; + ExceptionType** e = nullptr; ExceptionStorage::last_exception(&e); - if (*e == NULL) + if (*e == nullptr) { Assert::Failure("No exception was stored"); } diff --git a/include/snowhouse/macros.h b/include/snowhouse/macros.h index 8224ab5..31c81e8 100644 --- a/include/snowhouse/macros.h +++ b/include/snowhouse/macros.h @@ -14,7 +14,6 @@ SNOWHOUSE_MACROTOSTRING(SNOWHOUSE_PATCH) #if __cplusplus > 199711L || (defined(_MSC_VER) && _MSC_VER >= 1600) -# include # define SNOWHOUSE_HAS_NULLPTR #endif From 4117feaef537b2d196c92ed9bea6d0e9a9e7ca25 Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Mon, 24 Feb 2020 19:03:27 +0100 Subject: [PATCH 05/33] Remove SNOWHOUSE_HAS_NULLPTR We have nullptr now because of C++11. --- README.md | 4 +--- example/basic_assertions.cpp | 2 -- include/snowhouse/constraints/equalsconstraint.h | 2 -- include/snowhouse/fluent/expressionbuilder.h | 2 -- include/snowhouse/macros.h | 5 ----- include/snowhouse/stringize.h | 4 ---- include/snowhouse/stringizers.h | 4 ---- 7 files changed, 1 insertion(+), 22 deletions(-) diff --git a/README.md b/README.md index 313b2c7..fb99729 100644 --- a/README.md +++ b/README.md @@ -166,9 +166,6 @@ AssertThat(x, IsNull()); AssertThat(x, Is().Null()); ``` -Note that this feature is only available for C++11-compliant compilers. -In this case, the `SNOWHOUSE_HAS_NULLPTR` macro is defined. - ### String Constraints String assertions in Snowhouse are used to verify the values of @@ -519,6 +516,7 @@ Compatibility-breaking changes since version 3.0.0: Strings are put into quotation marks for improved readability. * Since version 5.0.0, the support for C++ versions prior to C++11 are dropped. + The definition of the macro `SNOWHOUSE_HAS_NULLPTR` is removed. ## Contributing diff --git a/example/basic_assertions.cpp b/example/basic_assertions.cpp index 7f0a661..7c0e92b 100644 --- a/example/basic_assertions.cpp +++ b/example/basic_assertions.cpp @@ -180,7 +180,6 @@ void BasicAssertions() "Expected: less than or equal to 5\nActual: 6\n"); } -#ifdef SNOWHOUSE_HAS_NULLPTR it("handles IsNull()"); { AssertThat(nullptr, IsNull()); @@ -220,5 +219,4 @@ void BasicAssertions() AssertTestFails(AssertThat(nullptr, !IsNull()), message.str()); } -#endif } diff --git a/include/snowhouse/constraints/equalsconstraint.h b/include/snowhouse/constraints/equalsconstraint.h index d799751..2c0f728 100644 --- a/include/snowhouse/constraints/equalsconstraint.h +++ b/include/snowhouse/constraints/equalsconstraint.h @@ -48,12 +48,10 @@ namespace snowhouse return EqualsConstraint(true); } -#ifdef SNOWHOUSE_HAS_NULLPTR inline EqualsConstraint IsNull() { return EqualsConstraint(nullptr); } -#endif template<> struct Stringizer > diff --git a/include/snowhouse/fluent/expressionbuilder.h b/include/snowhouse/fluent/expressionbuilder.h index c9a0516..ad1b2f7 100644 --- a/include/snowhouse/fluent/expressionbuilder.h +++ b/include/snowhouse/fluent/expressionbuilder.h @@ -91,13 +91,11 @@ namespace snowhouse return EqualTo(true); } -#ifdef SNOWHOUSE_HAS_NULLPTR ExpressionBuilder >, Nil> >::t> Null() { return EqualTo(nullptr); } -#endif ExpressionBuilder >, Nil> >::t> EqualTo(const char* expected) diff --git a/include/snowhouse/macros.h b/include/snowhouse/macros.h index 31c81e8..0309ee7 100644 --- a/include/snowhouse/macros.h +++ b/include/snowhouse/macros.h @@ -12,9 +12,4 @@ SNOWHOUSE_MACROTOSTRING(SNOWHOUSE_MAJOR) "." \ SNOWHOUSE_MACROTOSTRING(SNOWHOUSE_MINOR) "." \ SNOWHOUSE_MACROTOSTRING(SNOWHOUSE_PATCH) - -#if __cplusplus > 199711L || (defined(_MSC_VER) && _MSC_VER >= 1600) -# define SNOWHOUSE_HAS_NULLPTR -#endif - #endif diff --git a/include/snowhouse/stringize.h b/include/snowhouse/stringize.h index 420d4d7..c4e1673 100644 --- a/include/snowhouse/stringize.h +++ b/include/snowhouse/stringize.h @@ -53,13 +53,11 @@ namespace snowhouse static const bool value = sizeof(check(std::cout << x)) == sizeof(yes); }; -#ifdef SNOWHOUSE_HAS_NULLPTR template<> struct is_output_streamable { static const bool value = false; }; -#endif } namespace detail @@ -122,7 +120,6 @@ namespace snowhouse } }; -#ifdef SNOWHOUSE_HAS_NULLPTR // We need this because nullptr_t has ambiguous overloads of operator<< in the standard library. template<> struct Stringizer @@ -132,7 +129,6 @@ namespace snowhouse return "nullptr"; } }; -#endif } #endif diff --git a/include/snowhouse/stringizers.h b/include/snowhouse/stringizers.h index 096ec36..d4fb56c 100644 --- a/include/snowhouse/stringizers.h +++ b/include/snowhouse/stringizers.h @@ -48,11 +48,7 @@ namespace snowhouse template static no compile_time_check_const_iterator(...); -#ifdef SNOWHOUSE_HAS_NULLPTR static const bool value = sizeof(compile_time_check_const_iterator(nullptr)) == sizeof(yes); -#else - static const bool value = sizeof(compile_time_check_const_iterator(0)) == sizeof(yes); -#endif }; template::value> From a372a6be9063eee73cc9ea954fdfb8e0151a4f24 Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Mon, 24 Feb 2020 19:10:22 +0100 Subject: [PATCH 06/33] Remove pre-C++11 __cplusplus guards --- example/sequence_container_tests.cpp | 15 ++------------- include/snowhouse/assertionexception.h | 6 ------ .../constraints/equalscontainerconstraint.h | 8 -------- .../fluent/operators/constraintoperator.h | 6 ------ 4 files changed, 2 insertions(+), 33 deletions(-) diff --git a/example/sequence_container_tests.cpp b/example/sequence_container_tests.cpp index cb7039c..f1d998f 100644 --- a/example/sequence_container_tests.cpp +++ b/example/sequence_container_tests.cpp @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include "tests.h" @@ -38,10 +40,6 @@ void insert_numbers(std::set& container) container.insert(8); } -#if __cplusplus >= 201103L -#include -#include - template<> void insert_numbers(std::array& container) { @@ -61,7 +59,6 @@ void insert_numbers(std::forward_list& container) container.push_front(2); container.push_front(1); } -#endif template static void TestHasAll(const T& container) @@ -87,13 +84,11 @@ static void TestHasAll(const T& container) } } -#if __cplusplus >= 201103L template<> void TestHasAll(const std::forward_list&) { // The constraint is size-based but there is no size() method available } -#endif template static void TestLength(const T& container) @@ -119,13 +114,11 @@ static void TestLength(const T& container) } } -#if __cplusplus >= 201103L template<> void TestLength(const std::forward_list&) { // There is no size() method available } -#endif template static void TestEmpty(const T& container, const TEmpty& is_empty) @@ -158,14 +151,12 @@ void TestEmpty(const T& container) TestEmpty(container, is_empty); } -#if __cplusplus >= 201103L template<> void TestEmpty(const std::array& container) { std::array is_empty; TestEmpty(container, is_empty); } -#endif template static void SequenceContainerActual() @@ -289,11 +280,9 @@ void SequenceContainerTests() describe("Sequence containers (std::multiset)"); SequenceContainerActual >(); -#if __cplusplus >= 201103L describe("Sequence containers (std::array)"); SequenceContainerActual >(); describe("Sequence containers (std::forward_list)"); SequenceContainerActual >(); -#endif } diff --git a/include/snowhouse/assertionexception.h b/include/snowhouse/assertionexception.h index 3ac455c..dd676b2 100644 --- a/include/snowhouse/assertionexception.h +++ b/include/snowhouse/assertionexception.h @@ -25,15 +25,9 @@ namespace snowhouse { } -#if __cplusplus > 199711L AssertionException(const AssertionException&) = default; -#endif -#if __cplusplus > 199711L virtual ~AssertionException() noexcept -#else - virtual ~AssertionException() throw() -#endif { } diff --git a/include/snowhouse/constraints/equalscontainerconstraint.h b/include/snowhouse/constraints/equalscontainerconstraint.h index 50c5649..6e61d7d 100644 --- a/include/snowhouse/constraints/equalscontainerconstraint.h +++ b/include/snowhouse/constraints/equalscontainerconstraint.h @@ -46,14 +46,6 @@ namespace snowhouse const ExpectedType expected_; const BinaryPredicate predicate_; - - private: -#if __cplusplus <= 199711L - EqualsContainerConstraint& operator=(const EqualsContainerConstraint&) - { - return *this; - } -#endif }; template diff --git a/include/snowhouse/fluent/operators/constraintoperator.h b/include/snowhouse/fluent/operators/constraintoperator.h index b622c9d..6abb509 100644 --- a/include/snowhouse/fluent/operators/constraintoperator.h +++ b/include/snowhouse/fluent/operators/constraintoperator.h @@ -14,12 +14,6 @@ namespace snowhouse { struct ConstraintOperator { -#if __cplusplus <= 199711L - virtual ~ConstraintOperator() - { - } -#endif - virtual void PerformOperation(ResultStack& result) = 0; virtual int Precedence() const = 0; From 7794533e9fb7bb7771c35271841d584ed9cb3cf3 Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Mon, 24 Feb 2020 19:41:06 +0100 Subject: [PATCH 07/33] Use a range-based for loop Interestingly, there is only one location where we can do so. --- .../operators/collections/collectionconstraintevaluator.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/snowhouse/fluent/operators/collections/collectionconstraintevaluator.h b/include/snowhouse/fluent/operators/collections/collectionconstraintevaluator.h index e075da0..ea20833 100644 --- a/include/snowhouse/fluent/operators/collections/collectionconstraintevaluator.h +++ b/include/snowhouse/fluent/operators/collections/collectionconstraintevaluator.h @@ -23,10 +23,9 @@ namespace snowhouse operators, result); unsigned int passed_elements = 0; - typename ActualType::const_iterator it; - for (it = actual.begin(); it != actual.end(); ++it) + for (const auto member : actual) { - if (ConstraintOperator::EvaluateElementAgainstRestOfExpression(expression, *it)) + if (ConstraintOperator::EvaluateElementAgainstRestOfExpression(expression, member)) { ++passed_elements; } From cefdde35fa562f2a8d453db5a7dc14160c4a9fd6 Mon Sep 17 00:00:00 2001 From: Rasmus Thomsen Date: Tue, 25 Feb 2020 18:01:37 +0100 Subject: [PATCH 08/33] Print description of unexpected exception in AssertThrows This makes it easier to debug the failure fixes #47 --- include/snowhouse/exceptions.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/snowhouse/exceptions.h b/include/snowhouse/exceptions.h index 5cbd0f2..4da7667 100644 --- a/include/snowhouse/exceptions.h +++ b/include/snowhouse/exceptions.h @@ -85,6 +85,8 @@ namespace snowhouse SNOWHOUSE_TEMPVAR(storage).compiler_thinks_i_am_unused(); \ bool SNOWHOUSE_TEMPVAR(wrong_exception) = false; \ bool SNOWHOUSE_TEMPVAR(no_exception) = false; \ + bool SNOWHOUSE_TEMPVAR(more_info) = true; \ + std::string SNOWHOUSE_TEMPVAR(info_string); \ try \ { \ METHOD; \ @@ -97,6 +99,14 @@ namespace snowhouse catch (...) \ { \ SNOWHOUSE_TEMPVAR(wrong_exception) = true; \ + if (auto eptr = std::current_exception()) { \ + try { \ + std::rethrow_exception(eptr); \ + } catch (const std::exception& e) { \ + SNOWHOUSE_TEMPVAR(more_info) = true; \ + SNOWHOUSE_TEMPVAR(info_string) = e.what(); \ + } catch (...) {} \ + } \ } \ if (SNOWHOUSE_TEMPVAR(no_exception)) \ { \ @@ -108,6 +118,9 @@ namespace snowhouse { \ ::std::ostringstream SNOWHOUSE_TEMPVAR(stm); \ SNOWHOUSE_TEMPVAR(stm) << "Expected " #EXCEPTION_TYPE ". Wrong exception was thrown."; \ + if (SNOWHOUSE_TEMPVAR(more_info)) { \ + SNOWHOUSE_TEMPVAR(stm) << " Description of unwanted exception: " << SNOWHOUSE_TEMPVAR(info_string); \ + } \ ::snowhouse::ConfigurableAssert::Failure(SNOWHOUSE_TEMPVAR(stm).str()); \ } \ do {} while (false) From 78f6b9647ef62da8e6f956b2729400866a361baa Mon Sep 17 00:00:00 2001 From: Rasmus Thomsen Date: Tue, 25 Feb 2020 18:05:27 +0100 Subject: [PATCH 09/33] Test printing unexpected exception in AssertThrows --- example/exceptions_tests.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/example/exceptions_tests.cpp b/example/exceptions_tests.cpp index d050a07..6402abd 100644 --- a/example/exceptions_tests.cpp +++ b/example/exceptions_tests.cpp @@ -26,6 +26,14 @@ struct ClassWithExceptions } }; +struct ExpectedException : public std::exception +{ + const char* what() const throw() + { + return "Description of the exception we expected"; + } +}; + void ExceptionTests() { ClassWithExceptions objectUnderTest; @@ -89,4 +97,9 @@ void ExceptionTests() AssertThrows(AssertionException, LastException()); AssertThat(LastException().GetMessage(), Contains("No exception was stored")); } + + it("prints description of unwanted exception"); + { + AssertTestFails(AssertThrows(ExpectedException, objectUnderTest.LogicError()), "Expected ExpectedException. Wrong exception was thrown. Description of unwanted exception: not logical!"); + } } From 100fc64cfcc3959596ca5370f74ea63347768864 Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Wed, 26 Feb 2020 23:19:33 +0100 Subject: [PATCH 10/33] Use override keyword and, in one case, remove the default destructor. --- example/exceptions_tests.cpp | 2 +- include/snowhouse/assertionexception.h | 4 ---- include/snowhouse/fluent/operators/andoperator.h | 4 ++-- .../fluent/operators/collections/collectionoperator.h | 4 ++-- include/snowhouse/fluent/operators/notoperator.h | 4 ++-- include/snowhouse/fluent/operators/oroperator.h | 4 ++-- 6 files changed, 9 insertions(+), 13 deletions(-) diff --git a/example/exceptions_tests.cpp b/example/exceptions_tests.cpp index 6402abd..50dcfaa 100644 --- a/example/exceptions_tests.cpp +++ b/example/exceptions_tests.cpp @@ -28,7 +28,7 @@ struct ClassWithExceptions struct ExpectedException : public std::exception { - const char* what() const throw() + const char* what() const noexcept override { return "Description of the exception we expected"; } diff --git a/include/snowhouse/assertionexception.h b/include/snowhouse/assertionexception.h index dd676b2..703de6a 100644 --- a/include/snowhouse/assertionexception.h +++ b/include/snowhouse/assertionexception.h @@ -27,10 +27,6 @@ namespace snowhouse AssertionException(const AssertionException&) = default; - virtual ~AssertionException() noexcept - { - } - std::string GetMessage() const { return m_message; diff --git a/include/snowhouse/fluent/operators/andoperator.h b/include/snowhouse/fluent/operators/andoperator.h index 13baf2e..0648176 100644 --- a/include/snowhouse/fluent/operators/andoperator.h +++ b/include/snowhouse/fluent/operators/andoperator.h @@ -22,7 +22,7 @@ namespace snowhouse EvaluateConstraintList(list.m_tail, result, operators, actual); } - void PerformOperation(ResultStack& result) + void PerformOperation(ResultStack& result) override { if (result.size() < 2) { @@ -37,7 +37,7 @@ namespace snowhouse result.push(left && right); } - int Precedence() const + int Precedence() const override { return 3; } diff --git a/include/snowhouse/fluent/operators/collections/collectionoperator.h b/include/snowhouse/fluent/operators/collections/collectionoperator.h index a2f787b..43e9185 100644 --- a/include/snowhouse/fluent/operators/collections/collectionoperator.h +++ b/include/snowhouse/fluent/operators/collections/collectionoperator.h @@ -12,11 +12,11 @@ namespace snowhouse { struct CollectionOperator : public ConstraintOperator { - void PerformOperation(ResultStack&) + void PerformOperation(ResultStack&) override { } - int Precedence() const + int Precedence() const override { return 1; } diff --git a/include/snowhouse/fluent/operators/notoperator.h b/include/snowhouse/fluent/operators/notoperator.h index be7234d..ca9eec9 100644 --- a/include/snowhouse/fluent/operators/notoperator.h +++ b/include/snowhouse/fluent/operators/notoperator.h @@ -22,7 +22,7 @@ namespace snowhouse EvaluateConstraintList(list.m_tail, result, operators, actual); } - void PerformOperation(ResultStack& result) + void PerformOperation(ResultStack& result) override { if (result.size() < 1) { @@ -35,7 +35,7 @@ namespace snowhouse result.push(!right); } - int Precedence() const + int Precedence() const override { return 2; } diff --git a/include/snowhouse/fluent/operators/oroperator.h b/include/snowhouse/fluent/operators/oroperator.h index 9a328bd..6329d63 100644 --- a/include/snowhouse/fluent/operators/oroperator.h +++ b/include/snowhouse/fluent/operators/oroperator.h @@ -22,7 +22,7 @@ namespace snowhouse EvaluateConstraintList(list.m_tail, result, operators, actual); } - void PerformOperation(ResultStack& result) + void PerformOperation(ResultStack& result) override { if (result.size() < 2) { @@ -37,7 +37,7 @@ namespace snowhouse result.push(left || right); } - int Precedence() const + int Precedence() const override { return 4; } From 62d430eb02153a2ab769f58defd19780a72b950e Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Wed, 26 Feb 2020 23:49:03 +0100 Subject: [PATCH 11/33] Get rid of (since C++11 useless) space in nested templates Changes foo > to foo> and, while at it, updates .clang-format to apply that by setting C++11 as C++ standard. --- .clang-format | 2 +- example/sequence_container_tests.cpp | 14 +-- .../constraints/containsconstraint.h | 6 +- .../constraints/endswithconstraint.h | 4 +- .../snowhouse/constraints/equalsconstraint.h | 6 +- .../constraints/equalscontainerconstraint.h | 4 +- .../constraints/equalswithdeltaconstraint.h | 4 +- .../constraints/expressions/andexpression.h | 4 +- .../constraints/expressions/notexpression.h | 4 +- .../constraints/expressions/orexpression.h | 4 +- .../constraints/fulfillsconstraint.h | 4 +- .../constraints/haslengthconstraint.h | 4 +- .../constraints/isgreaterthanconstraint.h | 4 +- .../isgreaterthanorequaltoconstraint.h | 4 +- .../constraints/islessthanconstraint.h | 4 +- .../islessthanorequaltoconstraint.h | 4 +- .../constraints/startswithconstraint.h | 4 +- include/snowhouse/fluent/constraintadapter.h | 2 +- include/snowhouse/fluent/expressionbuilder.h | 98 +++++++++---------- .../collectionconstraintevaluator.h | 2 +- 20 files changed, 91 insertions(+), 91 deletions(-) diff --git a/.clang-format b/.clang-format index fbe462a..601c233 100644 --- a/.clang-format +++ b/.clang-format @@ -5,7 +5,7 @@ # before committing your changes. --- Language: Cpp -Standard: Cpp03 +Standard: Cpp11 ColumnLimit: 0 IndentWidth: 2 diff --git a/example/sequence_container_tests.cpp b/example/sequence_container_tests.cpp index f1d998f..d5b1694 100644 --- a/example/sequence_container_tests.cpp +++ b/example/sequence_container_tests.cpp @@ -266,23 +266,23 @@ static void SequenceContainerActual() void SequenceContainerTests() { describe("Sequence containers (std::vector)"); - SequenceContainerActual >(); + SequenceContainerActual>(); describe("Sequence containers (std::list)"); - SequenceContainerActual >(); + SequenceContainerActual>(); describe("Sequence containers (std::deque)"); - SequenceContainerActual >(); + SequenceContainerActual>(); describe("Sequence containers (std::set)"); - SequenceContainerActual >(); + SequenceContainerActual>(); describe("Sequence containers (std::multiset)"); - SequenceContainerActual >(); + SequenceContainerActual>(); describe("Sequence containers (std::array)"); - SequenceContainerActual >(); + SequenceContainerActual>(); describe("Sequence containers (std::forward_list)"); - SequenceContainerActual >(); + SequenceContainerActual>(); } diff --git a/include/snowhouse/constraints/containsconstraint.h b/include/snowhouse/constraints/containsconstraint.h index be37907..13b0ce0 100644 --- a/include/snowhouse/constraints/containsconstraint.h +++ b/include/snowhouse/constraints/containsconstraint.h @@ -24,7 +24,7 @@ namespace snowhouse }; template - struct find_in_container_traits > + struct find_in_container_traits> { template static bool find(const std::map& container, const ExpectedType& expected) @@ -34,7 +34,7 @@ namespace snowhouse }; template - struct ContainsConstraint : Expression > + struct ContainsConstraint : Expression> { ContainsConstraint(const ExpectedType& expected) : m_expected(expected) @@ -67,7 +67,7 @@ namespace snowhouse } template - struct Stringizer > + struct Stringizer> { static std::string ToString(const ContainsConstraint& constraint) { diff --git a/include/snowhouse/constraints/endswithconstraint.h b/include/snowhouse/constraints/endswithconstraint.h index 2d86949..192dcf4 100644 --- a/include/snowhouse/constraints/endswithconstraint.h +++ b/include/snowhouse/constraints/endswithconstraint.h @@ -11,7 +11,7 @@ namespace snowhouse { template - struct EndsWithConstraint : Expression > + struct EndsWithConstraint : Expression> { EndsWithConstraint(const ExpectedType& expected) : m_expected(expected) @@ -39,7 +39,7 @@ namespace snowhouse } template - struct Stringizer > + struct Stringizer> { static std::string ToString(const EndsWithConstraint& constraint) { diff --git a/include/snowhouse/constraints/equalsconstraint.h b/include/snowhouse/constraints/equalsconstraint.h index 2c0f728..c730097 100644 --- a/include/snowhouse/constraints/equalsconstraint.h +++ b/include/snowhouse/constraints/equalsconstraint.h @@ -11,7 +11,7 @@ namespace snowhouse { template - struct EqualsConstraint : Expression > + struct EqualsConstraint : Expression> { EqualsConstraint(const ExpectedType& expected) : m_expected(expected) @@ -54,7 +54,7 @@ namespace snowhouse } template<> - struct Stringizer > + struct Stringizer> { static std::string ToString(const EqualsConstraint& constraint) { @@ -63,7 +63,7 @@ namespace snowhouse }; template - struct Stringizer > + struct Stringizer> { static std::string ToString(const EqualsConstraint& constraint) { diff --git a/include/snowhouse/constraints/equalscontainerconstraint.h b/include/snowhouse/constraints/equalscontainerconstraint.h index 6e61d7d..df6d16d 100644 --- a/include/snowhouse/constraints/equalscontainerconstraint.h +++ b/include/snowhouse/constraints/equalscontainerconstraint.h @@ -20,7 +20,7 @@ namespace snowhouse } template - struct EqualsContainerConstraint : Expression > + struct EqualsContainerConstraint : Expression> { EqualsContainerConstraint(const ExpectedType& expected, const BinaryPredicate predicate) : expected_(expected), predicate_(predicate) @@ -61,7 +61,7 @@ namespace snowhouse } template - struct Stringizer > + struct Stringizer> { static std::string ToString(const EqualsContainerConstraint& constraint) { diff --git a/include/snowhouse/constraints/equalswithdeltaconstraint.h b/include/snowhouse/constraints/equalswithdeltaconstraint.h index f8cba04..b3d8c56 100644 --- a/include/snowhouse/constraints/equalswithdeltaconstraint.h +++ b/include/snowhouse/constraints/equalswithdeltaconstraint.h @@ -11,7 +11,7 @@ namespace snowhouse { template - struct EqualsWithDeltaConstraint : Expression > + struct EqualsWithDeltaConstraint : Expression> { EqualsWithDeltaConstraint(const ExpectedType& expected, const DeltaType& delta) : m_expected(expected), m_delta(delta) @@ -35,7 +35,7 @@ namespace snowhouse } template - struct Stringizer > + struct Stringizer> { static std::string ToString(const EqualsWithDeltaConstraint& constraint) { diff --git a/include/snowhouse/constraints/expressions/andexpression.h b/include/snowhouse/constraints/expressions/andexpression.h index 2b41ebe..370bab6 100644 --- a/include/snowhouse/constraints/expressions/andexpression.h +++ b/include/snowhouse/constraints/expressions/andexpression.h @@ -12,7 +12,7 @@ namespace snowhouse { template - struct AndExpression : Expression > + struct AndExpression : Expression> { AndExpression(const LeftExpression& left, const RightExpression& right) : m_left(left), m_right(right) @@ -30,7 +30,7 @@ namespace snowhouse }; template - struct Stringizer > + struct Stringizer> { static std::string ToString(const AndExpression& expression) { diff --git a/include/snowhouse/constraints/expressions/notexpression.h b/include/snowhouse/constraints/expressions/notexpression.h index 046aa7c..cbc76f1 100644 --- a/include/snowhouse/constraints/expressions/notexpression.h +++ b/include/snowhouse/constraints/expressions/notexpression.h @@ -12,7 +12,7 @@ namespace snowhouse { template - struct NotExpression : Expression > + struct NotExpression : Expression> { explicit NotExpression(const ExpressionType& expression) : m_expression(expression) @@ -29,7 +29,7 @@ namespace snowhouse }; template - struct Stringizer > + struct Stringizer> { static std::string ToString(const NotExpression& expression) { diff --git a/include/snowhouse/constraints/expressions/orexpression.h b/include/snowhouse/constraints/expressions/orexpression.h index 61192fc..7caabcd 100644 --- a/include/snowhouse/constraints/expressions/orexpression.h +++ b/include/snowhouse/constraints/expressions/orexpression.h @@ -12,7 +12,7 @@ namespace snowhouse { template - struct OrExpression : Expression > + struct OrExpression : Expression> { OrExpression(const LeftExpression& left, const RightExpression& right) : m_left(left), m_right(right) @@ -30,7 +30,7 @@ namespace snowhouse }; template - struct Stringizer > + struct Stringizer> { static std::string ToString(const OrExpression& expression) { diff --git a/include/snowhouse/constraints/fulfillsconstraint.h b/include/snowhouse/constraints/fulfillsconstraint.h index b94a56c..00c2146 100644 --- a/include/snowhouse/constraints/fulfillsconstraint.h +++ b/include/snowhouse/constraints/fulfillsconstraint.h @@ -11,7 +11,7 @@ namespace snowhouse { template - struct FulfillsConstraint : Expression > + struct FulfillsConstraint : Expression> { FulfillsConstraint(const MatcherType& matcher) : m_matcher(matcher) @@ -34,7 +34,7 @@ namespace snowhouse } template - struct Stringizer > + struct Stringizer> { static std::string ToString(const FulfillsConstraint& constraint) { diff --git a/include/snowhouse/constraints/haslengthconstraint.h b/include/snowhouse/constraints/haslengthconstraint.h index c4cd703..484d3ef 100644 --- a/include/snowhouse/constraints/haslengthconstraint.h +++ b/include/snowhouse/constraints/haslengthconstraint.h @@ -11,7 +11,7 @@ namespace snowhouse { template - struct HasLengthConstraint : Expression > + struct HasLengthConstraint : Expression> { HasLengthConstraint(const ExpectedType& expected) : m_expected(expected) @@ -41,7 +41,7 @@ namespace snowhouse } template - struct Stringizer > + struct Stringizer> { static std::string ToString(const HasLengthConstraint& constraint) { diff --git a/include/snowhouse/constraints/isgreaterthanconstraint.h b/include/snowhouse/constraints/isgreaterthanconstraint.h index c46231f..3f3586c 100644 --- a/include/snowhouse/constraints/isgreaterthanconstraint.h +++ b/include/snowhouse/constraints/isgreaterthanconstraint.h @@ -11,7 +11,7 @@ namespace snowhouse { template - struct IsGreaterThanConstraint : Expression > + struct IsGreaterThanConstraint : Expression> { IsGreaterThanConstraint(const ExpectedType& expected) : m_expected(expected) @@ -39,7 +39,7 @@ namespace snowhouse } template - struct Stringizer > + struct Stringizer> { static std::string ToString(const IsGreaterThanConstraint& constraint) { diff --git a/include/snowhouse/constraints/isgreaterthanorequaltoconstraint.h b/include/snowhouse/constraints/isgreaterthanorequaltoconstraint.h index 0046de2..8f08aa8 100644 --- a/include/snowhouse/constraints/isgreaterthanorequaltoconstraint.h +++ b/include/snowhouse/constraints/isgreaterthanorequaltoconstraint.h @@ -11,7 +11,7 @@ namespace snowhouse { template - struct IsGreaterThanOrEqualToConstraint : Expression > + struct IsGreaterThanOrEqualToConstraint : Expression> { IsGreaterThanOrEqualToConstraint(const ExpectedType& expected) : m_expected(expected) @@ -39,7 +39,7 @@ namespace snowhouse } template - struct Stringizer > + struct Stringizer> { static std::string ToString(const IsGreaterThanOrEqualToConstraint& constraint) { diff --git a/include/snowhouse/constraints/islessthanconstraint.h b/include/snowhouse/constraints/islessthanconstraint.h index d568ce2..8893780 100644 --- a/include/snowhouse/constraints/islessthanconstraint.h +++ b/include/snowhouse/constraints/islessthanconstraint.h @@ -11,7 +11,7 @@ namespace snowhouse { template - struct IsLessThanConstraint : Expression > + struct IsLessThanConstraint : Expression> { IsLessThanConstraint(const ExpectedType& expected) : m_expected(expected) @@ -39,7 +39,7 @@ namespace snowhouse } template - struct Stringizer > + struct Stringizer> { static std::string ToString(const IsLessThanConstraint& constraint) { diff --git a/include/snowhouse/constraints/islessthanorequaltoconstraint.h b/include/snowhouse/constraints/islessthanorequaltoconstraint.h index e44f3ad..5ba07e0 100644 --- a/include/snowhouse/constraints/islessthanorequaltoconstraint.h +++ b/include/snowhouse/constraints/islessthanorequaltoconstraint.h @@ -11,7 +11,7 @@ namespace snowhouse { template - struct IsLessThanOrEqualToConstraint : Expression > + struct IsLessThanOrEqualToConstraint : Expression> { IsLessThanOrEqualToConstraint(const ExpectedType& expected) : m_expected(expected) @@ -39,7 +39,7 @@ namespace snowhouse } template - struct Stringizer > + struct Stringizer> { static std::string ToString(const IsLessThanOrEqualToConstraint& constraint) { diff --git a/include/snowhouse/constraints/startswithconstraint.h b/include/snowhouse/constraints/startswithconstraint.h index 5f02cf5..9cb0e13 100644 --- a/include/snowhouse/constraints/startswithconstraint.h +++ b/include/snowhouse/constraints/startswithconstraint.h @@ -11,7 +11,7 @@ namespace snowhouse { template - struct StartsWithConstraint : Expression > + struct StartsWithConstraint : Expression> { StartsWithConstraint(const ExpectedType& expected) : m_expected(expected) @@ -38,7 +38,7 @@ namespace snowhouse } template - struct Stringizer > + struct Stringizer> { static std::string ToString(const StartsWithConstraint& constraint) { diff --git a/include/snowhouse/fluent/constraintadapter.h b/include/snowhouse/fluent/constraintadapter.h index ef9eebf..a4aca95 100644 --- a/include/snowhouse/fluent/constraintadapter.h +++ b/include/snowhouse/fluent/constraintadapter.h @@ -30,7 +30,7 @@ namespace snowhouse }; template - struct Stringizer > + struct Stringizer> { static std::string ToString(const ConstraintAdapter& constraintAdapter) { diff --git a/include/snowhouse/fluent/expressionbuilder.h b/include/snowhouse/fluent/expressionbuilder.h index ad1b2f7..913c06b 100644 --- a/include/snowhouse/fluent/expressionbuilder.h +++ b/include/snowhouse/fluent/expressionbuilder.h @@ -41,11 +41,11 @@ namespace snowhouse } template - ExpressionBuilder >, Nil> >::t> + ExpressionBuilder>, Nil>>::t> EqualTo(const ExpectedType& expected) { - typedef ConstraintAdapter > ConstraintAdapterType; - typedef ExpressionBuilder >::t> BuilderType; + typedef ConstraintAdapter> ConstraintAdapterType; + typedef ExpressionBuilder>::t> BuilderType; ConstraintAdapterType constraint(expected); ConstraintList node(constraint, Nil()); @@ -54,11 +54,11 @@ namespace snowhouse } template - ExpressionBuilder >, Nil> >::t> + ExpressionBuilder>, Nil>>::t> EqualToWithDelta(const ExpectedType& expected, const DeltaType& delta) { - typedef ConstraintAdapter > ConstraintAdapterType; - typedef ExpressionBuilder >::t> BuilderType; + typedef ConstraintAdapter> ConstraintAdapterType; + typedef ExpressionBuilder>::t> BuilderType; ConstraintAdapterType constraint(EqualsWithDeltaConstraint(expected, delta)); ConstraintList node(constraint, Nil()); @@ -67,11 +67,11 @@ namespace snowhouse } template - ExpressionBuilder >, Nil> >::t> + ExpressionBuilder>, Nil>>::t> Fulfilling(const MatcherType& matcher) { - typedef ConstraintAdapter > ConstraintAdapterType; - typedef ExpressionBuilder >::t> BuilderType; + typedef ConstraintAdapter> ConstraintAdapterType; + typedef ExpressionBuilder>::t> BuilderType; ConstraintAdapterType constraint(matcher); ConstraintList node(constraint, Nil()); @@ -79,175 +79,175 @@ namespace snowhouse return BuilderType(Concatenate(m_constraint_list, node)); } - ExpressionBuilder >, Nil> >::t> + ExpressionBuilder>, Nil>>::t> False() { return EqualTo(false); } - ExpressionBuilder >, Nil> >::t> + ExpressionBuilder>, Nil>>::t> True() { return EqualTo(true); } - ExpressionBuilder >, Nil> >::t> + ExpressionBuilder>, Nil>>::t> Null() { return EqualTo(nullptr); } - ExpressionBuilder >, Nil> >::t> + ExpressionBuilder>, Nil>>::t> EqualTo(const char* expected) { return EqualTo(std::string(expected)); } template - ExpressionBuilder >, Nil> >::t> + ExpressionBuilder>, Nil>>::t> GreaterThan(const ExpectedType& expected) { - typedef ConstraintAdapter > ConstraintAdapterType; + typedef ConstraintAdapter> ConstraintAdapterType; - typedef ExpressionBuilder >::t> BuilderType; + typedef ExpressionBuilder>::t> BuilderType; ConstraintAdapterType constraint(expected); ConstraintList node(constraint, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); } template - ExpressionBuilder >, Nil> >::t> + ExpressionBuilder>, Nil>>::t> GreaterThanOrEqualTo(const ExpectedType& expected) { - typedef ConstraintAdapter > ConstraintAdapterType; + typedef ConstraintAdapter> ConstraintAdapterType; - typedef ExpressionBuilder >::t> BuilderType; + typedef ExpressionBuilder>::t> BuilderType; ConstraintAdapterType constraint(expected); ConstraintList node(constraint, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); } template - ExpressionBuilder >, Nil> >::t> + ExpressionBuilder>, Nil>>::t> LessThan(const ExpectedType& expected) { - typedef ConstraintAdapter > ConstraintAdapterType; + typedef ConstraintAdapter> ConstraintAdapterType; - typedef ExpressionBuilder >::t> BuilderType; + typedef ExpressionBuilder>::t> BuilderType; ConstraintAdapterType constraint(expected); ConstraintList node(constraint, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); } template - ExpressionBuilder >, Nil> >::t> + ExpressionBuilder>, Nil>>::t> LessThanOrEqualTo(const ExpectedType& expected) { - typedef ConstraintAdapter > ConstraintAdapterType; + typedef ConstraintAdapter> ConstraintAdapterType; - typedef ExpressionBuilder >::t> BuilderType; + typedef ExpressionBuilder>::t> BuilderType; ConstraintAdapterType constraint(expected); ConstraintList node(constraint, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); } template - ExpressionBuilder >, Nil> >::t> + ExpressionBuilder>, Nil>>::t> Containing(const ExpectedType& expected) { - typedef ConstraintAdapter > ConstraintAdapterType; + typedef ConstraintAdapter> ConstraintAdapterType; - typedef ExpressionBuilder >::t> BuilderType; + typedef ExpressionBuilder>::t> BuilderType; ConstraintAdapterType constraint(expected); ConstraintList node(constraint, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); } - ExpressionBuilder >, Nil> >::t> + ExpressionBuilder>, Nil>>::t> Containing(const char* expected) { return Containing(std::string(expected)); } template - ExpressionBuilder >, Nil> >::t> + ExpressionBuilder>, Nil>>::t> EndingWith(const ExpectedType& expected) { - typedef ConstraintAdapter > ConstraintAdapterType; - typedef ExpressionBuilder >::t> BuilderType; + typedef ConstraintAdapter> ConstraintAdapterType; + typedef ExpressionBuilder>::t> BuilderType; ConstraintAdapterType constraint(expected); ConstraintList node(constraint, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); } - ExpressionBuilder >, Nil> >::t> + ExpressionBuilder>, Nil>>::t> EndingWith(const char* expected) { return EndingWith(std::string(expected)); } template - ExpressionBuilder >, Nil> >::t> + ExpressionBuilder>, Nil>>::t> StartingWith(const ExpectedType& expected) { - typedef ConstraintAdapter > ConstraintAdapterType; + typedef ConstraintAdapter> ConstraintAdapterType; - typedef ExpressionBuilder >::t> BuilderType; + typedef ExpressionBuilder>::t> BuilderType; ConstraintAdapterType constraint(expected); ConstraintList node(constraint, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); } - ExpressionBuilder >, Nil> >::t> + ExpressionBuilder>, Nil>>::t> StartingWith(const char* expected) { return StartingWith(std::string(expected)); } template - ExpressionBuilder >, Nil> >::t> + ExpressionBuilder>, Nil>>::t> OfLength(const ExpectedType& expected) { - typedef ConstraintAdapter > ConstraintAdapterType; + typedef ConstraintAdapter> ConstraintAdapterType; - typedef ExpressionBuilder >::t> BuilderType; + typedef ExpressionBuilder>::t> BuilderType; ConstraintAdapterType constraint(expected); ConstraintList node(constraint, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); } - ExpressionBuilder, Nil> >::t> + ExpressionBuilder, Nil>>::t> Empty() { typedef ConstraintAdapter ConstraintAdapterType; - typedef ExpressionBuilder >::t> BuilderType; + typedef ExpressionBuilder>::t> BuilderType; ConstraintAdapterType constraint(0); ConstraintList node(constraint, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); } template - ExpressionBuilder >, Nil> >::t> + ExpressionBuilder>, Nil>>::t> EqualToContainer(const ExpectedType& expected) { typedef bool (*DefaultBinaryPredivateType)(const typename ExpectedType::value_type&, const typename ExpectedType::value_type&); - typedef ConstraintAdapter > ConstraintAdapterType; + typedef ConstraintAdapter> ConstraintAdapterType; - typedef ExpressionBuilder >::t> BuilderType; + typedef ExpressionBuilder>::t> BuilderType; ConstraintAdapterType constraint(EqualsContainerConstraint(expected, constraint_internal::default_comparer)); ConstraintList node(constraint, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); } template - ExpressionBuilder >, Nil> >::t> + ExpressionBuilder>, Nil>>::t> EqualToContainer(const ExpectedType& expected, const BinaryPredicate predicate) { - typedef ConstraintAdapter > ConstraintAdapterType; + typedef ConstraintAdapter> ConstraintAdapterType; - typedef ExpressionBuilder >::t> BuilderType; + typedef ExpressionBuilder>::t> BuilderType; ConstraintAdapterType constraint(EqualsContainerConstraint(expected, predicate)); ConstraintList node(constraint, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); @@ -350,7 +350,7 @@ namespace snowhouse } template - struct Stringizer > + struct Stringizer> { static std::string ToString(const ExpressionBuilder& builder) { diff --git a/include/snowhouse/fluent/operators/collections/collectionconstraintevaluator.h b/include/snowhouse/fluent/operators/collections/collectionconstraintevaluator.h index ea20833..12cbc06 100644 --- a/include/snowhouse/fluent/operators/collections/collectionconstraintevaluator.h +++ b/include/snowhouse/fluent/operators/collections/collectionconstraintevaluator.h @@ -102,7 +102,7 @@ namespace snowhouse { std::vector lines; StringLineParser::Parse(actual, lines); - return CollectionConstraintEvaluator >::Evaluate(op, expression, result, operators, lines); + return CollectionConstraintEvaluator>::Evaluate(op, expression, result, operators, lines); } }; } From f6bd65aaefcdb820d8dc1ea7e12c28b1b5b3980d Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Wed, 26 Feb 2020 23:55:17 +0100 Subject: [PATCH 12/33] Use "using" instead of "typedef" While at it, fix a typo in DefaultBinaryPredicateType (was: DefaultBinaryPredivateType) --- include/snowhouse/assert.h | 2 +- .../constraints/haslengthconstraint.h | 2 +- include/snowhouse/fluent/constraintlist.h | 10 +-- include/snowhouse/fluent/expressionbuilder.h | 90 +++++++++---------- include/snowhouse/stringize.h | 2 +- include/snowhouse/stringizers.h | 8 +- 6 files changed, 57 insertions(+), 57 deletions(-) diff --git a/include/snowhouse/assert.h b/include/snowhouse/assert.h index 4e68d9f..dac11b8 100644 --- a/include/snowhouse/assert.h +++ b/include/snowhouse/assert.h @@ -110,7 +110,7 @@ namespace snowhouse } }; - typedef ConfigurableAssert Assert; + using Assert = ConfigurableAssert; } #endif diff --git a/include/snowhouse/constraints/haslengthconstraint.h b/include/snowhouse/constraints/haslengthconstraint.h index 484d3ef..c318a0d 100644 --- a/include/snowhouse/constraints/haslengthconstraint.h +++ b/include/snowhouse/constraints/haslengthconstraint.h @@ -21,7 +21,7 @@ namespace snowhouse template bool operator()(const ActualType& actual) const { - typedef typename ActualType::size_type SizeType; + using SizeType = typename ActualType::size_type; SizeType expectedSize = static_cast(m_expected); return (actual.size() == expectedSize); } diff --git a/include/snowhouse/fluent/constraintlist.h b/include/snowhouse/fluent/constraintlist.h index 21d84cc..346ba08 100644 --- a/include/snowhouse/fluent/constraintlist.h +++ b/include/snowhouse/fluent/constraintlist.h @@ -12,13 +12,13 @@ namespace snowhouse { struct ConstraintOperator; typedef std::stack ResultStack; - typedef std::stack OperatorStack; + using OperatorStack = std::stack; template struct ConstraintList { - typedef HT HeadType; - typedef TT TailType; + using HeadType = HT; + using TailType = TT; ConstraintList(const HeadType& head, const TailType& tail) : m_head(head), m_tail(tail) @@ -44,13 +44,13 @@ namespace snowhouse template struct type_concat { - typedef ConstraintList::t> t; + using t = ConstraintList::t>; }; template struct type_concat { - typedef L2 t; + using t = L2; }; template diff --git a/include/snowhouse/fluent/expressionbuilder.h b/include/snowhouse/fluent/expressionbuilder.h index 913c06b..354a882 100644 --- a/include/snowhouse/fluent/expressionbuilder.h +++ b/include/snowhouse/fluent/expressionbuilder.h @@ -45,7 +45,7 @@ namespace snowhouse EqualTo(const ExpectedType& expected) { typedef ConstraintAdapter> ConstraintAdapterType; - typedef ExpressionBuilder>::t> BuilderType; + using BuilderType = ExpressionBuilder>::t>; ConstraintAdapterType constraint(expected); ConstraintList node(constraint, Nil()); @@ -57,8 +57,8 @@ namespace snowhouse ExpressionBuilder>, Nil>>::t> EqualToWithDelta(const ExpectedType& expected, const DeltaType& delta) { - typedef ConstraintAdapter> ConstraintAdapterType; - typedef ExpressionBuilder>::t> BuilderType; + using ConstraintAdapterType = ConstraintAdapter>; + using BuilderType = ExpressionBuilder>::t>; ConstraintAdapterType constraint(EqualsWithDeltaConstraint(expected, delta)); ConstraintList node(constraint, Nil()); @@ -70,8 +70,8 @@ namespace snowhouse ExpressionBuilder>, Nil>>::t> Fulfilling(const MatcherType& matcher) { - typedef ConstraintAdapter> ConstraintAdapterType; - typedef ExpressionBuilder>::t> BuilderType; + using ConstraintAdapterType = ConstraintAdapter>; + using BuilderType = ExpressionBuilder>::t>; ConstraintAdapterType constraint(matcher); ConstraintList node(constraint, Nil()); @@ -107,9 +107,9 @@ namespace snowhouse ExpressionBuilder>, Nil>>::t> GreaterThan(const ExpectedType& expected) { - typedef ConstraintAdapter> ConstraintAdapterType; + using ConstraintAdapterType = ConstraintAdapter>; - typedef ExpressionBuilder>::t> BuilderType; + using BuilderType = ExpressionBuilder>::t>; ConstraintAdapterType constraint(expected); ConstraintList node(constraint, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); @@ -119,9 +119,9 @@ namespace snowhouse ExpressionBuilder>, Nil>>::t> GreaterThanOrEqualTo(const ExpectedType& expected) { - typedef ConstraintAdapter> ConstraintAdapterType; + using ConstraintAdapterType = ConstraintAdapter>; - typedef ExpressionBuilder>::t> BuilderType; + using BuilderType = ExpressionBuilder>::t>; ConstraintAdapterType constraint(expected); ConstraintList node(constraint, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); @@ -131,9 +131,9 @@ namespace snowhouse ExpressionBuilder>, Nil>>::t> LessThan(const ExpectedType& expected) { - typedef ConstraintAdapter> ConstraintAdapterType; + using ConstraintAdapterType = ConstraintAdapter>; - typedef ExpressionBuilder>::t> BuilderType; + using BuilderType = ExpressionBuilder>::t>; ConstraintAdapterType constraint(expected); ConstraintList node(constraint, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); @@ -143,9 +143,9 @@ namespace snowhouse ExpressionBuilder>, Nil>>::t> LessThanOrEqualTo(const ExpectedType& expected) { - typedef ConstraintAdapter> ConstraintAdapterType; + using ConstraintAdapterType = ConstraintAdapter>; - typedef ExpressionBuilder>::t> BuilderType; + using BuilderType = ExpressionBuilder>::t>; ConstraintAdapterType constraint(expected); ConstraintList node(constraint, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); @@ -155,9 +155,9 @@ namespace snowhouse ExpressionBuilder>, Nil>>::t> Containing(const ExpectedType& expected) { - typedef ConstraintAdapter> ConstraintAdapterType; + using ConstraintAdapterType = ConstraintAdapter>; - typedef ExpressionBuilder>::t> BuilderType; + using BuilderType = ExpressionBuilder>::t>; ConstraintAdapterType constraint(expected); ConstraintList node(constraint, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); @@ -173,8 +173,8 @@ namespace snowhouse ExpressionBuilder>, Nil>>::t> EndingWith(const ExpectedType& expected) { - typedef ConstraintAdapter> ConstraintAdapterType; - typedef ExpressionBuilder>::t> BuilderType; + using ConstraintAdapterType = ConstraintAdapter>; + using BuilderType = ExpressionBuilder>::t>; ConstraintAdapterType constraint(expected); ConstraintList node(constraint, Nil()); @@ -191,9 +191,9 @@ namespace snowhouse ExpressionBuilder>, Nil>>::t> StartingWith(const ExpectedType& expected) { - typedef ConstraintAdapter> ConstraintAdapterType; + using ConstraintAdapterType = ConstraintAdapter>; - typedef ExpressionBuilder>::t> BuilderType; + using BuilderType = ExpressionBuilder>::t>; ConstraintAdapterType constraint(expected); ConstraintList node(constraint, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); @@ -209,9 +209,9 @@ namespace snowhouse ExpressionBuilder>, Nil>>::t> OfLength(const ExpectedType& expected) { - typedef ConstraintAdapter> ConstraintAdapterType; + using ConstraintAdapterType = ConstraintAdapter>; - typedef ExpressionBuilder>::t> BuilderType; + using BuilderType = ExpressionBuilder>::t>; ConstraintAdapterType constraint(expected); ConstraintList node(constraint, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); @@ -220,9 +220,9 @@ namespace snowhouse ExpressionBuilder, Nil>>::t> Empty() { - typedef ConstraintAdapter ConstraintAdapterType; + using ConstraintAdapterType = ConstraintAdapter; - typedef ExpressionBuilder>::t> BuilderType; + using BuilderType = ExpressionBuilder>::t>; ConstraintAdapterType constraint(0); ConstraintList node(constraint, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); @@ -232,11 +232,11 @@ namespace snowhouse ExpressionBuilder>, Nil>>::t> EqualToContainer(const ExpectedType& expected) { - typedef bool (*DefaultBinaryPredivateType)(const typename ExpectedType::value_type&, const typename ExpectedType::value_type&); - typedef ConstraintAdapter> ConstraintAdapterType; + using DefaultBinaryPredicateType = bool (*)(const typename ExpectedType::value_type&, const typename ExpectedType::value_type&); + using ConstraintAdapterType = ConstraintAdapter>; - typedef ExpressionBuilder>::t> BuilderType; - ConstraintAdapterType constraint(EqualsContainerConstraint(expected, constraint_internal::default_comparer)); + using BuilderType = ExpressionBuilder>::t>; + ConstraintAdapterType constraint(EqualsContainerConstraint(expected, constraint_internal::default_comparer)); ConstraintList node(constraint, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); } @@ -245,26 +245,26 @@ namespace snowhouse ExpressionBuilder>, Nil>>::t> EqualToContainer(const ExpectedType& expected, const BinaryPredicate predicate) { - typedef ConstraintAdapter> ConstraintAdapterType; + using ConstraintAdapterType = ConstraintAdapter>; - typedef ExpressionBuilder>::t> BuilderType; + using BuilderType = ExpressionBuilder>::t>; ConstraintAdapterType constraint(EqualsContainerConstraint(expected, predicate)); ConstraintList node(constraint, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); } - typedef ConstraintList AndOperatorNode; - typedef ConstraintList OrOperatorNode; - typedef ConstraintList NotOperatorNode; - typedef ConstraintList AllOperatorNode; - typedef ConstraintList AtLeastOperatorNode; - typedef ConstraintList ExactlyOperatorNode; - typedef ConstraintList AtMostOperatorNode; - typedef ConstraintList NoneOperatorNode; + using AndOperatorNode = ConstraintList; + using OrOperatorNode = ConstraintList; + using NotOperatorNode = ConstraintList; + using AllOperatorNode = ConstraintList; + using AtLeastOperatorNode = ConstraintList; + using ExactlyOperatorNode = ConstraintList; + using AtMostOperatorNode = ConstraintList; + using NoneOperatorNode = ConstraintList; ExpressionBuilder::t> All() { - typedef ExpressionBuilder::t> BuilderType; + using BuilderType = ExpressionBuilder::t>; AllOperator op; AllOperatorNode node(op, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); @@ -272,7 +272,7 @@ namespace snowhouse ExpressionBuilder::t> AtLeast(unsigned int expected) { - typedef ExpressionBuilder::t> BuilderType; + using BuilderType = ExpressionBuilder::t>; AtLeastOperator op(expected); AtLeastOperatorNode node(op, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); @@ -280,7 +280,7 @@ namespace snowhouse ExpressionBuilder::t> Exactly(unsigned int expected) { - typedef ExpressionBuilder::t> BuilderType; + using BuilderType = ExpressionBuilder::t>; ExactlyOperator op(expected); ExactlyOperatorNode node(op, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); @@ -288,7 +288,7 @@ namespace snowhouse ExpressionBuilder::t> AtMost(unsigned int expected) { - typedef ExpressionBuilder::t> BuilderType; + using BuilderType = ExpressionBuilder::t>; AtMostOperator op(expected); AtMostOperatorNode node(op, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); @@ -296,7 +296,7 @@ namespace snowhouse ExpressionBuilder::t> None() { - typedef ExpressionBuilder::t> BuilderType; + using BuilderType = ExpressionBuilder::t>; NoneOperator op; NoneOperatorNode node(op, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); @@ -304,7 +304,7 @@ namespace snowhouse ExpressionBuilder::t> And() { - typedef ExpressionBuilder::t> BuilderType; + using BuilderType = ExpressionBuilder::t>; AndOperator op; AndOperatorNode node(op, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); @@ -312,7 +312,7 @@ namespace snowhouse ExpressionBuilder::t> Or() { - typedef ExpressionBuilder::t> BuilderType; + using BuilderType = ExpressionBuilder::t>; OrOperator op; OrOperatorNode node(op, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); @@ -320,7 +320,7 @@ namespace snowhouse ExpressionBuilder::t> Not() { - typedef ExpressionBuilder::t> BuilderType; + using BuilderType = ExpressionBuilder::t>; NotOperator op; NotOperatorNode node(op, Nil()); return BuilderType(Concatenate(m_constraint_list, node)); diff --git a/include/snowhouse/stringize.h b/include/snowhouse/stringize.h index c4e1673..97be91d 100644 --- a/include/snowhouse/stringize.h +++ b/include/snowhouse/stringize.h @@ -39,7 +39,7 @@ namespace snowhouse // directly and is chosen if T supports the expression. So using sizeof(check()) // returns 2 for the first overload and 1 for the second overload. typedef char yes; - typedef char (&no)[2]; + using no = char (&)[2]; no check(tag); diff --git a/include/snowhouse/stringizers.h b/include/snowhouse/stringizers.h index d4fb56c..ae10d49 100644 --- a/include/snowhouse/stringizers.h +++ b/include/snowhouse/stringizers.h @@ -19,7 +19,7 @@ namespace snowhouse ToString(const Container& cont) { std::ostringstream stm; - typedef typename Container::const_iterator Iterator; + using Iterator = typename Container::const_iterator; stm << "[ "; for (Iterator it = cont.begin(); it != cont.end();) @@ -54,7 +54,7 @@ namespace snowhouse template::value> struct is_container { - typedef typename T::const_iterator Iterator; + using Iterator = typename T::const_iterator; struct FallbackBeginEnd { @@ -62,7 +62,7 @@ namespace snowhouse Iterator end() const; }; - typedef Iterator (FallbackBeginEnd::*fallback_method)() const; + using fallback_method = Iterator (FallbackBeginEnd::*)() const; template struct is_of_type; @@ -109,7 +109,7 @@ namespace snowhouse template struct enable_if { - typedef TRUE_TYPE type; + using type = TRUE_TYPE; }; } From 2a351051032a615407aa8a0f14409a4ec7f42839 Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Thu, 27 Feb 2020 00:10:42 +0100 Subject: [PATCH 13/33] Use reference type in range-based for-loop This has been forgotten. Found by clang-tidy's performance-for-range-copy check. --- .../operators/collections/collectionconstraintevaluator.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/snowhouse/fluent/operators/collections/collectionconstraintevaluator.h b/include/snowhouse/fluent/operators/collections/collectionconstraintevaluator.h index 12cbc06..e5d9e38 100644 --- a/include/snowhouse/fluent/operators/collections/collectionconstraintevaluator.h +++ b/include/snowhouse/fluent/operators/collections/collectionconstraintevaluator.h @@ -23,7 +23,7 @@ namespace snowhouse operators, result); unsigned int passed_elements = 0; - for (const auto member : actual) + for (const auto& member : actual) { if (ConstraintOperator::EvaluateElementAgainstRestOfExpression(expression, member)) { From 3a5590a64398a4187f38433eac700f6d43e92076 Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Thu, 27 Feb 2020 00:11:24 +0100 Subject: [PATCH 14/33] Use std::string::find() with single character when possible This is faster. Found by clang-tidy's performance-faster-string-find check. --- .../operators/collections/collectionconstraintevaluator.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/snowhouse/fluent/operators/collections/collectionconstraintevaluator.h b/include/snowhouse/fluent/operators/collections/collectionconstraintevaluator.h index e5d9e38..e67dd78 100644 --- a/include/snowhouse/fluent/operators/collections/collectionconstraintevaluator.h +++ b/include/snowhouse/fluent/operators/collections/collectionconstraintevaluator.h @@ -75,12 +75,12 @@ namespace snowhouse return newline + 2; } - if (str.find("\n", newline) == newline) + if (str.find('\n', newline) == newline) { return newline + 1; } - if (str.find("\r", newline) == newline) + if (str.find('\r', newline) == newline) { return newline + 1; } From 1ac85cf937481a751e1b16b3d043876c35347f6d Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Thu, 27 Feb 2020 00:17:16 +0100 Subject: [PATCH 15/33] Use std::string::npos instead of str.npos npos is static, so use it as such. Found by clang-tidy's readability-static-accessed-through-instance check. --- include/snowhouse/constraints/containsconstraint.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/snowhouse/constraints/containsconstraint.h b/include/snowhouse/constraints/containsconstraint.h index 13b0ce0..8715a40 100644 --- a/include/snowhouse/constraints/containsconstraint.h +++ b/include/snowhouse/constraints/containsconstraint.h @@ -49,7 +49,7 @@ namespace snowhouse bool operator()(const std::string& actual) const { - return actual.find(m_expected) != actual.npos; + return actual.find(m_expected) != std::string::npos; } ExpectedType m_expected; From 4bd7b4f1143e330edb929e354149f843f3cf1ec6 Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Thu, 27 Feb 2020 00:19:48 +0100 Subject: [PATCH 16/33] Replace "result.size() < 1" by "result.empty()" for readability Found by clang-tidy's readability-container-size-empty check. --- include/snowhouse/fluent/operators/notoperator.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/snowhouse/fluent/operators/notoperator.h b/include/snowhouse/fluent/operators/notoperator.h index ca9eec9..613980e 100644 --- a/include/snowhouse/fluent/operators/notoperator.h +++ b/include/snowhouse/fluent/operators/notoperator.h @@ -24,7 +24,7 @@ namespace snowhouse void PerformOperation(ResultStack& result) override { - if (result.size() < 1) + if (result.empty()) { throw InvalidExpressionException("The expression contains a not operator without any operand"); } From 01959e0c2e78ba1f74b47efe97ee484a204005f6 Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Thu, 27 Feb 2020 00:55:20 +0100 Subject: [PATCH 17/33] Make naming of member variable consistent Snowhouse uses the m_name style much more often than the name_ style, so use it everywhere. We do not apply that for the tests and the documentation. --- .../constraints/equalscontainerconstraint.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/snowhouse/constraints/equalscontainerconstraint.h b/include/snowhouse/constraints/equalscontainerconstraint.h index df6d16d..ee47c6f 100644 --- a/include/snowhouse/constraints/equalscontainerconstraint.h +++ b/include/snowhouse/constraints/equalscontainerconstraint.h @@ -23,7 +23,7 @@ namespace snowhouse struct EqualsContainerConstraint : Expression> { EqualsContainerConstraint(const ExpectedType& expected, const BinaryPredicate predicate) - : expected_(expected), predicate_(predicate) + : m_expected(expected), m_predicate(predicate) { } @@ -33,19 +33,19 @@ namespace snowhouse typename ActualType::const_iterator actual_it; typename ExpectedType::const_iterator expected_it; - for (actual_it = actual.begin(), expected_it = expected_.begin(); actual_it != actual.end() && expected_it != expected_.end(); ++actual_it, ++expected_it) + for (actual_it = actual.begin(), expected_it = m_expected.begin(); actual_it != actual.end() && expected_it != m_expected.end(); ++actual_it, ++expected_it) { - if (!predicate_(*actual_it, *expected_it)) + if (!m_predicate(*actual_it, *expected_it)) { return false; } } - return actual_it == actual.end() && expected_it == expected_.end(); + return actual_it == actual.end() && expected_it == m_expected.end(); } - const ExpectedType expected_; - const BinaryPredicate predicate_; + const ExpectedType m_expected; + const BinaryPredicate m_predicate; }; template @@ -66,7 +66,7 @@ namespace snowhouse static std::string ToString(const EqualsContainerConstraint& constraint) { std::ostringstream builder; - builder << snowhouse::Stringize(constraint.expected_); + builder << snowhouse::Stringize(constraint.m_expected); return builder.str(); } }; From bbfdc2c6dec9dc071e5187453dc83fb4c9bb724b Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Thu, 27 Feb 2020 01:08:24 +0100 Subject: [PATCH 18/33] Make own exception messages more consistent --- example/operator_tests.cpp | 2 +- example/sequence_container_tests.cpp | 2 +- include/snowhouse/fluent/operators/andoperator.h | 2 +- include/snowhouse/fluent/operators/notoperator.h | 2 +- include/snowhouse/fluent/operators/oroperator.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/example/operator_tests.cpp b/example/operator_tests.cpp index 03ad59d..f9a9aec 100644 --- a/example/operator_tests.cpp +++ b/example/operator_tests.cpp @@ -93,7 +93,7 @@ void OperatorTests() it("yields error on malformed expression"); { AssertTestFails(AssertThat(4, Is().Not()), - "The expression contains a not operator without any operand"); + "The expression contains a \"not\" operator without any operand"); } it("handles failing EqualsWithDelta() when larger than delta"); diff --git a/example/sequence_container_tests.cpp b/example/sequence_container_tests.cpp index d5b1694..a98845e 100644 --- a/example/sequence_container_tests.cpp +++ b/example/sequence_container_tests.cpp @@ -75,7 +75,7 @@ static void TestHasAll(const T& container) it("handles invalid expression after All()"); { - AssertTestFails(AssertThat(container, Has().All().Not()), "The expression contains a not operator without any operand"); + AssertTestFails(AssertThat(container, Has().All().Not()), "The expression contains a \"not\" operator without any operand"); } it("handles no expression after All()"); diff --git a/include/snowhouse/fluent/operators/andoperator.h b/include/snowhouse/fluent/operators/andoperator.h index 0648176..034d04d 100644 --- a/include/snowhouse/fluent/operators/andoperator.h +++ b/include/snowhouse/fluent/operators/andoperator.h @@ -26,7 +26,7 @@ namespace snowhouse { if (result.size() < 2) { - throw InvalidExpressionException("The expression contains an and operator with too few operands"); + throw InvalidExpressionException("The expression contains an \"and\" operator with too few operands"); } bool right = result.top(); diff --git a/include/snowhouse/fluent/operators/notoperator.h b/include/snowhouse/fluent/operators/notoperator.h index 613980e..1af9b7d 100644 --- a/include/snowhouse/fluent/operators/notoperator.h +++ b/include/snowhouse/fluent/operators/notoperator.h @@ -26,7 +26,7 @@ namespace snowhouse { if (result.empty()) { - throw InvalidExpressionException("The expression contains a not operator without any operand"); + throw InvalidExpressionException("The expression contains a \"not\" operator without any operand"); } bool right = result.top(); diff --git a/include/snowhouse/fluent/operators/oroperator.h b/include/snowhouse/fluent/operators/oroperator.h index 6329d63..0b64854 100644 --- a/include/snowhouse/fluent/operators/oroperator.h +++ b/include/snowhouse/fluent/operators/oroperator.h @@ -26,7 +26,7 @@ namespace snowhouse { if (result.size() < 2) { - throw InvalidExpressionException("The expression contains an or operator with too few operands"); + throw InvalidExpressionException("The expression contains an \"or\" operator with too few operands"); } bool right = result.top(); From ecc25cd4db1f5d5c7a74ce13ec3b5459e2066ce3 Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Thu, 27 Feb 2020 11:06:15 +0100 Subject: [PATCH 19/33] Replace remaining typedefs by "using" clang-tidy's fix feature forgot some occurrences. --- include/snowhouse/fluent/constraintlist.h | 2 +- include/snowhouse/fluent/expressionbuilder.h | 2 +- include/snowhouse/stringize.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/snowhouse/fluent/constraintlist.h b/include/snowhouse/fluent/constraintlist.h index 346ba08..33e7a18 100644 --- a/include/snowhouse/fluent/constraintlist.h +++ b/include/snowhouse/fluent/constraintlist.h @@ -11,7 +11,7 @@ namespace snowhouse { struct ConstraintOperator; - typedef std::stack ResultStack; + using ResultStack = std::stack; using OperatorStack = std::stack; template diff --git a/include/snowhouse/fluent/expressionbuilder.h b/include/snowhouse/fluent/expressionbuilder.h index 354a882..cac2b6d 100644 --- a/include/snowhouse/fluent/expressionbuilder.h +++ b/include/snowhouse/fluent/expressionbuilder.h @@ -44,7 +44,7 @@ namespace snowhouse ExpressionBuilder>, Nil>>::t> EqualTo(const ExpectedType& expected) { - typedef ConstraintAdapter> ConstraintAdapterType; + using ConstraintAdapterType = ConstraintAdapter>; using BuilderType = ExpressionBuilder>::t>; ConstraintAdapterType constraint(expected); diff --git a/include/snowhouse/stringize.h b/include/snowhouse/stringize.h index 97be91d..157bc97 100644 --- a/include/snowhouse/stringize.h +++ b/include/snowhouse/stringize.h @@ -38,7 +38,7 @@ namespace snowhouse // T does not support the expression, such as <<, whereas the second overload returns a char // directly and is chosen if T supports the expression. So using sizeof(check()) // returns 2 for the first overload and 1 for the second overload. - typedef char yes; + using yes = char; using no = char (&)[2]; no check(tag); From 88ded8aa6d7ee9f4c4a15ce667eed9abc3089267 Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Fri, 28 Feb 2020 12:17:45 +0100 Subject: [PATCH 20/33] Make InvalidExpressionException inherit from std::runtime_error --- include/snowhouse/assert.h | 2 +- .../fluent/operators/invalidexpressionexception.h | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/include/snowhouse/assert.h b/include/snowhouse/assert.h index dac11b8..dc76a8f 100644 --- a/include/snowhouse/assert.h +++ b/include/snowhouse/assert.h @@ -71,7 +71,7 @@ namespace snowhouse } catch (const InvalidExpressionException& e) { - FailureHandler::Handle("Malformed expression: \"" + snowhouse::Stringize(expression) + "\"\n" + e.Message()); + FailureHandler::Handle("Malformed expression: \"" + snowhouse::Stringize(expression) + "\"\n" + e.what()); } } diff --git a/include/snowhouse/fluent/operators/invalidexpressionexception.h b/include/snowhouse/fluent/operators/invalidexpressionexception.h index 0e90035..4127ff1 100644 --- a/include/snowhouse/fluent/operators/invalidexpressionexception.h +++ b/include/snowhouse/fluent/operators/invalidexpressionexception.h @@ -6,23 +6,17 @@ #ifndef SNOWHOUSE_INVALIDEXPRESSIONEXCEPTION_H #define SNOWHOUSE_INVALIDEXPRESSIONEXCEPTION_H +#include #include namespace snowhouse { - struct InvalidExpressionException + struct InvalidExpressionException : public std::runtime_error { explicit InvalidExpressionException(const std::string& message) - : m_message(message) + : std::runtime_error(message) { } - - const std::string& Message() const - { - return m_message; - } - - std::string m_message; }; } From ba35d4b95a9694b5885ef9c1fa65e5f6c705b466 Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Fri, 28 Feb 2020 12:33:50 +0100 Subject: [PATCH 21/33] Make destructor of ConstraintOperator virtual This has currently no effect but can prevent future bugs in case a destructor of a derived class actually has to do anything. Also this change gets rid from -Wnon-virtual-dtor warnings. --- include/snowhouse/fluent/operators/constraintoperator.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/snowhouse/fluent/operators/constraintoperator.h b/include/snowhouse/fluent/operators/constraintoperator.h index 6abb509..8450bbb 100644 --- a/include/snowhouse/fluent/operators/constraintoperator.h +++ b/include/snowhouse/fluent/operators/constraintoperator.h @@ -14,6 +14,7 @@ namespace snowhouse { struct ConstraintOperator { + virtual ~ConstraintOperator() noexcept = default; virtual void PerformOperation(ResultStack& result) = 0; virtual int Precedence() const = 0; From 46e0860415b5d2776051d7183b29a2ddb1ee0893 Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Fri, 28 Feb 2020 12:38:56 +0100 Subject: [PATCH 22/33] Make AssertionException inherit from std::runtime_error --- README.md | 4 +++- example/basic_assertions.cpp | 4 ++-- example/exceptions_tests.cpp | 2 +- example/main.cpp | 2 +- example/tests.h | 2 +- include/snowhouse/assertionexception.h | 26 ++++++++++---------------- 6 files changed, 18 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index fb99729..2e12179 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ int main() catch(const AssertionException& ex) { std::cout << "Apparently this failed:" << std::endl; - std::cout << ex.GetMessage() << std::endl; + std::cout << ex.what() << std::endl; } return 0; @@ -517,6 +517,8 @@ Compatibility-breaking changes since version 3.0.0: * Since version 5.0.0, the support for C++ versions prior to C++11 are dropped. The definition of the macro `SNOWHOUSE_HAS_NULLPTR` is removed. + Our exceptions are now derived from the `std::exception` hierarchy, + thus their method names changed. ## Contributing diff --git a/example/basic_assertions.cpp b/example/basic_assertions.cpp index 7c0e92b..93f4e8c 100644 --- a/example/basic_assertions.cpp +++ b/example/basic_assertions.cpp @@ -88,8 +88,8 @@ void BasicAssertions() } catch (const AssertionException& e) { - line = e.GetLineNumber(); - file = e.GetFilename(); + line = e.line(); + file = e.file(); } AssertThat(line, Equals(32)); diff --git a/example/exceptions_tests.cpp b/example/exceptions_tests.cpp index 50dcfaa..7337e3c 100644 --- a/example/exceptions_tests.cpp +++ b/example/exceptions_tests.cpp @@ -95,7 +95,7 @@ void ExceptionTests() AssertThrows(std::logic_error, objectUnderTest.LogicError()); } AssertThrows(AssertionException, LastException()); - AssertThat(LastException().GetMessage(), Contains("No exception was stored")); + AssertThat(LastException().what(), Contains("No exception was stored")); } it("prints description of unwanted exception"); diff --git a/example/main.cpp b/example/main.cpp index b2c1340..bc37498 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -37,7 +37,7 @@ int main() catch (const AssertionException& e) { std::cout << "Tests failed!" << std::endl; - std::cout << e.GetMessage() << std::endl; + std::cout << e.what() << std::endl; return 1; } diff --git a/example/tests.h b/example/tests.h index 9d7a707..de31490 100644 --- a/example/tests.h +++ b/example/tests.h @@ -12,7 +12,7 @@ } \ catch (const AssertionException& exception_from_snowhouse_assertion) \ { \ - SNOWHOUSE_INTERNAL_expected_error = exception_from_snowhouse_assertion.GetMessage(); \ + SNOWHOUSE_INTERNAL_expected_error = exception_from_snowhouse_assertion.what(); \ } \ AssertThat(SNOWHOUSE_INTERNAL_expected_error, Is().Containing(expected_error_text)); // clang-format on diff --git a/include/snowhouse/assertionexception.h b/include/snowhouse/assertionexception.h index 703de6a..bd66968 100644 --- a/include/snowhouse/assertionexception.h +++ b/include/snowhouse/assertionexception.h @@ -6,45 +6,39 @@ #ifndef SNOWHOUSE_ASSERTIONEXCEPTION_H #define SNOWHOUSE_ASSERTIONEXCEPTION_H -#include +#include #include #include "macros.h" namespace snowhouse { - struct AssertionException : public std::exception + struct AssertionException : public std::runtime_error { - explicit AssertionException(const std::string& message) - : m_message(message), m_fileName(""), m_line(0) + explicit AssertionException(const std::string& message, const std::string& file, unsigned int line) + : std::runtime_error(message), m_file(file), m_line(line) { } - AssertionException(const std::string& message, const std::string& fileName, unsigned int line) - : m_message(message), m_fileName(fileName), m_line(line) + explicit AssertionException(const std::string& message) + : AssertionException(message, "", 0) { } AssertionException(const AssertionException&) = default; - std::string GetMessage() const - { - return m_message; - } - - std::string GetFilename() const + std::string file() const { - return m_fileName; + return m_file; } - unsigned int GetLineNumber() const + unsigned int line() const { return m_line; } private: - std::string m_message; - std::string m_fileName; + std::string m_file; unsigned int m_line; }; } From 7849a5c18fddb1aa4ef9dc722efb4a6888ab855a Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Fri, 28 Feb 2020 12:42:28 +0100 Subject: [PATCH 23/33] Use std::runtime_error constructors in InvalidExpressionException --- .../snowhouse/fluent/operators/invalidexpressionexception.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/snowhouse/fluent/operators/invalidexpressionexception.h b/include/snowhouse/fluent/operators/invalidexpressionexception.h index 4127ff1..975e970 100644 --- a/include/snowhouse/fluent/operators/invalidexpressionexception.h +++ b/include/snowhouse/fluent/operators/invalidexpressionexception.h @@ -13,10 +13,7 @@ namespace snowhouse { struct InvalidExpressionException : public std::runtime_error { - explicit InvalidExpressionException(const std::string& message) - : std::runtime_error(message) - { - } + using std::runtime_error::runtime_error; }; } From 48b87d8d275b5f39bff3452fe550b994dc3dbfcc Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Fri, 28 Feb 2020 13:06:49 +0100 Subject: [PATCH 24/33] Add notes on C++11 and pre-C++11 versions of Snowhouse --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 2e12179..1b059f2 100644 --- a/README.md +++ b/README.md @@ -505,6 +505,11 @@ Throw an exception and let our testing framework deal with the test failure. Snowhouse uses [Semantic Versioning 2.0.0](http://semver.org/spec/v2.0.0.html) since version 3.0.0. +Snowhouse requires C++11 since version 5.0.0. +Feel free to use Snowhouse with major version 4 if you want to use it +in a pre-C++11 setting. +Major version 4 is still maintained in the `maint-v4` branch (bug fixes, etc.). + The macros `SNOWHOUSE_MAJOR`, `SNOWHOUSE_MINOR` and `SNOWHOUSE_PATCH` are defined accordingly and `SNOWHOUSE_VERSION` contains the version string. Note that in prior versions `SNOWHOUSE_VERSION` was the only defined macro. From c4e11d0cdb16de2237176c7f8f29a98faa081d92 Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Fri, 28 Feb 2020 13:08:05 +0100 Subject: [PATCH 25/33] Rename some variables to defeat -Wshadow in some gcc versions --- include/snowhouse/assertionexception.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/snowhouse/assertionexception.h b/include/snowhouse/assertionexception.h index bd66968..6d51da5 100644 --- a/include/snowhouse/assertionexception.h +++ b/include/snowhouse/assertionexception.h @@ -15,8 +15,8 @@ namespace snowhouse { struct AssertionException : public std::runtime_error { - explicit AssertionException(const std::string& message, const std::string& file, unsigned int line) - : std::runtime_error(message), m_file(file), m_line(line) + explicit AssertionException(const std::string& message, const std::string& filename, unsigned int line_number) + : std::runtime_error(message), m_file(filename), m_line(line_number) { } From 4ff09dc12c2f02d4db4053da9feab774d8502b03 Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Fri, 28 Feb 2020 13:11:46 +0100 Subject: [PATCH 26/33] Remove explicit default copy constructor in AssertionException --- include/snowhouse/assertionexception.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/snowhouse/assertionexception.h b/include/snowhouse/assertionexception.h index 6d51da5..1db8e35 100644 --- a/include/snowhouse/assertionexception.h +++ b/include/snowhouse/assertionexception.h @@ -25,8 +25,6 @@ namespace snowhouse { } - AssertionException(const AssertionException&) = default; - std::string file() const { return m_file; From f547c2b4d357742e9397231b1d33707a548102a0 Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Mon, 2 Mar 2020 11:42:30 +0100 Subject: [PATCH 27/33] Activate some more warnings --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ebd0a43..f8345ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,9 @@ if (MSVC) endif() else() # Assume GCC-style arguments - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wfatal-errors -Wall -Wextra -Werror -Wfloat-equal -Wundef -Wendif-labels -Wshadow -pedantic-errors") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ + -Wall -Wextra -pedantic -Wdeprecated -Wdeprecated-declarations -Wnon-virtual-dtor \ + -Wshadow -Wfloat-equal -Wundef -Wendif-labels -Wno-error=unknown-pragmas") if(DEFINED std_name) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=${std_name}") From fce1328b1cd497837cc30e4d17495ef6c144a7af Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Mon, 2 Mar 2020 11:49:32 +0100 Subject: [PATCH 28/33] Require CMake 3.1 Update documentation while at it --- CMakeLists.txt | 27 +++++++-------------------- README.md | 21 +++++++++++++-------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f8345ba..27a9fc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.1) project(snowhouse) @@ -7,17 +7,15 @@ option(SNOWHOUSE_RUN_TESTS "Run the Snowhouse tests" OFF) set(SNOWHOUSE_CXX_STANDARD "C++11" CACHE STRING "The C++ standard the examples are compiled with") set_property(CACHE SNOWHOUSE_CXX_STANDARD PROPERTY STRINGS "C++11" "C++14" "C++17") -if (NOT ${CMAKE_VERSION} VERSION_LESS "3.0.0") - add_library(snowhouse INTERFACE) - target_include_directories(snowhouse INTERFACE include) -endif() +add_library(snowhouse INTERFACE) +target_include_directories(snowhouse INTERFACE include) if(SNOWHOUSE_CXX_STANDARD STREQUAL "C++11") - set(std_name "c++11") + set(CMAKE_CXX_STANDARD 11) elseif(SNOWHOUSE_CXX_STANDARD STREQUAL "C++14") - set(std_name "c++14") + set(CMAKE_CXX_STANDARD 14) elseif(SNOWHOUSE_CXX_STANDARD STREQUAL "C++17") - set(std_name "c++17") + set(CMAKE_CXX_STANDARD 17) else() message(WARNING "C++ standard \"${SNOWHOUSE_CXX_STANDARD}\" not known, falling back to default") endif() @@ -26,18 +24,11 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ./bin) if (MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /MP ") - if(DEFINED std_name) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:${std_name}") - endif() else() # Assume GCC-style arguments set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ -Wall -Wextra -pedantic -Wdeprecated -Wdeprecated-declarations -Wnon-virtual-dtor \ -Wshadow -Wfloat-equal -Wundef -Wendif-labels -Wno-error=unknown-pragmas") - - if(DEFINED std_name) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=${std_name}") - endif() endif() message(STATUS "C++ compiler flags: ${CMAKE_CXX_FLAGS}") @@ -45,11 +36,7 @@ message(STATUS "C++ compiler flags: ${CMAKE_CXX_FLAGS}") if (SNOWHOUSE_BUILD_TESTS) FILE(GLOB SnowhouseSpecSourceFiles example/*.cpp) add_executable(snowhouse-tests ${SnowhouseSpecSourceFiles}) - if (NOT ${CMAKE_VERSION} VERSION_LESS "3.0.0") - target_link_libraries(snowhouse-tests PRIVATE snowhouse) - else() - include_directories("${PROJECT_SOURCE_DIR}/include") - endif() + target_link_libraries(snowhouse-tests PRIVATE snowhouse) endif() if (SNOWHOUSE_BUILD_TESTS AND SNOWHOUSE_RUN_TESTS) diff --git a/README.md b/README.md index 1b059f2..468d5ca 100644 --- a/README.md +++ b/README.md @@ -8,16 +8,26 @@ snowhouse An assertion library for C++ Snowhouse is a stand-alone assertion framework for C++. - It is a header-only library. -You can simply use the `headers-only` branch as a submodule: + +Snowhouse requires a C++11-compatible compiler since version 5.0.0. +Feel free to use Snowhouse with major version 4 if you want to use it +in a pre-C++11 setting. +Major version 4 is still maintained in the `maint-v4` branch (bug fixes, etc.). + +For inclusion in your projects, you have several options: + +a) You can copy the code and just use it as the license allows. + +b) You can use the `headers-only` branch as a submodule: ```sh git submodule add -b headers-only https://github.com/banditcpp/snowhouse snowhouse git submodule update --init --recursive ``` -As an alternative, CMake >= 3.0 users can use Snowhouse with the provided library target. +c) If you use CMake >= 3.1 in your project, +you can use Snowhouse with the provided library target. Assuming you have cloned the `master` branch into a `snowhouse` subdirectory, your `CMakeLists.txt` might contain lines like the following: @@ -505,11 +515,6 @@ Throw an exception and let our testing framework deal with the test failure. Snowhouse uses [Semantic Versioning 2.0.0](http://semver.org/spec/v2.0.0.html) since version 3.0.0. -Snowhouse requires C++11 since version 5.0.0. -Feel free to use Snowhouse with major version 4 if you want to use it -in a pre-C++11 setting. -Major version 4 is still maintained in the `maint-v4` branch (bug fixes, etc.). - The macros `SNOWHOUSE_MAJOR`, `SNOWHOUSE_MINOR` and `SNOWHOUSE_PATCH` are defined accordingly and `SNOWHOUSE_VERSION` contains the version string. Note that in prior versions `SNOWHOUSE_VERSION` was the only defined macro. From 0a0ba88a5b0a5d2a6b41abb694be9fa48d5f2d5a Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Mon, 2 Mar 2020 12:20:35 +0100 Subject: [PATCH 29/33] Adhere to rule of three for ConstraintOperator clang 5.0 complains otherwise (more recent clang compilers don't complain). --- include/snowhouse/fluent/operators/constraintoperator.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/snowhouse/fluent/operators/constraintoperator.h b/include/snowhouse/fluent/operators/constraintoperator.h index 8450bbb..12830a5 100644 --- a/include/snowhouse/fluent/operators/constraintoperator.h +++ b/include/snowhouse/fluent/operators/constraintoperator.h @@ -14,6 +14,9 @@ namespace snowhouse { struct ConstraintOperator { + ConstraintOperator() = default; + explicit ConstraintOperator(const ConstraintOperator&) = default; + ConstraintOperator& operator=(const ConstraintOperator&) = default; virtual ~ConstraintOperator() noexcept = default; virtual void PerformOperation(ResultStack& result) = 0; virtual int Precedence() const = 0; From 921a51860f5c7df83b4e86779b3382cb02f72bc7 Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Tue, 3 Mar 2020 09:59:52 +0100 Subject: [PATCH 30/33] Set version to 5.0.0 --- include/snowhouse/macros.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/snowhouse/macros.h b/include/snowhouse/macros.h index 0309ee7..b6854f5 100644 --- a/include/snowhouse/macros.h +++ b/include/snowhouse/macros.h @@ -2,7 +2,7 @@ #define SNOWHOUSE_MACROS_H // clang-format off -#define SNOWHOUSE_MAJOR 4 +#define SNOWHOUSE_MAJOR 5 #define SNOWHOUSE_MINOR 0 #define SNOWHOUSE_PATCH 0 From bfe2b566ddc13bbe986042aaa8a87f5090ce586d Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Tue, 3 Mar 2020 10:23:48 +0100 Subject: [PATCH 31/33] Remove CI trigger on snowhouse-minimum and debian-stretch-compilers images We require CMake >= 3.1 now but these images have a too old CMake version installed. --- .travis.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4c474dc..7e935e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,10 +6,6 @@ services: - docker env: - - DOCKER_TAG=snowhouse-minimum CXX_STANDARD=11 CC=clang CXX=clang++ - - DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=11 CC=gcc-4.8 CXX=g++-4.8 - - DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=11 CC=gcc-4.9 CXX=g++-4.9 - - DOCKER_TAG=debian-jessie-compilers CXX_STANDARD=11 CC=clang-3.5 CXX=clang++-3.5 - DOCKER_TAG=debian-stretch-compilers CXX_STANDARD=11 CC=gcc-6 CXX=g++-6 - DOCKER_TAG=debian-stretch-compilers CXX_STANDARD=11 CC=clang-3.9 CXX=clang++-3.9 From 415152c96cf7f5faa21ec88178eea3b61796c14f Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Tue, 3 Mar 2020 11:40:21 +0100 Subject: [PATCH 32/33] Fix wrong indentation in example/tests.h --- example/tests.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/tests.h b/example/tests.h index de31490..e4abdf9 100644 --- a/example/tests.h +++ b/example/tests.h @@ -12,7 +12,7 @@ } \ catch (const AssertionException& exception_from_snowhouse_assertion) \ { \ - SNOWHOUSE_INTERNAL_expected_error = exception_from_snowhouse_assertion.what(); \ + SNOWHOUSE_INTERNAL_expected_error = exception_from_snowhouse_assertion.what(); \ } \ AssertThat(SNOWHOUSE_INTERNAL_expected_error, Is().Containing(expected_error_text)); // clang-format on From 23ed11185fece6f33e28aa2e882c36e1d82f5a2c Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Wed, 4 Mar 2020 00:26:28 +0100 Subject: [PATCH 33/33] Add a space after "catch" in example code in README.md I think missing spaces after keywords are just ugly. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 468d5ca..164f8b3 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ int main() { AssertThat(12, Is().LessThan(11).And().GreaterThan(99)); } - catch(const AssertionException& ex) + catch (const AssertionException& ex) { std::cout << "Apparently this failed:" << std::endl; std::cout << ex.what() << std::endl;