Skip to content

Commit

Permalink
Use #fileID/#filePath instead of #file (#359)
Browse files Browse the repository at this point in the history
Motivation:

#fileID introduced in Swift 5.3, so no longer need to use #file anywhere

Modifications:

Changed #file to #filePath or #fileID depending on situation
  • Loading branch information
carolinacass authored Nov 1, 2022
1 parent b1f1e68 commit d665696
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 171 deletions.
2 changes: 1 addition & 1 deletion Sources/NIOHTTP2/HTTP2ChannelHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ extension NIOHTTP2Handler {
private func failDroppedPromises(_ promises: CompoundOutboundBuffer.DroppedPromisesCollection,
streamID: HTTP2StreamID,
errorCode: HTTP2ErrorCode,
file: String = #file, line: UInt = #line) {
file: String = #fileID, line: UInt = #line) {
// 'NIOHTTP2Errors.streamClosed' always allocates, if there are no promises then there's no
// need to create the error.
guard promises.contains(where: { $0 != nil }) else {
Expand Down
158 changes: 79 additions & 79 deletions Sources/NIOHTTP2/HTTP2Error.swift

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ extension Array where Element == UInt8 {
}()

// The location of the test fixtures.
private static let fixtureDirectoryURL = URL(fileURLWithPath: #file).deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().appendingPathComponent("Tests").appendingPathComponent("NIOHPACKTests").appendingPathComponent("Fixtures").absoluteURL
private static let fixtureDirectoryURL = URL(fileURLWithPath: #filePath).deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().appendingPathComponent("Tests").appendingPathComponent("NIOHPACKTests").appendingPathComponent("Fixtures").absoluteURL
}


Expand Down
3 changes: 1 addition & 2 deletions Tests/NIOHPACKTests/HPACKIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ import NIOCore
@testable import NIOHPACK

class HPACKIntegrationTests : XCTestCase {

private let hpackTestsURL: URL = {
let myURL = URL(fileURLWithPath: #file, isDirectory: false)
let myURL = URL(fileURLWithPath: #filePath, isDirectory: false)
let result: URL
if #available(OSX 10.11, iOS 9.0, *) {
result = URL(fileURLWithPath: "../hpack-test-case", isDirectory: true, relativeTo: myURL).absoluteURL
Expand Down
2 changes: 1 addition & 1 deletion Tests/NIOHPACKTests/HeaderTableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import NIOCore
func XCTAssertEqualTuple<T1: Equatable, T2: Equatable>(_ expression1: @autoclosure () throws -> (T1, T2)?,
_ expression2: @autoclosure () throws -> (T1, T2)?,
_ message: @autoclosure () -> String = "",
file: StaticString = #file, line: UInt = #line) {
file: StaticString = #filePath, line: UInt = #line) {
let ex1: (T1, T2)?
let ex2: (T1, T2)?
do {
Expand Down
4 changes: 2 additions & 2 deletions Tests/NIOHPACKTests/HuffmanCodingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class HuffmanCodingTests: XCTestCase {

// MARK: - Helper Methods

func assertEqualContents(_ buffer: ByteBuffer, _ array: [UInt8], file: StaticString = #file, line: UInt = #line) {
func assertEqualContents(_ buffer: ByteBuffer, _ array: [UInt8], file: StaticString = #filePath, line: UInt = #line) {
XCTAssertEqual(buffer.readableBytes, array.count, "Buffer and array are different sizes", file: (file), line: line)
buffer.withUnsafeReadableBytes { bufPtr in
array.withUnsafeBytes { arrayPtr in
Expand All @@ -32,7 +32,7 @@ class HuffmanCodingTests: XCTestCase {
}
}

func verifyHuffmanCoding(_ string: String, _ bytes: [UInt8], file: StaticString = #file, line: UInt = #line) throws {
func verifyHuffmanCoding(_ string: String, _ bytes: [UInt8], file: StaticString = #filePath, line: UInt = #line) throws {
self.scratchBuffer.clear()

let utf8 = string.utf8
Expand Down
6 changes: 3 additions & 3 deletions Tests/NIOHTTP2Tests/CompoundOutboundBufferTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ extension CompoundOutboundBufferTest {
}

extension CompoundOutboundBuffer {
fileprivate mutating func receivedFrames(file: StaticString = #file, line: UInt = #line) -> [HTTP2Frame] {
fileprivate mutating func receivedFrames(file: StaticString = #filePath, line: UInt = #line) -> [HTTP2Frame] {
var receivedFrames: [HTTP2Frame] = Array()

loop: while true {
Expand All @@ -389,14 +389,14 @@ extension CompoundOutboundBuffer {
}

extension CompoundOutboundBuffer.FlushedWritableFrameResult {
internal func assertNoFrame(file: StaticString = #file, line: UInt = #line) {
internal func assertNoFrame(file: StaticString = #filePath, line: UInt = #line) {
guard case .noFrame = self else {
XCTFail("Expected .noFrame, got \(self)", file: (file), line: line)
return
}
}

internal func assertError<ErrorType: Error & Equatable>(_ error: ErrorType, file: StaticString = #file, line: UInt = #line) {
internal func assertError<ErrorType: Error & Equatable>(_ error: ErrorType, file: StaticString = #filePath, line: UInt = #line) {
guard case .error(let promise, let thrownError) = self else {
XCTFail("Expected .error, got \(self)", file: (file), line: line)
return
Expand Down
8 changes: 4 additions & 4 deletions Tests/NIOHTTP2Tests/ConcurrentStreamBufferTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ struct TestCaseError: Error { }
// We need these to work around the fact that neither EventLoopPromise or MarkedCircularBuffer have equatable
// conformances.
extension OutboundFrameAction {
internal func assertForward(file: StaticString = #file, line: UInt = #line) {
internal func assertForward(file: StaticString = #filePath, line: UInt = #line) {
guard case .forward = self else {
XCTFail("Expected .forward, got \(self)", file: (file), line: line)
return
}
}

internal func assertNothing(file: StaticString = #file, line: UInt = #line) {
internal func assertNothing(file: StaticString = #filePath, line: UInt = #line) {
guard case .nothing = self else {
XCTFail("Expected .nothing, got \(self)", file: (file), line: line)
return
}
}

internal func assertForwardAndDrop(file: StaticString = #file, line: UInt = #line) throws -> (MarkedCircularBuffer<(HTTP2Frame, EventLoopPromise<Void>?)>, NIOHTTP2Errors.StreamClosed) {
internal func assertForwardAndDrop(file: StaticString = #filePath, line: UInt = #line) throws -> (MarkedCircularBuffer<(HTTP2Frame, EventLoopPromise<Void>?)>, NIOHTTP2Errors.StreamClosed) {
guard case .forwardAndDrop(let promises, let error) = self else {
XCTFail("Expected .forwardAndDrop, got \(self)", file: (file), line: line)
throw TestCaseError()
Expand All @@ -48,7 +48,7 @@ extension OutboundFrameAction {
return (promises, error)
}

internal func assertSucceedAndDrop(file: StaticString = #file, line: UInt = #line) throws -> (MarkedCircularBuffer<(HTTP2Frame, EventLoopPromise<Void>?)>, NIOHTTP2Errors.StreamClosed) {
internal func assertSucceedAndDrop(file: StaticString = #filePath, line: UInt = #line) throws -> (MarkedCircularBuffer<(HTTP2Frame, EventLoopPromise<Void>?)>, NIOHTTP2Errors.StreamClosed) {
guard case .succeedAndDrop(let promises, let error) = self else {
XCTFail("Expected .succeedAndDrop, got \(self)", file: (file), line: line)
throw TestCaseError()
Expand Down
30 changes: 15 additions & 15 deletions Tests/NIOHTTP2Tests/ConnectionStateMachineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import NIOCore
import NIOHPACK
@testable import NIOHTTP2

func assertSucceeds(_ body: @autoclosure () -> StateMachineResult, file: StaticString = #file, line: UInt = #line) {
func assertSucceeds(_ body: @autoclosure () -> StateMachineResult, file: StaticString = #filePath, line: UInt = #line) {
switch body() {
case .succeed:
return
Expand All @@ -28,7 +28,7 @@ func assertSucceeds(_ body: @autoclosure () -> StateMachineResult, file: StaticS
}

@discardableResult
func assertConnectionError(type: HTTP2ErrorCode, _ body: @autoclosure () -> StateMachineResult, file: StaticString = #file, line: UInt = #line) -> Error? {
func assertConnectionError(type: HTTP2ErrorCode, _ body: @autoclosure () -> StateMachineResult, file: StaticString = #filePath, line: UInt = #line) -> Error? {
switch body() {
case .connectionError(underlyingError: let error, type: type):
return error
Expand All @@ -39,7 +39,7 @@ func assertConnectionError(type: HTTP2ErrorCode, _ body: @autoclosure () -> Stat
}

@discardableResult
func assertStreamError(type: HTTP2ErrorCode, _ body: @autoclosure () -> StateMachineResult, file: StaticString = #file, line: UInt = #line) -> Error? {
func assertStreamError(type: HTTP2ErrorCode, _ body: @autoclosure () -> StateMachineResult, file: StaticString = #filePath, line: UInt = #line) -> Error? {
switch body() {
case .streamError(streamID: _, underlyingError: let error, type: type):
return error
Expand All @@ -50,7 +50,7 @@ func assertStreamError(type: HTTP2ErrorCode, _ body: @autoclosure () -> StateMac
}

@discardableResult
func assertBadStreamStateTransition(type: NIOHTTP2StreamState, _ body: @autoclosure () -> StateMachineResultWithEffect, file: StaticString = #file, line: UInt = #line) -> NIOHTTP2Errors.BadStreamStateTransition? {
func assertBadStreamStateTransition(type: NIOHTTP2StreamState, _ body: @autoclosure () -> StateMachineResultWithEffect, file: StaticString = #filePath, line: UInt = #line) -> NIOHTTP2Errors.BadStreamStateTransition? {
let error: NIOHTTP2Errors.BadStreamStateTransition

switch body().result {
Expand All @@ -68,7 +68,7 @@ func assertBadStreamStateTransition(type: NIOHTTP2StreamState, _ body: @autoclos
return error
}

func assertIgnored(_ body: @autoclosure () -> StateMachineResult, file: StaticString = #file, line: UInt = #line) {
func assertIgnored(_ body: @autoclosure () -> StateMachineResult, file: StaticString = #filePath, line: UInt = #line) {
switch body() {
case .ignoreFrame:
return
Expand All @@ -77,39 +77,39 @@ func assertIgnored(_ body: @autoclosure () -> StateMachineResult, file: StaticSt
}
}

func assertSucceeds(_ body: @autoclosure () -> (StateMachineResultWithEffect, PostFrameOperation), file: StaticString = #file, line: UInt = #line) {
func assertSucceeds(_ body: @autoclosure () -> (StateMachineResultWithEffect, PostFrameOperation), file: StaticString = #filePath, line: UInt = #line) {
return assertSucceeds(body().0, file: (file), line: line)
}

func assertConnectionError(type: HTTP2ErrorCode, _ body: @autoclosure () -> (StateMachineResultWithEffect, PostFrameOperation), file: StaticString = #file, line: UInt = #line) {
func assertConnectionError(type: HTTP2ErrorCode, _ body: @autoclosure () -> (StateMachineResultWithEffect, PostFrameOperation), file: StaticString = #filePath, line: UInt = #line) {
assertConnectionError(type: type, body().0, file: (file), line: line)
}

func assertSucceeds(_ body: @autoclosure () -> StateMachineResultWithEffect, file: StaticString = #file, line: UInt = #line) {
func assertSucceeds(_ body: @autoclosure () -> StateMachineResultWithEffect, file: StaticString = #filePath, line: UInt = #line) {
return assertSucceeds(body().result, file: (file), line: line)
}

@discardableResult
func assertConnectionError(type: HTTP2ErrorCode, _ body: @autoclosure () -> StateMachineResultWithEffect, file: StaticString = #file, line: UInt = #line) -> Error? {
func assertConnectionError(type: HTTP2ErrorCode, _ body: @autoclosure () -> StateMachineResultWithEffect, file: StaticString = #filePath, line: UInt = #line) -> Error? {
// Errors must always lead to noChange.
let result = body()
return assertConnectionError(type: type, result.result, file: (file), line: line)
}

@discardableResult
func assertStreamError(type: HTTP2ErrorCode, _ body: @autoclosure () -> StateMachineResultWithEffect, file: StaticString = #file, line: UInt = #line) -> Error? {
func assertStreamError(type: HTTP2ErrorCode, _ body: @autoclosure () -> StateMachineResultWithEffect, file: StaticString = #filePath, line: UInt = #line) -> Error? {
// Errors must always lead to noChange.
let result = body()
return assertStreamError(type: type, result.result, file: (file), line: line)
}

func assertIgnored(_ body: @autoclosure () -> StateMachineResultWithEffect, file: StaticString = #file, line: UInt = #line) {
func assertIgnored(_ body: @autoclosure () -> StateMachineResultWithEffect, file: StaticString = #filePath, line: UInt = #line) {
// Ignored frames must always lead to noChange.
let result = body()
assertIgnored(result.result, file: (file), line: line)
}

func assertGoawaySucceeds(_ body: @autoclosure () -> StateMachineResultWithEffect, droppingStreams: [HTTP2StreamID]?, file: StaticString = #file, line: UInt = #line) {
func assertGoawaySucceeds(_ body: @autoclosure () -> StateMachineResultWithEffect, droppingStreams: [HTTP2StreamID]?, file: StaticString = #filePath, line: UInt = #line) {
let result = body()

if case .some(.bulkStreamClosure(let closedStreamsEvent)) = result.effect {
Expand Down Expand Up @@ -166,7 +166,7 @@ class ConnectionStateMachineTests: XCTestCase {
assertSucceeds(self.server.receiveSettings(.ack, frameEncoder: &self.serverEncoder, frameDecoder: &self.serverDecoder))
}

private func setupServerGoaway(streamsToOpen: [HTTP2StreamID], lastStreamID: HTTP2StreamID, expectedToClose: [HTTP2StreamID]?, file: StaticString = #file, line: UInt = #line) {
private func setupServerGoaway(streamsToOpen: [HTTP2StreamID], lastStreamID: HTTP2StreamID, expectedToClose: [HTTP2StreamID]?, file: StaticString = #filePath, line: UInt = #line) {
self.exchangePreamble()

// Client opens streams.
Expand All @@ -180,7 +180,7 @@ class ConnectionStateMachineTests: XCTestCase {
assertGoawaySucceeds(self.client.receiveGoaway(lastStreamID: lastStreamID), droppingStreams: expectedToClose, file: (file), line: line)
}

private func setupClientGoaway(clientStreamID: HTTP2StreamID, streamsToOpen: [HTTP2StreamID], lastStreamID: HTTP2StreamID, expectedToClose: [HTTP2StreamID]?, file: StaticString = #file, line: UInt = #line) {
private func setupClientGoaway(clientStreamID: HTTP2StreamID, streamsToOpen: [HTTP2StreamID], lastStreamID: HTTP2StreamID, expectedToClose: [HTTP2StreamID]?, file: StaticString = #filePath, line: UInt = #line) {
self.exchangePreamble()

// Client opens its stream, server sends response.
Expand Down Expand Up @@ -1317,7 +1317,7 @@ class ConnectionStateMachineTests: XCTestCase {
self.exchangePreamble()

// WindowUpdate frames are valid in a wide range of states. This test validates them in all of them, including proving that errors are correctly reported.
func assertCanWindowUpdate(client: HTTP2ConnectionStateMachine, server: HTTP2ConnectionStateMachine, file: StaticString = #file, line: UInt = #line) {
func assertCanWindowUpdate(client: HTTP2ConnectionStateMachine, server: HTTP2ConnectionStateMachine, file: StaticString = #filePath, line: UInt = #line) {
var client = client
var server = server

Expand Down
4 changes: 2 additions & 2 deletions Tests/NIOHTTP2Tests/HTTP2FrameParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class HTTP2FrameParserTests: XCTestCase {
}

private func assertEqualFrames(_ frame1: HTTP2Frame, _ frame2: HTTP2Frame,
file: StaticString = #file, line: UInt = #line) {
file: StaticString = #filePath, line: UInt = #line) {
XCTAssertEqual(frame1.streamID, frame2.streamID, "StreamID mismatch: \(frame1.streamID) != \(frame2.streamID)",
file: (file), line: line)

Expand Down Expand Up @@ -113,7 +113,7 @@ class HTTP2FrameParserTests: XCTestCase {

private func assertReadsFrame(from bytes: ByteBuffer, matching expectedFrame: HTTP2Frame,
expectedFlowControlledLength: Int = 0,
file: StaticString = #file, line: UInt = #line) throws {
file: StaticString = #filePath, line: UInt = #line) throws {
let totalFrameSize = bytes.readableBytes

var decoder = HTTP2FrameDecoder(allocator: self.allocator, expectClientMagic: false)
Expand Down
4 changes: 2 additions & 2 deletions Tests/NIOHTTP2Tests/HTTP2ToHTTP1CodecTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import NIOHTTP1

extension EmbeddedChannel {
/// Assert that we received a request head.
func assertReceivedServerRequestPart(_ part: HTTPServerRequestPart, file: StaticString = #file, line: UInt = #line) {
func assertReceivedServerRequestPart(_ part: HTTPServerRequestPart, file: StaticString = #filePath, line: UInt = #line) {
guard let actualPart: HTTPServerRequestPart = try? assertNoThrowWithValue(self.readInbound()) else {
XCTFail("No data received", file: (file), line: line)
return
Expand All @@ -31,7 +31,7 @@ extension EmbeddedChannel {
XCTAssertEqual(actualPart, part, file: (file), line: line)
}

func assertReceivedClientResponsePart(_ part: HTTPClientResponsePart, file: StaticString = #file, line: UInt = #line) {
func assertReceivedClientResponsePart(_ part: HTTPClientResponsePart, file: StaticString = #filePath, line: UInt = #line) {
guard let actualPart: HTTPClientResponsePart = try? assertNoThrowWithValue(self.readInbound()) else {
XCTFail("No data received", file: (file), line: line)
return
Expand Down
2 changes: 1 addition & 1 deletion Tests/NIOHTTP2Tests/OutboundFlowControlBufferTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class OutboundFlowControlBufferTests: XCTestCase {
return self.loop.makePromise()
}

private func receivedFrames(file: StaticString = #file, line: UInt = #line) -> [HTTP2Frame] {
private func receivedFrames(file: StaticString = #filePath, line: UInt = #line) -> [HTTP2Frame] {
var receivedFrames: [HTTP2Frame] = Array()

while let (bufferedFrame, promise) = self.buffer.nextFlushedWritableFrame() {
Expand Down
Loading

0 comments on commit d665696

Please sign in to comment.