Reporting timings feature displays BDD given-when-then in the wrong order
- Dominant language
- C++
- Stars
- 21.5k
- Forks
- 3.5k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 2
Description
## 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
#include
SCENARIO( "vectors can be sized and resized", "[vector]" ) {
GIVEN( "A vector with some items" ) {
std::vector 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)
Contributor guide
Assessment
This issue has not been assessed yet.