Skip to content

Commit

Permalink
tests: fix catch2 3 support (#980)
Browse files Browse the repository at this point in the history
Is there an easy way to pre-install this in CI or download it (perhaps
in meson)? It's bad that we aren't running in CI with version 3 (but
don't want to drop 2, since we can't drop it until we drop C++11).

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
henryiii and pre-commit-ci[bot] authored Jan 12, 2024
1 parent ef327b7 commit 20de8b7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
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); }

#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

0 comments on commit 20de8b7

Please sign in to comment.