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/.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/.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..7e935e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,19 +6,6 @@ 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..27a9fc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,27 +1,21 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.1) 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() +add_library(snowhouse INTERFACE) +target_include_directories(snowhouse INTERFACE include) -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") - set(std_name "c++11") +if(SNOWHOUSE_CXX_STANDARD STREQUAL "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() @@ -30,16 +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} -Wfatal-errors -Wall -Wextra -Werror -Wfloat-equal -Wundef -Wendif-labels -Wshadow -pedantic-errors") - - if(DEFINED std_name) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=${std_name}") - endif() + 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") endif() message(STATUS "C++ compiler flags: ${CMAKE_CXX_FLAGS}") @@ -47,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 2ade74b..164f8b3 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: @@ -43,10 +53,10 @@ 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.GetMessage() << std::endl; + std::cout << ex.what() << std::endl; } return 0; @@ -166,9 +176,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 @@ -518,6 +525,11 @@ 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. + 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 The development of Snowhouse takes place on [GitHub](//github.com/banditcpp/snowhouse). @@ -533,7 +545,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. diff --git a/example/basic_assertions.cpp b/example/basic_assertions.cpp index 7f0a661..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)); @@ -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/example/exceptions_tests.cpp b/example/exceptions_tests.cpp index d050a07..7337e3c 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 noexcept override + { + return "Description of the exception we expected"; + } +}; + void ExceptionTests() { ClassWithExceptions objectUnderTest; @@ -87,6 +95,11 @@ 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"); + { + AssertTestFails(AssertThrows(ExpectedException, objectUnderTest.LogicError()), "Expected ExpectedException. Wrong exception was thrown. Description of unwanted exception: not logical!"); } } 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/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 cb7039c..a98845e 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) @@ -78,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()"); @@ -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() @@ -275,25 +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>(); -#if __cplusplus >= 201103L describe("Sequence containers (std::array)"); - SequenceContainerActual >(); + SequenceContainerActual>(); describe("Sequence containers (std::forward_list)"); - SequenceContainerActual >(); -#endif + SequenceContainerActual>(); } diff --git a/example/tests.h b/example/tests.h index 9d7a707..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.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/assert.h b/include/snowhouse/assert.h index 4e68d9f..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()); } } @@ -110,7 +110,7 @@ namespace snowhouse } }; - typedef ConfigurableAssert Assert; + using Assert = ConfigurableAssert; } #endif diff --git a/include/snowhouse/assertionexception.h b/include/snowhouse/assertionexception.h index 3ac455c..1db8e35 100644 --- a/include/snowhouse/assertionexception.h +++ b/include/snowhouse/assertionexception.h @@ -6,55 +6,37 @@ #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) - { - } - - 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, const std::string& filename, unsigned int line_number) + : std::runtime_error(message), m_file(filename), m_line(line_number) { } -#if __cplusplus > 199711L - AssertionException(const AssertionException&) = default; -#endif - -#if __cplusplus > 199711L - virtual ~AssertionException() noexcept -#else - virtual ~AssertionException() throw() -#endif - { - } - - std::string GetMessage() const + explicit AssertionException(const std::string& message) + : AssertionException(message, "", 0) { - 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; }; } diff --git a/include/snowhouse/constraints/containsconstraint.h b/include/snowhouse/constraints/containsconstraint.h index be37907..8715a40 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) @@ -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; @@ -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 d799751..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) @@ -48,15 +48,13 @@ namespace snowhouse return EqualsConstraint(true); } -#ifdef SNOWHOUSE_HAS_NULLPTR inline EqualsConstraint IsNull() { return EqualsConstraint(nullptr); } -#endif template<> - struct Stringizer > + struct Stringizer> { static std::string ToString(const EqualsConstraint& constraint) { @@ -65,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 50c5649..ee47c6f 100644 --- a/include/snowhouse/constraints/equalscontainerconstraint.h +++ b/include/snowhouse/constraints/equalscontainerconstraint.h @@ -20,10 +20,10 @@ namespace snowhouse } template - struct EqualsContainerConstraint : Expression > + struct EqualsContainerConstraint : Expression> { EqualsContainerConstraint(const ExpectedType& expected, const BinaryPredicate predicate) - : expected_(expected), predicate_(predicate) + : m_expected(expected), m_predicate(predicate) { } @@ -33,27 +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_; - - private: -#if __cplusplus <= 199711L - EqualsContainerConstraint& operator=(const EqualsContainerConstraint&) - { - return *this; - } -#endif + const ExpectedType m_expected; + const BinaryPredicate m_predicate; }; template @@ -69,12 +61,12 @@ namespace snowhouse } template - struct Stringizer > + struct Stringizer> { static std::string ToString(const EqualsContainerConstraint& constraint) { std::ostringstream builder; - builder << snowhouse::Stringize(constraint.expected_); + builder << snowhouse::Stringize(constraint.m_expected); return builder.str(); } }; 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..c318a0d 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) @@ -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); } @@ -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/exceptions.h b/include/snowhouse/exceptions.h index 4518cd1..4da7667 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"); } @@ -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) 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/constraintlist.h b/include/snowhouse/fluent/constraintlist.h index 21d84cc..33e7a18 100644 --- a/include/snowhouse/fluent/constraintlist.h +++ b/include/snowhouse/fluent/constraintlist.h @@ -11,14 +11,14 @@ namespace snowhouse { struct ConstraintOperator; - typedef std::stack ResultStack; - typedef std::stack OperatorStack; + using ResultStack = std::stack; + 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 c9a0516..cac2b6d 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; + using ConstraintAdapterType = ConstraintAdapter>; + using BuilderType = ExpressionBuilder>::t>; 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; + using ConstraintAdapterType = ConstraintAdapter>; + using BuilderType = ExpressionBuilder>::t>; 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; + using ConstraintAdapterType = ConstraintAdapter>; + using BuilderType = ExpressionBuilder>::t>; ConstraintAdapterType constraint(matcher); ConstraintList node(constraint, Nil()); @@ -79,194 +79,192 @@ 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); } -#ifdef SNOWHOUSE_HAS_NULLPTR - ExpressionBuilder >, Nil> >::t> + ExpressionBuilder>, Nil>>::t> Null() { return EqualTo(nullptr); } -#endif - 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; + 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)); } template - ExpressionBuilder >, Nil> >::t> + 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)); } template - ExpressionBuilder >, Nil> >::t> + 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)); } template - ExpressionBuilder >, Nil> >::t> + 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)); } template - ExpressionBuilder >, Nil> >::t> + 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)); } - 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; + using ConstraintAdapterType = ConstraintAdapter>; + using BuilderType = ExpressionBuilder>::t>; 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; + 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)); } - 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; + 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)); } - ExpressionBuilder, Nil> >::t> + 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)); } 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; + 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)); } template - ExpressionBuilder >, Nil> >::t> + 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)); @@ -274,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)); @@ -282,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)); @@ -290,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)); @@ -298,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)); @@ -306,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)); @@ -314,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)); @@ -322,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)); @@ -352,7 +350,7 @@ namespace snowhouse } template - struct Stringizer > + struct Stringizer> { static std::string ToString(const ExpressionBuilder& builder) { diff --git a/include/snowhouse/fluent/operators/andoperator.h b/include/snowhouse/fluent/operators/andoperator.h index 13baf2e..034d04d 100644 --- a/include/snowhouse/fluent/operators/andoperator.h +++ b/include/snowhouse/fluent/operators/andoperator.h @@ -22,11 +22,11 @@ namespace snowhouse EvaluateConstraintList(list.m_tail, result, operators, actual); } - void PerformOperation(ResultStack& result) + void PerformOperation(ResultStack& result) override { 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(); @@ -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/collectionconstraintevaluator.h b/include/snowhouse/fluent/operators/collections/collectionconstraintevaluator.h index e075da0..e67dd78 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; } @@ -76,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; } @@ -103,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); } }; } 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/constraintoperator.h b/include/snowhouse/fluent/operators/constraintoperator.h index b622c9d..12830a5 100644 --- a/include/snowhouse/fluent/operators/constraintoperator.h +++ b/include/snowhouse/fluent/operators/constraintoperator.h @@ -14,12 +14,10 @@ namespace snowhouse { struct ConstraintOperator { -#if __cplusplus <= 199711L - virtual ~ConstraintOperator() - { - } -#endif - + 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; diff --git a/include/snowhouse/fluent/operators/invalidexpressionexception.h b/include/snowhouse/fluent/operators/invalidexpressionexception.h index 0e90035..975e970 100644 --- a/include/snowhouse/fluent/operators/invalidexpressionexception.h +++ b/include/snowhouse/fluent/operators/invalidexpressionexception.h @@ -6,23 +6,14 @@ #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) - { - } - - const std::string& Message() const - { - return m_message; - } - - std::string m_message; + using std::runtime_error::runtime_error; }; } diff --git a/include/snowhouse/fluent/operators/notoperator.h b/include/snowhouse/fluent/operators/notoperator.h index be7234d..1af9b7d 100644 --- a/include/snowhouse/fluent/operators/notoperator.h +++ b/include/snowhouse/fluent/operators/notoperator.h @@ -22,11 +22,11 @@ namespace snowhouse EvaluateConstraintList(list.m_tail, result, operators, actual); } - void PerformOperation(ResultStack& result) + void PerformOperation(ResultStack& result) override { - if (result.size() < 1) + 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(); @@ -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..0b64854 100644 --- a/include/snowhouse/fluent/operators/oroperator.h +++ b/include/snowhouse/fluent/operators/oroperator.h @@ -22,11 +22,11 @@ namespace snowhouse EvaluateConstraintList(list.m_tail, result, operators, actual); } - void PerformOperation(ResultStack& result) + void PerformOperation(ResultStack& result) override { 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(); @@ -37,7 +37,7 @@ namespace snowhouse result.push(left || right); } - int Precedence() const + int Precedence() const override { return 4; } diff --git a/include/snowhouse/macros.h b/include/snowhouse/macros.h index 5247cb6..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 @@ -12,18 +12,4 @@ SNOWHOUSE_MACROTOSTRING(SNOWHOUSE_MAJOR) "." \ 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 -#endif - #endif diff --git a/include/snowhouse/stringize.h b/include/snowhouse/stringize.h index 420d4d7..157bc97 100644 --- a/include/snowhouse/stringize.h +++ b/include/snowhouse/stringize.h @@ -38,8 +38,8 @@ 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; - typedef char (&no)[2]; + using yes = char; + using no = char (&)[2]; no check(tag); @@ -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..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();) @@ -48,17 +48,13 @@ 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> struct is_container { - typedef typename T::const_iterator Iterator; + using Iterator = typename T::const_iterator; struct FallbackBeginEnd { @@ -66,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; @@ -113,7 +109,7 @@ namespace snowhouse template struct enable_if { - typedef TRUE_TYPE type; + using type = TRUE_TYPE; }; } 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