Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When writing tests for code that does I/O or which requires setup that can theoretically fail, you may end up with a lot of expect/unwrap boiler plate. Unit tests can return
Result<(), E>
which enables using the?
operator to return early on error cases, but there is no way to achieve this in speculate.rs.This PR allows describe blocks to specify that their tests can return
Result<(), E>
by including anerrtype(E)
entry which will make all the tests in thatdescribe
block and any nesteddescribe
blocks returnResult<(), E>
. This includes anybefore
orafter
blocks. For example:This will desugar into a test which returns
Result<(), Error>
and gets anOk(())
appended at the end, e.g.I think using a predicate like this makes sense because it should not cause trouble, even if some or all of the covered tests happen not to contain
?
. Thus, this PR contains no way to annotate a specific test or for a nested block to opt out.There is one special case, namely that Rust requires
#[should_panic]
tests to return()
. Given that such tests are typically sprinkled among other tests, it would be annoying to have to isolate them in their owndescribe
. Instead, this PR detects such tests and avoids turning them into-> Result<(), E>
.Replaces #24.