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
Unlock expression expansions for negated expressions. (#364)
This PR enables expression expansion for expressions of the forms `!x`,
`!f()`, `!y.g()`, etc. such that the value of the expressions they
negate are available at runtime to inspect in a test failure. For
example, consider this test:
```swift
func f() -> Int { 123 }
func g() -> Int { 123 }
@test func myTest() {
#expect(!(f() == g())) // ♦️ Expectation failed: !(f() == g())
}
```
(i.e., testing that the result of `f()` is not equal to the result of
`g()`, but using `!(==)` instead of the more typical `!=`.)
This is a trivial/contrived example where we can tell at a glance that
the values equal `123`, of course. Still, previously this test would
(correctly) fail, but would not be able to provide the return values of
`f()` and `g()`. With this change, the following test issue is recorded:
```swift
#expect(!(f() == g())) // ♦️ Expectation failed: !((f() → 123) == (g() → 123) → true)
```
This increasing the amount of diagnostic information available.
This PR also makes adjustments to the `Expression` type to improve the
information we log during test runs. In particular, when `--verbose` is
passed to `swift test`, we will capture type information about more
parts of a failed expectation/expression.
### 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.
@@ -443,6 +447,23 @@ private func _parseCondition(from expr: MemberAccessExprSyntax, for macro: some
443
447
)
444
448
}
445
449
450
+
/// Parse a condition argument from a property access.
451
+
///
452
+
/// - Parameters:
453
+
/// - expr: The expression that was negated.
454
+
/// - isParenthetical: Whether or not `expression` was enclosed in
455
+
/// parentheses (and the `!` operator was outside it.) This argument
456
+
/// affects how this expression is represented as a string.
457
+
/// - macro: The macro expression being expanded.
458
+
/// - context: The macro context in which the expression is being parsed.
459
+
///
460
+
/// - Returns: An instance of ``Condition`` describing `expr`.
461
+
privatefunc _parseCondition(negating expr:ExprSyntax, isParenthetical:Bool, for macro:someFreestandingMacroExpansionSyntax, in context:someMacroExpansionContext)->Condition{
0 commit comments