antitypical / Assertions

Flexible XCTest assertions in Swift.
MIT License
40 stars 4 forks source link

Cannot convert value of type 'String' to expected argument type 'StaticString' (Swift 2) #13

Open ryanmasondavies opened 8 years ago

ryanmasondavies commented 8 years ago

This fails to build with Swift 2.2.1.

The errors are as follows:

/Users/Ryan/Downloads/Assertions-master/Assertions/Assertions.swift:87:25: Cannot convert value of type 'String' to expected argument type 'StaticString'
/Users/Ryan/Downloads/Assertions-master/Assertions/Assertions.swift:95:25: Cannot convert value of type 'String' to expected argument type 'StaticString'

The relevant code is:

// MARK: - Failure

/// Logs a failed assertion.
///
/// Returns nil, for use in `x ?? failure(…)` expressions.
public func failure<T>(message: String, file: String = __FILE__, line: UInt = __LINE__) -> T? {
    XCTFail(message, file: file, line: line)
    return nil
}

/// Logs a failed assertion.
///
/// Returns nil, for use in `x ?? failure(…)` expressions.
public func failure(message: String, file: String = __FILE__, line: UInt = __LINE__) -> Bool {
    XCTFail(message, file: file, line: line)
    return false
}

Looks like String needs conversion to StaticString for passing into XCTFail.

Maybe I'm missing something, but I can't find a clear way to perform that conversion. Any ideas?

robrix commented 8 years ago

IIRC, StaticStrings are compile-time only. Maybe we should pass message around as StaticString instead.