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

Reporting timings feature displays BDD given-when-then in the wrong order #1115

Open
lnorr opened this issue Nov 25, 2017 · 0 comments
Open

Comments

@lnorr
Copy link

lnorr commented Nov 25, 2017

Update

Duplicate of #886 but the cause seems to be the "-d yes" command-line args. To avoid further confusion, I recommend revising title of issue #886 and marking this issue as duplicate, or accepting this issue and marking #886 as duplicate.

Description

Reporting timings feature (using "-d yes" for duration) displays BDD given-when-then in the wrong order.

Expected behaviour:

Should display the given-when-then in the declared order of the CPP file.

Steps to reproduce:

GIVEN this CPP file:

#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include <chrono>
#include <thread>

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

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

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

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

            THEN( "the size and capacity change" ) {
                std::this_thread::sleep_for(std::chrono::seconds(1));
                REQUIRE( v.size() == 10 );
                REQUIRE( v.capacity() >= 10 );
            }
        }
        WHEN( "the size is reduced" ) {
            v.resize( 0 );

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

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

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

WHEN I run the test:

(c++ -std=c++11 bdd_test.cpp -o bdd_test && ./bdd_test -d yes) || echo 'Build failed \007'

THEN I do NOT want to get this result:

1.001 s:     Then: the size and capacity change
1.001 s:     When: the size is increased
1.001 s:    Given: A vector with some items
1.001 s: Scenario: vectors can be sized and resized
0.000 s:     Then: the size changes but not capacity
0.000 s:     When: the size is reduced
0.000 s:    Given: A vector with some items
0.000 s: Scenario: vectors can be sized and resized
0.000 s:     Then: the capacity changes but not the size
0.000 s:     When: more capacity is reserved
0.000 s:    Given: A vector with some items
0.000 s: Scenario: vectors can be sized and resized
0.000 s:     Then: neither size nor capacity are changed
0.000 s:     When: less capacity is reserved
0.000 s:    Given: A vector with some items
0.000 s: Scenario: vectors can be sized and resized
===============================================================================
All tests passed (16 assertions in 1 test case)

Expected behaviour:

Should display the given-when-then in the declared order of the CPP file.

Additional notes:

I tried different permutations, and without thread sleep and still encounter the same issue.

System information:

  • Catch version: v2.0.1
  • Operating System: Mac OS X 10.13.1
  • Compiler+version: Clang x86_64-apple-darwin17.2.0, Apple LLVM version 9.0.0 (clang-900.0.38)
@lnorr lnorr changed the title Catch "reporting timings" feature displays BDD given-when-then in the wrong order Reporting timings feature displays BDD given-when-then in the wrong order Nov 25, 2017
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

1 participant