diff --git a/Tests/NIOConcurrencyHelpersTests/NIOConcurrencyHelpersTests.swift b/Tests/NIOConcurrencyHelpersTests/NIOConcurrencyHelpersTests.swift index 541b6af32..632eec0a9 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 = #file, line: UInt = #line) { +func assert(_ condition: @autoclosure () -> Bool, within time: TimeAmount, testInterval: TimeAmount? = nil, _ message: String = "condition not satisfied in time", file: StaticString = fullFilePath(), line: UInt = #line) { let testInterval = testInterval ?? TimeAmount.nanoseconds(time.nanoseconds / 5) let endTime = NIODeadline.now() + time @@ -1053,3 +1053,13 @@ 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 7e3301341..05e782113 100644 --- a/Tests/NIOHTTP1Tests/HTTPServerUpgradeTests.swift +++ b/Tests/NIOHTTP1Tests/HTTPServerUpgradeTests.swift @@ -23,7 +23,7 @@ extension ChannelPipeline { } func assertDoesNotContain(handlerType: Handler.Type, - file: StaticString = #file, + file: StaticString = fullFilePath(), 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 61e5620f7..3eccc5758 100644 --- a/Tests/NIOTestUtilsTests/NIOHTTP1TestServerTest.swift +++ b/Tests/NIOTestUtilsTests/NIOHTTP1TestServerTest.swift @@ -281,7 +281,7 @@ private final class TestHTTPHandler: ChannelInboundHandler { } extension HTTPServerRequestPart { - func assertHead(expectedURI: String, file: StaticString = #file, line: UInt = #line) { + func assertHead(expectedURI: String, file: StaticString = fullFilePath(), line: UInt = #line) { switch self { case .head(let head): XCTAssertEqual(.GET, head.method) @@ -292,7 +292,7 @@ extension HTTPServerRequestPart { } } - func assertBody(expectedMessage: String, file: StaticString = #file, line: UInt = #line) { + func assertBody(expectedMessage: String, file: StaticString = fullFilePath(), line: UInt = #line) { switch self { case .body(let buffer): // Note that the test server coalesces the body parts for us. @@ -303,7 +303,7 @@ extension HTTPServerRequestPart { } } - func assertEnd(file: StaticString = #file, line: UInt = #line) { + func assertEnd(file: StaticString = fullFilePath(), line: UInt = #line) { switch self { case .end(_): () @@ -343,7 +343,11 @@ private enum ResponseError: Error { case missingResponse } -func assert(_ condition: @autoclosure () -> Bool, within time: TimeAmount, testInterval: TimeAmount? = nil, _ message: String = "condition not satisfied in time", file: StaticString = #file, line: UInt = #line) { +func assert(_ condition: @autoclosure () -> Bool, + within time: TimeAmount, + testInterval: TimeAmount? = nil, + _ message: String = "condition not satisfied in time", + file: StaticString = fullFilePath(), line: UInt = #line) { let testInterval = testInterval ?? TimeAmount.nanoseconds(time.nanoseconds / 5) let endTime = NIODeadline.now() + time @@ -356,3 +360,13 @@ func assert(_ condition: @autoclosure () -> Bool, within time: TimeAmount, testI 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 29e5d0d04..db88f8223 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 = #file, line: UInt = #line) { + func testIndexAndLengthFunc(_ body: (Int, Int) -> T?, file: StaticString = fullFilePath(), 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 = #file, line: UInt = #line) { + func testIndexOrLengthFunc(_ body: (Int) -> T?, file: StaticString = fullFilePath(), 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 12323f9ee..e2481f3ae 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 = #file, line: UInt = #line) { + private static func assertFulfilled(promise: EventLoopPromise?, promiseName: String, trigger: String, setter: String, file: StaticString = fullFilePath(), 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 205357e23..3ab36b656 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 = #file, + file: StaticString = fullFilePath(), 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 = #file, line: UInt = #line, _ body: () throws -> Void) { + func checkThatItThrowsInappropriateOperationForState(file: StaticString = fullFilePath(), 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 = #file, line: UInt = #line, _ body: (Channel) throws -> Void) { + func withChannel(skipDatagram: Bool = false, skipStream: Bool = false, skipServerSocket: Bool = false, file: StaticString = fullFilePath(), 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 a5a5cdbae..c307fd6d5 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 = #file, line: UInt = #line) throws { + private func testEncoder(_ handler: ChannelHandler, file: StaticString = fullFilePath(), 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 249721ba6..4a2d7dd8b 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 = #file, + file: StaticString = fullFilePath(), line: UInt = #line) { do { _ = try channel.readOutbound(as: Expected.self) diff --git a/Tests/NIOTests/MulticastTest.swift b/Tests/NIOTests/MulticastTest.swift index 15b37e92b..ca71b0627 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 = #file, line: UInt = #line) throws { + private func assertDatagramReaches(multicastChannel: Channel, sender: Channel, multicastAddress: SocketAddress, file: StaticString = fullFilePath(), 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 = #file, line: UInt = #line) throws { + file: StaticString = fullFilePath(), 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 2f2bf1699..941f909a8 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 = #file, + file: StaticString = fullFilePath(), line: UInt = #line) throws -> OverallWriteResult { var everythingState = 0 var singleState = 0 diff --git a/Tests/NIOTests/SocketOptionProviderTest.swift b/Tests/NIOTests/SocketOptionProviderTest.swift index f4b41f3fa..eb4091bfc 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 = #file, line: UInt = #line) throws -> SocketOptionProvider { + private func convertedChannel(file: StaticString = fullFilePath(), 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 = #file, line: UInt = #line) throws -> SocketOptionProvider { + private func ipv4MulticastProvider(file: StaticString = fullFilePath(), 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 = #file, line: UInt = #line) throws -> SocketOptionProvider? { + private func ipv6MulticastProvider(file: StaticString = fullFilePath(), 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 7a8e42afb..58b9d4ee3 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 = #file, line: UInt = #line) throws { +private func assertNoSelectorChanges(fd: CInt, file: StaticString = fullFilePath(), line: UInt = #line) throws { struct UnexpectedSelectorChanges: Error, CustomStringConvertible { let description: String } diff --git a/Tests/NIOTests/SyscallAbstractionLayer.swift b/Tests/NIOTests/SyscallAbstractionLayer.swift index 8bd91694b..57ce4e7d8 100644 --- a/Tests/NIOTests/SyscallAbstractionLayer.swift +++ b/Tests/NIOTests/SyscallAbstractionLayer.swift @@ -47,7 +47,11 @@ final class LockedBox { } } - init(_ value: T? = nil, description: String? = nil, file: String = #file, line: UInt = #line, didSet: @escaping (T?) -> Void = { _ in }) { + init(_ value: T? = nil, + description: String? = nil, + file: StaticString = fullFilePath(), + line: UInt = #line, + didSet: @escaping (T?) -> Void = { _ in }) { self._value = value self.didSet = didSet self.description = description ?? "\(file):\(line)" @@ -342,7 +346,7 @@ class HookedSocket: Socket, UserKernelInterface { extension HookedSelector { func assertSyscallAndReturn(_ result: KernelToUser, - file: StaticString = #file, + file: StaticString = fullFilePath(), line: UInt = #line, matcher: (UserToKernel) throws -> Bool) throws { let syscall = try self.userToKernel.takeValue() @@ -354,7 +358,7 @@ extension HookedSelector { } } - func assertWakeup(file: StaticString = #file, line: UInt = #line) throws { + func assertWakeup(file: StaticString = fullFilePath(), line: UInt = #line) throws { SAL.printIfDebug("\(#function)") try self.assertSyscallAndReturn(.returnSelectorEvent(nil), file: file, line: line) { syscall in if case .whenReady(.block) = syscall { @@ -370,7 +374,7 @@ extension HookedSelector { extension EventLoop { internal func runSAL(syscallAssertions: () throws -> Void = {}, - file: StaticString = #file, + file: StaticString = fullFilePath(), line: UInt = #line, _ body: @escaping () throws -> T) throws -> T { let hookedSelector = ((self as! SelectableEventLoop)._selector as! HookedSelector) @@ -454,7 +458,7 @@ extension SALTest { } private func makeSocketChannel(eventLoop: SelectableEventLoop, - file: StaticString = #file, line: UInt = #line) throws -> SocketChannel { + file: StaticString = fullFilePath(), line: UInt = #line) throws -> SocketChannel { let channel = try eventLoop.runSAL(syscallAssertions: { try self.assertdisableSIGPIPE(expectedFD: .max, result: .success(())) try self.assertLocalAddress(address: nil) @@ -493,7 +497,7 @@ extension SALTest { func makeConnectedSocketChannel(localAddress: SocketAddress?, remoteAddress: SocketAddress, - file: StaticString = #file, + file: StaticString = fullFilePath(), line: UInt = #line) throws -> SocketChannel { let channel = try self.makeSocketChannel(eventLoop: self.loop) let connectFuture = try channel.eventLoop.runSAL(syscallAssertions: { @@ -554,7 +558,7 @@ extension SALTest { self.wakeups = nil } - func assertParkedRightNow(file: StaticString = #file, line: UInt = #line) throws { + func assertParkedRightNow(file: StaticString = fullFilePath(), line: UInt = #line) throws { SAL.printIfDebug("\(#function)") let syscall = try self.userToKernelBox.waitForValue() if case .whenReady = syscall { @@ -565,7 +569,7 @@ extension SALTest { } func assertWaitingForNotification(result: SelectorEvent?, - file: StaticString = #file, line: UInt = #line) throws { + file: StaticString = fullFilePath(), line: UInt = #line) throws { SAL.printIfDebug("\(#function)(result: \(result.debugDescription))") try self.selector.assertSyscallAndReturn(.returnSelectorEvent(result), file: file, line: line) { syscall in @@ -577,13 +581,13 @@ extension SALTest { } } - func assertWakeup(file: StaticString = #file, line: UInt = #line) throws { + func assertWakeup(file: StaticString = fullFilePath(), line: UInt = #line) throws { try self.selector.assertWakeup(file: file, line: line) } func assertdisableSIGPIPE(expectedFD: CInt, result: Result, - file: StaticString = #file, line: UInt = #line) throws { + file: StaticString = fullFilePath(), line: UInt = #line) throws { SAL.printIfDebug("\(#function)") let ret: KernelToUser switch result { @@ -602,7 +606,7 @@ extension SALTest { } - func assertLocalAddress(address: SocketAddress?, file: StaticString = #file, line: UInt = #line) throws { + func assertLocalAddress(address: SocketAddress?, file: StaticString = fullFilePath(), line: UInt = #line) throws { SAL.printIfDebug("\(#function)") try self.selector.assertSyscallAndReturn(address.map { .returnSocketAddress($0) } ?? /* */ .error(.init(errnoCode: EOPNOTSUPP, reason: "nil passed")), @@ -615,7 +619,7 @@ extension SALTest { } } - func assertRemoteAddress(address: SocketAddress?, file: StaticString = #file, line: UInt = #line) throws { + func assertRemoteAddress(address: SocketAddress?, file: StaticString = fullFilePath(), line: UInt = #line) throws { SAL.printIfDebug("\(#function)") try self.selector.assertSyscallAndReturn(address.map { .returnSocketAddress($0) } ?? /* */ .error(.init(errnoCode: EOPNOTSUPP, reason: "nil passed")), @@ -628,7 +632,7 @@ extension SALTest { } } - func assertConnect(result: Bool, file: StaticString = #file, line: UInt = #line, _ matcher: (SocketAddress) -> Bool = { _ in true }) throws { + func assertConnect(result: Bool, file: StaticString = fullFilePath(), 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 { @@ -639,7 +643,7 @@ extension SALTest { } } - func assertClose(expectedFD: CInt, file: StaticString = #file, line: UInt = #line) throws { + func assertClose(expectedFD: CInt, file: StaticString = fullFilePath(), line: UInt = #line) throws { SAL.printIfDebug("\(#function)") try self.selector.assertSyscallAndReturn(.returnVoid, file: file, line: line) { syscall in if case .close(let fd) = syscall { @@ -652,7 +656,7 @@ extension SALTest { } - func assertRegister(file: StaticString = #file, line: UInt = #line, _ matcher: (Selectable, SelectorEventSet, NIORegistration) throws -> Bool) throws { + func assertRegister(file: StaticString = fullFilePath(), 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 { @@ -663,7 +667,7 @@ extension SALTest { } } - func assertReregister(file: StaticString = #file, line: UInt = #line, _ matcher: (Selectable, SelectorEventSet) throws -> Bool) throws { + func assertReregister(file: StaticString = fullFilePath(), 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 { @@ -674,7 +678,7 @@ extension SALTest { } } - func assertDeregister(file: StaticString = #file, line: UInt = #line, _ matcher: (Selectable) throws -> Bool) throws { + func assertDeregister(file: StaticString = fullFilePath(), 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 { @@ -685,7 +689,7 @@ extension SALTest { } } - func assertWrite(expectedFD: CInt, expectedBytes: ByteBuffer, return: IOResult, file: StaticString = #file, line: UInt = #line) throws { + func assertWrite(expectedFD: CInt, expectedBytes: ByteBuffer, return: IOResult, file: StaticString = fullFilePath(), 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 { @@ -696,7 +700,7 @@ extension SALTest { } } - func assertWritev(expectedFD: CInt, expectedBytes: [ByteBuffer], return: IOResult, file: StaticString = #file, line: UInt = #line) throws { + func assertWritev(expectedFD: CInt, expectedBytes: [ByteBuffer], return: IOResult, file: StaticString = fullFilePath(), 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 { @@ -708,7 +712,7 @@ extension SALTest { } func assertRead(expectedFD: CInt, expectedBufferSpace: Int, return: ByteBuffer, - file: StaticString = #file, line: UInt = #line) throws { + file: StaticString = fullFilePath(), 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 0a702f8e3..31610cc20 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 = #file, line: UInt = #line) throws -> T { +func assertNoThrowWithValue(_ body: @autoclosure () throws -> T, defaultValue: T? = nil, message: String? = nil, file: StaticString = fullFilePath(), 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 = #file, line: UInt = #line) { +func assert(_ condition: @autoclosure () -> Bool, within time: TimeAmount, testInterval: TimeAmount? = nil, _ message: String = "condition not satisfied in time", file: StaticString = fullFilePath(), 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 = #file, line: UInt = #line) throws -> Bool { + file: StaticString = fullFilePath(), 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 = #file, line: UInt = #line) { +func assertSuccess(_ result: Result, file: StaticString = fullFilePath(), 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 = #file, line: UInt = #line) { +func assertFailure(_ result: Result, file: StaticString = fullFilePath(), 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 = #file, +func forEachActiveChannelType(file: StaticString = fullFilePath(), line: UInt = #line, _ body: @escaping (Channel) throws -> T) throws -> [T] { let group = MultiThreadedEventLoopGroup(numberOfThreads: 1) @@ -519,7 +519,7 @@ func forEachActiveChannelType(file: StaticString = #file, func withTCPServerChannel(bindTarget: SocketAddress? = nil, group: EventLoopGroup, - file: StaticString = #file, + file: StaticString = fullFilePath(), 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 = #file, + file: StaticString = fullFilePath(), 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 = #file, + file: StaticString = fullFilePath(), 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 = #file, + file: StaticString = fullFilePath(), 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 = #file, + file: StaticString = fullFilePath(), 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 = #file, + file: StaticString = fullFilePath(), line: UInt = #line, _ body: (Channel, Channel) throws -> R) throws -> [R] { let r1 = try withCrossConnectedTCPChannels(forceSeparateEventLoops: forceSeparateEventLoops, body) @@ -701,3 +701,13 @@ 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 9e42eae99..96bfde6a3 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 = #file, + file: StaticString = fullFilePath(), line: UInt = #line) throws { XCTAssertThrowsError(try self.context(handlerType: handlerType).wait(), file: file, line: line) { error in XCTAssertEqual(.notFound, error as? ChannelPipelineError) @@ -411,3 +411,13 @@ 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