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

Add API for reporting failures #9

Closed
rollbear opened this issue May 25, 2016 · 4 comments
Closed

Add API for reporting failures #9

rollbear opened this issue May 25, 2016 · 4 comments

Comments

@rollbear
Copy link

It would be marvellous if there was a supported way to report failures from 3rd party tools. As mentioned, you can throw exceptions, but that is not always a good idea (during stack rollback, for example.) There is also the option to just use REQUIRE_FALSE(message), but it does not give as nice messages and attributes file/line to the function that does the reporting.

In a proof of concept reporter for trompeloeil mocking framework I successfully used:

struct initializer {
  initializer() {
    trompeloeil::set_reporter([](trompeloeil::severity s,
                                 char const *file,
                                 unsigned long line,
                                 std::string const& msg)
                              {
                                doctest::detail::logAssert(false,
                                                           msg.c_str(),
                                                           false,
                                                           s == trompeloeil::severity::fatal
                                                           ? "unexpected call"
                                                           : "unfulfilled expectation",
                                                           "trompeloeil violation",
                                                           file,
                                                           line);
                                if (s == trompeloeil::severity::fatal)
                                  throw std::runtime_error("fatal error in trompeloeil expectation");

                              });
  }
} initializer_obj;

This works fine, but relying on undocumented internal functions is never a good idea.

@onqtam onqtam modified the milestone: doctest 2.0 Jun 8, 2016
@onqtam onqtam added the for 2.0 label Jun 8, 2016
@onqtam onqtam removed this from the doctest 2.0 milestone Jun 8, 2016
@onqtam
Copy link
Member

onqtam commented Sep 23, 2016

Just to let you know - There will be a better way of doing this in the future :) (I also saw this - cool!)

@rollbear
Copy link
Author

Looking forward to it.

@onqtam onqtam removed the for 2.0 label Mar 15, 2017
@onqtam onqtam changed the title API for reporting failures wanted Add API for reporting failures Mar 28, 2017
onqtam added a commit that referenced this issue Mar 28, 2017
…(like warn/check/require) and the appropriate ADD_<LEVEL>_AT macros for integration with mocking frameworks and other third party - fixes #9
@onqtam
Copy link
Member

onqtam commented Mar 28, 2017

This is implemented in the dev branch. doctest version 1.2 is expected to ship in the near month and then this issue will be closed.

Use like this:

ADD_FAIL_AT("asd.cpp", 45, "some string" << some_variable << "more stuff");

Alternatively there is ADD_FAIL_CHECK_AT which will fail the test case but will not stop its execution - and will act as a CHECK assert.

@rollbear
Copy link
Author

Cool! Tried it, and am ready to update the documentation for Trompeloeil as soon as 1.2 is out.

onqtam added a commit that referenced this issue May 7, 2017
- added SUCCESS/FAILURE message at the end after running the tests
- FAIL/FAIL_CHECK are now counted as asserts!!!
- relates #67
- relates #9
@onqtam onqtam closed this as completed in 565c97f May 15, 2017
onqtam added a commit that referenced this issue May 15, 2017
- added SUCCESS/FAILURE message at the end after running the tests
- FAIL/FAIL_CHECK are now counted as asserts!!!
- relates #67
- relates #9
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

No branches or pull requests

2 participants