Comments (11)
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.
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.
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.
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.
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.
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.
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.
Seems to work beautifully now (with both NULL and nullptr).
from catch2.
Excellent news - thanks for checking
from catch2.
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.
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)
- XML Reporter doesn't output stderr / stdin when there is a segfault HOT 3
- unnecessary double promotion generate warning.
- Support multiple reporters for `catch_discover_tests` HOT 1
- Integrate Generators into reporters and CLI HOT 2
- Extend support for randomness generation in tests
- Finish JSON reporter & use it for more reliable CMake/CTest integration
- Update documentation for v3 HOT 2
- Provide Catch2's StringMaker specialization behind extra level of indirection
- Handle ANSI escape sequences during text wrapping
- Bring back Single-Header capability HOT 2
- AddressSanitizer reports container overflow during benchmarking HOT 3
- Latest macOS system header causes compilation failures on GCC HOT 4
- Compilation fails with `error: arithmetic on a pointer to an incomplete type` HOT 1
- Combine test filters with filenames HOT 2
- Section filter command line option only works for sections without whitespace in name HOT 1
- Separate headers for "extra" std types
- Catch2 does not appear to work with C++23
- version 3.5.4 does not compile
- JUnit and console reporter discrepency.
- Provide means to obtain current test case name and current section name HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from catch2.