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

SECTION nesting broken? #519

Closed
MoronsRuS opened this issue Oct 19, 2015 · 4 comments
Closed

SECTION nesting broken? #519

MoronsRuS opened this issue Oct 19, 2015 · 4 comments

Comments

@MoronsRuS
Copy link

Looking at this page https://github.com/philsquared/Catch/blob/master/docs/tutorial.md, I read this: "Sections can be nested to an arbitrary depth (limited only by your stack size). Each leaf section (i.e. a section that contains no nested sections) will be executed exactly once, on a separate path of execution from any other leaf section (so no leaf section can interfere with another). A failure in a parent section will prevent nested sections from running - but then that's the idea.".

That led me to believe that the following code would generate 3 errors:

TEST_CASE("SectionTests","Test that SECTIONs work the way I think they do")
{
    SECTION("A")
    {
        SECTION("C")
        {
            REQUIRE(true);
        }
        SECTION("D")
        {
            REQUIRE(false);
        }
    }
    SECTION("B")
    {
        SECTION("E")
        {
            REQUIRE(false);
        }
        SECTION("F")
        {
            REQUIRE(false);
        }
    }
}

There are 4 leaf SECTIONs, so I expect each of them to run once, and 3 will generate an error.
However, only leaf section C, D and E are run. Section F is not run. I thinks it's because the failure in section E counts as a failure in section B, which prevents anymore child sections of B from running.

Is this working as intended? When section E is fixed, section F will be run, so there's no harm done. But if this is working as intended, then the paragraph that I cited above should be updated to note that if a child SECTION fails, then any remaining sibling sections will not be run.

@philsquared
Copy link
Collaborator

This is not "working as intended". It's a bug. One I've not seen or had reported before, yet - after looking at the code - I can see it's been there for a long time!
Basically: when control leaves a leaf section before encountering further peer sections it doesn't know that there are more to discover. It used to (prior to changes that went in with v1.0) do one extra run through the last section to make sure. When the section tracking got reworked for v1.0 that step somehow got overlooked!

So thanks for bringing this up! I'll try and get it fixed in the near future. It's bad timing in a way because I'm having to redo the section tracking yet again (to be able to handle Generators) but that work is in progress and I don't know when it will be ready to roll in (and will possibly be a v2.0 thing anyway). So I'll have to fix this independently.

@philsquared
Copy link
Collaborator

The new section tracking code is in (on Develop) and fixes this bug. if you get a chance I'd appreciate if you could verify it and report back.

@MoronsRuS
Copy link
Author

Sorry for the delay. I've verified that it works on the branch 'develop' using "single_include/catch.hpp".

@philsquared
Copy link
Collaborator

Thanks for letting me know, @MoronsRuS.
I'll be rolling current Develop into master soon.

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