Catch2 nested Sections not working properly
See original GitHub issueChecklist
- The issue is about this extension and NOT about a fork.
- Check the known issues list.
- The latest version of the extension was used.
- It is not related to remote-vscode or I checked the following issue
- Imagine yourself into my position and think how hard to debug the issue without insufficient information. I understand that you have privacy concerns and I expect you to understand that this extension is developed for free. Thanks.
Describe the bug When using Catch2 (v3.1.1), repeated nested sections are not displayed properly. The Problem occurs if inside of a Section, there are two parallel Sections. See the following Code and Screenshot.
To Reproduce Compile the following Unit Test. The Test “Bar” is either missing from the Test Explorer or displayed at the top level.
#include <catch2/catch_test_macros.hpp>
TEST_CASE("SomeTest")
{
SECTION("Foo")
{
SECTION("Baz")
{
CHECK(true);
}
SECTION("Bar")
{
CHECK(true);
}
}
}
TEST_CASE("SomeOtherTest")
{
CHECK(true);
}
Screenshots
Desktop
- Extension Version: 4.3.4
- VS Code Version: 1.73.1
- Catch2 / Google Test / DOCTest Version: 3.1.1
- OS Type and Version: Windows 11
- Using remote-ssh/docker/wsl?: no
Regression bug? The oldest version I could Test ist 4.3.1, where the same error occurs. In all other Versions I just get an ENOENT during test discovery
Log In the following Logs I have replaced the local paths with [PATH_TO_CPP] and [EXE_NAME].
C++ Testmate Log Output
[2022-11-16 11:15:41.017] [DEBUG] findSourceFilePath: [PATH_TO_CPP] => [PATH_TO_CPP]
[2022-11-16 11:15:41.017] [DEBUG] findSourceFilePath: [PATH_TO_CPP] => [PATH_TO_CPP]
[2022-11-16 11:15:41.018] [INFO] TestItem locaction has been updated {
old: '[PATH_TO_CPP]',
current: '[PATH_TO_CPP]'
}
[2022-11-16 11:15:41.018] [DEBUG] findSourceFilePath: [PATH_TO_CPP] => [PATH_TO_CPP]
[2022-11-16 11:15:41.018] [INFO] Test Foo has started.
[2022-11-16 11:15:41.019] [DEBUG] findSourceFilePath: [PATH_TO_CPP] => [PATH_TO_CPP]
[2022-11-16 11:15:41.019] [INFO] Test Baz has started.
[2022-11-16 11:15:41.019] [INFO] Test Baz has stopped.
[2022-11-16 11:15:41.019] [INFO] Test Foo has stopped.
[2022-11-16 11:15:41.019] [DEBUG] findSourceFilePath: [PATH_TO_CPP] => [PATH_TO_CPP]
[2022-11-16 11:15:41.019] [DEBUG] findSourceFilePath: [PATH_TO_CPP] => [PATH_TO_CPP]
[2022-11-16 11:15:41.020] [INFO] Test Foo has started.
[2022-11-16 11:15:41.020] [DEBUG] findSourceFilePath: [PATH_TO_CPP] => [PATH_TO_CPP]
[2022-11-16 11:15:41.020] [INFO] Test Bar has started.
[2022-11-16 11:15:41.020] [INFO] Test Bar has stopped.
[2022-11-16 11:15:41.020] [INFO] Test Foo has stopped.
[2022-11-16 11:15:41.020] [INFO] Test SomeTest has stopped.
[2022-11-16 11:15:41.021] [INFO] Test SomeOtherTest has started.
[2022-11-16 11:15:41.021] [DEBUG] findSourceFilePath: [PATH_TO_CPP] => [PATH_TO_CPP]
[2022-11-16 11:15:41.021] [DEBUG] findSourceFilePath: [PATH_TO_CPP] => [PATH_TO_CPP]
[2022-11-16 11:15:41.021] [INFO] TestItem locaction has been updated {
old: '[PATH_TO_CPP]',
current: '[PATH_TO_CPP]'
}
[2022-11-16 11:15:41.021] [INFO] Test SomeOtherTest has stopped.
Unit Test run Output with parameter --reporter xml
<?xml version="1.0" encoding="UTF-8"?>
<Catch2TestRun name="[EXE_NAME].exe" rng-seed="10982" catch2-version="3.1.1">
<TestCase name="SomeTest" filename="[PATH_TO_CPP]" line="6">
<Section name="Foo" filename="[PATH_TO_CPP]" line="8">
<Section name="Baz" filename="[PATH_TO_CPP]" line="10">
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<Section name="Foo" filename="[PATH_TO_CPP]" line="8">
<Section name="Bar" filename="[PATH_TO_CPP]" line="14">
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<OverallResult success="true"/>
</TestCase>
<TestCase name="SomeOtherTest" filename="[PATH_TO_CPP]" line="21">
<OverallResult success="true"/>
</TestCase>
<OverallResults successes="3" failures="0" expectedFailures="0"/>
<OverallResultsCases successes="2" failures="0" expectedFailures="0"/>
</Catch2TestRun>
Issue Analytics
- State:
- Created 10 months ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Nested SECTIONS do not run the right order #42 - GitHub
See this example: [the current version runs "1.2" in the same pass as "1.3", which is not right]. define CATCH_CONFIG_MAIN. include "catch.hpp". include....
Read more >The Little Things: Testing with Catch2 - The Coding Nest
Sections are a feature that is not common in the xUnit family of testing frameworks. They allow defining multiple paths through a test...
Read more >The Little Things: Testing with Catch2 : r/cpp - Reddit
I can see how nested SECTION blocks could be very powerful if you nest them ... a templated test function which I call...
Read more >docs/tutorial.md · 57525c16c8facba9b034856347b58b1ac634103f ...
Sections can be nested to an arbitrary depth (limited only by your stack size). Each leaf section (i.e. a section that contains no...
Read more >Define TEST_CASE - API reference - Catch2 v2.13.2
No description yet. ... Tutorial / Test cases and sections; Tutorial / BDD-Style ... Fine tuning / String conversions / Enums; Running /...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed in v4.3.10.
This issue was mentioned in CHANGELOG.md under a released entry so it is assumed to be fixed. User verifications are always welcome.
I have tried debugging this problem by myself and observed the following in the function
createOrReplace
of theTestItemManager
: When the second “Foo” Test starts, the Item “SomeTest” has the child “Foo” with further subchild “Baz”. Then the existing “Foo” Item is deleted and replaced with a new, empty “Foo” Item. This Item is then subsequently filled with a child “Bar”.Now I modified the code in the
createOrReplace
function to first check for an existing Item an then returning the Item immediately in this case. This solved the problem, but I assume that this breaks something else? I’m not quite sure about all the cases this function covers.However, I was also able to determine why this bug only occurs on windows. In the
update
function of theTestItemManager
, the value ofitem.uri?.path
is “/C:/test/test.cpp”, while theresolvedFile
is “C:\test\test.cpp”. Indeed, I was also able to resolve the problem by first convertingresolvedFile
to avscode.Uri
and then comparing the two path properties.