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
Show subexpressions separately in expectation failures. (#1572)
This PR refactors how we capture and display subexpressions when an
expectation fails. For example, given the following test:
```swift
@test func foo() {
let lhs = "abc123"
let rhs = "d"
#expect(lhs.contains(rhs))
}
```
We currently output:
```
< > Test foo() started.
<X> Test foo() recorded an issue at FileName.swift:X:Y: Expectation failed: (lhs → "abc123").contains(rhs → "d")
<X> Test foo() failed after 0.003 seconds with 1 issue.
```
This can be hard to read for more complex expressions as the real values
are nested inside a single line. With this change, we instead output:
```
< > Test foo() started.
<X> Test foo() recorded an issue at FileName.swift:X:Y: Expectation failed: lhs.contains(rhs)
--> lhs.contains(rhs) → false
--> lhs → "abc123"
--> rhs → "d"
<X> Test foo() failed after 0.003 seconds with 1 issue.
```
This change also adds the subexpression breakdown to our JSON schema as
an experimental field of the "issue" event record:
```json
{
"kind" : "event",
"payload" : {
/* ... */
"issue" : {
/* ... */
"_expectation" : {
"_expression" : {
"children" : [
{
"runtimeTypeName" : "Swift.String",
"runtimeValue" : "\"abc123\"",
"sourceCode" : "lhs"
},
{
"runtimeTypeName" : "Swift.String",
"runtimeValue" : "\"d\"",
"sourceCode" : "rhs"
}
],
"runtimeTypeName" : "Swift.Bool",
"runtimeValue" : "false",
"sourceCode" : "lhs.contains(rhs)"
}
},
/* ... */
},
},
"version" : "99.0.0"
}
```
### 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