Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: fix catch2 3 support #980

Merged
merged 6 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
CTEST_OUTPUT_ON_FAILURE: "1"

jobs:
coverage:
name: Coverage
Expand Down Expand Up @@ -57,6 +60,30 @@ jobs:
files: build/coverage.info
functionalities: fixes

catch2-3:
name: Catch 2 3.x
runs-on: macos-latest
steps:
- uses: actions/checkout@v4

- name: Get Catch 2
run: brew install catch2

- name: Configure
run: |
cmake -S . -B build \
-DCMAKE_CXX_STANDARD=14 \
-DCLI11_SINGLE_FILE_TESTS=OFF \
-DCLI11_BUILD_EXAMPLES=OFF \
-DCLI11_PRECOMPILED=ON

- name: Build
run: cmake --build build -j4

- name: Test
run: cmake --build build --target test


clang-tidy:
name: Clang-Tidy
runs-on: ubuntu-latest
Expand Down Expand Up @@ -138,7 +165,7 @@ jobs:

- name: Build
run: meson compile -C build-meson

install:
name: install tests
runs-on: ubuntu-latest
Expand All @@ -155,7 +182,7 @@ jobs:
- name: Run tests
run: ctest --output-on-failure -L Packaging
working-directory: build

install-precompiled:
name: install tests precompiled
runs-on: ubuntu-latest
Expand All @@ -172,7 +199,7 @@ jobs:
- name: Run tests
run: ctest --output-on-failure -L Packaging
working-directory: build

install-single_file:
name: install tests single file
runs-on: ubuntu-latest
Expand Down Expand Up @@ -341,7 +368,7 @@ jobs:
with:
cmake-version: "3.27"
if: success() || failure()

- name: Check CMake 3.28 (full)
uses: ./.github/actions/quick_cmake
with:
Expand Down
5 changes: 3 additions & 2 deletions tests/OptionTypeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "app_helper.hpp"

#include "catch.hpp"

#include <algorithm>
#include <atomic>
#include <cmath>
Expand Down Expand Up @@ -243,7 +245,6 @@ static const std::map<std::string, double> testValuesDouble{
};

TEST_CASE_METHOD(TApp, "floatingConversions", "[optiontype]") {

auto test_data = GENERATE(from_range(testValuesDouble));

double val{0};
Expand All @@ -256,7 +257,7 @@ TEST_CASE_METHOD(TApp, "floatingConversions", "[optiontype]") {
CHECK(std::isnan(val));
} else {

CHECK_THAT(val, Catch::WithinRel(test_data.second, 1e-11));
CHECK_THAT(val, WithinRel(test_data.second, 1e-11));
}
}

Expand Down
2 changes: 2 additions & 0 deletions tests/OptionalTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
#endif
// [CLI11:verbatim]

TEST_CASE("OptionalNoEmpty") { CHECK(1 == 1); }
henryiii marked this conversation as resolved.
Show resolved Hide resolved

#if CLI11_STD_OPTIONAL

#ifdef _MSC_VER
Expand Down
9 changes: 7 additions & 2 deletions tests/catch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <catch2/generators/catch_generators_range.hpp>
#include <catch2/matchers/catch_matchers_floating_point.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)
using Catch::Approx; // NOLINT(google-global-names-in-headers)
using Catch::Generators::from_range; // NOLINT(google-global-names-in-headers)
using Catch::Matchers::Equals; // NOLINT(google-global-names-in-headers)
using Catch::Matchers::WithinRel; // NOLINT(google-global-names-in-headers)

inline auto Contains(const std::string &x) { return Catch::Matchers::ContainsSubstring(x); }

Expand All @@ -26,6 +30,7 @@ inline auto Contains(const std::string &x) { return Catch::Matchers::ContainsSub
#include <catch2/catch.hpp>

using Catch::Equals; // NOLINT(google-global-names-in-headers)
using Catch::WithinRel; // NOLINT(google-global-names-in-headers)
using Catch::Matchers::Contains; // NOLINT(google-global-names-in-headers)

#endif