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)
swiftNightly BOT 12/16/2021 3:57 AM
Test Suite 'All tests' started at 2021-12-16 04:09:15.831 Test Suite 'bin.xctest' started at 2021-12-16 04:09:15.832 Test Suite 'ATest' started at 2021-12-16 04:09:15.832 Test Case 'ATest.testFoo' started at 2021-12-16 04:09:15.832 Test Case 'ATest.testFoo' passed (0.001 seconds) Test Suite 'ATest' passed at 2021-12-16 04:09:15.833 Executed 1 test, with 0 failures (0 unexpected) in 0.001 (0.001) seconds Test Suite 'bin.xctest' passed at 2021-12-16 04:09:15.833 Executed 1 test, with 0 failures (0 unexpected) in 0.001 (0.001) seconds Test Suite 'All tests' passed at 2021-12-16 04:09:15.833 Executed 1 test, with 0 failures (0 unexpected) in 0.001 (0.001) seconds (edited)