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
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.
throwInternalError("makeTestManifestTargets should not be used for build plan which does not require additional derived test targets")
42
39
}
43
40
41
+
varexplicitlyEnabledDiscovery=false
42
+
varexplicitlySpecifiedPath:AbsolutePath?
43
+
if case let.entryPointExecutable(caseExplicitlyEnabledDiscovery, caseExplicitlySpecifiedPath)= destinationBuildParameters.testingParameters.testProductStyle {
// This module has no tests so just write an empty file for it.
145
+
try fileSystem.writeFileContents(file, bytes:"")
146
+
continue
151
147
}
148
+
trywrite(
149
+
tests: tests,
150
+
forModule: module,
151
+
fileSystem: fileSystem,
152
+
path: file
153
+
)
154
+
}
152
155
153
-
lettestsKeyword= tests.isEmpty ?"let":"var"
156
+
lettestsKeyword= tests.isEmpty ?"let":"var"
154
157
155
-
// Write the main file.
156
-
letstream=tryLocalFileOutputByteStream(mainFile)
158
+
// Write the main file.
159
+
letstream=tryLocalFileOutputByteStream(mainFile)
157
160
158
-
stream.send(
159
-
#"""
160
-
import XCTest
161
+
stream.send(
162
+
#"""
163
+
import XCTest
161
164
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]()
165
+
@available(*, deprecated, message: "Not actually deprecated. Marked as deprecated to allow inclusion of deprecated tests (which test deprecated functionality) without warnings")
166
+
@MainActor
167
+
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")
251
+
struct Runner {
252
+
private static func testingLibrary() -> String {
253
+
var iterator = CommandLine.arguments.makeIterator()
254
+
while let argument = iterator.next() {
255
+
if argument == "--testing-library", let libraryName = iterator.next() {
256
+
return libraryName.lowercased()
257
+
}
258
+
}
259
+
260
+
// Fallback if not specified: run XCTest (legacy behavior)
261
+
return "xctest"
262
+
}
263
+
264
+
static func main() async {
265
+
let testingLibrary = Self.testingLibrary()
266
+
#if \#(swiftTestingImportCondition)
267
+
if testingLibrary == "swift-testing" {
268
+
await Testing.__swiftPMEntryPoint() as Never
261
269
}
262
-
#else
263
-
static func main() {
270
+
#endif
271
+
#if \#(xctestImportCondition)
272
+
if testingLibrary == "xctest" {
264
273
\#(testObservabilitySetup)
274
+
#if os(WASI)
275
+
/// On WASI, we can't block the main thread, so XCTestMain is defined as async.
0 commit comments