Avatar
Avatar
norio_nomura
@swift-main -Xfrontend -enable-experimental-concurrency import XCTest extension Result where Failure == Swift.Error { public init(catching body: () async throws -> Success) reasync { do { self = .success(try await body()) } catch { self = .failure(error) } } } public func XCTAssertEqual2<T: Equatable>( _ expression1: @autoclosure () async throws -> T, _ expression2: @autoclosure () async throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line ) reasync { let (result1, result2) = await (Result(catching: expression1), Result(catching: expression2)) XCTAssertEqual(try result1.get(), try result2.get(), message(), file: file, line: line) } func foo() async -> Int { 1 } class ATest: XCTestCase { func testFoo() async { await XCTAssertEqual2(await foo(), 1) } static let allTests = [("testFoo", asyncTest(testFoo))] } XCTMain([testCase(ATest.allTests)]) (edited)
reasyncはとりあえず入っているけどまだ途中段階なんだと思ってます(rethrowsと連動しているんですかね?)。 https://forums.swift.org/t/pitch-fix-rethrows-checking-and-add-rethrows-unsafe/44863 https://github.com/apple/swift/pull/36007