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

Feature request: print subcase when an exception is thrown inside one #136

Closed
blastrock opened this issue May 28, 2018 · 4 comments
Closed

Comments

@blastrock
Copy link

blastrock commented May 28, 2018

Description

If an exception is thrown in a SUBCASE, the logged error only contain the TEST_CASE name.

This might be related to #125

Steps to reproduce

Here's a simple program:

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

TEST_CASE("tc")
{
    SUBCASE("ab")
    {
        std::cout << "ab" << std::endl;
    }
    SUBCASE("ab, c")
    {
        throw std::runtime_error("fail");
    }
}

The output is

ab
===============================================================================
test.cpp:4:
TEST CASE:  tc

test.cpp:4: ERROR: test case THREW exception: fail

===============================================================================

There is no information about which SUBCASE failed.

Extra information

SUBCASEs seems to be implemented as ifs, I'm not sure this feature can be implemented in such a way. Maybe SUBCASEs should actually set up a lambda, but that means the user needs to add a ';' at the end of each SUBCASE. Also it wouldn't work with C++ < 11.


  • doctest version: master cd1d747
  • Operating System: debian unstable
  • Compiler+version: clang 5.0.0
@onqtam
Copy link
Member

onqtam commented May 28, 2018

This seems reasonable! And indeed it is connected to #125
It can be implemented in C++98 without any troubles. Perhaps I'll look into fixing both issues!

@onqtam
Copy link
Member

onqtam commented Mar 23, 2019

I haven't made progress in this regard with the default console reporter but the just released version 2.3 supports xml as the output and there you will get a much better context of where the exception was thrown from.

Anyway this is still a deficit of the console reporter so this issue will remain open until I fix that.

@onqtam
Copy link
Member

onqtam commented Sep 22, 2019

fixed! releasing version 2.3.5 right now.

@Scorbutics
Copy link

Just a message to thank you a lot for having fixed this.
I have around 400 test cases, which are mostly subcases because they are ideal to avoid duplicating function calls, so until now I've had a lot of troubles to track where exceptions came from.
Now it will be a lot easier.

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

3 participants