From e321e4d20e26928737a2755384f111670600851a Mon Sep 17 00:00:00 2001 From: David Nadoba Date: Thu, 25 Nov 2021 16:16:16 +0100 Subject: [PATCH 1/7] add XCTAsyncTest and NOTICE.txt --- NOTICE.txt | 43 ++++++++++++ .../XCTest+AsyncAwait.swift | 66 +++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 NOTICE.txt create mode 100644 Tests/AsyncHTTPClientTests/XCTest+AsyncAwait.swift diff --git a/NOTICE.txt b/NOTICE.txt new file mode 100644 index 000000000..264c1dcbe --- /dev/null +++ b/NOTICE.txt @@ -0,0 +1,43 @@ + + The AsyncHTTPClient Project + =========================== + +Please visit the AsyncHTTPClient web site for more information: + + * https://github.com/swift-server/async-http-client + +Copyright 2017-2021 The AsyncHTTPClient Project + +The AsyncHTTPClient Project licenses this file to you under the Apache License, +version 2.0 (the "License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at: + + https://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +License for the specific language governing permissions and limitations +under the License. + +Also, please refer to each LICENSE.txt file, which is located in +the 'license' directory of the distribution file, for the license terms of the +components that this product depends on. + +------------------------------------------------------------------------------- + + +This product contains a derivation various scripts from SwiftNIO and contains "XCTest+AsyncAwait.swift" from gRPC Swift. + + * LICENSE (Apache License 2.0): + * https://www.apache.org/licenses/LICENSE-2.0 + * HOMEPAGE: + * https://github.com/apple/swift-nio + + * LICENSE (Apache License 2.0): + * https://www.apache.org/licenses/LICENSE-2.0 + * HOMEPAGE: + * https://github.com/grpc/grpc-swift + + +------------------------------------------------------------------------------- diff --git a/Tests/AsyncHTTPClientTests/XCTest+AsyncAwait.swift b/Tests/AsyncHTTPClientTests/XCTest+AsyncAwait.swift new file mode 100644 index 000000000..bb92b0702 --- /dev/null +++ b/Tests/AsyncHTTPClientTests/XCTest+AsyncAwait.swift @@ -0,0 +1,66 @@ +/* + * Copyright 2021, gRPC Authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#if compiler(>=5.5) +import XCTest + +extension XCTestCase { + @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) + /// Cross-platform XCTest support for async-await tests. + /// + /// Currently the Linux implementation of XCTest doesn't have async-await support. + /// Until it does, we make use of this shim which uses a detached `Task` along with + /// `XCTest.wait(for:timeout:)` to wrap the operation. + /// + /// - NOTE: Support for Linux is tracked by https://bugs.swift.org/browse/SR-14403. + /// - NOTE: Implementation currently in progress: https://github.com/apple/swift-corelibs-xctest/pull/326 + func XCTAsyncTest( + expectationDescription: String = "Async operation", + timeout: TimeInterval = 30, + file: StaticString = #filePath, + line: UInt = #line, + function: StaticString = #function, + operation: @escaping () async throws -> Void + ) { + let expectation = self.expectation(description: expectationDescription) + Task { + do { + try await operation() + } catch { + XCTFail("Error thrown while executing \(function): \(error)", file: file, line: line) + Thread.callStackSymbols.forEach { print($0) } + } + expectation.fulfill() + } + self.wait(for: [expectation], timeout: timeout) + } +} + +@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) +internal func XCTAssertThrowsError( + _ expression: @autoclosure () async throws -> T, + verify: (Error) -> Void = { _ in }, + file: StaticString = #file, + line: UInt = #line +) async { + do { + _ = try await expression() + XCTFail("Expression did not throw error", file: file, line: line) + } catch { + verify(error) + } +} + +#endif // compiler(>=5.5) From 4fcc5f370be80a8d3f7a644335aba9cfef1710d7 Mon Sep 17 00:00:00 2001 From: David Nadoba Date: Thu, 25 Nov 2021 16:22:13 +0100 Subject: [PATCH 2/7] run swift-format --- .../XCTest+AsyncAwait.swift | 90 +++++++++---------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/Tests/AsyncHTTPClientTests/XCTest+AsyncAwait.swift b/Tests/AsyncHTTPClientTests/XCTest+AsyncAwait.swift index bb92b0702..538d5a6d2 100644 --- a/Tests/AsyncHTTPClientTests/XCTest+AsyncAwait.swift +++ b/Tests/AsyncHTTPClientTests/XCTest+AsyncAwait.swift @@ -14,53 +14,53 @@ * limitations under the License. */ #if compiler(>=5.5) -import XCTest + import XCTest -extension XCTestCase { - @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) - /// Cross-platform XCTest support for async-await tests. - /// - /// Currently the Linux implementation of XCTest doesn't have async-await support. - /// Until it does, we make use of this shim which uses a detached `Task` along with - /// `XCTest.wait(for:timeout:)` to wrap the operation. - /// - /// - NOTE: Support for Linux is tracked by https://bugs.swift.org/browse/SR-14403. - /// - NOTE: Implementation currently in progress: https://github.com/apple/swift-corelibs-xctest/pull/326 - func XCTAsyncTest( - expectationDescription: String = "Async operation", - timeout: TimeInterval = 30, - file: StaticString = #filePath, - line: UInt = #line, - function: StaticString = #function, - operation: @escaping () async throws -> Void - ) { - let expectation = self.expectation(description: expectationDescription) - Task { - do { - try await operation() - } catch { - XCTFail("Error thrown while executing \(function): \(error)", file: file, line: line) - Thread.callStackSymbols.forEach { print($0) } - } - expectation.fulfill() + extension XCTestCase { + @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) + /// Cross-platform XCTest support for async-await tests. + /// + /// Currently the Linux implementation of XCTest doesn't have async-await support. + /// Until it does, we make use of this shim which uses a detached `Task` along with + /// `XCTest.wait(for:timeout:)` to wrap the operation. + /// + /// - NOTE: Support for Linux is tracked by https://bugs.swift.org/browse/SR-14403. + /// - NOTE: Implementation currently in progress: https://github.com/apple/swift-corelibs-xctest/pull/326 + func XCTAsyncTest( + expectationDescription: String = "Async operation", + timeout: TimeInterval = 30, + file: StaticString = #filePath, + line: UInt = #line, + function: StaticString = #function, + operation: @escaping () async throws -> Void + ) { + let expectation = self.expectation(description: expectationDescription) + Task { + do { + try await operation() + } catch { + XCTFail("Error thrown while executing \(function): \(error)", file: file, line: line) + Thread.callStackSymbols.forEach { print($0) } + } + expectation.fulfill() + } + self.wait(for: [expectation], timeout: timeout) + } } - self.wait(for: [expectation], timeout: timeout) - } -} -@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) -internal func XCTAssertThrowsError( - _ expression: @autoclosure () async throws -> T, - verify: (Error) -> Void = { _ in }, - file: StaticString = #file, - line: UInt = #line -) async { - do { - _ = try await expression() - XCTFail("Expression did not throw error", file: file, line: line) - } catch { - verify(error) - } -} + @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) + internal func XCTAssertThrowsError( + _ expression: @autoclosure () async throws -> T, + verify: (Error) -> Void = { _ in }, + file: StaticString = #file, + line: UInt = #line + ) async { + do { + _ = try await expression() + XCTFail("Expression did not throw error", file: file, line: line) + } catch { + verify(error) + } + } #endif // compiler(>=5.5) From b0da0eb170e4f6dda03b6e3b2fec92fbd60e3779 Mon Sep 17 00:00:00 2001 From: David Nadoba Date: Thu, 25 Nov 2021 16:32:58 +0100 Subject: [PATCH 3/7] use our copright header --- Tests/AsyncHTTPClientTests/XCTest+AsyncAwait.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Tests/AsyncHTTPClientTests/XCTest+AsyncAwait.swift b/Tests/AsyncHTTPClientTests/XCTest+AsyncAwait.swift index 538d5a6d2..21379bc0a 100644 --- a/Tests/AsyncHTTPClientTests/XCTest+AsyncAwait.swift +++ b/Tests/AsyncHTTPClientTests/XCTest+AsyncAwait.swift @@ -1,3 +1,16 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the AsyncHTTPClient open source project +// +// Copyright (c) 2021 Apple Inc. and the AsyncHTTPClient project authors +// Licensed under Apache License v2.0 +// +// See LICENSE.txt for license information +// See CONTRIBUTORS.txt for the list of AsyncHTTPClient project authors +// +// SPDX-License-Identifier: Apache-2.0 +// +//===----------------------------------------------------------------------===// /* * Copyright 2021, gRPC Authors All rights reserved. * From c2e33b9dd76afbdf3700cc434f8ad8c5281f9b7b Mon Sep 17 00:00:00 2001 From: David Nadoba Date: Thu, 25 Nov 2021 17:08:42 +0100 Subject: [PATCH 4/7] fix wording --- NOTICE.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NOTICE.txt b/NOTICE.txt index 264c1dcbe..339e34e2f 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -27,7 +27,7 @@ components that this product depends on. ------------------------------------------------------------------------------- -This product contains a derivation various scripts from SwiftNIO and contains "XCTest+AsyncAwait.swift" from gRPC Swift. +This product contains derivations of various scripts from SwiftNIO and contains "XCTest+AsyncAwait.swift" from gRPC Swift. * LICENSE (Apache License 2.0): * https://www.apache.org/licenses/LICENSE-2.0 From 4cb1f45f58102234d577c4eee90cb1b2e92824ef Mon Sep 17 00:00:00 2001 From: David Nadoba Date: Thu, 25 Nov 2021 17:10:05 +0100 Subject: [PATCH 5/7] run SwiftFormat --- .../XCTest+AsyncAwait.swift | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/Tests/AsyncHTTPClientTests/XCTest+AsyncAwait.swift b/Tests/AsyncHTTPClientTests/XCTest+AsyncAwait.swift index 21379bc0a..7ec398602 100644 --- a/Tests/AsyncHTTPClientTests/XCTest+AsyncAwait.swift +++ b/Tests/AsyncHTTPClientTests/XCTest+AsyncAwait.swift @@ -27,53 +27,53 @@ * limitations under the License. */ #if compiler(>=5.5) - import XCTest +import XCTest - extension XCTestCase { - @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) - /// Cross-platform XCTest support for async-await tests. - /// - /// Currently the Linux implementation of XCTest doesn't have async-await support. - /// Until it does, we make use of this shim which uses a detached `Task` along with - /// `XCTest.wait(for:timeout:)` to wrap the operation. - /// - /// - NOTE: Support for Linux is tracked by https://bugs.swift.org/browse/SR-14403. - /// - NOTE: Implementation currently in progress: https://github.com/apple/swift-corelibs-xctest/pull/326 - func XCTAsyncTest( - expectationDescription: String = "Async operation", - timeout: TimeInterval = 30, - file: StaticString = #filePath, - line: UInt = #line, - function: StaticString = #function, - operation: @escaping () async throws -> Void - ) { - let expectation = self.expectation(description: expectationDescription) - Task { - do { - try await operation() - } catch { - XCTFail("Error thrown while executing \(function): \(error)", file: file, line: line) - Thread.callStackSymbols.forEach { print($0) } - } - expectation.fulfill() +extension XCTestCase { + @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) + /// Cross-platform XCTest support for async-await tests. + /// + /// Currently the Linux implementation of XCTest doesn't have async-await support. + /// Until it does, we make use of this shim which uses a detached `Task` along with + /// `XCTest.wait(for:timeout:)` to wrap the operation. + /// + /// - NOTE: Support for Linux is tracked by https://bugs.swift.org/browse/SR-14403. + /// - NOTE: Implementation currently in progress: https://github.com/apple/swift-corelibs-xctest/pull/326 + func XCTAsyncTest( + expectationDescription: String = "Async operation", + timeout: TimeInterval = 30, + file: StaticString = #filePath, + line: UInt = #line, + function: StaticString = #function, + operation: @escaping () async throws -> Void + ) { + let expectation = self.expectation(description: expectationDescription) + Task { + do { + try await operation() + } catch { + XCTFail("Error thrown while executing \(function): \(error)", file: file, line: line) + Thread.callStackSymbols.forEach { print($0) } } - self.wait(for: [expectation], timeout: timeout) + expectation.fulfill() } + self.wait(for: [expectation], timeout: timeout) } +} - @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) - internal func XCTAssertThrowsError( - _ expression: @autoclosure () async throws -> T, - verify: (Error) -> Void = { _ in }, - file: StaticString = #file, - line: UInt = #line - ) async { - do { - _ = try await expression() - XCTFail("Expression did not throw error", file: file, line: line) - } catch { - verify(error) - } +@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) +internal func XCTAssertThrowsError( + _ expression: @autoclosure () async throws -> T, + verify: (Error) -> Void = { _ in }, + file: StaticString = #file, + line: UInt = #line +) async { + do { + _ = try await expression() + XCTFail("Expression did not throw error", file: file, line: line) + } catch { + verify(error) } +} #endif // compiler(>=5.5) From 736e2349063cbe82d4c983787b430fac9a079bae Mon Sep 17 00:00:00 2001 From: David Nadoba Date: Thu, 25 Nov 2021 17:28:07 +0100 Subject: [PATCH 6/7] add Tony Stone's 'process_test_files.rb' to NOTICE and move "XCTest+AsyncAwait.swift" from gRPC Swift into its own section --- NOTICE.txt | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/NOTICE.txt b/NOTICE.txt index 339e34e2f..9a197a894 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -24,20 +24,32 @@ Also, please refer to each LICENSE.txt file, which is located in the 'license' directory of the distribution file, for the license terms of the components that this product depends on. -------------------------------------------------------------------------------- +--- - -This product contains derivations of various scripts from SwiftNIO and contains "XCTest+AsyncAwait.swift" from gRPC Swift. +This product contains derivations of various scripts from SwiftNIO. * LICENSE (Apache License 2.0): * https://www.apache.org/licenses/LICENSE-2.0 * HOMEPAGE: * https://github.com/apple/swift-nio +--- + +This product contains "XCTest+AsyncAwait.swift" from gRPC Swift. + * LICENSE (Apache License 2.0): * https://www.apache.org/licenses/LICENSE-2.0 * HOMEPAGE: * https://github.com/grpc/grpc-swift +--- + +This product contains a derivation of the Tony Stone's 'process_test_files.rb'. + + * LICENSE (Apache License 2.0): + * https://www.apache.org/licenses/LICENSE-2.0 + * HOMEPAGE: + * https://github.com/tonystone/build-tools/commit/6c417b7569df24597a48a9aa7b505b636e8f73a1 + * https://github.com/tonystone/build-tools/blob/master/source/xctest_tool.rb -------------------------------------------------------------------------------- +--- From ae49e03d23a9ab14238f3f91aab6eae90d9f62fe Mon Sep 17 00:00:00 2001 From: David Nadoba Date: Thu, 25 Nov 2021 18:27:33 +0100 Subject: [PATCH 7/7] mark `XCTAsyncTest` `operation` closure as `@Sendable` --- NOTICE.txt | 2 +- Tests/AsyncHTTPClientTests/XCTest+AsyncAwait.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NOTICE.txt b/NOTICE.txt index 9a197a894..31a622348 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -35,7 +35,7 @@ This product contains derivations of various scripts from SwiftNIO. --- -This product contains "XCTest+AsyncAwait.swift" from gRPC Swift. +This product contains a derivation of "XCTest+AsyncAwait.swift" from gRPC Swift. * LICENSE (Apache License 2.0): * https://www.apache.org/licenses/LICENSE-2.0 diff --git a/Tests/AsyncHTTPClientTests/XCTest+AsyncAwait.swift b/Tests/AsyncHTTPClientTests/XCTest+AsyncAwait.swift index 7ec398602..493296df5 100644 --- a/Tests/AsyncHTTPClientTests/XCTest+AsyncAwait.swift +++ b/Tests/AsyncHTTPClientTests/XCTest+AsyncAwait.swift @@ -45,7 +45,7 @@ extension XCTestCase { file: StaticString = #filePath, line: UInt = #line, function: StaticString = #function, - operation: @escaping () async throws -> Void + operation: @escaping @Sendable () async throws -> Void ) { let expectation = self.expectation(description: expectationDescription) Task {