@@ -59,11 +59,11 @@ struct TestToolOptions: ParsableArguments {
59
59
60
60
return . runSerial
61
61
}
62
-
62
+
63
63
@Flag ( name: . customLong( " skip-build " ) ,
64
64
help: " Skip building the test target " )
65
65
var shouldSkipBuilding : Bool = false
66
-
66
+
67
67
/// If the test target should be built before testing.
68
68
var shouldBuildTests : Bool {
69
69
!shouldSkipBuilding
@@ -97,7 +97,7 @@ struct TestToolOptions: ParsableArguments {
97
97
if !filter. isEmpty {
98
98
return . regex( filter)
99
99
}
100
-
100
+
101
101
return _testCaseSpecifier. map { . specific( $0) } ?? . none
102
102
}
103
103
@@ -115,7 +115,7 @@ struct TestToolOptions: ParsableArguments {
115
115
if let override = testCaseSkipOverride ( ) {
116
116
return override
117
117
}
118
-
118
+
119
119
return _testCaseSkip. isEmpty
120
120
? . none
121
121
: . skip( _testCaseSkip)
@@ -197,11 +197,11 @@ public struct SwiftTestTool: SwiftCommand {
197
197
198
198
@OptionGroup ( )
199
199
var options : TestToolOptions
200
-
200
+
201
201
var shouldEnableCodeCoverage : Bool {
202
202
swiftOptions. shouldEnableCodeCoverage
203
203
}
204
-
204
+
205
205
public func run( _ swiftTool: SwiftTool ) throws {
206
206
// Validate commands arguments
207
207
try self . validateArguments ( observabilityScope: swiftTool. observabilityScope)
@@ -501,25 +501,26 @@ public struct SwiftTestTool: SwiftCommand {
501
501
/// - Returns: Array of TestSuite
502
502
fileprivate func getTestSuites( fromTestAt path: AbsolutePath , swiftTool: SwiftTool ) throws -> [ TestSuite ] {
503
503
// Run the correct tool.
504
- #if os(macOS)
504
+ #if os(macOS)
505
505
let data : String = try withTemporaryFile { tempFile in
506
506
let args = [ try xctestHelperPath ( swiftTool: swiftTool) . pathString, path. pathString, tempFile. path. pathString]
507
507
var env = try constructTestEnvironment ( toolchain: try swiftTool. getToolchain ( ) , options: swiftOptions, buildParameters: swiftTool. buildParametersForTest ( ) )
508
508
// Add the sdk platform path if we have it. If this is not present, we
509
509
// might always end up failing.
510
510
if let sdkPlatformFrameworksPath = Destination . sdkPlatformFrameworkPaths ( ) {
511
- env [ " DYLD_FRAMEWORK_PATH " ] = sdkPlatformFrameworksPath. fwk. pathString
512
- env [ " DYLD_LIBRARY_PATH " ] = sdkPlatformFrameworksPath. lib. pathString
511
+ // appending since we prefer the user setting (if set) to the one we inject
512
+ env. appendPath ( " DYLD_FRAMEWORK_PATH " , value: sdkPlatformFrameworksPath. fwk. pathString)
513
+ env. appendPath ( " DYLD_LIBRARY_PATH " , value: sdkPlatformFrameworksPath. lib. pathString)
513
514
}
514
515
try Process . checkNonZeroExit ( arguments: args, environment: env)
515
516
// Read the temporary file's content.
516
517
return try localFileSystem. readFileContents ( tempFile. path) . validDescription ?? " "
517
518
}
518
- #else
519
+ #else
519
520
let env = try constructTestEnvironment ( toolchain: try swiftTool. getToolchain ( ) , options: swiftOptions, buildParameters: swiftTool. buildParametersForTest ( ) )
520
521
let args = [ path. description, " --dump-tests-json " ]
521
522
let data = try Process . checkNonZeroExit ( arguments: args, environment: env)
522
- #endif
523
+ #endif
523
524
// Parse json and return TestSuites.
524
525
return try TestSuite . parse ( jsonString: data)
525
526
}
@@ -542,12 +543,12 @@ public struct SwiftTestTool: SwiftCommand {
542
543
throw ExitCode . failure
543
544
}
544
545
}
545
-
546
+
546
547
if options. shouldGenerateLinuxMain {
547
548
observabilityScope. emit ( warning: " '--generate-linuxmain' option is deprecated; tests are automatically discovered on all platforms " )
548
549
}
549
550
}
550
-
551
+
551
552
public init ( ) { }
552
553
}
553
554
@@ -1016,8 +1017,8 @@ fileprivate func constructTestEnvironment(
1016
1017
toolchain: UserToolchain ,
1017
1018
options: SwiftToolOptions ,
1018
1019
buildParameters: BuildParameters
1019
- ) throws -> [ String : String ] {
1020
- var env = ProcessEnv . vars
1020
+ ) throws -> EnvironmentVariables {
1021
+ var env = EnvironmentVariables . process ( )
1021
1022
1022
1023
// Add the code coverage related variables.
1023
1024
if options. shouldEnableCodeCoverage {
@@ -1034,7 +1035,7 @@ fileprivate func constructTestEnvironment(
1034
1035
#if !os(macOS)
1035
1036
#if os(Windows)
1036
1037
if let location = toolchain. configuration. xctestPath {
1037
- env [ " Path " ] = " \( location. pathString) ; \( env [ " Path " ] ?? " " ) "
1038
+ env. prependPath ( " Path " , value : location. pathString)
1038
1039
}
1039
1040
#endif
1040
1041
return env
0 commit comments