Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1119893

Browse files
authored
AddXCTAsyncTest andXCTAssertThrowsError from gRPC Swift (#493)
1 parentf2bb283 commit1119893

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed

‎NOTICE.txt‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
The AsyncHTTPClient Project
3+
===========================
4+
5+
Please visit the AsyncHTTPClient web site for more information:
6+
7+
* https://github.com/swift-server/async-http-client
8+
9+
Copyright 2017-2021 The AsyncHTTPClient Project
10+
11+
The AsyncHTTPClient Project licenses this file to you under the Apache License,
12+
version 2.0 (the "License"); you may not use this file except in compliance
13+
with the License. You may obtain a copy of the License at:
14+
15+
https://www.apache.org/licenses/LICENSE-2.0
16+
17+
Unless required by applicable law or agreed to in writing, software
18+
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
19+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
20+
License for the specific language governing permissions and limitations
21+
under the License.
22+
23+
Also, please refer to each LICENSE.txt file, which is located in
24+
the 'license' directory of the distribution file, for the license terms of the
25+
components that this product depends on.
26+
27+
---
28+
29+
This product contains derivations of various scripts from SwiftNIO.
30+
31+
* LICENSE (Apache License 2.0):
32+
* https://www.apache.org/licenses/LICENSE-2.0
33+
* HOMEPAGE:
34+
* https://github.com/apple/swift-nio
35+
36+
---
37+
38+
This product contains a derivation of "XCTest+AsyncAwait.swift" from gRPC Swift.
39+
40+
* LICENSE (Apache License 2.0):
41+
* https://www.apache.org/licenses/LICENSE-2.0
42+
* HOMEPAGE:
43+
* https://github.com/grpc/grpc-swift
44+
45+
---
46+
47+
This product contains a derivation of the Tony Stone's 'process_test_files.rb'.
48+
49+
* LICENSE (Apache License 2.0):
50+
* https://www.apache.org/licenses/LICENSE-2.0
51+
* HOMEPAGE:
52+
* https://github.com/tonystone/build-tools/commit/6c417b7569df24597a48a9aa7b505b636e8f73a1
53+
* https://github.com/tonystone/build-tools/blob/master/source/xctest_tool.rb
54+
55+
---
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the AsyncHTTPClient open source project
4+
//
5+
// Copyright (c) 2021 Apple Inc. and the AsyncHTTPClient project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of AsyncHTTPClient project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
/*
15+
* Copyright 2021, gRPC Authors All rights reserved.
16+
*
17+
* Licensed under the Apache License, Version 2.0 (the "License");
18+
* you may not use this file except in compliance with the License.
19+
* You may obtain a copy of the License at
20+
*
21+
* http://www.apache.org/licenses/LICENSE-2.0
22+
*
23+
* Unless required by applicable law or agreed to in writing, software
24+
* distributed under the License is distributed on an "AS IS" BASIS,
25+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26+
* See the License for the specific language governing permissions and
27+
* limitations under the License.
28+
*/
29+
#if compiler(>=5.5)
30+
import XCTest
31+
32+
extensionXCTestCase{
33+
@available(macOS12, iOS15, tvOS15, watchOS8,*)
34+
/// Cross-platform XCTest support for async-await tests.
35+
///
36+
/// Currently the Linux implementation of XCTest doesn't have async-await support.
37+
/// Until it does, we make use of this shim which uses a detached `Task` along with
38+
/// `XCTest.wait(for:timeout:)` to wrap the operation.
39+
///
40+
/// - NOTE: Support for Linux is tracked by https://bugs.swift.org/browse/SR-14403.
41+
/// - NOTE: Implementation currently in progress: https://github.com/apple/swift-corelibs-xctest/pull/326
42+
func XCTAsyncTest(
43+
expectationDescription:String="Async operation",
44+
timeout:TimeInterval=30,
45+
file:StaticString= #filePath,
46+
line:UInt= #line,
47+
function:StaticString= #function,
48+
operation:@escaping@Sendable()asyncthrows->Void
49+
){
50+
letexpectation=self.expectation(description: expectationDescription)
51+
Task{
52+
do{
53+
tryawaitoperation()
54+
}catch{
55+
XCTFail("Error thrown while executing\(function):\(error)", file: file, line: line)
56+
Thread.callStackSymbols.forEach{print($0)}
57+
}
58+
expectation.fulfill()
59+
}
60+
self.wait(for:[expectation], timeout: timeout)
61+
}
62+
}
63+
64+
@available(macOS12, iOS15, tvOS15, watchOS8,*)
65+
internalfunc XCTAssertThrowsError<T>(
66+
_ expression:@autoclosure()asyncthrows->T,
67+
verify:(Error)->Void={ _in},
68+
file:StaticString= #file,
69+
line:UInt= #line
70+
)async{
71+
do{
72+
_=tryawaitexpression()
73+
XCTFail("Expression did not throw error", file: file, line: line)
74+
}catch{
75+
verify(error)
76+
}
77+
}
78+
79+
#endif // compiler(>=5.5)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp