Compile errors in C++ complex number tests

I recently updated the tests for Complex Numbers in C++. Now I’m seeing a whole bunch of compile errors that I cannot seem to reproduce locally:

/tmp/complex-numbers/complex_numbers_test.cpp:29:55: error: expected template-name before '<' token
   29 | class ComplexApproxMatcher : public Catch::MatcherBase<Complex> {
      |                                                       ^
/tmp/complex-numbers/complex_numbers_test.cpp:29:55: error: expected '{' before '<' token
/tmp/complex-numbers/complex_numbers_test.cpp:29:55: error: expected unqualified-id before '<' token
/tmp/complex-numbers/complex_numbers_test.cpp:53:60: error: return type 'class ComplexApproxMatcher' is incomplete
   53 |                                              double epsilon) {
      |                                                            ^
...

My solution is here. What I am doing wrong?

I think the namespace is missing there, it should be complex_numbers::Complex

There’s a using on top of the file, but instead of using complex_numbers::Complex I think it should’ve been using Complex = complex_numbers::Complex

I’m not sure, though.

Well, tested it here and my solution gets the same error on the web test runner, but it works locally.

Tested your solution too and the result is the same. It works locally, but not on the web test runner.

So I think my comment above is wrong and I’m not sure what is the issue.

I saw my solution was marked out of date, so I updated and now I have the same error. The update involved adding a catch2 custom matcher and that seems to be the problem. According to the Google AI summary, in catch2 v3, “matcher namespaces were reorganized and flattened, primarily moving matchers into the Catch::Matchers namespace for a cleaner structure.” So I think that in v3, line 29 of the test code should read

class ComplexApproxMatcher : public Catch::Matchers::MatcherBase<Complex> {

It seems local files use Catch v2 while the test runner uses Catch v3.

Also, MatcherBase is indeed inside a Catch::Matchers namespace

That seems to explain why things work locally.

Well, this is a total mess! I installed catch2 3.4.10, like this, replacing my existing installation of catch2 2.3.10, made the suggested change to complex_test.cpp, and tried to compile this. I hit a compiler error about catch2/catch.hpp not being found. It seems like that header file is now called catch2/catch_all.hpp. I added a symlink to fix that. Once I made all these changes, I was able to get all the tests to pass locally.

I would make a PR to fix this, but I have no idea what all I need to change. I’ll leave this up to the maintainers of this track. Also, I’m curious how this even passes the CI. It seems like that should have failed once catch2 3.x was introduced.

Thanks. I added a comment to the pull request that introduced this change to make sure that the responsible parties are aware of the probelm.

1 Like

cpp/.github/workflows/ci.yml at main · exercism/cpp · GitHub doesn’t use the test runner image.

Among the tracks I’ve seen, it’s common (and desirable) to not run the test runner image within the CI. That way, you upgrade the test runner and the exercise solutions simultaneously. Otherwise, you’d need to deploy the upgraded test runner first and then update the exercises. If the CI breaks, that’s now you need to fix while the test runner is live. If it ends up being a test runner issue, only guardians can sign off on the PR so that lengthens the maintenance window.

Thanks for flagging this! It was indeed caused by the inconsistency of Catch2 versions being used between cpp repo and test runner. A workaround has been merged now, so things should be working as expected again. However, I think it also makes sense to include a CI job that tests against the test runner. It’s not the first time we have an issue like this, unfortunately…

3 Likes