#include using text = std::string; const lest::test specification[]...">

Repeated descriptions in the test output · Issue #65 · martinmoene/lest (original) (raw)

Hi,
I customized example 10-bdd.cpp adding SCENARIO and CASE assertions as follows:

#include "lest.hpp"
#include <vector>
#include <cmath>

using text = std::string;

const lest::test specification[] = {

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

    GIVEN( "A vector with some items" ) {
        std::vector<int> v( 5 );

        EXPECT( v.size() == 5u );
        EXPECT( v.capacity() >= 5u );

        WHEN( "the size is increased" ) {
            v.resize( 10 );

            THEN( "the size and capacity change" ) {
                EXPECT( v.size() == 19u);                   <== this changed to fail test
                EXPECT( v.capacity() >= 10u );
            }
        }
        WHEN( "the size is reduced" ) {
            v.resize( 0 );

            THEN( "the size changes but not capacity" ) {
                EXPECT( v.size() == 0u );
                EXPECT( v.capacity() >= 5u );
            }
        }
        WHEN( "more capacity is reserved" ) {
            v.reserve( 10 );

            THEN( "the capacity changes but not the size" ) {
                EXPECT( v.size() == 5u );
                EXPECT( v.capacity() >= 10u );
            }
            WHEN( "less capacity is reserved again" ) {
                v.reserve( 7 );

                THEN( "capacity remains unchanged" ) {
                    EXPECT( v.capacity() >= 10u );
                }
            }
        }
        WHEN( "less capacity is reserved" ) {
            v.reserve( 0 );

            THEN( "neither size nor capacity are changed" ) {
                EXPECT( v.size() == 5u );
                EXPECT( v.capacity() >= 5u );
            }
        }
    }
},

SCENARIO( "A some failing function return" "[func]" ) {
    EXPECT( std::pow(2, 10) == 1025ul );
},

CASE( "A failing test" "[fail]" )
{
    EXPECT( 42 == 7 );
}

};

int main( int argc, char * argv[] )
{
    return lest::run( specification, argc, argv );
}

compile and run it on Debian 4.9.18-1 amd64 x86_64 with gcc 7.2.1:

# g++ -Wall -Wextra -std=c++11 -I ../include/lest/ -o custom-10-bdd custom-10-bdd.cpp
# ./custom-10-bdd -v

And I did get the next output:

custom-10-bdd.cpp:23: failed: Scenario: vectors can be sized and resized[vector]
     Given: A vector with some items
      When: the size is increased
      Then: the size and capacity change: v.size() == 19u for 10 == 19
custom-10-bdd.cpp:62: failed: Scenario: A some failing function return[func]
     Given: A vector with some items                                             // <== ?
      When: the size is increased                                                // <== ?
      Then: the size and capacity change: std::pow(2, 10) == 1025ul for 1024 == 1025    // <== ?
custom-10-bdd.cpp:67: failed: A failing test[fail]
     Given: A vector with some items                                             // <== ?
      When: the size is increased                                                // <== ?
      Then: the size and capacity change: 42 == 7 for 42 == 7               // <== ?
3 out of 3 selected tests failed.

Why text descriptions from the first SCENARIO repeating in others? Is it a bug or I use it in a wrong way?