Skip to content

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

@kkarbowiak

Description

@kkarbowiak

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.

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions