Coder Social home page Coder Social logo

Comments (11)

jalfd avatar jalfd commented on May 21, 2024

Yeah, I just ran into that too.

the following minimal test fails:
TEST_CASE("", "")
{
int i = 0;
REQUIRE(i++ == 0);
}

Very unintuitive, and I'm assuming it's a bug :)

from catch2.

philsquared avatar philsquared commented on May 21, 2024

It's sort-of-a-bug. More specifically it's a known deficiency :-)

I have a few alternative implementations on the go at the moment to deal with it. So far they introduce more extra complexities than I am happy with - but since I'm getting more and more people hitting this now I do need to deal with it.

I'll update soon. Thanks for the reports, guys.

from catch2.

jalfd avatar jalfd commented on May 21, 2024

Sorry to be a pain, but any progress on this one? ;)
I'm basically having to rewrite a bunch of tests as

bool res = foo();
REQUIRE(res);

which obviously means no useful information is printed if the test fails.

from catch2.

philsquared avatar philsquared commented on May 21, 2024

Hi Jalfd,

Sorry it's taking a while. I had a few more critical issues to address. I'm back on this again now. I have a solution that I'm just ironing out.

from catch2.

philsquared avatar philsquared commented on May 21, 2024

For anyone following this - I've checked in a candidate approach to get this working with single evaluation. There were some obstacles to getting this going (in particular having to deal with signed/ unsigned warnings when comparing unsigned ints against int literals) - but I think I have got it all sorted now.
The approach is sufficiently complex that I've checked it into a separate branch for now. I'd appreciate your feedback - good or bad - before I merge it to master.

from catch2.

jalfd avatar jalfd commented on May 21, 2024

Just gave it a whirl. I run into one new compile error:

REQUIRE(p != NULL); where p is a pointer type. It can't find an operator!= for pointer and int operands. If I cast NULL to void*, it everything works fine. (I assume, but haven't checked, that the same issue exists for operator==).

and, just FYI, using a C++0x compiler, it also fails if I use nullptr instead of NULL. (with a different error though: it can't find an appropriate operator<<). I know you've never even claimed C++0x support, so I it's perfectly fair that it doesn't work. But I might as well let you know about it. :)

Apart from that, I don't see any problems. It compiles, and my tests pass perfectly.

Great job! I really appreciate the work you're putting into this.

from catch2.

philsquared avatar philsquared commented on May 21, 2024

Damn. That really should have been under test - since it's one of the most common types of test (test that a pointer is not NULL)!

I see the issue, and have reproduced it. It's because in a template situation NULL is deduced to be of type long.

A naive fix worked but gave me a warning about comparing a pointer type with an int. A slightly less naive fix worked but gave me a warning about passing NULL to something that takes a long!

My final fix works and gives no warnings (at least for me in XCode's GCC (4.2) and WIndows (VC++10). The approach is to overload ->* to return a different RHS collector object for pointers. That then only supports == and != against another pointer type (which will give an error, but the same one you'd see in normal code) or against the same pointer type (non-const) - which NULL when then decay to and it all works as expected.

It all works for me. Let me know if it works for you now.

I haven't tried nullptr yet (need to get set up with a C++0x compiler), although I see that gcc 4.2 defines NULL as __nullptr - which added its own wrinkles.

If nullptr doesn't work out of the box now it should be trivial to add for support for.

from catch2.

jalfd avatar jalfd commented on May 21, 2024

Seems to work beautifully now (with both NULL and nullptr).

from catch2.

philsquared avatar philsquared commented on May 21, 2024

Excellent news - thanks for checking

from catch2.

philsquared avatar philsquared commented on May 21, 2024

I'm going to leave this ticket open for now - and keep the new code on the branch - until it's settled in a bit more. If anyone else has tried it I'd appreciate comments - good or bad.
Thanks.

from catch2.

philsquared avatar philsquared commented on May 21, 2024

FYI I've merged the SingleEvaluation branch back into trunk.
There's still one or two things that I'm not entirely happy with (such as the const_cast on operator forwarding), but given how pernicious the double-evaluation issue is I think this is stable enough now.
Thanks for all the help and comments I've had.

from catch2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.