Skip to content

Commit

Permalink
forward #file to #filePath differently
Browse files Browse the repository at this point in the history
Motivation:

only works if done when _calling_ a function, not when defining one :|.

- 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:

Silence #file to #filePath differently.

Result:

Hopefully at some point we get this working.
  • Loading branch information
weissi committed Jun 18, 2020
1 parent a5aa6ca commit a1f2491
Show file tree
Hide file tree
Showing 10 changed files with 246 additions and 244 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ Package.pins
Package.resolved
*.pem
DerivedData
.swiftpm
Tests/hpack-test-case

8 changes: 4 additions & 4 deletions Tests/NIOHPACKTests/HeaderTableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import NIO
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 = #file, line: UInt = #line) {
let ex1: (T1, T2)?
let ex2: (T1, T2)?
do {
ex1 = try expression1()
ex2 = try expression2()
} catch {
XCTFail("Unexpected exception: \(error) \(message())", file: file, line: line)
XCTFail("Unexpected exception: \(error) \(message())", file: (file), line: line)
return
}

Expand All @@ -35,8 +35,8 @@ func XCTAssertEqualTuple<T1: Equatable, T2: Equatable>(_ expression1: @autoclosu
let left2 = ex1?.1
let right2 = ex2?.1

XCTAssertEqual(left1, right1, message(), file: file, line: line)
XCTAssertEqual(left2, right2, message(), file: file, line: line)
XCTAssertEqual(left1, right1, message(), file: (file), line: line)
XCTAssertEqual(left2, right2, message(), file: (file), line: line)
}

class HeaderTableTests: XCTestCase {
Expand Down
14 changes: 7 additions & 7 deletions Tests/NIOHPACKTests/HuffmanCodingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@ class HuffmanCodingTests: XCTestCase {

// MARK: - Helper Methods

func assertEqualContents(_ buffer: ByteBuffer, _ array: [UInt8], file: StaticString = (#file), line: UInt = #line) {
XCTAssertEqual(buffer.readableBytes, array.count, "Buffer and array are different sizes", file: file, line: line)
func assertEqualContents(_ buffer: ByteBuffer, _ array: [UInt8], file: StaticString = #file, 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
XCTAssertEqual(memcmp(bufPtr.baseAddress!, arrayPtr.baseAddress!, arrayPtr.count), 0, "Buffer contents don't match", file: file, line: line)
XCTAssertEqual(memcmp(bufPtr.baseAddress!, arrayPtr.baseAddress!, arrayPtr.count), 0, "Buffer contents don't match", file: (file), line: line)
}
}
}

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

let utf8 = string.utf8
let numBytes = self.scratchBuffer.writeHuffmanEncoded(bytes: utf8)
XCTAssertEqual(numBytes, bytes.count, "Wrong length encoding '\(string)'", file: file, line: line)
XCTAssertEqual(numBytes, bytes.count, "Wrong length encoding '\(string)'", file: (file), line: line)

assertEqualContents(self.scratchBuffer, bytes, file: file, line: line)
assertEqualContents(self.scratchBuffer, bytes, file: (file), line: line)

let decoded = try scratchBuffer.getHuffmanEncodedString(at: self.scratchBuffer.readerIndex, length: self.scratchBuffer.readableBytes)
XCTAssertEqual(decoded, string, "Failed to decode '\(string)'", file: file, line: line)
XCTAssertEqual(decoded, string, "Failed to decode '\(string)'", file: (file), line: line)
}

func testBasicCoding() throws {
Expand Down
14 changes: 7 additions & 7 deletions Tests/NIOHTTP2Tests/CompoundOutboundBufferTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ extension CompoundOutboundBufferTest {
}

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

loop: while true {
Expand All @@ -379,7 +379,7 @@ extension CompoundOutboundBuffer {
promise?.succeed(())
case .error(let promise, let error):
promise?.fail(error)
XCTFail("Caught error: \(error)", file: file, line: line)
XCTFail("Caught error: \(error)", file: (file), line: line)
}
}

Expand All @@ -388,21 +388,21 @@ extension CompoundOutboundBuffer {
}

extension CompoundOutboundBuffer.FlushedWritableFrameResult {
internal func assertNoFrame(file: StaticString = (#file), line: UInt = #line) {
internal func assertNoFrame(file: StaticString = #file, line: UInt = #line) {
guard case .noFrame = self else {
XCTFail("Expected .noFrame, got \(self)", file: file, line: line)
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 = #file, line: UInt = #line) {
guard case .error(let promise, let thrownError) = self else {
XCTFail("Expected .error, got \(self)", file: file, line: line)
XCTFail("Expected .error, got \(self)", file: (file), line: line)
return
}

guard let castError = thrownError as? ErrorType, castError == error else {
XCTFail("Expected \(error), got \(thrownError)", file: file, line: line)
XCTFail("Expected \(error), got \(thrownError)", file: (file), line: line)
return
}

Expand Down
16 changes: 8 additions & 8 deletions Tests/NIOHTTP2Tests/ConcurrentStreamBufferTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,32 @@ 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 = #file, line: UInt = #line) {
guard case .forward = self else {
XCTFail("Expected .forward, got \(self)", file: file, line: line)
XCTFail("Expected .forward, got \(self)", file: (file), line: line)
return
}
}

internal func assertNothing(file: StaticString = (#file), line: UInt = #line) {
internal func assertNothing(file: StaticString = #file, line: UInt = #line) {
guard case .nothing = self else {
XCTFail("Expected .nothing, got \(self)", file: file, line: line)
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 = #file, 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)
XCTFail("Expected .forwardAndDrop, got \(self)", file: (file), line: line)
throw TestCaseError()
}

return (promises, error)
}

internal func assertSucceedAndDrop(file: StaticString = (#file), line: UInt = #line) throws -> (MarkedCircularBuffer<(HTTP2Frame, EventLoopPromise<Void>?)>, NIOHTTP2Errors.StreamClosed) {
internal func assertSucceedAndDrop(file: StaticString = #file, 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)
XCTFail("Expected .succeedAndDrop, got \(self)", file: (file), line: line)
throw TestCaseError()
}

Expand Down
Loading

0 comments on commit a1f2491

Please sign in to comment.