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

Multiple assertions in single test result in incorrect abort test #1391

Closed
michaelcowan opened this issue Sep 22, 2018 · 1 comment
Closed
Labels

Comments

@michaelcowan
Copy link
Contributor

Description

The abort after value is tested for equality against total failed assertions here :

bool RunContext::aborting() const {
    return m_totals.assertions.failed == static_cast<std::size_t>(m_config->abortAfter());
}

However it is possible, under the incorrect use of REQUIRE, for this comparison to fail by nesting calls to REQUIRE.

Steps to reproduce

I couldn't see a nice way to write a test to demonstrate this, but here is a contrived example

namespace MyTests {
    bool doSomeRequirement() {
        REQUIRE(false);        // Clearly we should not nest REQUIRE but this is still valid
        return false;
    }

    TEST_CASE("Session should abort after this test") {
        REQUIRE(doSomeRequirement());
    }

    TEST_CASE("This test should not be executed") {
        REQUIRE(false);        // This is executed even though the first test fails
    }
}

void main() {
    Catch::ConfigData config;
    config.abortAfter = 1;     // I want to abort after a single assertion fails

    Catch::Session session;
    session.useConfigData(config);
    session.run();
}

Extra information

  • Catch version: v2.4.0
  • Operating System: Windows 10
  • Compiler+version: 19.14.26433
@horenmar
Copy link
Member

Well, that is kinda embarrassing.

Anyway, I agree that nested REQUIREs are perfectly reasonable, even though they can cause some bugs (there is at least one more open, but that one is mostly cosmetic).

@horenmar horenmar added the Bug label Sep 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants