@@ -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 {
@@ -238,7 +242,7 @@ public struct SwiftTestTool: SwiftCommand {
238
242
guard let rootManifest = rootManifests. values. first else {
239
243
throw StringError ( " invalid manifests at \( root. packages) " )
240
244
}
241
- let buildParameters = try swiftTool. buildParametersForTest ( )
245
+ let buildParameters = try swiftTool. buildParametersForTest ( options : self . options )
242
246
print ( codeCovAsJSONPath ( buildParameters: buildParameters, packageName: rootManifest. displayName) )
243
247
244
248
case . generateLinuxMain:
@@ -259,7 +263,7 @@ public struct SwiftTestTool: SwiftCommand {
259
263
case . runSerial:
260
264
let toolchain = try swiftTool. getToolchain ( )
261
265
let testProducts = try buildTestsIfNeeded ( swiftTool: swiftTool)
262
- let buildParameters = try swiftTool. buildParametersForTest ( )
266
+ let buildParameters = try swiftTool. buildParametersForTest ( options : self . options )
263
267
264
268
// Clean out the code coverage directory that may contain stale
265
269
// profraw files from a previous run of the code coverage tool.
@@ -327,7 +331,7 @@ public struct SwiftTestTool: SwiftCommand {
327
331
let tests = try testSuites
328
332
. filteredTests ( specifier: options. testCaseSpecifier)
329
333
. skippedTests ( specifier: options. testCaseSkip)
330
- let buildParameters = try swiftTool. buildParametersForTest ( )
334
+ let buildParameters = try swiftTool. buildParametersForTest ( options : self . options )
331
335
332
336
// If there were no matches, emit a warning and exit.
333
337
if tests. isEmpty {
@@ -383,7 +387,7 @@ public struct SwiftTestTool: SwiftCommand {
383
387
// Merge all the profraw files to produce a single profdata file.
384
388
try mergeCodeCovRawDataFiles ( swiftTool: swiftTool)
385
389
386
- let buildParameters = try swiftTool. buildParametersForTest ( )
390
+ let buildParameters = try swiftTool. buildParametersForTest ( options : self . options )
387
391
for product in testProducts {
388
392
// Export the codecov data as JSON.
389
393
let jsonPath = codeCovAsJSONPath (
@@ -399,7 +403,7 @@ public struct SwiftTestTool: SwiftCommand {
399
403
let llvmProf = try swiftTool. getToolchain ( ) . getLLVMProf ( )
400
404
401
405
// Get the profraw files.
402
- let buildParameters = try swiftTool. buildParametersForTest ( )
406
+ let buildParameters = try swiftTool. buildParametersForTest ( options : self . options )
403
407
let codeCovFiles = try localFileSystem. getDirectoryContents ( buildParameters. codeCovPath)
404
408
405
409
// Construct arguments for invoking the llvm-prof tool.
@@ -423,7 +427,7 @@ public struct SwiftTestTool: SwiftCommand {
423
427
private func exportCodeCovAsJSON( to path: AbsolutePath , testBinary: AbsolutePath , swiftTool: SwiftTool ) throws {
424
428
// Export using the llvm-cov tool.
425
429
let llvmCov = try swiftTool. getToolchain ( ) . getLLVMCov ( )
426
- let buildParameters = try swiftTool. buildParametersForTest ( )
430
+ let buildParameters = try swiftTool. buildParametersForTest ( options : self . options )
427
431
let args = [
428
432
llvmCov. pathString,
429
433
" export " ,
@@ -443,7 +447,8 @@ public struct SwiftTestTool: SwiftCommand {
443
447
///
444
448
/// - Returns: The paths to the build test products.
445
449
private func buildTestsIfNeeded( swiftTool: SwiftTool ) throws -> [ BuiltTestProduct ] {
446
- let buildSystem = try swiftTool. createBuildSystem ( buildParameters: swiftTool. buildParametersForTest ( ) )
450
+ let buildParameters = try swiftTool. buildParametersForTest ( options: self . options)
451
+ let buildSystem = try swiftTool. createBuildSystem ( buildParameters: buildParameters)
447
452
448
453
if options. shouldBuildTests {
449
454
let subset = options. testProduct. map ( BuildSubset . product) ?? . allIncludingTests
@@ -1019,8 +1024,17 @@ final class XUnitGenerator {
1019
1024
}
1020
1025
}
1021
1026
1027
+ extension SwiftTool {
1028
+ func buildParametersForTest( options: TestToolOptions ) throws -> BuildParameters {
1029
+ try self . buildParametersForTest (
1030
+ enableTestability: options. enableTestableImports
1031
+ )
1032
+ }
1033
+ }
1034
+
1022
1035
private extension Basics . Diagnostic {
1023
1036
static var noMatchingTests : Self {
1024
1037
. warning( " No matching test cases were run " )
1025
1038
}
1026
1039
}
1040
+
0 commit comments