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

Nested sections are not run #9

Closed
wichert opened this issue Jan 29, 2011 · 14 comments
Closed

Nested sections are not run #9

wichert opened this issue Jan 29, 2011 · 14 comments

Comments

@wichert
Copy link
Contributor

wichert commented Jan 29, 2011

I have a test which looks like this:

TEST_CASE("MyClass", "MyClass basic tests") {
    SECTION("MyClass::MyClass", "MyClass constructor tests") {
        SECTION("defaults", "Default values for member varirables") {
            MyClass obj;
            REQUIRE(obj.a==0);
        }
    }
}

The test compiles correctly, but no tests are run. If I remove the inner SECTION and move the code up to the outer SECTION block they are run correctly.

@philsquared
Copy link
Collaborator

Yikes! I see the problem - and know how I broke it.
Will have a fix soon. Thanks for pointing it out.

@wichert
Copy link
Contributor Author

wichert commented Feb 15, 2011

Hi Phil. I was wondering if you can provide an indication when you'll have a fix for this?

@philsquared
Copy link
Collaborator

Hi wichert.
I have a little backlog of smaller issues to get through first - as this will require a bit more attention. I'm hoping to be on it this week, though.

@philsquared
Copy link
Collaborator

I've checked in an initial improvement. It's not a complete fix but it might get you out of trouble for now.
I'm working on a complete fix now.

@philsquared
Copy link
Collaborator

Sorry - I should have said what this fixes. It should work if there is a single subsection

@philsquared
Copy link
Collaborator

I checked in a more complete fix now. It passes the skimpy tests I have in there but I need to add more before I can really say this is done. Would appreciate your feedback if you give it a try, though.

@wichert
Copy link
Contributor Author

wichert commented Feb 24, 2011

I will do some more testing in the next few days. I should be able to provide feedback before Monday.

@philsquared
Copy link
Collaborator

Cool, thanks

@wichert
Copy link
Contributor Author

wichert commented Feb 25, 2011

One thing I noticed is that nested sections are not shown running the tests with -s. With the above example the output looks like this:

Running: MyClass
[Start section: 'defaults']
..
[End of section: 'defaults' ..]

Notice how the MyClass::MyClass level is skipped in the output.

@wichert
Copy link
Contributor Author

wichert commented Feb 26, 2011

So far everything is looking correct: tests in nested sections are run correctly, and the XML report shows them as well.

I'll leave closing this until you have decided if the nested sections should be shown in the -s output, which they are not at the moment.

@wichert
Copy link
Contributor Author

wichert commented Feb 26, 2011

Found a possible problem. I have a test which looks like this:

TEST_CASE("MyClass", "MyClass basic tests") {
    SECTION("MyClass::MyClass", "MyClass constructor tests") {
        MyFixture fixture;

        SECTION("defaults", "Default values for member varirables") {
             // ...
        }
        SECTION("other", "Other tests") {
             // ...
        }
    }
}

MyFixture is a simple class which prepares a test environment in its constructor and rests everything in its destructor. The test segfault in a way which suggests that the fixture is torn down before the "other" section is run.

Is there another way to setup test fixture? I couldn't find anything in the tests, and this pattern felt quite natural.

@wichert
Copy link
Contributor Author

wichert commented Feb 26, 2011

I found an error in my test fixture which caused the segfault. As far as I can see nested sections work correctly now.

@philsquared
Copy link
Collaborator

Cool - glad you found the issue. I couldn't see any way that the scoping wouldn't have worked.

As for the -s reporting issue - thanks for pointing that out. It only occurred if a parent test had no assertions of its own (which would commonly be the case, but none of my meta tests were written that way! :-s ). Anyway, I've reproduced in the meta-tests and it's now all fixed. Would appreciate your verification, though.

@wichert
Copy link
Contributor Author

wichert commented Feb 28, 2011

Looks fine, thanks!

This issue was closed.
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