Skip to content

Commit 5286de5

Browse files
authored
fix(complex-numbers): use runner's Catch2 version (#996)
The test runner uses Catch2 v3.4.0, while locally we still had v2.13.6. The recent changes to the complex-numbers test work with v2.13.6, while they don't work with v3.4.0, causing compilation to always fail in the test runner. This commit changes the test to be compatible with v3.4.0 and updates the local Catch2 copy.
1 parent 85e3313 commit 5286de5

File tree

7 files changed

+23948
-17947
lines changed

7 files changed

+23948
-17947
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
exclude: 'test/(catch.hpp|tests-main.cpp)'
1+
exclude: 'test/(catch(_amalgamated)?.[ch]pp|tests-main.cpp)'
22

33
repos:
44
- repo: https://github.com/pre-commit/mirrors-clang-format

exercises/practice/complex-numbers/CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ else()
1717
set(exercise_cpp "")
1818
endif()
1919

20-
# Use the common Catch library?
21-
if(EXERCISM_COMMON_CATCH)
22-
# For Exercism track development only
23-
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h $<TARGET_OBJECTS:catchlib>)
24-
elseif(EXERCISM_TEST_SUITE)
20+
if(EXERCISM_TEST_SUITE)
2521
# The Exercism test suite is being run, the Docker image already
2622
# includes a pre-built version of Catch.
2723
find_package(Catch2 REQUIRED)
@@ -32,7 +28,11 @@ elseif(EXERCISM_TEST_SUITE)
3228
target_compile_definitions(${exercise} PRIVATE EXERCISM_TEST_SUITE)
3329
else()
3430
# Build executable from sources and headers
35-
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h test/tests-main.cpp)
31+
# Other exercises have a third case where we use a local Catch2 copy from `test/`,
32+
# which then only needs to be built once and not individually for each exercise.
33+
# However, for complex-numbers we currently use a different version of Catch2 and
34+
# therefore always build the version local to the exercise.
35+
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h test/catch_amalgamated.cpp test/tests-main.cpp)
3636
endif()
3737

3838
set_target_properties(${exercise} PROPERTIES

exercises/practice/complex-numbers/complex_numbers_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifdef EXERCISM_TEST_SUITE
77
#include <catch2/catch.hpp>
88
#else
9-
#include "test/catch.hpp"
9+
#include "test/catch_amalgamated.hpp"
1010
#endif
1111

1212
// Complex Numbers exercise test case data version 1.3.0
@@ -26,7 +26,7 @@ using complex_numbers::Complex;
2626
static constexpr double eps = 0.005;
2727

2828
// Custom Catch2 matcher for approximate equality of Complex numbers
29-
class ComplexApproxMatcher : public Catch::MatcherBase<Complex> {
29+
class ComplexApproxMatcher : public Catch::Matchers::MatcherBase<Complex> {
3030
public:
3131
ComplexApproxMatcher(const Complex& expected, double epsilon)
3232
: expected{expected}, epsilon{epsilon} {}

0 commit comments

Comments
 (0)