Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle #file/#filePath distinction in Swift 5.3 #167

Merged
merged 2 commits into from
Jun 24, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions MobiusNimble/Test/TestUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
}