From d12f99ef1bc488605c86d4bf1bc19b83b4fc3b3e Mon Sep 17 00:00:00 2001 From: Sho Ikeda Date: Sun, 5 Aug 2018 01:01:30 +0900 Subject: [PATCH 1/3] Add a failing test for `Predicate.fromDeprecatedClosure` (and `ExpectationMessage.update(failureMessage:)`) --- Tests/NimbleTests/SynchronousTests.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Tests/NimbleTests/SynchronousTests.swift b/Tests/NimbleTests/SynchronousTests.swift index ce8181b04..639b67892 100644 --- a/Tests/NimbleTests/SynchronousTests.swift +++ b/Tests/NimbleTests/SynchronousTests.swift @@ -16,6 +16,7 @@ final class SynchronousTest: XCTestCase, XCTestCaseProvider { ("testToNotProvidesActualValueExpression", testToNotProvidesActualValueExpression), ("testToNotProvidesAMemoizedActualValueExpression", testToNotProvidesAMemoizedActualValueExpression), ("testToNotProvidesAMemoizedActualValueExpressionIsEvaluatedAtMatcherControl", testToNotProvidesAMemoizedActualValueExpressionIsEvaluatedAtMatcherControl), + ("testToNegativeMatches", testToNegativeMatches), ("testToNotNegativeMatches", testToNotNegativeMatches), ("testNotToMatchesLikeToNot", testNotToMatchesLikeToNot), ] @@ -116,6 +117,15 @@ final class SynchronousTest: XCTestCase, XCTestCaseProvider { expect(callCount).to(equal(1)) } + func testToNegativeMatches() { + failsWithErrorMessage("expected to match, got <1>") { + expect(1).to(MatcherFunc { _, _ in false }) + } + failsWithErrorMessage("expected to match, got <1>") { + expect(1).to(MatcherFunc { _, _ in false }.predicate) + } + } + func testToNotNegativeMatches() { failsWithErrorMessage("expected to not match, got <1>") { expect(1).toNot(MatcherFunc { _, _ in true }) From 13a1ed11d9d63105b957040b29a09825675c012d Mon Sep 17 00:00:00 2001 From: Sho Ikeda Date: Sun, 5 Aug 2018 01:08:14 +0900 Subject: [PATCH 2/3] Fix `ExpectationMessage.update(failureMessage:)` not to update a `FailureMessage` instance with empty string The followings is the previous behavior: - `FailureMessage().toExpectationMessage()` will be `ExpectationMessage.fail("")` - `ExpectationMessage.fail("").update(failureMessage: aMessage)` will set `aMessage.stringValue = ""` - Thus the error message of `expect(1).to(MatcherFunc { _, _ in false }.predicate)` will be empty --- Sources/Nimble/ExpectationMessage.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/Nimble/ExpectationMessage.swift b/Sources/Nimble/ExpectationMessage.swift index 992ee0ef9..7aae34149 100644 --- a/Sources/Nimble/ExpectationMessage.swift +++ b/Sources/Nimble/ExpectationMessage.swift @@ -152,8 +152,10 @@ public indirect enum ExpectationMessage { // Backwards compatibility: converts ExpectationMessage tree to FailureMessage internal func update(failureMessage: FailureMessage) { switch self { - case let .fail(msg): + case let .fail(msg) where !msg.isEmpty: failureMessage.stringValue = msg + case .fail: + break case let .expectedTo(msg): failureMessage.actualValue = nil failureMessage.postfixMessage = msg From ac0ce5bdae8416f0356ccf07ddb02c02caa595c9 Mon Sep 17 00:00:00 2001 From: Sho Ikeda Date: Sun, 5 Aug 2018 02:35:55 +0900 Subject: [PATCH 3/3] Update `SynchronousTest.testToNotNegativeMatches()` as well --- Tests/NimbleTests/SynchronousTests.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Tests/NimbleTests/SynchronousTests.swift b/Tests/NimbleTests/SynchronousTests.swift index 639b67892..dfa6885b4 100644 --- a/Tests/NimbleTests/SynchronousTests.swift +++ b/Tests/NimbleTests/SynchronousTests.swift @@ -130,6 +130,9 @@ final class SynchronousTest: XCTestCase, XCTestCaseProvider { failsWithErrorMessage("expected to not match, got <1>") { expect(1).toNot(MatcherFunc { _, _ in true }) } + failsWithErrorMessage("expected to not match, got <1>") { + expect(1).toNot(MatcherFunc { _, _ in true }.predicate) + } } func testNotToMatchesLikeToNot() {