trompeloeil icon indicating copy to clipboard operation
trompeloeil copied to clipboard

doctest: Trompeloeil error reporting via doctest/trompeloeil.hpp gives unhelpful output

Open SimonKagstrom opened this issue 3 years ago • 4 comments

Environment: Trompeloeil v42, doctest v2.4.9 from conan packages. G++-11

When a trompeloeil expectation fails, doctest only reports an address, which makes it harder to understand what the actual error was:

[doctest] run with "--help" for options
===============================================================================
/tmp/trompeloeil_test.cpp:46:
  Scenario: trompeloeil + doctest error reporting works

/tmp/trompeloeil_test.cpp:50: ERROR: 0x55af94acfb20

===============================================================================
[doctest] test cases: 1 | 0 passed | 1 failed | 0 skipped
[doctest] assertions: 1 | 0 passed | 1 failed |
[doctest] Status: FAILURE!

A test program to reproduce this is:

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest/doctest.h"
#include "doctest/trompeloeil.hpp"

class Test
{
public:
    MAKE_MOCK0(x, void());
};

SCENARIO("trompeloeil + doctest error reporting works")
{
    Test t;

    REQUIRE_CALL(t, x());
}

And the problem can be fixed by passing a std::string to DOCTEST_ADD_FAIL_MESSAGE from reporter<specialized>::send():

      DOCTEST_ADD_FAIL_CHECK_AT(f, line, std::string(msg));

SimonKagstrom avatar Sep 12 '22 12:09 SimonKagstrom

Interesting. This seems to be caused by a change in doctest. The same in 2.3.8 works.

https://godbolt.org/z/31czP6hTo

I'll look into it. Thanks.

rollbear avatar Sep 13 '22 08:09 rollbear

Can you try with the branch fix_doctest_adapter, which I think should solve your problem?

rollbear avatar Sep 13 '22 09:09 rollbear

Works fine!

[doctest] doctest version is "2.4.9"
[doctest] run with "--help" for options
===============================================================================
/tmp/trompeloeil_test.cpp:12:
  Scenario: trompeloeil + doctest error reporting works

/tmp/trompeloeil_test.cpp:16: ERROR: Unfulfilled expectation:
Expected t.x() to be called once, actually never called


===============================================================================
[doctest] test cases: 1 | 0 passed | 1 failed | 0 skipped
[doctest] assertions: 1 | 0 passed | 1 failed |
[doctest] Status: FAILURE!

the only comment I have on the commit is that my name is misspelled in the ChangeLog :-)

SimonKagstrom avatar Sep 13 '22 10:09 SimonKagstrom

Ops. Fixed.

Leaving this open until a release has been tagged.

rollbear avatar Sep 13 '22 14:09 rollbear

Just released v43 which includes this fix. Closing now.

rollbear avatar Oct 26 '22 10:10 rollbear