diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7edf580e9..5c8e754de 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,7 +14,7 @@ jobs: - uses: actions/checkout@v3 - name: "Formatting and License Headers check" run: | - SWIFTFORMAT_VERSION=0.49.4 + SWIFTFORMAT_VERSION=0.52.0 git clone --depth 1 --branch "$SWIFTFORMAT_VERSION" "https://github.com/nicklockwood/SwiftFormat" "$HOME/SwiftFormat" swift build -c release --package-path "$HOME/SwiftFormat" --product swiftformat export PATH=$PATH:"$(swift build -c release --package-path "$HOME/SwiftFormat" --show-bin-path)" diff --git a/.swiftformat b/.swiftformat index 9410761e8..f18a823ae 100644 --- a/.swiftformat +++ b/.swiftformat @@ -41,3 +41,20 @@ # Put ACLs on declarations within an extension rather than the extension itself. --extensionacl on-declarations + +# Don't remove internal ACLs +--disable redundantInternal + +# Don't remove redundant parenstheses, because no all of them are redundant. +--disable redundantParens + +# Don't remove static Self +--disable redundantStaticSelf + +# Hoisting try and await causes a bunch of issues (and churn) in 0.52.0. Disable +# them for the time being. +--disable hoistTry +--disable hoistAwait + +# Disabled as enabling causes a lot of churn. +--disable wrapSingleLineComments diff --git a/Examples/Google/SpeechToText/Sources/Launch/AppDelegate.swift b/Examples/Google/SpeechToText/Sources/Launch/AppDelegate.swift index 0ec34cc1b..4d4a6a931 100644 --- a/Examples/Google/SpeechToText/Sources/Launch/AppDelegate.swift +++ b/Examples/Google/SpeechToText/Sources/Launch/AppDelegate.swift @@ -16,7 +16,7 @@ import UIKit -@UIApplicationMain +@main class AppDelegate: UIResponder, UIApplicationDelegate { func application( _ application: UIApplication, diff --git a/Examples/Google/SpeechToText/Sources/ViewController.swift b/Examples/Google/SpeechToText/Sources/ViewController.swift index 6b4d283f3..f1c4451ef 100644 --- a/Examples/Google/SpeechToText/Sources/ViewController.swift +++ b/Examples/Google/SpeechToText/Sources/ViewController.swift @@ -27,7 +27,7 @@ final class ViewController: UIViewController { button.backgroundColor = .darkGray button.layer.cornerRadius = 15 button.clipsToBounds = true - button.addTarget(self, action: #selector(recordTapped), for: .touchUpInside) + button.addTarget(self, action: #selector(self.recordTapped), for: .touchUpInside) return button }() @@ -110,7 +110,7 @@ final class ViewController: UIViewController { self.textView.snp.makeConstraints { make in make.top.equalTo(view.safeAreaLayoutGuide.snp.topMargin) make.left.right.equalToSuperview() - make.bottom.equalTo(recordButton.snp.top) + make.bottom.equalTo(self.recordButton.snp.top) } self.recordButton.snp.makeConstraints { make in diff --git a/Package.swift b/Package.swift index 6e3f2f007..393599af8 100644 --- a/Package.swift +++ b/Package.swift @@ -16,7 +16,7 @@ */ import PackageDescription // swiftformat puts the next import before the tools version. -// swiftformat:disable:next sortedImports +// swiftformat:disable:next sortImports import class Foundation.ProcessInfo let grpcPackageName = "grpc-swift" diff --git a/Performance/QPSBenchmark/Sources/QPSBenchmark/Runtime/Async/AsyncPingPongRequestMaker.swift b/Performance/QPSBenchmark/Sources/QPSBenchmark/Runtime/Async/AsyncPingPongRequestMaker.swift index ae497d80c..c5df08cd5 100644 --- a/Performance/QPSBenchmark/Sources/QPSBenchmark/Runtime/Async/AsyncPingPongRequestMaker.swift +++ b/Performance/QPSBenchmark/Sources/QPSBenchmark/Runtime/Async/AsyncPingPongRequestMaker.swift @@ -68,7 +68,7 @@ final class AsyncPingPongRequestMaker: AsyncRequestMaker, @unchecked Sendable { while !self.stopRequested.load(ordering: .relaxed), self.messagesPerStream == 0 || messagesSent < self.messagesPerStream { try await streamingCall.requestStream.send(self.requestMessage) - let _ = try await responseStream.next() + _ = try await responseStream.next() let endTime = grpcTimeNow() self.stats.add(latency: endTime - startTime) messagesSent += 1 diff --git a/Sources/GRPC/ServerCallContexts/StreamingResponseCallContext.swift b/Sources/GRPC/ServerCallContexts/StreamingResponseCallContext.swift index 1dcfa6aa4..a8ededb5e 100644 --- a/Sources/GRPC/ServerCallContexts/StreamingResponseCallContext.swift +++ b/Sources/GRPC/ServerCallContexts/StreamingResponseCallContext.swift @@ -237,7 +237,9 @@ internal final class _StreamingResponseCallContext: /// Concrete implementation of `StreamingResponseCallContext` used for testing. /// /// Simply records all sent messages. -open class StreamingResponseCallContextTestStub: StreamingResponseCallContext { +open class StreamingResponseCallContextTestStub: StreamingResponseCallContext< + ResponsePayload +> { open var recordedResponses: [ResponsePayload] = [] override open func sendResponse( diff --git a/Sources/GRPCPerformanceTests/Benchmarks/UnaryThroughput.swift b/Sources/GRPCPerformanceTests/Benchmarks/UnaryThroughput.swift index 8ee6b46ad..1fdf58fc0 100644 --- a/Sources/GRPCPerformanceTests/Benchmarks/UnaryThroughput.swift +++ b/Sources/GRPCPerformanceTests/Benchmarks/UnaryThroughput.swift @@ -79,7 +79,7 @@ class Unary: ServerProvidingBenchmark { let upperBound = min(lowerBound + batchSize, self.requestCount) let requests = (lowerBound ..< upperBound).map { _ in - client.get(Echo_EchoRequest.with { $0.text = self.requestText }).response + self.client.get(Echo_EchoRequest.with { $0.text = self.requestText }).response } messages += requests.count diff --git a/Tests/GRPCTests/ClientInterceptorPipelineTests.swift b/Tests/GRPCTests/ClientInterceptorPipelineTests.swift index 3e2e08283..0804d22c8 100644 --- a/Tests/GRPCTests/ClientInterceptorPipelineTests.swift +++ b/Tests/GRPCTests/ClientInterceptorPipelineTests.swift @@ -159,7 +159,7 @@ class ClientInterceptorPipelineTests: GRPCTestCase { assertThat(cancelled, .is(false)) cancelled = true // We don't expect a promise: this cancellation is fired by the pipeline. - assertThat(promise, .is(.nil())) + assertThat(promise, .is(.none())) }, onRequestPart: { _, _ in XCTFail("Unexpected request part") @@ -202,14 +202,14 @@ class ClientInterceptorPipelineTests: GRPCTestCase { assertThat(cancellations, .is(0)) cancellations += 1 // We don't expect a promise: this cancellation is fired by the pipeline. - assertThat(promise, .is(.nil())) + assertThat(promise, .is(.none())) }, onRequestPart: { _, _ in XCTFail("Unexpected request part") }, onResponsePart: { part in // We only expect the end. - assertThat(part.end, .is(.notNil())) + assertThat(part.end, .is(.some())) } ) diff --git a/Tests/GRPCTests/ConnectionPool/GRPCChannelPoolTests.swift b/Tests/GRPCTests/ConnectionPool/GRPCChannelPoolTests.swift index 8fbb6b2b9..7edc6e564 100644 --- a/Tests/GRPCTests/ConnectionPool/GRPCChannelPoolTests.swift +++ b/Tests/GRPCTests/ConnectionPool/GRPCChannelPoolTests.swift @@ -303,7 +303,7 @@ final class GRPCChannelPoolTests: GRPCTestCase { // If we express no event loop preference then we should not get the loaded loop. let indifferentLoopRPCs = (1 ... 10).map { - _ in echo.get(.with { $0.text = "" }) + _ in self.echo.get(.with { $0.text = "" }) } XCTAssert(indifferentLoopRPCs.map { $0.eventLoop }.allSatisfy { $0 !== loop }) diff --git a/Tests/GRPCTests/GRPCAsyncClientCallTests.swift b/Tests/GRPCTests/GRPCAsyncClientCallTests.swift index 647db7370..2754ba32d 100644 --- a/Tests/GRPCTests/GRPCAsyncClientCallTests.swift +++ b/Tests/GRPCTests/GRPCAsyncClientCallTests.swift @@ -160,12 +160,12 @@ class GRPCAsyncClientCallTests: GRPCTestCase { var responseStreamIterator = update.responseStream.makeAsyncIterator() for word in ["boyle", "jeffers", "holt"] { try await update.requestStream.send(.with { $0.text = word }) - await assertThat(try await responseStreamIterator.next(), .is(.notNil())) + await assertThat(try await responseStreamIterator.next(), .is(.some())) } update.requestStream.finish() - await assertThat(try await responseStreamIterator.next(), .is(.nil())) + await assertThat(try await responseStreamIterator.next(), .is(.none())) await assertThat(try await update.trailingMetadata, .is(.equalTo(Self.OKTrailingMetadata))) await assertThat(await update.status, .hasCode(.ok)) diff --git a/Tests/GRPCTests/GRPCPingHandlerTests.swift b/Tests/GRPCTests/GRPCPingHandlerTests.swift index 6d86ef0b2..1434c4273 100644 --- a/Tests/GRPCTests/GRPCPingHandlerTests.swift +++ b/Tests/GRPCTests/GRPCPingHandlerTests.swift @@ -387,7 +387,7 @@ extension PingHandler.Action: Equatable { extension GRPCPingHandlerTests { func testSingleAckIsEmittedOnPing() throws { let client = EmbeddedChannel() - let _ = try client.configureHTTP2Pipeline(mode: .client) { _ in + _ = try client.configureHTTP2Pipeline(mode: .client) { _ in fatalError("Unexpected inbound stream") }.wait() diff --git a/Tests/GRPCTests/GRPCWebToHTTP2ServerCodecTests.swift b/Tests/GRPCTests/GRPCWebToHTTP2ServerCodecTests.swift index 72f144ff6..1e1b81a82 100644 --- a/Tests/GRPCTests/GRPCWebToHTTP2ServerCodecTests.swift +++ b/Tests/GRPCTests/GRPCWebToHTTP2ServerCodecTests.swift @@ -47,7 +47,7 @@ class GRPCWebToHTTP2ServerCodecTests: GRPCTestCase { ) assertThat(try channel.writeInbound(HTTPServerRequestPart.head(head)), .doesNotThrow()) let headersPayload = try channel.readInbound(as: HTTP2Frame.FramePayload.self) - assertThat(headersPayload, .notNil(.headers(.contains(":path", [path])))) + assertThat(headersPayload, .some(.headers(.contains(":path", [path])))) } private func receiveBytes( @@ -59,14 +59,14 @@ class GRPCWebToHTTP2ServerCodecTests: GRPCTestCase { if let expectedBytes = expectedBytes { let dataPayload = try channel.readInbound(as: HTTP2Frame.FramePayload.self) - assertThat(dataPayload, .notNil(.data(buffer: ByteBuffer(bytes: expectedBytes)))) + assertThat(dataPayload, .some(.data(buffer: ByteBuffer(bytes: expectedBytes)))) } } private func receiveEnd(on channel: EmbeddedChannel) throws { assertThat(try channel.writeInbound(HTTPServerRequestPart.end(nil)), .doesNotThrow()) let dataEndPayload = try channel.readInbound(as: HTTP2Frame.FramePayload.self) - assertThat(dataEndPayload, .notNil(.data(buffer: ByteBuffer(), endStream: true))) + assertThat(dataEndPayload, .some(.data(buffer: ByteBuffer(), endStream: true))) } private func sendResponseHeaders(on channel: EmbeddedChannel) throws { @@ -74,7 +74,7 @@ class GRPCWebToHTTP2ServerCodecTests: GRPCTestCase { let headerPayload: HTTP2Frame.FramePayload = .headers(.init(headers: responseHeaders)) assertThat(try channel.writeOutbound(headerPayload), .doesNotThrow()) let responseHead = try channel.readOutbound(as: HTTPServerResponsePart.self) - assertThat(responseHead, .notNil(.head(status: .ok))) + assertThat(responseHead, .some(.head(status: .ok))) } private func sendTrailersOnlyResponse(on channel: EmbeddedChannel) throws { @@ -83,9 +83,9 @@ class GRPCWebToHTTP2ServerCodecTests: GRPCTestCase { assertThat(try channel.writeOutbound(headerPayload), .doesNotThrow()) let responseHead = try channel.readOutbound(as: HTTPServerResponsePart.self) - assertThat(responseHead, .notNil(.head(status: .ok))) + assertThat(responseHead, .some(.head(status: .ok))) let end = try channel.readOutbound(as: HTTPServerResponsePart.self) - assertThat(end, .notNil(.end())) + assertThat(end, .some(.end())) } private func sendBytes( @@ -99,9 +99,9 @@ class GRPCWebToHTTP2ServerCodecTests: GRPCTestCase { if let expectedBytes = expectedBytes { let expectedBuffer = ByteBuffer(bytes: expectedBytes) - assertThat(try channel.readOutbound(), .notNil(.body(.is(expectedBuffer)))) + assertThat(try channel.readOutbound(), .some(.body(.is(expectedBuffer)))) } else { - assertThat(try channel.readOutbound(as: HTTPServerResponsePart.self), .doesNotThrow(.nil())) + assertThat(try channel.readOutbound(as: HTTPServerResponsePart.self), .doesNotThrow(.none())) } } @@ -115,10 +115,10 @@ class GRPCWebToHTTP2ServerCodecTests: GRPCTestCase { assertThat(try channel.writeOutbound(headersPayload), .doesNotThrow()) if let expectedBytes = expectedBytes { - assertThat(try channel.readOutbound(), .notNil(.body(.is(expectedBytes)))) + assertThat(try channel.readOutbound(), .some(.body(.is(expectedBytes)))) } - assertThat(try channel.readOutbound(), .notNil(.end())) + assertThat(try channel.readOutbound(), .some(.end())) } func testWebBinaryHappyPath() throws { diff --git a/Tests/GRPCTests/ServerInterceptorPipelineTests.swift b/Tests/GRPCTests/ServerInterceptorPipelineTests.swift index 9143e0339..1f594278e 100644 --- a/Tests/GRPCTests/ServerInterceptorPipelineTests.swift +++ b/Tests/GRPCTests/ServerInterceptorPipelineTests.swift @@ -60,7 +60,7 @@ class ServerInterceptorPipelineTests: GRPCTestCase { onRequestPart: { requestParts.append($0) }, onResponsePart: { part, promise in responseParts.append(part) - assertThat(promise, .is(.nil())) + assertThat(promise, .is(.none())) } ) @@ -80,7 +80,7 @@ class ServerInterceptorPipelineTests: GRPCTestCase { assertThat(responseParts, .hasCount(3)) assertThat(responseParts[0].metadata, .is([:])) assertThat(responseParts[1].message, .is("bar")) - assertThat(responseParts[2].end, .is(.notNil())) + assertThat(responseParts[2].end, .is(.some())) // Pipelines should now be closed. We can't send or receive. let p = self.embeddedEventLoop.makePromise(of: Void.self) @@ -110,15 +110,15 @@ class ServerInterceptorPipelineTests: GRPCTestCase { // Check the request parts are there. assertThat(recorder.requestParts, .hasCount(3)) - assertThat(recorder.requestParts[0].metadata, .is(.notNil())) - assertThat(recorder.requestParts[1].message, .is(.notNil())) + assertThat(recorder.requestParts[0].metadata, .is(.some())) + assertThat(recorder.requestParts[1].message, .is(.some())) assertThat(recorder.requestParts[2].isEnd, .is(true)) // Check the response parts are there. assertThat(recorder.responseParts, .hasCount(3)) - assertThat(recorder.responseParts[0].metadata, .is(.notNil())) - assertThat(recorder.responseParts[1].message, .is(.notNil())) - assertThat(recorder.responseParts[2].end, .is(.notNil())) + assertThat(recorder.responseParts[0].metadata, .is(.some())) + assertThat(recorder.responseParts[1].message, .is(.some())) + assertThat(recorder.responseParts[2].end, .is(.some())) } } diff --git a/Tests/GRPCTests/ServerInterceptorTests.swift b/Tests/GRPCTests/ServerInterceptorTests.swift index 9cc090446..df77d82cf 100644 --- a/Tests/GRPCTests/ServerInterceptorTests.swift +++ b/Tests/GRPCTests/ServerInterceptorTests.swift @@ -98,9 +98,9 @@ class ServerInterceptorTests: GRPCTestCase { handler.receiveEnd() // Expect responses. - assertThat(self.recorder.metadata, .is(.notNil())) + assertThat(self.recorder.metadata, .is(.some())) assertThat(self.recorder.messages.count, .is(1)) - assertThat(self.recorder.status, .is(.notNil())) + assertThat(self.recorder.status, .is(.some())) // We expect 2 request parts: the provider responds before it sees end, that's fine. assertThat(recordingInterceptor.requestParts, .hasCount(2)) @@ -123,9 +123,9 @@ class ServerInterceptorTests: GRPCTestCase { handler.receiveEnd() // Get the responses. - assertThat(self.recorder.metadata, .is(.notNil())) + assertThat(self.recorder.metadata, .is(.some())) assertThat(self.recorder.messages.count, .is(1)) - assertThat(self.recorder.status, .is(.notNil())) + assertThat(self.recorder.status, .is(.some())) } func testClientStreamingFromInterceptor() throws { @@ -140,9 +140,9 @@ class ServerInterceptorTests: GRPCTestCase { handler.receiveEnd() // Get the responses. - assertThat(self.recorder.metadata, .is(.notNil())) + assertThat(self.recorder.metadata, .is(.some())) assertThat(self.recorder.messages.count, .is(1)) - assertThat(self.recorder.status, .is(.notNil())) + assertThat(self.recorder.status, .is(.some())) } func testServerStreamingFromInterceptor() throws { @@ -155,9 +155,9 @@ class ServerInterceptorTests: GRPCTestCase { handler.receiveEnd() // Get the responses. - assertThat(self.recorder.metadata, .is(.notNil())) + assertThat(self.recorder.metadata, .is(.some())) assertThat(self.recorder.messages.count, .is(3)) - assertThat(self.recorder.status, .is(.notNil())) + assertThat(self.recorder.status, .is(.some())) } func testBidirectionalStreamingFromInterceptor() throws { @@ -172,9 +172,9 @@ class ServerInterceptorTests: GRPCTestCase { handler.receiveEnd() // Get the responses. - assertThat(self.recorder.metadata, .is(.notNil())) + assertThat(self.recorder.metadata, .is(.some())) assertThat(self.recorder.messages.count, .is(3)) - assertThat(self.recorder.status, .is(.notNil())) + assertThat(self.recorder.status, .is(.some())) } } diff --git a/Tests/GRPCTests/ServerThrowingTests.swift b/Tests/GRPCTests/ServerThrowingTests.swift index 55ccf6939..2d943810d 100644 --- a/Tests/GRPCTests/ServerThrowingTests.swift +++ b/Tests/GRPCTests/ServerThrowingTests.swift @@ -150,7 +150,7 @@ class ServerThrowingTests: EchoTestCaseBase { } } XCTAssertThrowsError(try call.response.wait()) { - XCTAssertEqual(expectedError, $0 as? GRPCStatus) + XCTAssertEqual(self.expectedError, $0 as? GRPCStatus) } } @@ -170,7 +170,7 @@ class ServerThrowingTests: EchoTestCaseBase { // With `ErrorReturningEchoProvider` we actually _return_ a response, which means that the `response` future // will _not_ fail, so in that case this test doesn't apply. XCTAssertThrowsError(try call.response.wait()) { - XCTAssertEqual(expectedError, $0 as? GRPCStatus) + XCTAssertEqual(self.expectedError, $0 as? GRPCStatus) } } } diff --git a/Tests/GRPCTests/ServerWebTests.swift b/Tests/GRPCTests/ServerWebTests.swift index f5eeed860..a2ebef8b3 100644 --- a/Tests/GRPCTests/ServerWebTests.swift +++ b/Tests/GRPCTests/ServerWebTests.swift @@ -157,7 +157,7 @@ extension ServerWebTests { var expectedData = Data() var index = 0 message.split(separator: " ").forEach { component in - expectedData.append(gRPCEncodedEchoRequest("Swift echo expand (\(index)): \(component)")) + expectedData.append(self.gRPCEncodedEchoRequest("Swift echo expand (\(index)): \(component)")) index += 1 } expectedData.append(self.gRPCWebTrailers()) diff --git a/Tests/GRPCTests/UnaryServerHandlerTests.swift b/Tests/GRPCTests/UnaryServerHandlerTests.swift index e6df95817..2dcd06641 100644 --- a/Tests/GRPCTests/UnaryServerHandlerTests.swift +++ b/Tests/GRPCTests/UnaryServerHandlerTests.swift @@ -149,7 +149,7 @@ class UnaryServerHandlerTests: ServerHandlerTestCaseBase { assertThat(self.recorder.messages.first, .is(buffer)) assertThat(self.recorder.messageMetadata.first?.compress, .is(false)) - assertThat(self.recorder.status, .notNil(.hasCode(.ok))) + assertThat(self.recorder.status, .some(.hasCode(.ok))) assertThat(self.recorder.trailers, .is([:])) } @@ -199,7 +199,7 @@ class UnaryServerHandlerTests: ServerHandlerTestCaseBase { handler.receiveMessage(buffer) assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.internalError))) + assertThat(self.recorder.status, .some(.hasCode(.internalError))) } func testThrowingSerializer() { @@ -219,7 +219,7 @@ class UnaryServerHandlerTests: ServerHandlerTestCaseBase { handler.receiveEnd() assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.internalError))) + assertThat(self.recorder.status, .some(.hasCode(.internalError))) } func testUserFunctionReturnsFailedFuture() { @@ -234,7 +234,7 @@ class UnaryServerHandlerTests: ServerHandlerTestCaseBase { handler.receiveMessage(buffer) assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.unavailable))) + assertThat(self.recorder.status, .some(.hasCode(.unavailable))) assertThat(self.recorder.status?.message, .is(":(")) } @@ -242,9 +242,9 @@ class UnaryServerHandlerTests: ServerHandlerTestCaseBase { let handler = self.makeHandler(function: self.neverCalled(_:context:)) handler.receiveMessage(ByteBuffer(string: "foo")) - assertThat(self.recorder.metadata, .is(.nil())) + assertThat(self.recorder.metadata, .is(.none())) assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.internalError))) + assertThat(self.recorder.status, .some(.hasCode(.internalError))) } func testReceiveMultipleHeaders() { @@ -255,7 +255,7 @@ class UnaryServerHandlerTests: ServerHandlerTestCaseBase { handler.receiveMetadata([:]) assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.internalError))) + assertThat(self.recorder.status, .some(.hasCode(.internalError))) } func testReceiveMultipleMessages() { @@ -271,17 +271,17 @@ class UnaryServerHandlerTests: ServerHandlerTestCaseBase { handler.receiveMessage(buffer) assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.internalError))) + assertThat(self.recorder.status, .some(.hasCode(.internalError))) } func testFinishBeforeStarting() { let handler = self.makeHandler(function: self.neverCalled(_:context:)) handler.finish() - assertThat(self.recorder.metadata, .is(.nil())) + assertThat(self.recorder.metadata, .is(.none())) assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .is(.nil())) - assertThat(self.recorder.trailers, .is(.nil())) + assertThat(self.recorder.status, .is(.none())) + assertThat(self.recorder.trailers, .is(.none())) } func testFinishAfterHeaders() { @@ -292,7 +292,7 @@ class UnaryServerHandlerTests: ServerHandlerTestCaseBase { handler.finish() assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.unavailable))) + assertThat(self.recorder.status, .some(.hasCode(.unavailable))) assertThat(self.recorder.trailers, .is([:])) } @@ -304,7 +304,7 @@ class UnaryServerHandlerTests: ServerHandlerTestCaseBase { handler.finish() assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.unavailable))) + assertThat(self.recorder.status, .some(.hasCode(.unavailable))) assertThat(self.recorder.trailers, .is([:])) } } @@ -376,7 +376,7 @@ class ClientStreamingServerHandlerTests: ServerHandlerTestCaseBase { assertThat(self.recorder.messages.first, .is(ByteBuffer(string: "1 2 3"))) assertThat(self.recorder.messageMetadata.first?.compress, .is(false)) - assertThat(self.recorder.status, .notNil(.hasCode(.ok))) + assertThat(self.recorder.status, .some(.hasCode(.ok))) assertThat(self.recorder.trailers, .is([:])) } @@ -430,7 +430,7 @@ class ClientStreamingServerHandlerTests: ServerHandlerTestCaseBase { handler.receiveMessage(buffer) assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.internalError))) + assertThat(self.recorder.status, .some(.hasCode(.internalError))) } func testThrowingSerializer() { @@ -450,7 +450,7 @@ class ClientStreamingServerHandlerTests: ServerHandlerTestCaseBase { handler.receiveEnd() assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.internalError))) + assertThat(self.recorder.status, .some(.hasCode(.internalError))) } func testObserverFactoryReturnsFailedFuture() { @@ -460,7 +460,7 @@ class ClientStreamingServerHandlerTests: ServerHandlerTestCaseBase { handler.receiveMetadata([:]) assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.unavailable))) + assertThat(self.recorder.status, .some(.hasCode(.unavailable))) assertThat(self.recorder.status?.message, .is(":(")) } @@ -485,7 +485,7 @@ class ClientStreamingServerHandlerTests: ServerHandlerTestCaseBase { handler.receiveEnd() assertThat(self.recorder.messages.first, .is(ByteBuffer(string: "1 2 3 4 5"))) - assertThat(self.recorder.status, .notNil(.hasCode(.ok))) + assertThat(self.recorder.status, .some(.hasCode(.ok))) } func testDelayedObserverFactoryAllMessagesBeforeSucceeding() { @@ -506,16 +506,16 @@ class ClientStreamingServerHandlerTests: ServerHandlerTestCaseBase { promise.succeed(()) assertThat(self.recorder.messages.first, .is(ByteBuffer(string: "1 2 3"))) - assertThat(self.recorder.status, .notNil(.hasCode(.ok))) + assertThat(self.recorder.status, .some(.hasCode(.ok))) } func testReceiveMessageBeforeHeaders() { let handler = self.makeHandler(observerFactory: self.neverCalled(context:)) handler.receiveMessage(ByteBuffer(string: "foo")) - assertThat(self.recorder.metadata, .is(.nil())) + assertThat(self.recorder.metadata, .is(.none())) assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.internalError))) + assertThat(self.recorder.status, .some(.hasCode(.internalError))) } func testReceiveMultipleHeaders() { @@ -526,17 +526,17 @@ class ClientStreamingServerHandlerTests: ServerHandlerTestCaseBase { handler.receiveMetadata([:]) assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.internalError))) + assertThat(self.recorder.status, .some(.hasCode(.internalError))) } func testFinishBeforeStarting() { let handler = self.makeHandler(observerFactory: self.neverCalled(context:)) handler.finish() - assertThat(self.recorder.metadata, .is(.nil())) + assertThat(self.recorder.metadata, .is(.none())) assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .is(.nil())) - assertThat(self.recorder.trailers, .is(.nil())) + assertThat(self.recorder.status, .is(.none())) + assertThat(self.recorder.trailers, .is(.none())) } func testFinishAfterHeaders() { @@ -547,7 +547,7 @@ class ClientStreamingServerHandlerTests: ServerHandlerTestCaseBase { handler.finish() assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.unavailable))) + assertThat(self.recorder.status, .some(.hasCode(.unavailable))) assertThat(self.recorder.trailers, .is([:])) } @@ -559,7 +559,7 @@ class ClientStreamingServerHandlerTests: ServerHandlerTestCaseBase { handler.finish() assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.unavailable))) + assertThat(self.recorder.status, .some(.hasCode(.unavailable))) assertThat(self.recorder.trailers, .is([:])) } } @@ -620,7 +620,7 @@ class ServerStreamingServerHandlerTests: ServerHandlerTestCaseBase { .is([ByteBuffer(string: "a"), ByteBuffer(string: "b")]) ) assertThat(self.recorder.messageMetadata.map { $0.compress }, .is([false, false])) - assertThat(self.recorder.status, .notNil(.hasCode(.ok))) + assertThat(self.recorder.status, .some(.hasCode(.ok))) assertThat(self.recorder.trailers, .is([:])) } @@ -670,7 +670,7 @@ class ServerStreamingServerHandlerTests: ServerHandlerTestCaseBase { handler.receiveMessage(buffer) assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.internalError))) + assertThat(self.recorder.status, .some(.hasCode(.internalError))) } func testThrowingSerializer() { @@ -690,7 +690,7 @@ class ServerStreamingServerHandlerTests: ServerHandlerTestCaseBase { handler.receiveEnd() assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.internalError))) + assertThat(self.recorder.status, .some(.hasCode(.internalError))) } func testUserFunctionReturnsFailedFuture() { @@ -705,7 +705,7 @@ class ServerStreamingServerHandlerTests: ServerHandlerTestCaseBase { handler.receiveMessage(buffer) assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.unavailable))) + assertThat(self.recorder.status, .some(.hasCode(.unavailable))) assertThat(self.recorder.status?.message, .is(":(")) } @@ -713,9 +713,9 @@ class ServerStreamingServerHandlerTests: ServerHandlerTestCaseBase { let handler = self.makeHandler(userFunction: self.neverCalled(_:context:)) handler.receiveMessage(ByteBuffer(string: "foo")) - assertThat(self.recorder.metadata, .is(.nil())) + assertThat(self.recorder.metadata, .is(.none())) assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.internalError))) + assertThat(self.recorder.status, .some(.hasCode(.internalError))) } func testReceiveMultipleHeaders() { @@ -726,7 +726,7 @@ class ServerStreamingServerHandlerTests: ServerHandlerTestCaseBase { handler.receiveMetadata([:]) assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.internalError))) + assertThat(self.recorder.status, .some(.hasCode(.internalError))) } func testReceiveMultipleMessages() { @@ -742,17 +742,17 @@ class ServerStreamingServerHandlerTests: ServerHandlerTestCaseBase { handler.receiveMessage(buffer) assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.internalError))) + assertThat(self.recorder.status, .some(.hasCode(.internalError))) } func testFinishBeforeStarting() { let handler = self.makeHandler(userFunction: self.neverCalled(_:context:)) handler.finish() - assertThat(self.recorder.metadata, .is(.nil())) + assertThat(self.recorder.metadata, .is(.none())) assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .is(.nil())) - assertThat(self.recorder.trailers, .is(.nil())) + assertThat(self.recorder.status, .is(.none())) + assertThat(self.recorder.trailers, .is(.none())) } func testFinishAfterHeaders() { @@ -763,7 +763,7 @@ class ServerStreamingServerHandlerTests: ServerHandlerTestCaseBase { handler.finish() assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.unavailable))) + assertThat(self.recorder.status, .some(.hasCode(.unavailable))) assertThat(self.recorder.trailers, .is([:])) } @@ -775,7 +775,7 @@ class ServerStreamingServerHandlerTests: ServerHandlerTestCaseBase { handler.finish() assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.unavailable))) + assertThat(self.recorder.status, .some(.hasCode(.unavailable))) assertThat(self.recorder.trailers, .is([:])) } } @@ -849,7 +849,7 @@ class BidirectionalStreamingServerHandlerTests: ServerHandlerTestCaseBase { .is([ByteBuffer(string: "1"), ByteBuffer(string: "2"), ByteBuffer(string: "3")]) ) assertThat(self.recorder.messageMetadata.map { $0.compress }, .is([false, false, false])) - assertThat(self.recorder.status, .notNil(.hasCode(.ok))) + assertThat(self.recorder.status, .some(.hasCode(.ok))) assertThat(self.recorder.trailers, .is([:])) } @@ -909,7 +909,7 @@ class BidirectionalStreamingServerHandlerTests: ServerHandlerTestCaseBase { handler.receiveMessage(buffer) assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.internalError))) + assertThat(self.recorder.status, .some(.hasCode(.internalError))) } func testThrowingSerializer() { @@ -929,7 +929,7 @@ class BidirectionalStreamingServerHandlerTests: ServerHandlerTestCaseBase { handler.receiveEnd() assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.internalError))) + assertThat(self.recorder.status, .some(.hasCode(.internalError))) } func testObserverFactoryReturnsFailedFuture() { @@ -939,7 +939,7 @@ class BidirectionalStreamingServerHandlerTests: ServerHandlerTestCaseBase { handler.receiveMetadata([:]) assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.unavailable))) + assertThat(self.recorder.status, .some(.hasCode(.unavailable))) assertThat(self.recorder.status?.message, .is(":(")) } @@ -964,7 +964,7 @@ class BidirectionalStreamingServerHandlerTests: ServerHandlerTestCaseBase { self.recorder.messages, .is([ByteBuffer(string: "1"), ByteBuffer(string: "2")]) ) - assertThat(self.recorder.status, .notNil(.hasCode(.ok))) + assertThat(self.recorder.status, .some(.hasCode(.ok))) } func testDelayedObserverFactoryAllMessagesBeforeSucceeding() { @@ -987,16 +987,16 @@ class BidirectionalStreamingServerHandlerTests: ServerHandlerTestCaseBase { self.recorder.messages, .is([ByteBuffer(string: "1"), ByteBuffer(string: "2")]) ) - assertThat(self.recorder.status, .notNil(.hasCode(.ok))) + assertThat(self.recorder.status, .some(.hasCode(.ok))) } func testReceiveMessageBeforeHeaders() { let handler = self.makeHandler(observerFactory: self.neverCalled(context:)) handler.receiveMessage(ByteBuffer(string: "foo")) - assertThat(self.recorder.metadata, .is(.nil())) + assertThat(self.recorder.metadata, .is(.none())) assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.internalError))) + assertThat(self.recorder.status, .some(.hasCode(.internalError))) } func testReceiveMultipleHeaders() { @@ -1007,17 +1007,17 @@ class BidirectionalStreamingServerHandlerTests: ServerHandlerTestCaseBase { handler.receiveMetadata([:]) assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.internalError))) + assertThat(self.recorder.status, .some(.hasCode(.internalError))) } func testFinishBeforeStarting() { let handler = self.makeHandler(observerFactory: self.neverCalled(context:)) handler.finish() - assertThat(self.recorder.metadata, .is(.nil())) + assertThat(self.recorder.metadata, .is(.none())) assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .is(.nil())) - assertThat(self.recorder.trailers, .is(.nil())) + assertThat(self.recorder.status, .is(.none())) + assertThat(self.recorder.trailers, .is(.none())) } func testFinishAfterHeaders() { @@ -1028,7 +1028,7 @@ class BidirectionalStreamingServerHandlerTests: ServerHandlerTestCaseBase { handler.finish() assertThat(self.recorder.messages, .isEmpty()) - assertThat(self.recorder.status, .notNil(.hasCode(.unavailable))) + assertThat(self.recorder.status, .some(.hasCode(.unavailable))) assertThat(self.recorder.trailers, .is([:])) } @@ -1040,7 +1040,7 @@ class BidirectionalStreamingServerHandlerTests: ServerHandlerTestCaseBase { handler.finish() assertThat(self.recorder.messages.first, .is(ByteBuffer(string: "hello"))) - assertThat(self.recorder.status, .notNil(.hasCode(.unavailable))) + assertThat(self.recorder.status, .some(.hasCode(.unavailable))) assertThat(self.recorder.trailers, .is([:])) } } diff --git a/Tests/GRPCTests/UserInfoTests.swift b/Tests/GRPCTests/UserInfoTests.swift index 8e1bc14dd..e9546ecd9 100644 --- a/Tests/GRPCTests/UserInfoTests.swift +++ b/Tests/GRPCTests/UserInfoTests.swift @@ -26,10 +26,10 @@ class UserInfoTests: GRPCTestCase { assertThat(userInfo[BarKey.self], .is(42)) userInfo[FooKey.self] = nil - assertThat(userInfo[FooKey.self], .is(.nil())) + assertThat(userInfo[FooKey.self], .is(.none())) userInfo[BarKey.self] = nil - assertThat(userInfo[BarKey.self], .is(.nil())) + assertThat(userInfo[BarKey.self], .is(.none())) } func testWithExtensions() { @@ -42,10 +42,10 @@ class UserInfoTests: GRPCTestCase { assertThat(userInfo.bar, .is(42)) userInfo.foo = nil - assertThat(userInfo.foo, .is(.nil())) + assertThat(userInfo.foo, .is(.none())) userInfo.bar = nil - assertThat(userInfo.bar, .is(.nil())) + assertThat(userInfo.bar, .is(.none())) } func testDescription() { diff --git a/Tests/GRPCTests/XCTestHelpers.swift b/Tests/GRPCTests/XCTestHelpers.swift index 5da278d0e..a760b3d2e 100644 --- a/Tests/GRPCTests/XCTestHelpers.swift +++ b/Tests/GRPCTests/XCTestHelpers.swift @@ -133,7 +133,7 @@ struct Matcher { } /// Matches if the value is `nil`. - static func `nil`() -> Matcher { + static func none() -> Matcher { return .init { actual in actual == nil ? .match @@ -142,7 +142,7 @@ struct Matcher { } /// Matches if the value is not `nil`. - static func notNil(_ matcher: Matcher? = nil) -> Matcher { + static func some(_ matcher: Matcher? = nil) -> Matcher { return .init { actual in if let actual = actual { return matcher?.evaluate(actual) ?? .match diff --git a/scripts/format.sh b/scripts/format.sh index 2384068fd..f73f366b6 100755 --- a/scripts/format.sh +++ b/scripts/format.sh @@ -22,7 +22,7 @@ SWIFTFORMAT_DIR="$HERE/.swiftformat-source" # Important: if this is changed then make sure to update the version # in the .github/workflows/ci.yaml as well! -SWIFTFORMAT_VERSION=0.49.4 +SWIFTFORMAT_VERSION=0.52.0 # Clone SwiftFormat if we don't already have it. if [ ! -d "$SWIFTFORMAT_DIR" ]; then