From dfebac90baa7537fa9b488d8f5a7dd004327a705 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Sun, 10 Mar 2024 22:47:42 +0000 Subject: [PATCH] Fix XCTest entrypoint for WASI by making it async This change makes the XCTest entrypoint async on WASI, as it is required to not block the main thread. The entrypoint has been changed during the upstreaming work for WebAssembly support in XCTest. --- ...BuildOperationBuildSystemDelegateHandler.swift | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Sources/Build/BuildOperationBuildSystemDelegateHandler.swift b/Sources/Build/BuildOperationBuildSystemDelegateHandler.swift index 2341eac5466..0a6559c9cab 100644 --- a/Sources/Build/BuildOperationBuildSystemDelegateHandler.swift +++ b/Sources/Build/BuildOperationBuildSystemDelegateHandler.swift @@ -264,17 +264,18 @@ final class TestEntryPointCommand: CustomLLBuildCommand, TestBuildCommand { @main @available(*, deprecated, message: "Not actually deprecated. Marked as deprecated to allow inclusion of deprecated tests (which test deprecated functionality) without warnings") struct Runner { + #if os(WASI) + /// On WASI, we can't block the main thread, so XCTestMain is defined as async. + static func main() async { + \#(testObservabilitySetup) + await XCTMain(__allDiscoveredTests()) as Never + } + #else static func main() { \#(testObservabilitySetup) - #if os(WASI) - // FIXME: On WASI, XCTest uses `Task` based waiting not to block the whole process, so - // the `XCTMain` call can return the control and the process will exit by `exit(0)` later. - // This is a workaround until we have WASI threads or swift-testing, which does not block threads. - XCTMain(__allDiscoveredTests()) - #else XCTMain(__allDiscoveredTests()) as Never - #endif } + #endif } """# )