You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[WIP] Build Swift Testing and XCTest content in a single product.
This PR refactors the previously-experimental Swift Testing support logic so
that only a single build product is produced when using both XCTest and Swift
Testing, and detection of Swift Testing usage is no longer needed at compile
time.
On macOS, Xcode 16 is responsible for hosting Swift Testing content, so
additional changes may be needed in Xcode to support this refactoring. Such
changes are beyond the purview of the Swift open source project.
// This module has no tests so just write an empty file for it.
136
+
try fileSystem.writeFileContents(file, bytes:"")
137
+
continue
151
138
}
139
+
trywrite(
140
+
tests: tests,
141
+
forModule: module,
142
+
fileSystem: fileSystem,
143
+
path: file
144
+
)
145
+
}
152
146
153
-
lettestsKeyword= tests.isEmpty ?"let":"var"
147
+
lettestsKeyword= tests.isEmpty ?"let":"var"
154
148
155
-
// Write the main file.
156
-
letstream=tryLocalFileOutputByteStream(mainFile)
149
+
// Write the main file.
150
+
letstream=tryLocalFileOutputByteStream(mainFile)
157
151
158
-
stream.send(
159
-
#"""
160
-
import XCTest
152
+
stream.send(
153
+
#"""
154
+
import XCTest
161
155
162
-
@available(*, deprecated, message: "Not actually deprecated. Marked as deprecated to allow inclusion of deprecated tests (which test deprecated functionality) without warnings")
163
-
@MainActor
164
-
public func __allDiscoveredTests() -> [XCTestCaseEntry] {
165
-
\#(testsKeyword)tests = [XCTestCaseEntry]()
156
+
@available(*, deprecated, message: "Not actually deprecated. Marked as deprecated to allow inclusion of deprecated tests (which test deprecated functionality) without warnings")
157
+
@MainActor
158
+
public func __allDiscoveredTests() -> [XCTestCaseEntry] {
@available(*, deprecated, message: "Not actually deprecated. Marked as deprecated to allow inclusion of deprecated tests (which test deprecated functionality) without warnings")
255
-
struct Runner {
256
-
#if os(WASI)
257
-
/// On WASI, we can't block the main thread, so XCTestMain is defined as async.
@available(*, deprecated, message: "Not actually deprecated. Marked as deprecated to allow inclusion of deprecated tests (which test deprecated functionality) without warnings")
234
+
struct Runner {
235
+
static func which() -> String {
236
+
// HACK: abstract this check properly!
237
+
let args = CommandLine.arguments
238
+
if args.contains("--testing-library=swift-testing") {
239
+
return "swift-testing"
240
+
} else if args.contains("--testing-library=xctest") {
241
+
return "XCTest"
242
+
}
243
+
// Fallback if not specified: run XCTest (legacy behavior)
244
+
return "XCTest"
245
+
}
246
+
static func main() async {
247
+
let which = Self.which()
248
+
#if canImport(Testing)
249
+
if which == "swift-testing" {
250
+
await Testing.__swiftPMEntryPoint() as Never
261
251
}
262
-
#else
263
-
static func main() {
252
+
#endif
253
+
#if canImport(XCTest)
254
+
if which == "XCTest" {
264
255
\#(testObservabilitySetup)
256
+
#if os(WASI)
257
+
/// On WASI, we can't block the main thread, so XCTestMain is defined as async.
0 commit comments