Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor unit tests to use more convenient doctest assertion macros #3365

Closed
kkarbowiak opened this issue Mar 2, 2022 · 2 comments · Fixed by #3393 or #3405
Closed

Refactor unit tests to use more convenient doctest assertion macros #3365

kkarbowiak opened this issue Mar 2, 2022 · 2 comments · Fixed by #3393 or #3405

Comments

@kkarbowiak
Copy link
Contributor

Hello,

Since version 2.3.5 doctest supports new assertion macros that assert both exception type and message, in the form of *_THROWS_WITH_AS (e.g. CHECK_THROWS_WITH_AS).

With those, some code duplication in unit tests can be avoided, as for example the following (test/src/unit-constructor1.cpp):

CHECK_THROWS_AS((j.get<std::pair<int, int>>()), json::out_of_range&);
CHECK_THROWS_WITH((j.get<std::pair<int, int>>()), "[json.exception.out_of_range.401] array index 1 is out of range");

can be replaced with:

CHECK_THROWS_WITH_AS((j.get<std::pair<int, int>>()), "[json.exception.out_of_range.401] array index 1 is out of range", json::out_of_range&);

Would you be interested in that? If so, I can create a pull request.

@nlohmann
Copy link
Owner

nlohmann commented Mar 7, 2022

Hey @kkarbowiak - yes, why not! I hope you can do this automatically as there are 979 CHECK_THROWS_AS calls and 1020 CHECK_THROWS_WITH calls...

@kkarbowiak
Copy link
Contributor Author

I hope so too ;-) I will get back with a PR.

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