@@ -232,12 +232,16 @@ extension ExitTest {
232
232
// can precompute them.
233
233
let childProcessExecutablePath = Result { try CommandLine . executablePath }
234
234
235
- // We only need to pass arguments when hosted by XCTest.
235
+ // Construct appropriate arguments for the child process. Generally these
236
+ // arguments are going to be whatever's necessary to respawn the current
237
+ // executable and get back into Swift Testing.
236
238
let childArguments : [ String ] = {
237
239
var result = [ String] ( )
240
+
241
+ let parentArguments = CommandLine . arguments
238
242
#if SWT_TARGET_OS_APPLE
239
243
lazy var xctestTargetPath = Environment . variable ( named: " XCTestBundlePath " )
240
- ?? CommandLine . arguments . dropFirst ( ) . last
244
+ ?? parentArguments . dropFirst ( ) . last
241
245
// If the running executable appears to be the XCTest runner executable in
242
246
// Xcode, figure out the path to the running XCTest bundle. If we can find
243
247
// it, then we can re-run the host XCTestCase instance.
@@ -261,7 +265,23 @@ extension ExitTest {
261
265
// to run.
262
266
result += [ " -XCTest " , " / " , xctestTargetPath]
263
267
}
268
+
269
+ // When hosted by Swift Package Manager, forward all arguments to the
270
+ // child process. (They aren't all meaningful in the context of an exit
271
+ // test, but it keeps this code fairly simple!)
272
+ lazy var isHostedBySwiftPM = parentArguments. contains ( " --test-bundle-path " )
273
+ if !isHostedByXCTest && isHostedBySwiftPM {
274
+ result += parentArguments. dropFirst ( )
275
+ }
276
+ #else
277
+ // When hosted by Swift Package Manager, we'll need to specify exactly
278
+ // which testing library to call into from the shared test executable.
279
+ let hasTestingLibraryArgument : Bool = parentArguments. contains { $0. starts ( with: " --testing-library " ) }
280
+ if hasTestingLibraryArgument {
281
+ result += [ " --testing-library " , " swift-testing " ]
282
+ }
264
283
#endif
284
+
265
285
return result
266
286
} ( )
267
287
0 commit comments