Skip to content

Conversation

@Lucky-Armin
Copy link
Contributor

in exercises/practice/complex_numbers/complex_numbers_test.cpp: when running the first few test cases without the use of the require_approx_equal helper function, a warning is issued which will be treated as an error

in exercises/practice/complex_numbers/complex_numbers_test.cpp
when running the first test cases without use of
the require_approx_equal helper function, a warning
is issued which will be treated as an error
@github-actions
Copy link
Contributor

github-actions bot commented Aug 3, 2025

Hello. Thanks for opening a PR on Exercism 🙂

We ask that all changes to Exercism are discussed on our Community Forum before being opened on GitHub. To enforce this, we automatically close all PRs that are submitted. That doesn't mean your PR is rejected but that we want the initial discussion about it to happen on our forum where a wide range of key contributors across the Exercism ecosystem can weigh in.

You can use this link to copy this into a new topic on the forum. If we decide the PR is appropriate, we'll reopen it and continue with it, so please don't delete your local branch.

If you're interested in learning more about this auto-responder, please read this blog post.


Note: If this PR has been pre-approved, please link back to this PR on the forum thread and a maintainer or staff member will reopen it.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 3, 2025

This PR touches files which potentially affect the outcome of the tests of an exercise. This will cause all students' solutions to affected exercises to be re-tested.

If this PR does not affect the result of the test (or, for example, adds an edge case that is not worth rerunning all tests for), please add the following to the merge-commit message which will stops student's tests from re-running. Please copy-paste to avoid typos.

[no important files changed]

For more information, refer to the documentation. If you are unsure whether to add the message or not, please ping @exercism/maintainers-admin in a comment. Thank you!

@github-actions github-actions bot closed this Aug 3, 2025
@vaeng vaeng reopened this Aug 3, 2025
@vaeng
Copy link
Contributor

vaeng commented Aug 3, 2025

Hm. Is that something new, that is flagged now, but wasn't before? @ahans

Copy link
Contributor

@vaeng vaeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable.

Where did the error occur for you? In the test runner?

@ahans
Copy link
Contributor

ahans commented Aug 3, 2025

It will probably happen whenever you have all tests commented out that don't use that function. The maybe_unused fixes it, but I think we have better options.

First, having a static function is not recommended in C++ for that usecase. Using an anonymous namespace would be better. Not sure it would not create a warning/error though.

Second, having functions for checks like that I consider a bit of an anti pattern. If there is a test failure, it will be reported for the line of the function and not the line in the test case that we are actually interested in. I would just skip this and use the two calls wherever they are needed. Alternatively, writing a proper Catch2 matcher would be the better option over such a plain function.

a custom matcher for testing approximate equality
of the real and imaginary part of complex numbers
in complex_numbers_test.cpp has been added
@Lucky-Armin
Copy link
Contributor Author

It will probably happen whenever you have all tests commented out that don't use that function. The maybe_unused fixes it, but I think we have better options.

First, having a static function is not recommended in C++ for that usecase. Using an anonymous namespace would be better. Not sure it would not create a warning/error though.

Second, having functions for checks like that I consider a bit of an anti pattern. If there is a test failure, it will be reported for the line of the function and not the line in the test case that we are actually interested in. I would just skip this and use the two calls wherever they are needed. Alternatively, writing a proper Catch2 matcher would be the better option over such a plain function.

I opted for solution #2 and added a custom Catch2 matcher

@Lucky-Armin Lucky-Armin changed the title bugfix: added [[maybe_unused]] attribute in complex_numbers_test.cpp bugfix: unused function complex_numbers_test.cpp Aug 4, 2025
@Lucky-Armin Lucky-Armin requested a review from vaeng August 4, 2025 12:06
Copy link
Contributor

@ahans ahans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for taking the effort of implementing a proper matcher. Not only did this fix the compiler warning (treated as error in our setup), but also made this test better in following Catch2 best practices! I hope you don't mind that I did a few stylistic changes which I pushed to your branch before merging.

@ahans ahans merged commit 85e3313 into exercism:main Aug 5, 2025
8 checks passed
@blakelewis
Copy link

In case you haven't seen the discussion in the forum, this code currently fails to compile in the test runner. The code is written for catch2 v2, while the Dockerfile in the test runner gets the latest (v3) version and there are incompatible changes between v2 and v3. There seems to be a choice between changing the Dockerfile to get the older version or updating the test code to use v3.

@vaeng
Copy link
Contributor

vaeng commented Aug 10, 2025

We would "just" update the catch version on this exercise of the client copy with v3. It's a "feature", that the client side is done on a per exercise basis.

It's mostly a cop paste job and the custom comparison has to be redone.. sorry for not seeing this, my headspace currently doesn't allow for exercise tasks to be run 😵

@ahans
Copy link
Contributor

ahans commented Aug 11, 2025

@vaeng I have this already fixed locally. Will open a PR in a moment. The only thing that needed fixing was the namespace. "Old-style matchers" are still supported.

What again was the reason we have a different Catch2 version in the runner than we have here next to the exercises and in test/catch.hpp?

@vaeng
Copy link
Contributor

vaeng commented Aug 11, 2025

I'm not sure. Probably something to do with the ever elusive combination of "when we update from c++17, when we can have shared user files and laziness to update every single exercise"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants