diff --git a/Sources/Nimble/Adapters/NimbleXCTestHandler.swift b/Sources/Nimble/Adapters/NimbleXCTestHandler.swift index 36c1e8e09..3e338c368 100644 --- a/Sources/Nimble/Adapters/NimbleXCTestHandler.swift +++ b/Sources/Nimble/Adapters/NimbleXCTestHandler.swift @@ -69,8 +69,11 @@ public func recordFailure(_ message: String, location: SourceLocation) { let line = Int(location.line) testCase.recordFailure(withDescription: message, inFile: location.file, atLine: line, expected: true) } else { - let msg = "Attempted to report a test failure to XCTest while no test case was running. " + - "The failure was:\n\"\(message)\"\nIt occurred at: \(location.file):\(location.line)" + let msg = """ + Attempted to report a test failure to XCTest while no test case was running. The failure was: + \"\(message)\" + It occurred at: \(location.file):\(location.line) + """ NSException(name: .internalInconsistencyException, reason: msg, userInfo: nil).raise() } #endif diff --git a/Sources/Nimble/DSL.swift b/Sources/Nimble/DSL.swift index e49bb0c31..69179be05 100644 --- a/Sources/Nimble/DSL.swift +++ b/Sources/Nimble/DSL.swift @@ -56,9 +56,12 @@ internal func nimblePrecondition( } internal func internalError(_ msg: String, file: FileString = #file, line: UInt = #line) -> Never { + // swiftlint:disable line_length fatalError( - "Nimble Bug Found: \(msg) at \(file):\(line).\n" + - "Please file a bug to Nimble: https://github.com/Quick/Nimble/issues with the " + - "code snippet that caused this error." + """ + Nimble Bug Found: \(msg) at \(file):\(line). + Please file a bug to Nimble: https://github.com/Quick/Nimble/issues with the code snippet that caused this error. + """ ) + // swiftlint:enable line_length } diff --git a/Sources/Nimble/Matchers/AsyncMatcherWrapper.swift b/Sources/Nimble/Matchers/AsyncMatcherWrapper.swift index 3af3737b3..5b2deb7fe 100644 --- a/Sources/Nimble/Matchers/AsyncMatcherWrapper.swift +++ b/Sources/Nimble/Matchers/AsyncMatcherWrapper.swift @@ -111,8 +111,10 @@ internal struct AsyncMatcherWrapper: Matcher } private let toEventuallyRequiresClosureError = FailureMessage( - // swiftlint:disable:next line_length - stringValue: "expect(...).toEventually(...) requires an explicit closure (eg - expect { ... }.toEventually(...) )\nSwift 1.2 @autoclosure behavior has changed in an incompatible way for Nimble to function" + stringValue: """ + expect(...).toEventually(...) requires an explicit closure (eg - expect { ... }.toEventually(...) ) + Swift 1.2 @autoclosure behavior has changed in an incompatible way for Nimble to function + """ ) extension Expectation { diff --git a/Sources/Nimble/Utils/Async.swift b/Sources/Nimble/Utils/Async.swift index b9898f804..ffc0e1912 100644 --- a/Sources/Nimble/Utils/Async.swift +++ b/Sources/Nimble/Utils/Async.swift @@ -45,10 +45,15 @@ internal class AssertionWaitLock: WaitLock { nimblePrecondition( currentWaiter == nil, "InvalidNimbleAPIUsage", - "Nested async expectations are not allowed to avoid creating flaky tests.\n\n" + - "The call to\n\t\(info)\n" + - "triggered this exception because\n\t\(currentWaiter!)\n" + - "is currently managing the main run loop." + """ + Nested async expectations are not allowed to avoid creating flaky tests. + + The call to + \t\(info) + triggered this exception because + \t\(currentWaiter!) + is currently managing the main run loop. + """ ) currentWaiter = info } diff --git a/Tests/NimbleTests/AsynchronousTest.swift b/Tests/NimbleTests/AsynchronousTest.swift index 5a48e0a2b..bfa34c252 100644 --- a/Tests/NimbleTests/AsynchronousTest.swift +++ b/Tests/NimbleTests/AsynchronousTest.swift @@ -130,15 +130,16 @@ final class AsyncTest: XCTestCase, XCTestCaseProvider { func testCombiningAsyncWaitUntilAndToEventuallyIsNotAllowed() { // Currently we are unable to catch Objective-C exceptions when built by the Swift Package Manager #if !SWIFT_PACKAGE - let referenceLine = #line + 9 - var msg = "Unexpected exception raised: Nested async expectations are not allowed " - msg += "to avoid creating flaky tests." - msg += "\n\n" - msg += "The call to\n\t" - msg += "expect(...).toEventually(...) at \(#file):\(referenceLine + 7)\n" - msg += "triggered this exception because\n\t" - msg += "waitUntil(...) at \(#file):\(referenceLine + 1)\n" - msg += "is currently managing the main run loop." + let referenceLine = #line + 10 + let msg = """ + Unexpected exception raised: Nested async expectations are not allowed to avoid creating flaky tests. + + The call to + \texpect(...).toEventually(...) at \(#file):\(referenceLine + 7) + triggered this exception because + \twaitUntil(...) at \(#file):\(referenceLine + 1) + is currently managing the main run loop. + """ failsWithErrorMessage(msg) { // reference line waitUntil(timeout: 2.0) { done in var protected: Int = 0 diff --git a/Tests/NimbleTests/Helpers/utils.swift b/Tests/NimbleTests/Helpers/utils.swift index a1bbc681b..373bd1be5 100644 --- a/Tests/NimbleTests/Helpers/utils.swift +++ b/Tests/NimbleTests/Helpers/utils.swift @@ -37,7 +37,12 @@ func failsWithErrorMessage(_ messages: [String], file: FileString = #file, line: } else { let knownFailures = recorder.assertions.filter { !$0.success }.map { $0.message.stringValue } let knownFailuresJoined = knownFailures.joined(separator: ", ") - message = "Expected error message (\(msg)), got (\(knownFailuresJoined))\n\nAssertions Received:\n\(recorder.assertions)" + message = """ + Expected error message (\(msg)), got (\(knownFailuresJoined)) + + Assertions Received: + \(recorder.assertions) + """ } NimbleAssertionHandler.assert(false, message: FailureMessage(stringValue: message), diff --git a/Tests/NimbleTests/Matchers/HaveCountTest.swift b/Tests/NimbleTests/Matchers/HaveCountTest.swift index 7845e6dc6..4ef610ea6 100644 --- a/Tests/NimbleTests/Matchers/HaveCountTest.swift +++ b/Tests/NimbleTests/Matchers/HaveCountTest.swift @@ -6,11 +6,21 @@ final class HaveCountTest: XCTestCase, XCTestCaseProvider { expect([1, 2, 3]).to(haveCount(3)) expect([1, 2, 3]).notTo(haveCount(1)) - failsWithErrorMessage("expected to have Array with count 1, got 3\nActual Value: [1, 2, 3]") { + failsWithErrorMessage( + """ + expected to have Array with count 1, got 3 + Actual Value: [1, 2, 3] + """ + ) { expect([1, 2, 3]).to(haveCount(1)) } - failsWithErrorMessage("expected to not have Array with count 3, got 3\nActual Value: [1, 2, 3]") { + failsWithErrorMessage( + """ + expected to not have Array with count 3, got 3 + Actual Value: [1, 2, 3] + """ + ) { expect([1, 2, 3]).notTo(haveCount(3)) } } @@ -20,13 +30,22 @@ final class HaveCountTest: XCTestCase, XCTestCaseProvider { expect(dictionary).to(haveCount(3)) expect(dictionary).notTo(haveCount(1)) - failsWithErrorMessage("expected to have Dictionary with count 1, got 3\nActual Value: \(stringify(dictionary))") { + failsWithErrorMessage( + """ + expected to have Dictionary with count 1, got 3 + Actual Value: \(stringify(dictionary)) + """ + ) { expect(dictionary).to(haveCount(1)) } - failsWithErrorMessage("expected to not have Dictionary with count 3, got 3" + - "\nActual Value: \(stringify(dictionary))") { - expect(dictionary).notTo(haveCount(3)) + failsWithErrorMessage( + """ + expected to not have Dictionary with count 3, got 3 + Actual Value: \(stringify(dictionary)) + """ + ) { + expect(dictionary).notTo(haveCount(3)) } } @@ -35,14 +54,22 @@ final class HaveCountTest: XCTestCase, XCTestCaseProvider { expect(set).to(haveCount(3)) expect(set).notTo(haveCount(1)) - failsWithErrorMessage("expected to have Set with count 1, got 3" + - "\nActual Value: \(stringify(set))") { - expect(set).to(haveCount(1)) + failsWithErrorMessage( + """ + expected to have Set with count 1, got 3 + Actual Value: \(stringify(set)) + """ + ) { + expect(set).to(haveCount(1)) } - failsWithErrorMessage("expected to not have Set with count 3, got 3" + - "\nActual Value: \(stringify(set))") { - expect(set).notTo(haveCount(3)) + failsWithErrorMessage( + """ + expected to not have Set with count 3, got 3 + Actual Value: \(stringify(set)) + """ + ) { + expect(set).notTo(haveCount(3)) } } } diff --git a/Tests/NimbleTests/UserDescriptionTest.swift b/Tests/NimbleTests/UserDescriptionTest.swift index 69a6fccd2..0c451c849 100644 --- a/Tests/NimbleTests/UserDescriptionTest.swift +++ b/Tests/NimbleTests/UserDescriptionTest.swift @@ -4,49 +4,67 @@ import Nimble final class UserDescriptionTest: XCTestCase, XCTestCaseProvider { func testToMatcher_CustomFailureMessage() { failsWithErrorMessage( - "These aren't equal!\n" + - "expected to match, got <1>") { - expect(1).to(MatcherFunc { _, _ in false }, description: "These aren't equal!") + """ + These aren't equal! + expected to match, got <1> + """ + ) { + expect(1).to(MatcherFunc { _, _ in false }, description: "These aren't equal!") } } func testNotToMatcher_CustomFailureMessage() { failsWithErrorMessage( - "These aren't equal!\n" + - "expected to not match, got <1>") { - expect(1).notTo(MatcherFunc { _, _ in true }, description: "These aren't equal!") + """ + These aren't equal! + expected to not match, got <1> + """ + ) { + expect(1).notTo(MatcherFunc { _, _ in true }, description: "These aren't equal!") } } func testToNotMatcher_CustomFailureMessage() { failsWithErrorMessage( - "These aren't equal!\n" + - "expected to not match, got <1>") { - expect(1).toNot(MatcherFunc { _, _ in true }, description: "These aren't equal!") + """ + These aren't equal! + expected to not match, got <1> + """ + ) { + expect(1).toNot(MatcherFunc { _, _ in true }, description: "These aren't equal!") } } func testToEventuallyMatch_CustomFailureMessage() { failsWithErrorMessage( - "These aren't eventually equal!\n" + - "expected to eventually equal <1>, got <0>") { - expect { 0 }.toEventually(equal(1), description: "These aren't eventually equal!") + """ + These aren't eventually equal! + expected to eventually equal <1>, got <0> + """ + ) { + expect { 0 }.toEventually(equal(1), description: "These aren't eventually equal!") } } func testToEventuallyNotMatch_CustomFailureMessage() { failsWithErrorMessage( - "These are eventually equal!\n" + - "expected to eventually not equal <1>, got <1>") { - expect { 1 }.toEventuallyNot(equal(1), description: "These are eventually equal!") + """ + These are eventually equal! + expected to eventually not equal <1>, got <1> + """ + ) { + expect { 1 }.toEventuallyNot(equal(1), description: "These are eventually equal!") } } func testToNotEventuallyMatch_CustomFailureMessage() { failsWithErrorMessage( - "These are eventually equal!\n" + - "expected to eventually not equal <1>, got <1>") { - expect { 1 }.toEventuallyNot(equal(1), description: "These are eventually equal!") + """ + These are eventually equal! + expected to eventually not equal <1>, got <1> + """ + ) { + expect { 1 }.toEventuallyNot(equal(1), description: "These are eventually equal!") } }