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

Add an exception translation mechanism + the ability for users to extend it with custom exception types #12

Closed
RaviGaddipati opened this issue May 26, 2016 · 11 comments

Comments

@RaviGaddipati
Copy link

In some cases a test will fail because an exception is thrown. Right now it just says
"TEST CASE FAILED! (threw exception)"
It would be very helpful if it says what exception is thrown and the message.

@onqtam
Copy link
Member

onqtam commented May 26, 2016

this is planned - also the user will be able to extend the reporting by teaching the framework about custom exception types.

@RaviGaddipati
Copy link
Author

Great, loving the framework so far!

@onqtam onqtam modified the milestone: doctest 2.0 Jun 8, 2016
@onqtam onqtam added the for 2.0 label Jun 8, 2016
@onqtam onqtam removed this from the doctest 2.0 milestone Jun 8, 2016
@arximboldi
Copy link

Related: I would like to prevent Doctest from catching the exception alltogether, so the program crashes and the backtrace is shown directly in the debugger.

@onqtam
Copy link
Member

onqtam commented Jul 27, 2016

@arximboldi I might add a configuration identifier for this

@arximboldi
Copy link

Makes sense, thanks!

@onqtam onqtam removed the for 2.0 label Mar 15, 2017
@onqtam onqtam changed the title Printing exceptions Add an exception translation mechanism + the ability for users to extend it with custom exception types Mar 15, 2017
onqtam added a commit that referenced this issue Mar 16, 2017
…ows - relates #12

- exception translators can be registered with REGISTER_EXCEPTION_TRANSLATOR
onqtam added a commit that referenced this issue Mar 17, 2017
…sers to extend it with custom exception types" - fixes #12
@onqtam
Copy link
Member

onqtam commented Mar 17, 2017

This should be done in the dev branch - docs also in the dev branch!

Also the request of @arximboldi has been added to the roadmap but no ETA on it.

onqtam added a commit that referenced this issue Mar 17, 2017
- added builds with -fno-exceptions to travis CI
@onqtam
Copy link
Member

onqtam commented May 1, 2017

@arximboldi do you think that using DOCTEST_CONFIG_NO_EXCEPTIONS will be sufficient for your needs? it's already in the library and I don't want to complicate matters any further with more configuration options...

@arximboldi
Copy link

Aha! no, but DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS which I found in the same document is enough for me indeed. Sorry I missed that and thanks!

@onqtam
Copy link
Member

onqtam commented May 1, 2017

@arximboldi but using only DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS will still result in exceptions thrown from a test case (or assert evaluation) being caught by the test runner and I don't think there will be a backtrace in that case...

@arximboldi
Copy link

Oh I missed that. I will try the other one then. I wonder if that will also make tests that check that an exception is thrown fail? But I guess those are just disabled, which is fine most of the time. This may not cover the case where you have a test checking an exception, an except different type is thrown, and you want to get the backtrace of where that comes from. Also, it would be nice to not have to recompile to do this... But all this is icing on the cake, I think this is good all for now.

@onqtam
Copy link
Member

onqtam commented May 1, 2017

@arximboldi When using DOCTEST_CONFIG_NO_EXCEPTIONS the REQUIRE asserts and asserts that deal with exceptions (xxx_THROWS / xxx_THROWS_AS / xxx_NOTHROW) are gone - meaning that using them will result in a compilation error. Thats what DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS is for - it makes REQUIRE act like CHECK and the exception macros are turned into a no-op.

I'm not sure that introducing a new identifier to circumvent catching exceptions in the test runner is actually even possible without disabling other functionality - REQUIRE macros throw an exception to terminate the current test case (unlike CHECK). I could have a try/catch only for doctest::detail::TestFailureException - and if I don't catch it there (but instead end up in the default (...) catch clause) I could just rethrow the exception so the program crashes - but in that case I'm not sure what you'll get in the backtrace - the point of rethrowing or the point of the original exception...

If you test this in a simple program and get the full backtrace even after rethrowing from a lower frame in the callstack then I might add a separate identifier - otherwise I'd advice using DOCTEST_CONFIG_NO_EXCEPTIONS.

Also note that in version 1.2 there will be crash handling support - using signals under UNIX - and if a signal is caught doctest will report the current test case and subcases (and I might even add in the future the ability to print which was the last assert that passed successfully for additional context)

onqtam added a commit that referenced this issue May 15, 2017
…ows - relates #12

- exception translators can be registered with REGISTER_EXCEPTION_TRANSLATOR
@onqtam onqtam closed this as completed in 408d1f9 May 15, 2017
onqtam added a commit that referenced this issue May 15, 2017
- added builds with -fno-exceptions to travis CI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants