Skip to content

When are test cases run without sections? #552

@joto

Description

@joto

I am a bit unclear on when the code in a TEST_CASE is run when there are nested SECTIONs. I can't find anything about the details in the documentation so I am not sure what the intended action is here and whether there is a bug or not.

Here is some example code:

TEST_CASE("run once with section") {
    printf("a0\n");
    SECTION("foo") {
        printf("a1\n");
    }
    printf("a2\n");
}

TEST_CASE("run twice with and without section") {
    int error = 0;

    printf("b0\n");
    try {
        printf("b1\n");
        SECTION("bar") {
            printf("b2\n");
            throw 1;
        }
        printf("b3\n");
    } catch (int e) {
        printf("b4\n");
        error = e;
    }
    printf("b5\n");

    REQUIRE(error > 0);
}

This prints out:

a0
a1
a2
b0
b1
b2
b4
b5
b0
b1
b3
b5

indicating that the first example was only run once, but the second was run twice, once without and once with the SECTION("bar") code.

See also #191.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions