From 6349f81de0f4bec88dc42175af14c4b2b5e38b5a Mon Sep 17 00:00:00 2001 From: Vitaly Zaitsev Date: Thu, 16 Mar 2023 08:36:08 +0100 Subject: [PATCH] Added packaged Catch2 support and upgraded to modern v3 branch. Also switched to CMAKE_INSTALL_INCLUDEDIR in install interface. --- .appveyor.yml | 1 - CMakeLists.txt | 22 +++++++++++++--------- tests/assertions.cpp | 2 +- tests/assignment.cpp | 2 +- tests/bases.cpp | 2 +- tests/constexpr.cpp | 2 +- tests/constructors.cpp | 2 +- tests/emplace.cpp | 2 +- tests/extensions.cpp | 2 +- tests/issues.cpp | 2 +- tests/main.cpp | 2 -- tests/noexcept.cpp | 2 +- tests/observers.cpp | 2 +- tests/relops.cpp | 2 +- tests/swap.cpp | 2 +- 15 files changed, 25 insertions(+), 24 deletions(-) delete mode 100644 tests/main.cpp diff --git a/.appveyor.yml b/.appveyor.yml index f63c5b6..a8436b1 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,5 +1,4 @@ os: -- Visual Studio 2015 - Visual Studio 2017 - Visual Studio 2019 - Visual Studio 2022 diff --git a/CMakeLists.txt b/CMakeLists.txt index ddab64e..622be7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ add_library(expected INTERFACE) target_include_directories(expected INTERFACE $ - $) + $) if (NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) add_library(tl::expected ALIAS expected) @@ -63,13 +63,17 @@ install(FILES install(DIRECTORY "include/" TYPE INCLUDE) if(EXPECTED_BUILD_TESTS) - set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) - set(CATCH_INSTALL_HELPERS OFF) - set(CATCH_BUILD_TESTING OFF) - set(CATCH_INSTALL_DOCS OFF) - FetchContent_Declare(Catch2 URL - https://github.com/catchorg/Catch2/archive/v2.13.10.zip) - FetchContent_MakeAvailable(Catch2) + find_package(Catch2 3 QUIET) + if (NOT Catch2_FOUND) + message(STATUS "Bundled version of Catch will be downloaded and used.") + set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) + set(CATCH_INSTALL_HELPERS OFF) + set(CATCH_BUILD_TESTING OFF) + set(CATCH_INSTALL_DOCS OFF) + FetchContent_Declare(Catch2 URL + https://github.com/catchorg/Catch2/archive/v3.3.2.zip) + FetchContent_MakeAvailable(Catch2) + endif() file(GLOB test-sources CONFIGURE_DEPENDS tests/*.cpp) list(FILTER test-sources EXCLUDE REGEX "tests/test.cpp") @@ -79,7 +83,7 @@ if(EXPECTED_BUILD_TESTS) target_link_libraries(${PROJECT_NAME}-tests PRIVATE - Catch2::Catch2 + Catch2::Catch2WithMain expected) add_test(NAME tl::expected::tests COMMAND ${PROJECT_NAME}-tests) endif() diff --git a/tests/assertions.cpp b/tests/assertions.cpp index f109097..a0a935f 100644 --- a/tests/assertions.cpp +++ b/tests/assertions.cpp @@ -1,4 +1,4 @@ -#include +#include #include #define TL_ASSERT(cond) if (!(cond)) { throw std::runtime_error(std::string("assertion failure")); } diff --git a/tests/assignment.cpp b/tests/assignment.cpp index 2d6bf6b..62ff169 100644 --- a/tests/assignment.cpp +++ b/tests/assignment.cpp @@ -1,4 +1,4 @@ -#include +#include #include TEST_CASE("Simple assignment", "[assignment.simple]") { diff --git a/tests/bases.cpp b/tests/bases.cpp index fe8d6aa..4352eb6 100644 --- a/tests/bases.cpp +++ b/tests/bases.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/tests/constexpr.cpp b/tests/constexpr.cpp index 9046592..194c605 100644 --- a/tests/constexpr.cpp +++ b/tests/constexpr.cpp @@ -1,4 +1,4 @@ -#include +#include #include TEST_CASE("Constexpr", "[constexpr]") { diff --git a/tests/constructors.cpp b/tests/constructors.cpp index df168ba..ffe9987 100644 --- a/tests/constructors.cpp +++ b/tests/constructors.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/tests/emplace.cpp b/tests/emplace.cpp index 9449079..12b28af 100644 --- a/tests/emplace.cpp +++ b/tests/emplace.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/tests/extensions.cpp b/tests/extensions.cpp index 14c180f..4c12384 100644 --- a/tests/extensions.cpp +++ b/tests/extensions.cpp @@ -1,4 +1,4 @@ -#include +#include #include #define TOKENPASTE(x, y) x##y diff --git a/tests/issues.cpp b/tests/issues.cpp index c26617f..df6b135 100644 --- a/tests/issues.cpp +++ b/tests/issues.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/tests/main.cpp b/tests/main.cpp deleted file mode 100644 index 4ed06df..0000000 --- a/tests/main.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#define CATCH_CONFIG_MAIN -#include diff --git a/tests/noexcept.cpp b/tests/noexcept.cpp index f5c688f..858b8a0 100644 --- a/tests/noexcept.cpp +++ b/tests/noexcept.cpp @@ -1,4 +1,4 @@ -#include +#include #include TEST_CASE("Noexcept", "[noexcept]") { diff --git a/tests/observers.cpp b/tests/observers.cpp index 5d8473c..696d152 100644 --- a/tests/observers.cpp +++ b/tests/observers.cpp @@ -1,4 +1,4 @@ -#include +#include #include struct move_detector { diff --git a/tests/relops.cpp b/tests/relops.cpp index 99dee5f..eead7c1 100644 --- a/tests/relops.cpp +++ b/tests/relops.cpp @@ -1,4 +1,4 @@ -#include +#include #include TEST_CASE("Relational operators", "[relops]") { diff --git a/tests/swap.cpp b/tests/swap.cpp index a5c92c3..092eae8 100644 --- a/tests/swap.cpp +++ b/tests/swap.cpp @@ -1,4 +1,4 @@ -#include +#include #include struct no_throw {