swiftlang / swift-corelibs-xctest

The XCTest Project, A Swift core library for providing unit test support
swift.org
Apache License 2.0
1.15k stars 267 forks source link

Add `XCTAssertNoThrowAsync` and `XCTAssertThrowsErrorAsync` #485

Closed jiyimeta closed 7 months ago

jiyimeta commented 7 months ago

Add XCTAssertNoThrowAsync and XCTAssertThrowsErrorAsync, which are the async versions of XCTAssertNoThrow and XCTAssertThrowsError.

I adopted different names from sync ones in order to avoid confusion of overloads. For example, if the sync and async versions have the same name XCTAssertThrowsError,

func testExample() async {
    XCTAssertThrowsError(try functionThatDoesThrowError())
}

such a sync assertion in an async context will cause compile error with message Expression is 'async' but is not marked with 'await', despite success before this change.

Resolves #419.

briancroom commented 7 months ago

Hi @jiyimeta, thanks for your interest in improving XCTest. Unfortunately we aren't accepting new APIs here on the swift-corelibs-xctest repository, because its primary purpose is to provide a compatible implementation of the APIs provided by the XCTest that ships with Xcode, for use when targeting platforms that Xcode doesn't support.

I recommend that you keep these additional APIs in your own project/package, and file an Xcode enhancement request at http://bugreport.apple.com.