From f9dd74600d74aca439a05df62f18fb934e680e50 Mon Sep 17 00:00:00 2001 From: Jens Ayton Date: Tue, 23 Jun 2020 11:02:51 +0200 Subject: [PATCH] Handle #file/#filePath distinction in Swift 5.3 --- MobiusNimble/Test/TestUtil.swift | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/MobiusNimble/Test/TestUtil.swift b/MobiusNimble/Test/TestUtil.swift index 1a2b5394..4112cec1 100644 --- a/MobiusNimble/Test/TestUtil.swift +++ b/MobiusNimble/Test/TestUtil.swift @@ -34,6 +34,25 @@ extension AssertionRecorder { // The assertions in these tests are using XCTest assertions since the assertion handler for Nimble // is replaced in order to be inspected + #if swift(>=5.3) + func assertExpectationSucceeded(file: StaticString = #filePath, line: UInt = #line) { + XCTAssertTrue(last.success, "Expected expectation to succeed - it failed", file: file, line: line) + } + + func assertExpectationFailed(file: StaticString = #filePath, line: UInt = #line) { + XCTAssertFalse(last.success, "Expected expectation to fail - it succeeded", file: file, line: line) + } + + func assertLastErrorMessageHasSuffix(_ suffix: String, file: StaticString = #filePath, line: UInt = #line) { + let errorDescription = "Error message doesn't match: Expected message <\(lastMessage)> to have suffix <\(suffix)>" + XCTAssert(lastMessage.hasSuffix(suffix), errorDescription, file: file, line: line) + } + + func assertLastErrorMessageContains(_ string: String, file: StaticString = #filePath, line: UInt = #line) { + let errorDescription = "Error message doesn't match: Expected message <\(lastMessage)> to contain <\(string)>" + XCTAssert(lastMessage.contains(string), errorDescription, file: file, line: line) + } + #else func assertExpectationSucceeded(file: StaticString = #file, line: UInt = #line) { XCTAssertTrue(last.success, "Expected expectation to succeed - it failed", file: file, line: line) } @@ -51,4 +70,5 @@ extension AssertionRecorder { let errorDescription = "Error message doesn't match: Expected message <\(lastMessage)> to contain <\(string)>" XCTAssert(lastMessage.contains(string), errorDescription, file: file, line: line) } + #endif }