@@ -138,6 +138,10 @@ struct TestToolOptions: ParsableArguments {
138
138
@Option ( help: " Test the specified product. " )
139
139
var testProduct : String ?
140
140
141
+ /// Generate LinuxMain entries and exit.
142
+ @Flag ( name: . customLong( " testable-imports " ) , inversion: . prefixedEnableDisable, help: " Enable or disable testable imports. Enabled by default. " )
143
+ var enableTestableImports : Bool = true
144
+
141
145
/// Returns the test case specifier if overridden in the env.
142
146
private func testCaseSkipOverride( ) -> TestCaseSpecifier ? {
143
147
guard let override = ProcessEnv . vars [ " _SWIFTPM_SKIP_TESTS_LIST " ] else {
@@ -235,7 +239,7 @@ public struct SwiftTestTool: SwiftCommand {
235
239
guard let rootManifest = rootManifests. values. first else {
236
240
throw StringError ( " invalid manifests at \( root. packages) " )
237
241
}
238
- let buildParameters = try swiftTool. buildParametersForTest ( )
242
+ let buildParameters = try swiftTool. buildParametersForTest ( options : self . options )
239
243
print ( codeCovAsJSONPath ( buildParameters: buildParameters, packageName: rootManifest. displayName) )
240
244
241
245
case . generateLinuxMain:
@@ -256,7 +260,7 @@ public struct SwiftTestTool: SwiftCommand {
256
260
case . runSerial:
257
261
let toolchain = try swiftTool. getToolchain ( )
258
262
let testProducts = try buildTestsIfNeeded ( swiftTool: swiftTool)
259
- let buildParameters = try swiftTool. buildParametersForTest ( )
263
+ let buildParameters = try swiftTool. buildParametersForTest ( options : self . options )
260
264
261
265
// Clean out the code coverage directory that may contain stale
262
266
// profraw files from a previous run of the code coverage tool.
@@ -324,7 +328,7 @@ public struct SwiftTestTool: SwiftCommand {
324
328
let tests = try testSuites
325
329
. filteredTests ( specifier: options. testCaseSpecifier)
326
330
. skippedTests ( specifier: options. testCaseSkip)
327
- let buildParameters = try swiftTool. buildParametersForTest ( )
331
+ let buildParameters = try swiftTool. buildParametersForTest ( options : self . options )
328
332
329
333
// If there were no matches, emit a warning and exit.
330
334
if tests. isEmpty {
@@ -380,7 +384,7 @@ public struct SwiftTestTool: SwiftCommand {
380
384
// Merge all the profraw files to produce a single profdata file.
381
385
try mergeCodeCovRawDataFiles ( swiftTool: swiftTool)
382
386
383
- let buildParameters = try swiftTool. buildParametersForTest ( )
387
+ let buildParameters = try swiftTool. buildParametersForTest ( options : self . options )
384
388
for product in testProducts {
385
389
// Export the codecov data as JSON.
386
390
let jsonPath = codeCovAsJSONPath (
@@ -396,7 +400,7 @@ public struct SwiftTestTool: SwiftCommand {
396
400
let llvmProf = try swiftTool. getToolchain ( ) . getLLVMProf ( )
397
401
398
402
// Get the profraw files.
399
- let buildParameters = try swiftTool. buildParametersForTest ( )
403
+ let buildParameters = try swiftTool. buildParametersForTest ( options : self . options )
400
404
let codeCovFiles = try localFileSystem. getDirectoryContents ( buildParameters. codeCovPath)
401
405
402
406
// Construct arguments for invoking the llvm-prof tool.
@@ -420,7 +424,7 @@ public struct SwiftTestTool: SwiftCommand {
420
424
private func exportCodeCovAsJSON( to path: AbsolutePath , testBinary: AbsolutePath , swiftTool: SwiftTool ) throws {
421
425
// Export using the llvm-cov tool.
422
426
let llvmCov = try swiftTool. getToolchain ( ) . getLLVMCov ( )
423
- let buildParameters = try swiftTool. buildParametersForTest ( )
427
+ let buildParameters = try swiftTool. buildParametersForTest ( options : self . options )
424
428
let args = [
425
429
llvmCov. pathString,
426
430
" export " ,
@@ -440,7 +444,8 @@ public struct SwiftTestTool: SwiftCommand {
440
444
///
441
445
/// - Returns: The paths to the build test products.
442
446
private func buildTestsIfNeeded( swiftTool: SwiftTool ) throws -> [ BuiltTestProduct ] {
443
- let buildSystem = try swiftTool. createBuildSystem ( buildParameters: swiftTool. buildParametersForTest ( ) )
447
+ let buildParameters = try swiftTool. buildParametersForTest ( options: self . options)
448
+ let buildSystem = try swiftTool. createBuildSystem ( buildParameters: buildParameters)
444
449
445
450
if options. shouldBuildTests {
446
451
let subset = options. testProduct. map ( BuildSubset . product) ?? . allIncludingTests
@@ -1016,8 +1021,17 @@ final class XUnitGenerator {
1016
1021
}
1017
1022
}
1018
1023
1024
+ extension SwiftTool {
1025
+ func buildParametersForTest( options: TestToolOptions ) throws -> BuildParameters {
1026
+ try self . buildParametersForTest (
1027
+ enableTestability: options. enableTestableImports
1028
+ )
1029
+ }
1030
+ }
1031
+
1019
1032
private extension Basics . Diagnostic {
1020
1033
static var noMatchingTests : Self {
1021
1034
. warning( " No matching test cases were run " )
1022
1035
}
1023
1036
}
1037
+
0 commit comments