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

When one subcase fails, other independent sibling subcases are not executed anymore #844

Open
svdHero opened this issue Feb 17, 2024 · 2 comments

Comments

@svdHero
Copy link

svdHero commented Feb 17, 2024

Description

The documentation states:

For each SUBCASE() the TEST_CASE() is executed from the start

and

Each leaf subcase (a subcase that contains no nested subcases) will be executed exactly once on a separate path of execution from any other leaf subcase (so no leaf subcase can interfere with another).

However, when one leaf subcase fails, other, independent, sibling subcase leafs are not executed anymore. This is highly unsatisfying and not what I expect migrating from Catch2 and based on the documentation above.

Steps to reproduce

Execute the following tests.

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"

SCENARIO("My Scenario")
{
    GIVEN("Something")
    {
        WHEN("A")
        {
            THEN("Expected result A-1")
            {
                REQUIRE(0==0);  // Succeeds
            }
            THEN("Expected result A-2")
            {
                REQUIRE(0==1);  // Fails
            }
            THEN("Expected result A-3")
            {
                REQUIRE(0==0);  // Is Not executed
            }
        }
        WHEN("B")
        {
            THEN("Expected result B-1")
            {
                REQUIRE(0==1);  // Is not executed
            }
            THEN("Expected result B-2")
            {
                REQUIRE(0==0);  // Is not executed
            }
        }
    }
}

Test output is:

2 test cases: 1 failed, 1 succeeded

So only 2 test cases are executed instead of 5.

When "A-2" fails, the whole scenario is stopped. Why are "A-3", "B-1" and "B-2" not executed?

They should be totally independent of "A-2".

Expected / desired behaviour

When one leaf fails, still continue with the execution of ancestor and sibling paths to other independent leafs. Compare Catch2 behaviour.

Extra information

  • doctest version: 2.4.9
  • Operating System: Ubuntu 20.04.6 LTS x86_64
  • Compiler+version: Platformio Core 6.1.13 Home 3.4.4 via Platformio IDE 3.3.3 (I assume gcc 9.4.0 for native platform)
@svdHero svdHero changed the title When one test tree leaf fails, other, independent sibling leafs are not executed anymore When one subcase fails, other independent sibling subcases are not executed anymore Feb 17, 2024
@mitchgrout
Copy link

Issue still exists on 2.4.11.

As a note, you have your desired behaviour if your REQUIRE is replaced with CHECK. However, REQUIRE is good practice for things like asserting valid memory prior to dereferencing it in a CHECK. Can't immediately see what the issue is but I can try having a dig around.

Unsure if the repo has any active maintainers at the moment though, so even if it's patchable, unsure if it'll be merged.

@svdHero
Copy link
Author

svdHero commented Mar 22, 2024

@mitchgrout thanks for your comment. Yes, I know about CHECK. However, I do need the REQUIRE functionality in my case, because within the test case, I want to fail fast and not continue. Other independent test cases should still be unaffected, as specified by the documentation.

Have you had any luck, digging around?

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

2 participants