mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-05-02 13:43:52 +00:00
fix(tests): experimental support for external Catch3 (#827)
* fix(tests): experimental support for external Catch3 Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * style: pre-commit.ci fixes --------- Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
0a615f854d
commit
8e4fd15a23
3
.gitignore
vendored
3
.gitignore
vendored
@ -15,3 +15,6 @@ a.out*
|
||||
/package.json
|
||||
/yarn.lock
|
||||
/CLI11.hpp
|
||||
|
||||
/subprojects/Catch2-*
|
||||
/subprojects/packagecache
|
||||
|
@ -142,8 +142,6 @@ TEST_CASE_METHOD(TApp, "StrangeFlagNames", "[app]") {
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(TApp, "RequireOptionsError", "[app]") {
|
||||
using Catch::Matchers::Contains;
|
||||
|
||||
app.add_flag("-c");
|
||||
app.add_flag("--q");
|
||||
app.add_flag("--this,--that");
|
||||
|
@ -66,32 +66,39 @@ endif()
|
||||
|
||||
set(CLI11_MULTIONLY_TESTS TimerTest)
|
||||
|
||||
add_library(catch_main main.cpp catch.hpp)
|
||||
target_include_directories(catch_main PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
|
||||
find_package(Catch2 CONFIG)
|
||||
|
||||
if(Catch2_FOUND)
|
||||
if(NOT TARGET Catch2::Catch2)
|
||||
message(FATAL_ERROR "Found Catch2 at ${Catch2_DIR} but targets are missing.")
|
||||
endif()
|
||||
message(STATUS "Found Catch2")
|
||||
target_link_libraries(catch_main PUBLIC Catch2::Catch2)
|
||||
message(STATUS "Found Catch2 ${Catch2_VERSION}")
|
||||
|
||||
if(Catch2_VERSION VERSION_LESS 3)
|
||||
add_library(catch_main main.cpp catch.hpp)
|
||||
target_include_directories(catch_main PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
target_link_libraries(catch_main PUBLIC Catch2::Catch2)
|
||||
else()
|
||||
add_library(catch_main ALIAS Catch2::Catch2WithMain)
|
||||
target_compile_definitions(Catch2::Catch2WithMain INTERFACE -DCLI11_CATCH3)
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "Downloading Catch2")
|
||||
|
||||
# FetchContent would be better, but requires newer CMake.
|
||||
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/catch2")
|
||||
set(url https://github.com/philsquared/Catch/releases/download/v2.13.7/catch.hpp)
|
||||
set(url https://github.com/philsquared/Catch/releases/download/v2.13.10/catch.hpp)
|
||||
file(
|
||||
DOWNLOAD ${url} "${CMAKE_CURRENT_BINARY_DIR}/catch2/catch.hpp"
|
||||
STATUS status
|
||||
EXPECTED_HASH SHA256=ea379c4a3cb5799027b1eb451163dff065a3d641aaba23bf4e24ee6b536bd9bc)
|
||||
EXPECTED_HASH SHA256=3725c0f0a75f376a5005dde31ead0feb8f7da7507644c201b814443de8355170)
|
||||
list(GET status 0 error)
|
||||
if(error)
|
||||
message(FATAL_ERROR "Could not download ${url}, and Catch2 not found on your system.")
|
||||
endif()
|
||||
target_include_directories(catch_main PUBLIC "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
add_library(catch_main main.cpp catch.hpp)
|
||||
target_include_directories(catch_main PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}")
|
||||
endif()
|
||||
|
||||
# Add special target that copies the data directory for tests
|
||||
|
@ -9,8 +9,6 @@
|
||||
#include <complex>
|
||||
#include <cstdint>
|
||||
|
||||
using Catch::Matchers::Contains;
|
||||
|
||||
using cx = std::complex<double>;
|
||||
|
||||
CLI::Option *
|
||||
|
@ -9,8 +9,6 @@
|
||||
#include <cstdio>
|
||||
#include <sstream>
|
||||
|
||||
using Catch::Matchers::Contains;
|
||||
|
||||
TEST_CASE("StringBased: convert_arg_for_ini", "[config]") {
|
||||
|
||||
CHECK("\"\"" == CLI::detail::convert_arg_for_ini(std::string{}));
|
||||
|
@ -6,8 +6,6 @@
|
||||
|
||||
#include "app_helper.hpp"
|
||||
|
||||
using Catch::Matchers::Contains;
|
||||
|
||||
TEST_CASE("Deprecated: Empty", "[deprecated]") {
|
||||
// No deprecated features at this time.
|
||||
CHECK(true);
|
||||
|
@ -13,8 +13,6 @@
|
||||
#include "catch.hpp"
|
||||
#include <fstream>
|
||||
|
||||
using Catch::Matchers::Contains;
|
||||
|
||||
class SimpleFormatter : public CLI::FormatterBase {
|
||||
public:
|
||||
SimpleFormatter() : FormatterBase() {}
|
||||
|
@ -13,8 +13,6 @@
|
||||
#include "catch.hpp"
|
||||
#include <fstream>
|
||||
|
||||
using Catch::Matchers::Contains;
|
||||
|
||||
TEST_CASE("THelp: Basic", "[help]") {
|
||||
CLI::App app{"My prog"};
|
||||
|
||||
@ -1313,7 +1311,7 @@ TEST_CASE("TVersion: parse_throw", "[help]") {
|
||||
try {
|
||||
app.parse("--Version");
|
||||
} catch(const CLI::CallForVersion &v) {
|
||||
CHECK_THAT(CLI11_VERSION, Catch::Equals(v.what()));
|
||||
CHECK_THAT(CLI11_VERSION, Equals(v.what()));
|
||||
CHECK(0 == v.get_exit_code());
|
||||
const auto &appc = app;
|
||||
const auto *cptr = appc.get_version_ptr();
|
||||
|
@ -10,8 +10,6 @@
|
||||
#include <cstdint>
|
||||
#include <utility>
|
||||
|
||||
using Catch::Matchers::Contains;
|
||||
|
||||
using cx = std::complex<double>;
|
||||
|
||||
TEST_CASE_METHOD(TApp, "ComplexOption", "[newparse]") {
|
||||
|
@ -6,8 +6,6 @@
|
||||
|
||||
#include "app_helper.hpp"
|
||||
|
||||
using Catch::Matchers::Contains;
|
||||
|
||||
using vs_t = std::vector<std::string>;
|
||||
|
||||
TEST_CASE_METHOD(TApp, "BasicOptionGroup", "[optiongroup]") {
|
||||
|
@ -6,8 +6,6 @@
|
||||
|
||||
#include "app_helper.hpp"
|
||||
|
||||
using Catch::Matchers::Contains;
|
||||
|
||||
using vs_t = std::vector<std::string>;
|
||||
|
||||
TEST_CASE_METHOD(TApp, "BasicSubcommands", "[subcom]") {
|
||||
|
@ -12,8 +12,6 @@
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
using Catch::Matchers::Contains;
|
||||
|
||||
TEST_CASE("Timer: MSTimes", "[timer]") {
|
||||
CLI::Timer timer{"My Timer"};
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(123));
|
||||
|
@ -6,4 +6,26 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#ifdef CLI11_CATCH3
|
||||
|
||||
#include <catch2/catch_approx.hpp>
|
||||
#include <catch2/catch_template_test_macros.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/generators/catch_generators.hpp>
|
||||
#include <catch2/matchers/catch_matchers_string.hpp>
|
||||
|
||||
using Catch::Approx; // NOLINT(google-global-names-in-headers)
|
||||
using Catch::Matchers::Equals; // NOLINT(google-global-names-in-headers)
|
||||
|
||||
inline auto Contains(const std::string &x) { return Catch::Matchers::ContainsSubstring(x); }
|
||||
|
||||
#else
|
||||
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
using Catch::Equals; // NOLINT(google-global-names-in-headers)
|
||||
using Catch::Matchers::Contains; // NOLINT(google-global-names-in-headers)
|
||||
|
||||
#endif
|
||||
|
@ -1,14 +1,21 @@
|
||||
catch2 = dependency('catch2')
|
||||
|
||||
testmain = static_library(
|
||||
'catch_main',
|
||||
'main.cpp', 'catch.hpp',
|
||||
dependencies: catch2,
|
||||
)
|
||||
testdep = declare_dependency(
|
||||
link_with: testmain,
|
||||
dependencies: [catch2, CLI11_dep]
|
||||
)
|
||||
if catch2.version().version_compare('<3')
|
||||
testmain = static_library(
|
||||
'catch_main',
|
||||
'main.cpp', 'catch.hpp',
|
||||
dependencies: catch2,
|
||||
)
|
||||
testdep = declare_dependency(
|
||||
link_with: testmain,
|
||||
dependencies: [catch2, CLI11_dep]
|
||||
)
|
||||
else
|
||||
testdep = declare_dependency(
|
||||
dependencies: [CLI11_dep, dependency('catch2-with-main')],
|
||||
compile_args: '-DCLI11_CATCH3'
|
||||
)
|
||||
endif
|
||||
|
||||
link_test_lib = library(
|
||||
'link_test_1',
|
||||
|
Loading…
x
Reference in New Issue
Block a user