mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Rather than blanket-disabling concurrency tests when we aren't using a just-built concurrency library, enable them whenever we have a suitable concurrency runtime, either just-built, in the OS, or via the back-deployment libraries.
54 lines
1.3 KiB
Swift
54 lines
1.3 KiB
Swift
// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -parse-as-library) | %FileCheck %s
|
|
|
|
// REQUIRES: executable_test
|
|
// REQUIRES: concurrency
|
|
|
|
// rdar://76038845
|
|
// REQUIRES: concurrency_runtime
|
|
// UNSUPPORTED: back_deployment_runtime
|
|
|
|
struct Boom: Error {}
|
|
struct IgnoredBoom: Error {}
|
|
|
|
@available(SwiftStdlib 5.5, *)
|
|
func echo(_ i: Int) async -> Int { i }
|
|
@available(SwiftStdlib 5.5, *)
|
|
func boom() async throws -> Int { throw Boom() }
|
|
|
|
@available(SwiftStdlib 5.5, *)
|
|
func test_taskGroup_throws_rethrows() async {
|
|
do {
|
|
let got = try await withThrowingTaskGroup(of: Int.self, returning: Int.self) { group in
|
|
group.addTask { await echo(1) }
|
|
group.addTask { await echo(2) }
|
|
group.addTask { try await boom() }
|
|
|
|
do {
|
|
while let r = try await group.next() {
|
|
print("next: \(r)")
|
|
}
|
|
} catch {
|
|
// CHECK: error caught and rethrown in group: Boom()
|
|
print("error caught and rethrown in group: \(error)")
|
|
throw error
|
|
}
|
|
|
|
print("should have thrown")
|
|
return 0
|
|
}
|
|
|
|
print("Expected error to be thrown, but got: \(got)")
|
|
} catch {
|
|
// CHECK: rethrown: Boom()
|
|
print("rethrown: \(error)")
|
|
}
|
|
}
|
|
|
|
|
|
@available(SwiftStdlib 5.5, *)
|
|
@main struct Main {
|
|
static func main() async {
|
|
await test_taskGroup_throws_rethrows()
|
|
}
|
|
}
|