-
-
Notifications
You must be signed in to change notification settings - Fork 649
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
Print the SUBCASE path when an assert fails in the TEST_CASE body #125
Comments
actually currently you do get a "stack of currently entered subcases" - see that in the second assert failure you have "subcase 1" printed after the test case name But I do think this can be improved a lot... And it would be nice to be able to see not just which subcases are currently entered, but also which ones were already entered and exited in the current test case entrance: TEST_CASE("data-driven") {
int a;
SUBCASE("subcase 1")
a = 5;
SUBCASE("subcase 2")
a = 42;
CHECK(a == 6);
} here it would be cool to see which subcase was entered (and already exited) for when the asserts gets triggered. This is in the roadmap. |
also this seems to be related: catchorg/Catch2#734 |
This is largely a hack to give us at least *something* for data driven testing (doctest#215). In that pattern, it's common to structure code in a way that first "generates the data", and only then executes the actual test. It can look like this: TEST_CASE("parsing stuff") { std::string input; Something expected; DOCTEST_SUBCASE("single-line") { DOCTEST_SUBCASE("empty") {} DOCTEST_SUBCASE("trivial") { input = "create foo"; expected = {OP_CREATE, {"foo",}}; } DOCTEST_SUBCASE("two args") { input = "create blah bar"; expected = {OP_CREATE, {"blah", "bar",}}; } } DOCTEST_SUBCASE("multi-line") { DOCTEST_SUBCASE("trailing whitespace") { input = "create foo\n\n"; expected = {OP_CREATE, {"foo,}}; } DOCTEST_SUBCASE("one word per line, two words") { input = "create\nfoo"; expected = {OP_CREATE, {"foo",}}; } } REQUIRE(parse(input) == expected); } The important part is that once we're executing actual tests, the subsections will have been exited already, so the usual ways of showing the subcase stack can be no longer applied. In Catch2, there was a patch which tried to track the deepest subcase stack so far. Let's try to implement something very simple, just printing the current state of the stack once it is entered. It does not tie into any error handling, so the output will be always there, and it also probably does not support any fancy filtering when skipping subcases. However, it's something which at least shows what is going on when an error gets reported. Cc: doctest#215 Cc: doctest#125
This is largely a hack to give us at least *something* for data driven testing (doctest#215). In that pattern, it's common to structure code in a way that first "generates the data", and only then executes the actual test. It can look like this: TEST_CASE("parsing stuff") { std::string input; Something expected; DOCTEST_SUBCASE("single-line") { DOCTEST_SUBCASE("empty") {} DOCTEST_SUBCASE("trivial") { input = "create foo"; expected = {OP_CREATE, {"foo",}}; } DOCTEST_SUBCASE("two args") { input = "create blah bar"; expected = {OP_CREATE, {"blah", "bar",}}; } } DOCTEST_SUBCASE("multi-line") { DOCTEST_SUBCASE("trailing whitespace") { input = "create foo\n\n"; expected = {OP_CREATE, {"foo,}}; } DOCTEST_SUBCASE("one word per line, two words") { input = "create\nfoo"; expected = {OP_CREATE, {"foo",}}; } } REQUIRE(parse(input) == expected); } The important part is that once we're executing actual tests, the subsections will have been exited already, so the usual ways of showing the subcase stack can be no longer applied. In Catch2, there was a patch which tried to track the deepest subcase stack so far. Let's try to implement something very simple, just printing the current state of the stack once it is entered. It does not tie into any error handling, so the output will be always there, and it also probably does not support any fancy filtering when skipping subcases. However, it's something which at least shows what is going on when an error gets reported. Cc: doctest#215 Cc: doctest#125
done - for a program like this: TEST_CASE("data-driven") {
int a;
SUBCASE("subcase 1")
a = 5;
SUBCASE("subcase 2")
a = 42;
CHECK(a == 6);
} the output will be something like this:
that message will be printed only if the deepest subcase stack is different from the current one. Also the current subcase stack will be printed below the |
Simple test:
The result is
The problem is that in the current version it is impossible to find out (without using a debugger or printing) which test failed if an assert in the body fails. Not user friendly.
The text was updated successfully, but these errors were encountered: