From a8793591f96ff1c399301b44cb26e1e3d3e49dd6 Mon Sep 17 00:00:00 2001 From: Corentin Schreiber Date: Wed, 30 Nov 2022 21:20:36 +0000 Subject: [PATCH 1/4] Compile tests with Catch2 --- oup.sublime-project | 14 +++++--- tests/CMakeLists.txt | 11 +++--- ...runtime_tests_observer_assignment_copy.cpp | 12 +++---- tests/runtime_tests_observer_from_this.cpp | 28 +++++++-------- tests/testing.hpp | 36 ++++++++++++++++++- 5 files changed, 70 insertions(+), 31 deletions(-) diff --git a/oup.sublime-project b/oup.sublime-project index 1aac163..95bb906 100644 --- a/oup.sublime-project +++ b/oup.sublime-project @@ -57,6 +57,14 @@ "name": "oup_runtime_tests_run", "shell_cmd": "make -j12 oup_runtime_tests_run", }, + { + "name": "Catch2", + "shell_cmd": "make -j12 Catch2", + }, + { + "name": "Catch2WithMain", + "shell_cmd": "make -j12 Catch2WithMain", + }, { "name": "oup_runtime_tests", "shell_cmd": "make -j12 oup_runtime_tests", @@ -67,11 +75,7 @@ }, { "name": "oup_speed_benchmark", - "shell_cmd": "make -j12 oup_speed_benchmark", - }, - { - "name": "snatch", - "shell_cmd": "make -j12 snatch", + "shell_cmd": "make -j12 oup_speed_benchmark" }, ], "working_dir": "$folder/build", diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e14920f..14718ba 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -17,6 +17,7 @@ function(add_platform_definitions TARGET) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") target_compile_options(${TARGET} PRIVATE -Wall) target_compile_options(${TARGET} PRIVATE -Wextra) + target_compile_options(${TARGET} PRIVATE -Wno-nonnull) target_compile_options(${TARGET} PRIVATE -Werror) elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") target_compile_options(${TARGET} PRIVATE -Wall) @@ -31,10 +32,10 @@ endfunction() include(FetchContent) -FetchContent_Declare(snatch - GIT_REPOSITORY https://github.com/cschreib/snatch.git - GIT_TAG v0.1.3) -FetchContent_MakeAvailable(snatch) +FetchContent_Declare(catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v3.2.0) +FetchContent_MakeAvailable(catch2) set(RUNTIME_TEST_FILES ${PROJECT_SOURCE_DIR}/tests/tests_common.cpp @@ -61,7 +62,7 @@ set(RUNTIME_TEST_FILES add_executable(oup_runtime_tests ${RUNTIME_TEST_FILES}) target_link_libraries(oup_runtime_tests PRIVATE oup::oup) -target_link_libraries(oup_runtime_tests PRIVATE snatch::snatch) +target_link_libraries(oup_runtime_tests PRIVATE Catch2::Catch2WithMain) add_platform_definitions(oup_runtime_tests) add_custom_target(oup_runtime_tests_run diff --git a/tests/runtime_tests_observer_assignment_copy.cpp b/tests/runtime_tests_observer_assignment_copy.cpp index d2cfaee..27502dc 100644 --- a/tests/runtime_tests_observer_assignment_copy.cpp +++ b/tests/runtime_tests_observer_assignment_copy.cpp @@ -217,10 +217,10 @@ TEMPLATE_LIST_TEST_CASE( { TestType ptr = make_pointer_deleter_1(); observer_ptr optr{ptr}; - SNATCH_WARNING_PUSH; - SNATCH_WARNING_DISABLE_SELF_ASSIGN; + // SNATCH_WARNING_PUSH; + // SNATCH_WARNING_DISABLE_SELF_ASSIGN; optr = optr; - SNATCH_WARNING_POP; + // SNATCH_WARNING_POP; CHECK(optr.get() == ptr.get()); CHECK(optr.expired() == false); @@ -236,10 +236,10 @@ TEMPLATE_LIST_TEST_CASE( { observer_ptr optr; - SNATCH_WARNING_PUSH; - SNATCH_WARNING_DISABLE_SELF_ASSIGN; + // SNATCH_WARNING_PUSH; + // SNATCH_WARNING_DISABLE_SELF_ASSIGN; optr = optr; - SNATCH_WARNING_POP; + // SNATCH_WARNING_POP; CHECK(optr.get() == nullptr); CHECK(optr.expired() == true); diff --git a/tests/runtime_tests_observer_from_this.cpp b/tests/runtime_tests_observer_from_this.cpp index 5f7295c..76e00fc 100644 --- a/tests/runtime_tests_observer_from_this.cpp +++ b/tests/runtime_tests_observer_from_this.cpp @@ -74,13 +74,13 @@ TEMPLATE_LIST_TEST_CASE( } else { REQUIRE_THROWS_MATCHES( (make_observer_from_this(orig_ptr)), oup::bad_observer_from_this, - snatch::matchers::with_what_contains{ - "observer_from_this() called with uninitialized control block"}); + Catch::Matchers::Message( + "observer_from_this() called with uninitialized control block")); REQUIRE_THROWS_MATCHES( (make_const_observer_from_this(orig_ptr)), oup::bad_observer_from_this, - snatch::matchers::with_what_contains{ - "observer_from_this() called with uninitialized control block"}); + Catch::Matchers::Message( + "observer_from_this() called with uninitialized control block")); } CHECK_INSTANCES(1, 0); @@ -110,12 +110,12 @@ TEMPLATE_LIST_TEST_CASE("observer from this no owner stack", "[observer_from_thi } else { REQUIRE_THROWS_MATCHES( (make_observer_from_this(&obj)), oup::bad_observer_from_this, - snatch::matchers::with_what_contains{ - "observer_from_this() called with uninitialized control block"}); + Catch::Matchers::Message( + "observer_from_this() called with uninitialized control block")); REQUIRE_THROWS_MATCHES( (make_const_observer_from_this(&obj)), oup::bad_observer_from_this, - snatch::matchers::with_what_contains{ - "observer_from_this() called with uninitialized control block"}); + Catch::Matchers::Message( + "observer_from_this() called with uninitialized control block")); } CHECK_INSTANCES(1, 0); @@ -147,13 +147,13 @@ TEMPLATE_LIST_TEST_CASE( } else { REQUIRE_THROWS_MATCHES( (make_observer_from_this(orig_ptr)), oup::bad_observer_from_this, - snatch::matchers::with_what_contains{ - "observer_from_this() called with uninitialized control block"}); + Catch::Matchers::Message( + "observer_from_this() called with uninitialized control block")); REQUIRE_THROWS_MATCHES( (make_const_observer_from_this(orig_ptr)), oup::bad_observer_from_this, - snatch::matchers::with_what_contains{ - "observer_from_this() called with uninitialized control block"}); + Catch::Matchers::Message( + "observer_from_this() called with uninitialized control block")); } } @@ -388,8 +388,8 @@ TEMPLATE_LIST_TEST_CASE("observer from this in constructor", "[observer_from_thi next_test_object_constructor_calls_observer_from_this = true; REQUIRE_THROWS_MATCHES( (make_pointer_deleter_1()), oup::bad_observer_from_this, - snatch::matchers::with_what_contains{ - "observer_from_this() called with uninitialized control block"}); + Catch::Matchers::Message( + "observer_from_this() called with uninitialized control block")); next_test_object_constructor_calls_observer_from_this = false; } diff --git a/tests/testing.hpp b/tests/testing.hpp index 3651ece..2bf03d1 100644 --- a/tests/testing.hpp +++ b/tests/testing.hpp @@ -1 +1,35 @@ -#include "snatch/snatch.hpp" +#include "catch2/catch_template_test_macros.hpp" +#include "catch2/catch_test_macros.hpp" +#include "catch2/matchers/catch_matchers_exception.hpp" + +namespace snatch::impl { +template +constexpr std::string_view get_type_name() noexcept { +#if defined(__clang__) + constexpr auto prefix = std::string_view{"[T = "}; + constexpr auto suffix = "]"; + constexpr auto function = std::string_view{__PRETTY_FUNCTION__}; +#elif defined(__GNUC__) + constexpr auto prefix = std::string_view{"with T = "}; + constexpr auto suffix = "; "; + constexpr auto function = std::string_view{__PRETTY_FUNCTION__}; +#elif defined(_MSC_VER) + constexpr auto prefix = std::string_view{"get_type_name<"}; + constexpr auto suffix = ">(void)"; + constexpr auto function = std::string_view{__FUNCSIG__}; +#else +# error Unsupported compiler +#endif + + const auto start = function.find(prefix) + prefix.size(); + const auto end = function.find(suffix); + const auto size = end - start; + + return function.substr(start, size); +} +} // namespace snatch::impl + +namespace snatch { +template +constexpr std::string_view type_name = impl::get_type_name(); +} // namespace snatch From dd4913567118757ea8dceae3b73af70cddc4d325 Mon Sep 17 00:00:00 2001 From: Corentin Schreiber Date: Sun, 15 Jan 2023 16:33:28 +0000 Subject: [PATCH 2/4] Fix Catch2 not supporting std::string_view if not compiled in C++17 --- tests/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 14718ba..bca3710 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -32,6 +32,8 @@ endfunction() include(FetchContent) +set(CMAKE_CXX_STANDARD 17) # enable C++17 in Catch2... + FetchContent_Declare(catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git GIT_TAG v3.2.0) From 3fc0771d3daf720bf9aaf0620226bbbfcfd30f70 Mon Sep 17 00:00:00 2001 From: Corentin Schreiber Date: Sun, 20 Aug 2023 18:30:06 +0100 Subject: [PATCH 3/4] Update catch2 --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index bca3710..7c9243d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -36,7 +36,7 @@ set(CMAKE_CXX_STANDARD 17) # enable C++17 in Catch2... FetchContent_Declare(catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v3.2.0) + GIT_TAG v3.4.0) FetchContent_MakeAvailable(catch2) set(RUNTIME_TEST_FILES From df3b9edc7c666a5cdbb3dc4dd63774e97485a5ca Mon Sep 17 00:00:00 2001 From: Corentin Schreiber Date: Tue, 12 Aug 2025 14:31:14 +0100 Subject: [PATCH 4/4] Update catch2 --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7c9243d..8082c2a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -36,7 +36,7 @@ set(CMAKE_CXX_STANDARD 17) # enable C++17 in Catch2... FetchContent_Declare(catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v3.4.0) + GIT_TAG v3.9.1) FetchContent_MakeAvailable(catch2) set(RUNTIME_TEST_FILES