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

INTERNAL_CHECK_THAT evaluates argument twice #642

Closed
TorstenRobitzki opened this issue Apr 20, 2016 · 1 comment
Closed

INTERNAL_CHECK_THAT evaluates argument twice #642

TorstenRobitzki opened this issue Apr 20, 2016 · 1 comment

Comments

@TorstenRobitzki
Copy link

Hi,
is there a chance to change INTERNAL_CHECK_THAT, so that the expression to be tested is evaluated only once. It's a little bit counter intuitive to have the argument evaluated twice.

REQUIRE_THAT( f(), check_f );

Will call f() two times and if f() is not Idempotent, we have to write:

const auto x = f();
REQUIRE_THAT( x, check_f );

kind regards,
Torsten

@horenmar
Copy link
Member

horenmar commented Mar 8, 2017

This is no longer true. When I try this against Catch v1.8.1:

int cnt = 0;

std::string foo() {
    ++cnt;
    return "aaa";
}

TEST_CASE("Double eval") {
    REQUIRE_THAT(foo(), Catch::EndsWith("a"));
    std::cout << cnt << '\n';
}

it prints out 1. Not sure at which point it was fixed, but the matchers were recently completely reworked, so...

@horenmar horenmar closed this as completed Mar 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants