Skip to content

Commit 8268caa

Browse files
Fix XCTest entrypoint for WASI by making it async (#7400)
1 parent 24cd4a2 commit 8268caa

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Sources/Build/BuildOperationBuildSystemDelegateHandler.swift

+8-7
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,18 @@ final class TestEntryPointCommand: CustomLLBuildCommand, TestBuildCommand {
264264
@main
265265
@available(*, deprecated, message: "Not actually deprecated. Marked as deprecated to allow inclusion of deprecated tests (which test deprecated functionality) without warnings")
266266
struct Runner {
267+
#if os(WASI)
268+
/// On WASI, we can't block the main thread, so XCTestMain is defined as async.
269+
static func main() async {
270+
\#(testObservabilitySetup)
271+
await XCTMain(__allDiscoveredTests()) as Never
272+
}
273+
#else
267274
static func main() {
268275
\#(testObservabilitySetup)
269-
#if os(WASI)
270-
// FIXME: On WASI, XCTest uses `Task` based waiting not to block the whole process, so
271-
// the `XCTMain` call can return the control and the process will exit by `exit(0)` later.
272-
// This is a workaround until we have WASI threads or swift-testing, which does not block threads.
273-
XCTMain(__allDiscoveredTests())
274-
#else
275276
XCTMain(__allDiscoveredTests()) as Never
276-
#endif
277277
}
278+
#endif
278279
}
279280
"""#
280281
)

0 commit comments

Comments
 (0)