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

Failing on purpose #765

Closed
semmel opened this issue Dec 16, 2016 · 4 comments
Closed

Failing on purpose #765

semmel opened this issue Dec 16, 2016 · 4 comments

Comments

@semmel
Copy link

semmel commented Dec 16, 2016

Sometimes I find it useful to let a test fail deliberately.
For this matter I discovered the FAIL macro digging around in catch.hpp.
Nice! 👍

However FAIL - like REQUIRE - aborts the execution of the local scope.
I needed something like FAIL but in the flavor of CHECK:

#define FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, "FAIL", __VA_ARGS__ )

Is that macro future-proof? I.e is FAIL part of Catch' public API?
INTERNAL_CATCH_MSG is certainly not meant to be used be clients, or is it?

Now I can let the test fail deliberately e.g. from inside a timeout callback which has previously crashed using FAIL
Example with Reactive Extensions for C++:

auto sequence = rxcpp::observable<>::interval(std::chrono::milliseconds(100));
sequence
.take(2)
.timeout(std::chrono::milliseconds(50))
.subscribe([](int value)
{
	CHECK(value == 1);
},
[](std::exception_ptr exPtr)
{
	try
	{
		std::rethrow_exception(exPtr);
	} 
	catch (const rxcpp::timeout_error&)
	{
		FAIL_CHECK("expected timeout failure");
	}
});
@philsquared
Copy link
Collaborator

You're right to be suspicious of using anything that starts with INTERNAL_.
In practice that's been stable for a long time.
But in this case this feature probably makes sense in the framework itself. I'll try and get it added soon.

philsquared added a commit that referenced this issue Mar 8, 2017
Works like FAIL, but does not abort test.
As proposed in #765
@philsquared
Copy link
Collaborator

That's in now on master (but not the single include).
I'm going to mark this issue for closure soon.

@philsquared philsquared added the Resolved - pending review Issue waiting for feedback from the original author label Mar 8, 2017
@semmel
Copy link
Author

semmel commented Mar 8, 2017

Great! 👍
Thanks!

@horenmar
Copy link
Member

This is in the latest release, so I am going to close the issue.

@horenmar horenmar removed the Resolved - pending review Issue waiting for feedback from the original author label Mar 13, 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

3 participants