From adeafa9ce15fc37f8324444ee0d3582835d02af4 Mon Sep 17 00:00:00 2001 From: Johannes Weiss Date: Fri, 5 Jun 2020 11:13:09 +0100 Subject: [PATCH] remove fullFilePath() hack (#1544) Motivation: The fullFilePath() hack doesn't actually work (https://bugs.swift.org/browse/SR-12934). This is expected behaviour so currently, the only workaround would be to `#if` whole function bodies which is a lot of work. Given that in Swift 5.3 `#file` == `#filePath` still, we can just silence the warning for now. Modifications: - Replace `fullFilePath()` by `(#file)`. Result: - file locations working properly again. Co-authored-by: George Barnett --- .../NIOConcurrencyHelpersTests.swift | 12 +----- .../HTTPServerUpgradeTests.swift | 2 +- .../NIOHTTP1TestServerTest.swift | 18 ++------- Tests/NIOTests/ByteBufferTest.swift | 4 +- Tests/NIOTests/ChannelNotificationTest.swift | 2 +- Tests/NIOTests/ChannelTests.swift | 6 +-- Tests/NIOTests/CodecTest.swift | 2 +- Tests/NIOTests/EmbeddedChannelTest.swift | 2 +- Tests/NIOTests/MulticastTest.swift | 4 +- .../PendingDatagramWritesManagerTests.swift | 2 +- Tests/NIOTests/SocketOptionProviderTest.swift | 6 +-- Tests/NIOTests/StreamChannelsTest.swift | 2 +- Tests/NIOTests/SyscallAbstractionLayer.swift | 40 +++++++++---------- Tests/NIOTests/TestUtils.swift | 34 ++++++---------- .../WebSocketClientEndToEndTests.swift | 12 +----- 15 files changed, 54 insertions(+), 94 deletions(-) diff --git a/Tests/NIOConcurrencyHelpersTests/NIOConcurrencyHelpersTests.swift b/Tests/NIOConcurrencyHelpersTests/NIOConcurrencyHelpersTests.swift index 632eec0a9..e29d37426 100644 --- a/Tests/NIOConcurrencyHelpersTests/NIOConcurrencyHelpersTests.swift +++ b/Tests/NIOConcurrencyHelpersTests/NIOConcurrencyHelpersTests.swift @@ -1025,7 +1025,7 @@ func spawnAndJoinRacingThreads(count: Int, _ body: @escaping (Int) -> Void) { group.wait() } -func assert(_ condition: @autoclosure () -> Bool, within time: TimeAmount, testInterval: TimeAmount? = nil, _ message: String = "condition not satisfied in time", file: StaticString = fullFilePath(), line: UInt = #line) { +func assert(_ condition: @autoclosure () -> Bool, within time: TimeAmount, testInterval: TimeAmount? = nil, _ message: String = "condition not satisfied in time", file: StaticString = (#file), line: UInt = #line) { let testInterval = testInterval ?? TimeAmount.nanoseconds(time.nanoseconds / 5) let endTime = NIODeadline.now() + time @@ -1053,13 +1053,3 @@ fileprivate class IntHolderWithDeallocationTracking { _ = self.allDeallocations.add(1) } } - -#if compiler(>=5.3) -internal func fullFilePath(_ filePath: StaticString = #filePath) -> StaticString { - return filePath -} -#else -internal func fullFilePath(_ filePath: StaticString = #file) -> StaticString { - return filePath -} -#endif diff --git a/Tests/NIOHTTP1Tests/HTTPServerUpgradeTests.swift b/Tests/NIOHTTP1Tests/HTTPServerUpgradeTests.swift index 4717abc4c..167ecef88 100644 --- a/Tests/NIOHTTP1Tests/HTTPServerUpgradeTests.swift +++ b/Tests/NIOHTTP1Tests/HTTPServerUpgradeTests.swift @@ -23,7 +23,7 @@ extension ChannelPipeline { } func assertDoesNotContain(handlerType: Handler.Type, - file: StaticString = fullFilePath(), + file: StaticString = (#file), line: UInt = #line) throws { do { let context = try self.context(handlerType: handlerType).wait() diff --git a/Tests/NIOTestUtilsTests/NIOHTTP1TestServerTest.swift b/Tests/NIOTestUtilsTests/NIOHTTP1TestServerTest.swift index 0477defca..ec900360d 100644 --- a/Tests/NIOTestUtilsTests/NIOHTTP1TestServerTest.swift +++ b/Tests/NIOTestUtilsTests/NIOHTTP1TestServerTest.swift @@ -277,7 +277,7 @@ private final class TestHTTPHandler: ChannelInboundHandler { } extension HTTPServerRequestPart { - func assertHead(expectedURI: String, file: StaticString = fullFilePath(), line: UInt = #line) { + func assertHead(expectedURI: String, file: StaticString = (#file), line: UInt = #line) { switch self { case .head(let head): XCTAssertEqual(.GET, head.method) @@ -288,7 +288,7 @@ extension HTTPServerRequestPart { } } - func assertBody(expectedMessage: String, file: StaticString = fullFilePath(), line: UInt = #line) { + func assertBody(expectedMessage: String, file: StaticString = (#file), line: UInt = #line) { switch self { case .body(let buffer): // Note that the test server coalesces the body parts for us. @@ -299,7 +299,7 @@ extension HTTPServerRequestPart { } } - func assertEnd(file: StaticString = fullFilePath(), line: UInt = #line) { + func assertEnd(file: StaticString = (#file), line: UInt = #line) { switch self { case .end(_): () @@ -339,7 +339,7 @@ func assert(_ condition: @autoclosure () -> Bool, within time: TimeAmount, testInterval: TimeAmount? = nil, _ message: String = "condition not satisfied in time", - file: StaticString = fullFilePath(), line: UInt = #line) { + file: StaticString = (#file), line: UInt = #line) { let testInterval = testInterval ?? TimeAmount.nanoseconds(time.nanoseconds / 5) let endTime = NIODeadline.now() + time @@ -352,13 +352,3 @@ func assert(_ condition: @autoclosure () -> Bool, XCTFail(message, file: file, line: line) } } - -#if compiler(>=5.3) -internal func fullFilePath(_ filePath: StaticString = #filePath) -> StaticString { - return filePath -} -#else -internal func fullFilePath(_ filePath: StaticString = #file) -> StaticString { - return filePath -} -#endif diff --git a/Tests/NIOTests/ByteBufferTest.swift b/Tests/NIOTests/ByteBufferTest.swift index cd1c0305c..79bb52075 100644 --- a/Tests/NIOTests/ByteBufferTest.swift +++ b/Tests/NIOTests/ByteBufferTest.swift @@ -1120,7 +1120,7 @@ class ByteBufferTest: XCTestCase { buf.reserveCapacity(1024) buf.writeStaticString("hello world, just some trap bytes here") - func testIndexAndLengthFunc(_ body: (Int, Int) -> T?, file: StaticString = fullFilePath(), line: UInt = #line) { + func testIndexAndLengthFunc(_ body: (Int, Int) -> T?, file: StaticString = (#file), line: UInt = #line) { XCTAssertNil(body(Int.max, 1), file: file, line: line) XCTAssertNil(body(Int.max - 1, 2), file: file, line: line) XCTAssertNil(body(1, Int.max), file: file, line: line) @@ -1131,7 +1131,7 @@ class ByteBufferTest: XCTestCase { XCTAssertNil(body(Int.min, Int.max), file: file, line: line) } - func testIndexOrLengthFunc(_ body: (Int) -> T?, file: StaticString = fullFilePath(), line: UInt = #line) { + func testIndexOrLengthFunc(_ body: (Int) -> T?, file: StaticString = (#file), line: UInt = #line) { XCTAssertNil(body(Int.max)) XCTAssertNil(body(Int.max - 1)) XCTAssertNil(body(Int.min)) diff --git a/Tests/NIOTests/ChannelNotificationTest.swift b/Tests/NIOTests/ChannelNotificationTest.swift index e2481f3ae..433bba5a8 100644 --- a/Tests/NIOTests/ChannelNotificationTest.swift +++ b/Tests/NIOTests/ChannelNotificationTest.swift @@ -17,7 +17,7 @@ import XCTest class ChannelNotificationTest: XCTestCase { - private static func assertFulfilled(promise: EventLoopPromise?, promiseName: String, trigger: String, setter: String, file: StaticString = fullFilePath(), line: UInt = #line) { + private static func assertFulfilled(promise: EventLoopPromise?, promiseName: String, trigger: String, setter: String, file: StaticString = (#file), line: UInt = #line) { if let promise = promise { XCTAssertTrue(promise.futureResult.isFulfilled, "\(promiseName) not fulfilled before \(trigger) was called", file: file, line: line) } else { diff --git a/Tests/NIOTests/ChannelTests.swift b/Tests/NIOTests/ChannelTests.swift index 3ab36b656..abf5965e5 100644 --- a/Tests/NIOTests/ChannelTests.swift +++ b/Tests/NIOTests/ChannelTests.swift @@ -255,7 +255,7 @@ public final class ChannelTests: XCTestCase { expectedFileWritabilities: [(Int, Int)]?, returns: [IOResult], promiseStates: [[Bool]], - file: StaticString = fullFilePath(), + file: StaticString = (#file), line: UInt = #line) throws -> OverallWriteResult { var everythingState = 0 var singleState = 0 @@ -1959,7 +1959,7 @@ public final class ChannelTests: XCTestCase { } func testAppropriateAndInappropriateOperationsForUnregisteredSockets() throws { - func checkThatItThrowsInappropriateOperationForState(file: StaticString = fullFilePath(), line: UInt = #line, _ body: () throws -> Void) { + func checkThatItThrowsInappropriateOperationForState(file: StaticString = (#file), line: UInt = #line, _ body: () throws -> Void) { XCTAssertThrowsError(try body(), file: file, line: line) { error in XCTAssertEqual(.inappropriateOperationForState, error as? ChannelError) } @@ -1969,7 +1969,7 @@ public final class ChannelTests: XCTestCase { XCTAssertNoThrow(try elg.syncShutdownGracefully()) } - func withChannel(skipDatagram: Bool = false, skipStream: Bool = false, skipServerSocket: Bool = false, file: StaticString = fullFilePath(), line: UInt = #line, _ body: (Channel) throws -> Void) { + func withChannel(skipDatagram: Bool = false, skipStream: Bool = false, skipServerSocket: Bool = false, file: StaticString = (#file), line: UInt = #line, _ body: (Channel) throws -> Void) { XCTAssertNoThrow(try { let el = elg.next() as! SelectableEventLoop let channels: [Channel] = (skipDatagram ? [] : [try DatagramChannel(eventLoop: el, protocolFamily: .inet)]) + diff --git a/Tests/NIOTests/CodecTest.swift b/Tests/NIOTests/CodecTest.swift index c307fd6d5..f0eaf9244 100644 --- a/Tests/NIOTests/CodecTest.swift +++ b/Tests/NIOTests/CodecTest.swift @@ -1541,7 +1541,7 @@ public final class MessageToByteEncoderTest: XCTestCase { try testEncoder(MessageToByteHandler(Int32ToByteEncoderWithDefaultImpl())) } - private func testEncoder(_ handler: ChannelHandler, file: StaticString = fullFilePath(), line: UInt = #line) throws { + private func testEncoder(_ handler: ChannelHandler, file: StaticString = (#file), line: UInt = #line) throws { let channel = EmbeddedChannel() XCTAssertNoThrow(try channel.pipeline.addHandler(MessageToByteHandler(Int32ToByteEncoder())).wait(), diff --git a/Tests/NIOTests/EmbeddedChannelTest.swift b/Tests/NIOTests/EmbeddedChannelTest.swift index 8ce6fb5ea..a62b86f43 100644 --- a/Tests/NIOTests/EmbeddedChannelTest.swift +++ b/Tests/NIOTests/EmbeddedChannelTest.swift @@ -165,7 +165,7 @@ class EmbeddedChannelTest: XCTestCase { func check(expected: Expected.Type, actual: Actual.Type, - file: StaticString = fullFilePath(), + file: StaticString = (#file), line: UInt = #line) { do { _ = try channel.readOutbound(as: Expected.self) diff --git a/Tests/NIOTests/MulticastTest.swift b/Tests/NIOTests/MulticastTest.swift index a557fa69a..6a5860549 100644 --- a/Tests/NIOTests/MulticastTest.swift +++ b/Tests/NIOTests/MulticastTest.swift @@ -118,7 +118,7 @@ final class MulticastTest: XCTestCase { } } - private func assertDatagramReaches(multicastChannel: Channel, sender: Channel, multicastAddress: SocketAddress, file: StaticString = fullFilePath(), line: UInt = #line) throws { + private func assertDatagramReaches(multicastChannel: Channel, sender: Channel, multicastAddress: SocketAddress, file: StaticString = (#file), line: UInt = #line) throws { let receivedMulticastDatagram = multicastChannel.eventLoop.makePromise(of: AddressedEnvelope.self) XCTAssertNoThrow(try multicastChannel.pipeline.addHandler(PromiseOnReadHandler(promise: receivedMulticastDatagram)).wait()) @@ -140,7 +140,7 @@ final class MulticastTest: XCTestCase { after timeout: TimeAmount, sender: Channel, multicastAddress: SocketAddress, - file: StaticString = fullFilePath(), line: UInt = #line) throws { + file: StaticString = (#file), line: UInt = #line) throws { let timeoutPromise = multicastChannel.eventLoop.makePromise(of: Void.self) let receivedMulticastDatagram = multicastChannel.eventLoop.makePromise(of: AddressedEnvelope.self) XCTAssertNoThrow(try multicastChannel.pipeline.addHandler(PromiseOnReadHandler(promise: receivedMulticastDatagram)).wait()) diff --git a/Tests/NIOTests/PendingDatagramWritesManagerTests.swift b/Tests/NIOTests/PendingDatagramWritesManagerTests.swift index 941f909a8..e931fa4e9 100644 --- a/Tests/NIOTests/PendingDatagramWritesManagerTests.swift +++ b/Tests/NIOTests/PendingDatagramWritesManagerTests.swift @@ -102,7 +102,7 @@ class PendingDatagramWritesManagerTests: XCTestCase { expectedVectorWritabilities: [[(Int, SocketAddress)]]?, returns: [Result, Error>], promiseStates: [[Bool]], - file: StaticString = fullFilePath(), + file: StaticString = (#file), line: UInt = #line) throws -> OverallWriteResult { var everythingState = 0 var singleState = 0 diff --git a/Tests/NIOTests/SocketOptionProviderTest.swift b/Tests/NIOTests/SocketOptionProviderTest.swift index eb4091bfc..003b2aacb 100644 --- a/Tests/NIOTests/SocketOptionProviderTest.swift +++ b/Tests/NIOTests/SocketOptionProviderTest.swift @@ -24,7 +24,7 @@ final class SocketOptionProviderTest: XCTestCase { struct CastError: Error { } - private func convertedChannel(file: StaticString = fullFilePath(), line: UInt = #line) throws -> SocketOptionProvider { + private func convertedChannel(file: StaticString = (#file), line: UInt = #line) throws -> SocketOptionProvider { guard let provider = self.clientChannel as? SocketOptionProvider else { XCTFail("Unable to cast \(String(describing: self.clientChannel)) to SocketOptionProvider", file: file, line: line) throw CastError() @@ -32,7 +32,7 @@ final class SocketOptionProviderTest: XCTestCase { return provider } - private func ipv4MulticastProvider(file: StaticString = fullFilePath(), line: UInt = #line) throws -> SocketOptionProvider { + private func ipv4MulticastProvider(file: StaticString = (#file), line: UInt = #line) throws -> SocketOptionProvider { guard let provider = self.ipv4DatagramChannel as? SocketOptionProvider else { XCTFail("Unable to cast \(String(describing: self.ipv4DatagramChannel)) to SocketOptionProvider", file: file, line: line) throw CastError() @@ -40,7 +40,7 @@ final class SocketOptionProviderTest: XCTestCase { return provider } - private func ipv6MulticastProvider(file: StaticString = fullFilePath(), line: UInt = #line) throws -> SocketOptionProvider? { + private func ipv6MulticastProvider(file: StaticString = (#file), line: UInt = #line) throws -> SocketOptionProvider? { guard let ipv6Channel = self.ipv6DatagramChannel else { return nil } diff --git a/Tests/NIOTests/StreamChannelsTest.swift b/Tests/NIOTests/StreamChannelsTest.swift index 58b9d4ee3..8e207b5e2 100644 --- a/Tests/NIOTests/StreamChannelsTest.swift +++ b/Tests/NIOTests/StreamChannelsTest.swift @@ -836,7 +836,7 @@ final class AccumulateAllReads: ChannelInboundHandler { } } -private func assertNoSelectorChanges(fd: CInt, file: StaticString = fullFilePath(), line: UInt = #line) throws { +private func assertNoSelectorChanges(fd: CInt, file: StaticString = (#file), line: UInt = #line) throws { struct UnexpectedSelectorChanges: Error, CustomStringConvertible { let description: String } diff --git a/Tests/NIOTests/SyscallAbstractionLayer.swift b/Tests/NIOTests/SyscallAbstractionLayer.swift index 57ce4e7d8..5dd604549 100644 --- a/Tests/NIOTests/SyscallAbstractionLayer.swift +++ b/Tests/NIOTests/SyscallAbstractionLayer.swift @@ -49,7 +49,7 @@ final class LockedBox { init(_ value: T? = nil, description: String? = nil, - file: StaticString = fullFilePath(), + file: StaticString = (#file), line: UInt = #line, didSet: @escaping (T?) -> Void = { _ in }) { self._value = value @@ -346,7 +346,7 @@ class HookedSocket: Socket, UserKernelInterface { extension HookedSelector { func assertSyscallAndReturn(_ result: KernelToUser, - file: StaticString = fullFilePath(), + file: StaticString = (#file), line: UInt = #line, matcher: (UserToKernel) throws -> Bool) throws { let syscall = try self.userToKernel.takeValue() @@ -358,7 +358,7 @@ extension HookedSelector { } } - func assertWakeup(file: StaticString = fullFilePath(), line: UInt = #line) throws { + func assertWakeup(file: StaticString = (#file), line: UInt = #line) throws { SAL.printIfDebug("\(#function)") try self.assertSyscallAndReturn(.returnSelectorEvent(nil), file: file, line: line) { syscall in if case .whenReady(.block) = syscall { @@ -374,7 +374,7 @@ extension HookedSelector { extension EventLoop { internal func runSAL(syscallAssertions: () throws -> Void = {}, - file: StaticString = fullFilePath(), + file: StaticString = (#file), line: UInt = #line, _ body: @escaping () throws -> T) throws -> T { let hookedSelector = ((self as! SelectableEventLoop)._selector as! HookedSelector) @@ -458,7 +458,7 @@ extension SALTest { } private func makeSocketChannel(eventLoop: SelectableEventLoop, - file: StaticString = fullFilePath(), line: UInt = #line) throws -> SocketChannel { + file: StaticString = (#file), line: UInt = #line) throws -> SocketChannel { let channel = try eventLoop.runSAL(syscallAssertions: { try self.assertdisableSIGPIPE(expectedFD: .max, result: .success(())) try self.assertLocalAddress(address: nil) @@ -497,7 +497,7 @@ extension SALTest { func makeConnectedSocketChannel(localAddress: SocketAddress?, remoteAddress: SocketAddress, - file: StaticString = fullFilePath(), + file: StaticString = (#file), line: UInt = #line) throws -> SocketChannel { let channel = try self.makeSocketChannel(eventLoop: self.loop) let connectFuture = try channel.eventLoop.runSAL(syscallAssertions: { @@ -558,7 +558,7 @@ extension SALTest { self.wakeups = nil } - func assertParkedRightNow(file: StaticString = fullFilePath(), line: UInt = #line) throws { + func assertParkedRightNow(file: StaticString = (#file), line: UInt = #line) throws { SAL.printIfDebug("\(#function)") let syscall = try self.userToKernelBox.waitForValue() if case .whenReady = syscall { @@ -569,7 +569,7 @@ extension SALTest { } func assertWaitingForNotification(result: SelectorEvent?, - file: StaticString = fullFilePath(), line: UInt = #line) throws { + file: StaticString = (#file), line: UInt = #line) throws { SAL.printIfDebug("\(#function)(result: \(result.debugDescription))") try self.selector.assertSyscallAndReturn(.returnSelectorEvent(result), file: file, line: line) { syscall in @@ -581,13 +581,13 @@ extension SALTest { } } - func assertWakeup(file: StaticString = fullFilePath(), line: UInt = #line) throws { + func assertWakeup(file: StaticString = (#file), line: UInt = #line) throws { try self.selector.assertWakeup(file: file, line: line) } func assertdisableSIGPIPE(expectedFD: CInt, result: Result, - file: StaticString = fullFilePath(), line: UInt = #line) throws { + file: StaticString = (#file), line: UInt = #line) throws { SAL.printIfDebug("\(#function)") let ret: KernelToUser switch result { @@ -606,7 +606,7 @@ extension SALTest { } - func assertLocalAddress(address: SocketAddress?, file: StaticString = fullFilePath(), line: UInt = #line) throws { + func assertLocalAddress(address: SocketAddress?, file: StaticString = (#file), line: UInt = #line) throws { SAL.printIfDebug("\(#function)") try self.selector.assertSyscallAndReturn(address.map { .returnSocketAddress($0) } ?? /* */ .error(.init(errnoCode: EOPNOTSUPP, reason: "nil passed")), @@ -619,7 +619,7 @@ extension SALTest { } } - func assertRemoteAddress(address: SocketAddress?, file: StaticString = fullFilePath(), line: UInt = #line) throws { + func assertRemoteAddress(address: SocketAddress?, file: StaticString = (#file), line: UInt = #line) throws { SAL.printIfDebug("\(#function)") try self.selector.assertSyscallAndReturn(address.map { .returnSocketAddress($0) } ?? /* */ .error(.init(errnoCode: EOPNOTSUPP, reason: "nil passed")), @@ -632,7 +632,7 @@ extension SALTest { } } - func assertConnect(result: Bool, file: StaticString = fullFilePath(), line: UInt = #line, _ matcher: (SocketAddress) -> Bool = { _ in true }) throws { + func assertConnect(result: Bool, file: StaticString = (#file), line: UInt = #line, _ matcher: (SocketAddress) -> Bool = { _ in true }) throws { SAL.printIfDebug("\(#function)") try self.selector.assertSyscallAndReturn(.returnBool(result), file: file, line: line) { syscall in if case .connect(let address) = syscall { @@ -643,7 +643,7 @@ extension SALTest { } } - func assertClose(expectedFD: CInt, file: StaticString = fullFilePath(), line: UInt = #line) throws { + func assertClose(expectedFD: CInt, file: StaticString = (#file), line: UInt = #line) throws { SAL.printIfDebug("\(#function)") try self.selector.assertSyscallAndReturn(.returnVoid, file: file, line: line) { syscall in if case .close(let fd) = syscall { @@ -656,7 +656,7 @@ extension SALTest { } - func assertRegister(file: StaticString = fullFilePath(), line: UInt = #line, _ matcher: (Selectable, SelectorEventSet, NIORegistration) throws -> Bool) throws { + func assertRegister(file: StaticString = (#file), line: UInt = #line, _ matcher: (Selectable, SelectorEventSet, NIORegistration) throws -> Bool) throws { SAL.printIfDebug("\(#function)") try self.selector.assertSyscallAndReturn(.returnVoid, file: file, line: line) { syscall in if case .register(let selectable, let eventSet, let registration) = syscall { @@ -667,7 +667,7 @@ extension SALTest { } } - func assertReregister(file: StaticString = fullFilePath(), line: UInt = #line, _ matcher: (Selectable, SelectorEventSet) throws -> Bool) throws { + func assertReregister(file: StaticString = (#file), line: UInt = #line, _ matcher: (Selectable, SelectorEventSet) throws -> Bool) throws { SAL.printIfDebug("\(#function)") try self.selector.assertSyscallAndReturn(.returnVoid, file: file, line: line) { syscall in if case .reregister(let selectable, let eventSet) = syscall { @@ -678,7 +678,7 @@ extension SALTest { } } - func assertDeregister(file: StaticString = fullFilePath(), line: UInt = #line, _ matcher: (Selectable) throws -> Bool) throws { + func assertDeregister(file: StaticString = (#file), line: UInt = #line, _ matcher: (Selectable) throws -> Bool) throws { SAL.printIfDebug("\(#function)") try self.selector.assertSyscallAndReturn(.returnVoid, file: file, line: line) { syscall in if case .deregister(let selectable) = syscall { @@ -689,7 +689,7 @@ extension SALTest { } } - func assertWrite(expectedFD: CInt, expectedBytes: ByteBuffer, return: IOResult, file: StaticString = fullFilePath(), line: UInt = #line) throws { + func assertWrite(expectedFD: CInt, expectedBytes: ByteBuffer, return: IOResult, file: StaticString = (#file), line: UInt = #line) throws { SAL.printIfDebug("\(#function)") try self.selector.assertSyscallAndReturn(.returnIOResultInt(`return`), file: file, line: line) { syscall in if case .write(let actualFD, let actualBytes) = syscall { @@ -700,7 +700,7 @@ extension SALTest { } } - func assertWritev(expectedFD: CInt, expectedBytes: [ByteBuffer], return: IOResult, file: StaticString = fullFilePath(), line: UInt = #line) throws { + func assertWritev(expectedFD: CInt, expectedBytes: [ByteBuffer], return: IOResult, file: StaticString = (#file), line: UInt = #line) throws { SAL.printIfDebug("\(#function)") try self.selector.assertSyscallAndReturn(.returnIOResultInt(`return`), file: file, line: line) { syscall in if case .writev(let actualFD, let actualBytes) = syscall { @@ -712,7 +712,7 @@ extension SALTest { } func assertRead(expectedFD: CInt, expectedBufferSpace: Int, return: ByteBuffer, - file: StaticString = fullFilePath(), line: UInt = #line) throws { + file: StaticString = (#file), line: UInt = #line) throws { SAL.printIfDebug("\(#function)") try self.selector.assertSyscallAndReturn(.returnBytes(`return`), file: file, line: line) { syscall in diff --git a/Tests/NIOTests/TestUtils.swift b/Tests/NIOTests/TestUtils.swift index 31610cc20..4f623c187 100644 --- a/Tests/NIOTests/TestUtils.swift +++ b/Tests/NIOTests/TestUtils.swift @@ -244,7 +244,7 @@ func assertSetGetOptionOnOpenAndClosed(channel: Channel, } } -func assertNoThrowWithValue(_ body: @autoclosure () throws -> T, defaultValue: T? = nil, message: String? = nil, file: StaticString = fullFilePath(), line: UInt = #line) throws -> T { +func assertNoThrowWithValue(_ body: @autoclosure () throws -> T, defaultValue: T? = nil, message: String? = nil, file: StaticString = (#file), line: UInt = #line) throws -> T { do { return try body() } catch { @@ -283,7 +283,7 @@ func resolverDebugInformation(eventLoop: EventLoop, host: String, previouslyRece """ } -func assert(_ condition: @autoclosure () -> Bool, within time: TimeAmount, testInterval: TimeAmount? = nil, _ message: String = "condition not satisfied in time", file: StaticString = fullFilePath(), line: UInt = #line) { +func assert(_ condition: @autoclosure () -> Bool, within time: TimeAmount, testInterval: TimeAmount? = nil, _ message: String = "condition not satisfied in time", file: StaticString = (#file), line: UInt = #line) { let testInterval = testInterval ?? TimeAmount.nanoseconds(time.nanoseconds / 5) let endTime = NIODeadline.now() + time @@ -298,15 +298,15 @@ func assert(_ condition: @autoclosure () -> Bool, within time: TimeAmount, testI } func getBoolSocketOption(channel: Channel, level: NIOBSDSocket.OptionLevel, name: NIOBSDSocket.Option, - file: StaticString = fullFilePath(), line: UInt = #line) throws -> Bool { + file: StaticString = (#file), line: UInt = #line) throws -> Bool { return try assertNoThrowWithValue(channel.getOption(ChannelOptions.Types.SocketOption(level: level, name: name)), file: file, line: line).wait() != 0 } -func assertSuccess(_ result: Result, file: StaticString = fullFilePath(), line: UInt = #line) { +func assertSuccess(_ result: Result, file: StaticString = (#file), line: UInt = #line) { guard case .success = result else { return XCTFail("Expected result to be successful", file: file, line: line) } } -func assertFailure(_ result: Result, file: StaticString = fullFilePath(), line: UInt = #line) { +func assertFailure(_ result: Result, file: StaticString = (#file), line: UInt = #line) { guard case .failure = result else { return XCTFail("Expected result to be a failure", file: file, line: line) } } @@ -479,7 +479,7 @@ final class FulfillOnFirstEventHandler: ChannelDuplexHandler { } } -func forEachActiveChannelType(file: StaticString = fullFilePath(), +func forEachActiveChannelType(file: StaticString = (#file), line: UInt = #line, _ body: @escaping (Channel) throws -> T) throws -> [T] { let group = MultiThreadedEventLoopGroup(numberOfThreads: 1) @@ -519,7 +519,7 @@ func forEachActiveChannelType(file: StaticString = fullFilePath(), func withTCPServerChannel(bindTarget: SocketAddress? = nil, group: EventLoopGroup, - file: StaticString = fullFilePath(), + file: StaticString = (#file), line: UInt = #line, _ body: (Channel) throws -> R) throws -> R { let server = try ServerBootstrap(group: group) @@ -538,7 +538,7 @@ func withTCPServerChannel(bindTarget: SocketAddress? = nil, func withCrossConnectedSockAddrChannels(bindTarget: SocketAddress, forceSeparateEventLoops: Bool = false, - file: StaticString = fullFilePath(), + file: StaticString = (#file), line: UInt = #line, _ body: (Channel, Channel) throws -> R) throws -> R { let serverGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) @@ -588,7 +588,7 @@ func withCrossConnectedSockAddrChannels(bindTarget: SocketAddress, } func withCrossConnectedTCPChannels(forceSeparateEventLoops: Bool = false, - file: StaticString = fullFilePath(), + file: StaticString = (#file), line: UInt = #line, _ body: (Channel, Channel) throws -> R) throws -> R { return try withCrossConnectedSockAddrChannels(bindTarget: .init(ipAddress: "127.0.0.1", port: 0), @@ -597,7 +597,7 @@ func withCrossConnectedTCPChannels(forceSeparateEventLoops: Bool = false, } func withCrossConnectedUnixDomainSocketChannels(forceSeparateEventLoops: Bool = false, - file: StaticString = fullFilePath(), + file: StaticString = (#file), line: UInt = #line, _ body: (Channel, Channel) throws -> R) throws -> R { return try withTemporaryDirectory { tempDir in @@ -609,7 +609,7 @@ func withCrossConnectedUnixDomainSocketChannels(forceSeparateEventLoops: Bool } func withCrossConnectedPipeChannels(forceSeparateEventLoops: Bool = false, - file: StaticString = fullFilePath(), + file: StaticString = (#file), line: UInt = #line, _ body: (Channel, Channel) throws -> R) throws -> R { let channel1Group = MultiThreadedEventLoopGroup(numberOfThreads: 1) @@ -664,7 +664,7 @@ func withCrossConnectedPipeChannels(forceSeparateEventLoops: Bool = false, } func forEachCrossConnectedStreamChannelPair(forceSeparateEventLoops: Bool = false, - file: StaticString = fullFilePath(), + file: StaticString = (#file), line: UInt = #line, _ body: (Channel, Channel) throws -> R) throws -> [R] { let r1 = try withCrossConnectedTCPChannels(forceSeparateEventLoops: forceSeparateEventLoops, body) @@ -701,13 +701,3 @@ extension EventLoopFuture { } } } - -#if compiler(>=5.3) -internal func fullFilePath(_ filePath: StaticString = #filePath) -> StaticString { - return filePath -} -#else -internal func fullFilePath(_ filePath: StaticString = #file) -> StaticString { - return filePath -} -#endif diff --git a/Tests/NIOWebSocketTests/WebSocketClientEndToEndTests.swift b/Tests/NIOWebSocketTests/WebSocketClientEndToEndTests.swift index c1cf5657b..268fa2404 100644 --- a/Tests/NIOWebSocketTests/WebSocketClientEndToEndTests.swift +++ b/Tests/NIOWebSocketTests/WebSocketClientEndToEndTests.swift @@ -32,7 +32,7 @@ extension EmbeddedChannel { extension ChannelPipeline { fileprivate func assertDoesNotContain(handlerType: Handler.Type, - file: StaticString = fullFilePath(), + file: StaticString = (#file), line: UInt = #line) throws { XCTAssertThrowsError(try self.context(handlerType: handlerType).wait(), file: file, line: line) { error in XCTAssertEqual(.notFound, error as? ChannelPipelineError) @@ -403,13 +403,3 @@ class WebSocketClientEndToEndTests: XCTestCase { XCTAssertNoThrow(try clientChannel.close().wait()) } } - -#if compiler(>=5.3) -internal func fullFilePath(_ filePath: StaticString = #filePath) -> StaticString { - return filePath -} -#else -internal func fullFilePath(_ filePath: StaticString = #file) -> StaticString { - return filePath -} -#endif