Skip to content

Commit b144799

Browse files
authored
Merge pull request #587 from Quick/fix-predicate-fromdeprecatedclosure
[7.x] Fix `ExpectationMessage.update(failureMessage:)` not to update a `FailureMessage` instance with empty string
2 parents 23eab12 + ac0ce5b commit b144799

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Sources/Nimble/ExpectationMessage.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,10 @@ public indirect enum ExpectationMessage {
152152
// Backwards compatibility: converts ExpectationMessage tree to FailureMessage
153153
internal func update(failureMessage: FailureMessage) {
154154
switch self {
155-
case let .fail(msg):
155+
case let .fail(msg) where !msg.isEmpty:
156156
failureMessage.stringValue = msg
157+
case .fail:
158+
break
157159
case let .expectedTo(msg):
158160
failureMessage.actualValue = nil
159161
failureMessage.postfixMessage = msg

Tests/NimbleTests/SynchronousTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ final class SynchronousTest: XCTestCase, XCTestCaseProvider {
1616
("testToNotProvidesActualValueExpression", testToNotProvidesActualValueExpression),
1717
("testToNotProvidesAMemoizedActualValueExpression", testToNotProvidesAMemoizedActualValueExpression),
1818
("testToNotProvidesAMemoizedActualValueExpressionIsEvaluatedAtMatcherControl", testToNotProvidesAMemoizedActualValueExpressionIsEvaluatedAtMatcherControl),
19+
("testToNegativeMatches", testToNegativeMatches),
1920
("testToNotNegativeMatches", testToNotNegativeMatches),
2021
("testNotToMatchesLikeToNot", testNotToMatchesLikeToNot),
2122
]
@@ -116,10 +117,22 @@ final class SynchronousTest: XCTestCase, XCTestCaseProvider {
116117
expect(callCount).to(equal(1))
117118
}
118119

120+
func testToNegativeMatches() {
121+
failsWithErrorMessage("expected to match, got <1>") {
122+
expect(1).to(MatcherFunc { _, _ in false })
123+
}
124+
failsWithErrorMessage("expected to match, got <1>") {
125+
expect(1).to(MatcherFunc { _, _ in false }.predicate)
126+
}
127+
}
128+
119129
func testToNotNegativeMatches() {
120130
failsWithErrorMessage("expected to not match, got <1>") {
121131
expect(1).toNot(MatcherFunc { _, _ in true })
122132
}
133+
failsWithErrorMessage("expected to not match, got <1>") {
134+
expect(1).toNot(MatcherFunc { _, _ in true }.predicate)
135+
}
123136
}
124137

125138
func testNotToMatchesLikeToNot() {

0 commit comments

Comments
 (0)