0

The Catch2 unit test framework allows you to have test sections. From the docs:

TEST_CASE( "vectors can be sized and resized", "[vector]" ) {

    std::vector<int> v( 5 );

    REQUIRE( v.size() == 5 );
    REQUIRE( v.capacity() >= 5 );

    SECTION( "resizing bigger changes size and capacity" ) {
        v.resize( 10 );

        REQUIRE( v.size() == 10 );
        REQUIRE( v.capacity() >= 10 );
    }
    SECTION( "resizing smaller changes size but not capacity" ) {
        v.resize( 0 );

        REQUIRE( v.size() == 0 );
        REQUIRE( v.capacity() >= 5 );
    }

    // ...
}

Is there a way to identify up front, at the time of testCaseStarting(), what is the list of SECTIONs that the particular run? As an example, given:

TEST_CASE("a", "[tag]") {
    SECTION("b") {
    }

    SECTION("c") {
        SECTION("d") { }
        SECTION("e") { }
    }
}

I want some way to get {b} for the first run, {c, d} for the second, and {c, e} for the third. Is there any way to do this?

Barry
  • 286,269
  • 29
  • 621
  • 977

2 Answers2

1

I don't think so. SECTION expands into INTERNAL_CATCH_SECTION which is just an if statement creating SectionInfo class instance :

   #define INTERNAL_CATCH_SECTION( ... ) \
    if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) )
user7860670
  • 35,849
  • 4
  • 58
  • 84
1

There is not, especially since sections can be "dynamic" in that they can be hidden behind extra ifs, be run inside a loop and so on.

Xarn
  • 3,460
  • 1
  • 21
  • 43