Skip to content

Commit 20de8b7

Browse files
tests: fix catch2 3 support (#980)
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 <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent ef327b7 commit 20de8b7

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

.github/workflows/tests.yml

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ concurrency:
1010
group: ${{ github.workflow }}-${{ github.ref }}
1111
cancel-in-progress: true
1212

13+
env:
14+
CTEST_OUTPUT_ON_FAILURE: "1"
15+
1316
jobs:
1417
coverage:
1518
name: Coverage
@@ -57,6 +60,30 @@ jobs:
5760
files: build/coverage.info
5861
functionalities: fixes
5962

63+
catch2-3:
64+
name: Catch 2 3.x
65+
runs-on: macos-latest
66+
steps:
67+
- uses: actions/checkout@v4
68+
69+
- name: Get Catch 2
70+
run: brew install catch2
71+
72+
- name: Configure
73+
run: |
74+
cmake -S . -B build \
75+
-DCMAKE_CXX_STANDARD=14 \
76+
-DCLI11_SINGLE_FILE_TESTS=OFF \
77+
-DCLI11_BUILD_EXAMPLES=OFF \
78+
-DCLI11_PRECOMPILED=ON
79+
80+
- name: Build
81+
run: cmake --build build -j4
82+
83+
- name: Test
84+
run: cmake --build build --target test
85+
86+
6087
clang-tidy:
6188
name: Clang-Tidy
6289
runs-on: ubuntu-latest
@@ -138,7 +165,7 @@ jobs:
138165

139166
- name: Build
140167
run: meson compile -C build-meson
141-
168+
142169
install:
143170
name: install tests
144171
runs-on: ubuntu-latest
@@ -155,7 +182,7 @@ jobs:
155182
- name: Run tests
156183
run: ctest --output-on-failure -L Packaging
157184
working-directory: build
158-
185+
159186
install-precompiled:
160187
name: install tests precompiled
161188
runs-on: ubuntu-latest
@@ -172,7 +199,7 @@ jobs:
172199
- name: Run tests
173200
run: ctest --output-on-failure -L Packaging
174201
working-directory: build
175-
202+
176203
install-single_file:
177204
name: install tests single file
178205
runs-on: ubuntu-latest
@@ -341,7 +368,7 @@ jobs:
341368
with:
342369
cmake-version: "3.27"
343370
if: success() || failure()
344-
371+
345372
- name: Check CMake 3.28 (full)
346373
uses: ./.github/actions/quick_cmake
347374
with:

tests/OptionTypeTest.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include "app_helper.hpp"
88

9+
#include "catch.hpp"
10+
911
#include <algorithm>
1012
#include <atomic>
1113
#include <cmath>
@@ -243,7 +245,6 @@ static const std::map<std::string, double> testValuesDouble{
243245
};
244246

245247
TEST_CASE_METHOD(TApp, "floatingConversions", "[optiontype]") {
246-
247248
auto test_data = GENERATE(from_range(testValuesDouble));
248249

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

259-
CHECK_THAT(val, Catch::WithinRel(test_data.second, 1e-11));
260+
CHECK_THAT(val, WithinRel(test_data.second, 1e-11));
260261
}
261262
}
262263

tests/OptionalTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
#endif
5454
// [CLI11:verbatim]
5555

56+
TEST_CASE("OptionalNoEmpty") { CHECK(1 == 1); }
57+
5658
#if CLI11_STD_OPTIONAL
5759

5860
#ifdef _MSC_VER

tests/catch.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
#include <catch2/catch_template_test_macros.hpp>
1515
#include <catch2/catch_test_macros.hpp>
1616
#include <catch2/generators/catch_generators.hpp>
17+
#include <catch2/generators/catch_generators_range.hpp>
18+
#include <catch2/matchers/catch_matchers_floating_point.hpp>
1719
#include <catch2/matchers/catch_matchers_string.hpp>
1820

19-
using Catch::Approx; // NOLINT(google-global-names-in-headers)
20-
using Catch::Matchers::Equals; // NOLINT(google-global-names-in-headers)
21+
using Catch::Approx; // NOLINT(google-global-names-in-headers)
22+
using Catch::Generators::from_range; // NOLINT(google-global-names-in-headers)
23+
using Catch::Matchers::Equals; // NOLINT(google-global-names-in-headers)
24+
using Catch::Matchers::WithinRel; // NOLINT(google-global-names-in-headers)
2125

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

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

2832
using Catch::Equals; // NOLINT(google-global-names-in-headers)
33+
using Catch::WithinRel; // NOLINT(google-global-names-in-headers)
2934
using Catch::Matchers::Contains; // NOLINT(google-global-names-in-headers)
3035

3136
#endif

0 commit comments

Comments
 (0)