swift-testing
swift-testing copied to clipboard
Adopt typed throws in the implementation of `#expect()`/`#require()`.
This PR adopts typed throws (throws(E) instead of throws) in the #expect() and #require() macros' declarations and in their implementations. In particular, the return type of the implementation functions changes from Result<R, any Error> to Result<R, ExpectationFailedError> and all implementation functions that take a closure have been updated with an additional generic E parameter.
#expect(throws:) and #require(throws:) take two generic error types, EExpected and EActual. The former is the error type specified by the test author, while the latter is the actual error type inferred from the body closure. In common usage, both will resolve to any Error.
The deprecated #expect {} throws: {} and #require {} throws: {} variants are marked @_unavailableInEmbedded and continue to use any Error.
If you see throws(any Error) in the diff, take it as meaning that section of the code was audited, but for now we don't have something better to use than any Error.
Checklist:
- [x] Code and documentation should follow the style of the Style Guide.
- [x] If public symbols are renamed or modified, DocC references should be updated.