Skip to content

Commit

Permalink
Silence #file/#filePath warnings in XCTest
Browse files Browse the repository at this point in the history
Motivation:

Swift 5.3 warns when `#file` is passed to a function expecting
`#filePath` even though the values are currently the same.

- swiftlang/swift#32445
- https://bugs.swift.org/browse/SR-12936
- https://bugs.swift.org/browse/SR-12934
- https://bugs.swift.org/browse/SR-13041

Modifications:

- Wrap `file` in parentheses to silence warnings.

Result:

- No warnings, uglier code
  • Loading branch information
glbrntt committed Jun 30, 2020
1 parent 5a6ad12 commit 7b4b1c1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Tests/NIOSSLTests/NIOSSLIntegrationTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public func assertNoThrowWithValue<T>(_ body: @autoclosure () throws -> T, defau
do {
return try body()
} catch {
XCTFail("unexpected error \(error) thrown", file: file, line: line)
XCTFail("unexpected error \(error) thrown", file: (file), line: line)
if let defaultValue = defaultValue {
return defaultValue
} else {
Expand Down
16 changes: 8 additions & 8 deletions Tests/NIOSSLTests/TLSConfigurationTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ class TLSConfigurationTest: XCTestCase {
switch eventHandler.errors[0] {
case .handshakeFailed(.sslError(let errs)):
let correctError: Bool = messages.map { errs[0].description.contains($0) }.reduce(false) { $0 || $1 }
XCTAssert(correctError, errs[0].description, file: file, line: line)
XCTAssert(correctError, errs[0].description, file: (file), line: line)
default:
XCTFail("Unexpected error: \(eventHandler.errors[0])", file: file, line: line)
XCTFail("Unexpected error: \(eventHandler.errors[0])", file: (file), line: line)
}

XCTAssertFalse(handshakeHandler.handshakeSucceeded, file: file, line: line)
XCTAssertFalse(handshakeHandler.handshakeSucceeded, file: (file), line: line)
}
try clientChannel.closeFuture.wait()
}
Expand All @@ -159,18 +159,18 @@ class TLSConfigurationTest: XCTestCase {

// We expect the channel to be closed fairly swiftly as the handshake should fail.
clientChannel.closeFuture.whenComplete { _ in
XCTAssertEqual(eventHandler.errors.count, 1, file: file, line: line)
XCTAssertEqual(eventHandler.errors.count, 1, file: (file), line: line)

switch eventHandler.errors[0] {
case .sslError(let errs):
XCTAssertEqual(errs.count, 1, file: file, line: line)
XCTAssertEqual(errs.count, 1, file: (file), line: line)
let correctError: Bool = messages.map { errs[0].description.contains($0) }.reduce(false) { $0 || $1 }
XCTAssert(correctError, errs[0].description, file: file, line: line)
XCTAssert(correctError, errs[0].description, file: (file), line: line)
default:
XCTFail("Unexpected error: \(eventHandler.errors[0])", file: file, line: line)
XCTFail("Unexpected error: \(eventHandler.errors[0])", file: (file), line: line)
}

XCTAssertTrue(handshakeHandler.handshakeSucceeded, file: file, line: line)
XCTAssertTrue(handshakeHandler.handshakeSucceeded, file: (file), line: line)
}
try clientChannel.closeFuture.wait()
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/NIOSSLTests/UnwrappingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ extension ChannelPipeline {
do {
_ = try self.context(handler: handler).wait()
} catch {
XCTFail("Handler \(handler) missing from \(self)", file: file, line: line)
XCTFail("Handler \(handler) missing from \(self)", file: (file), line: line)
}
}

func assertDoesNotContain(handler: ChannelHandler, file: StaticString = #file, line: UInt = #line) {
do {
_ = try self.context(handler: handler).wait()
XCTFail("Handler \(handler) present in \(self)", file: file, line: line)
XCTFail("Handler \(handler) present in \(self)", file: (file), line: line)
} catch {
// Expected
}
Expand Down

0 comments on commit 7b4b1c1

Please sign in to comment.