catchorg / catchorg/Catch2

Unexpected number of assertions when failing one in a nested section

Open
#1,160 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
21.5k
Forks
3.5k
Avg merge
3d 16h
Merged PRs (30d)
2

Description

## Description

When running the following test case

```cpp
#define CATCH_CONFIG_MAIN
#include "catch.hpp"

namespace {
#if 1
int value = 2;
#else
int value = 1;
#endif
}

TEST_CASE("A testcase", "[catch2]") {
SECTION("A") {
REQUIRE(0 == 0);
SECTION("A.1") {
REQUIRE(value == 2);
}
}
SECTION("B") {
REQUIRE(1 == 1);
}
}
```
I get `All tests passed (3 assertions in 1 test case)` which is expected. However, when I change the `value` variable so that the second `REQUIRE` fails, I get `assertions: 4 | 3 passed | 1 failed`, i.e. one assertion more than before. I get that failing assertions can skip other assertions so that the total number decreases, but an increase was unexpected to me.

### Steps to reproduce

Compile and run the above test program with `#if 1`, and then recompile and rerun with `#if 0`. Compiler flags used: `-std=c++11 -Wall -Wextra -g`

### Extra information

* Catch version: **v2.1.0** (Generated: 2018-01-10 13:51:15.378034)
* Operating System: **Ubuntu 17.10 x86_64**
* Compiler+version: **gcc version 7.2.0 (Ubuntu 7.2.0-8ubuntu3)**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.