You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR is a follow-up of #1572 and #1581. It cleans up the output
produced by the `#expect(throws:)` and `#expect(processExitsWith:)`
macros to more closely match what we now output for boolean and optional
expectations.
For instance, the following test:
```swift
@test func foo() {
#expect(throws: MyError()) {
throw MyParameterizedError(index: 0)
}
}
```
Previously output:
```
◇ Test foo() started.
✘ Test foo() recorded an issue at [...]: Expectation failed: expected error "MyError()", but "MyParameterizedError(index: 0)" was thrown instead
↳ throw MyParameterizedError(index: 0) → MyParameterizedError(index: 0)
✘ Test foo() failed after 0.001 seconds with 1 issue.
```
But will now output:
```
◇ Test foo() started.
✘ Test foo() recorded an issue at [...]: Expectation failed: expected error "MyError()", but "MyParameterizedError(index: 0)" was thrown instead
↳ MyError() → MyParameterizedError(index: 0)
↳ index → 0
✘ Test foo() failed after 0.001 seconds with 1 issue.
```
And the following exit test:
```swift
@test func bar() async {
await #expect(processExitsWith: .exitCode(EX_USAGE)) {
exit(EX_IOERR)
}
}
```
Previously output:
```
◇ Test bar() started.
✘ Test bar() recorded an issue at [...]: Expectation failed: .exitCode(EX_USAGE → 64)
↳ .exitCode(EX_USAGE → 64) → .exitCode(EX_IOERR → 74)
✘ Test bar() failed after 0.040 seconds with 1 issue.
```
But will now output:
```
◇ Test bar() started.
✘ Test bar() recorded an issue at [...]: Expectation failed: expected exit status ".exitCode(EX_USAGE)", but ".exitCode(EX_IOERR)" was reported instead
↳ .exitCode(EX_USAGE) → .exitCode(EX_IOERR)
↳ EX_USAGE → 64
↳ EX_IOERR → 74
✘ Test bar() failed after 0.038 seconds with 1 issue.
```
We already have code in Swift Testing that uses reflection to extract
information about fields of captured values, and Xcode uses this code,
but it's effectively dead when using `swift test`. With this change in
place, we'll output those subexpressions recursively. For example, the
following test:
```swift
struct S: Equatable, CustomStringConvertible {
var x: Int
var description: String { "DESC" }
}
@test func quux() {
let s1 = S(x: 1)
let s2 = S(x: 2)
#expect(s1 == s2)
}
```
Would previously output:
```
◇ Test quux() started.
✘ Test quux() recorded an issue at [...]: Expectation failed: s1 == s2
↳ s1 == s2 → false
↳ s1 → DESC
↳ s2 → DESC
✘ Test quux() failed after 0.001 seconds with 1 issue.
```
And will now output:
```
◇ Test quux() started.
✘ Test quux() recorded an issue at [...]: Expectation failed: s1 == s2
↳ s1 == s2 → false
↳ s1 → DESC
↳ x → 1
↳ s2 → DESC
↳ x → 2
✘ Test quux() failed after 0.001 seconds with 1 issue.
```
### Checklist:
- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
0 commit comments