catchorg / catchorg/Catch2

Skipping last section runs the test another time without sections

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

Description

**Describe the bug**
If the last section is skipped then it seems that the TEST_CASE will run an additional time without going into any section, which can cause failures if the test contains common assertions after the sections.

**Expected behavior**
Skipping the last section would end the TEST_CASE

**Reproduction steps**
Steps to reproduce the bug.
```
TEST_CASE("Last Section skipped") {
int foo = 0;
SECTION("1") {
foo = 1;
}
SECTION("2") {
SKIP();
}
CHECK(foo != 0);
}

TEST_CASE("First Section skipped") {
int foo = 0;
SECTION("2") {
SKIP();
}
SECTION("1") {
foo = 1;
}
CHECK(foo != 0);
}
```
In the example above if the Last section is skipped the CHECK will fail, however if we change the order of the sections it will pass.

**Platform information:**

- OS: **macOS 13.4.1 22F82 arm64**
- Compiler+version: **Apple clang version 14.0.3 (clang-1403.0.22.14.1)**
- Catch version: **v3.4.0**

---

- OS: **Arch Linux x86_64**
- Compiler+version: **gcc 12.3.0**
- Catch version: **v3.4.0**

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.