@@ -59,11 +59,11 @@ struct TestToolOptions: ParsableArguments {
5959
6060 return . runSerial
6161 }
62-
62+
6363 @Flag ( name: . customLong( " skip-build " ) ,
6464 help: " Skip building the test target " )
6565 var shouldSkipBuilding : Bool = false
66-
66+
6767 /// If the test target should be built before testing.
6868 var shouldBuildTests : Bool {
6969 !shouldSkipBuilding
@@ -97,7 +97,7 @@ struct TestToolOptions: ParsableArguments {
9797 if !filter. isEmpty {
9898 return . regex( filter)
9999 }
100-
100+
101101 return _testCaseSpecifier. map { . specific( $0) } ?? . none
102102 }
103103
@@ -115,7 +115,7 @@ struct TestToolOptions: ParsableArguments {
115115 if let override = testCaseSkipOverride ( ) {
116116 return override
117117 }
118-
118+
119119 return _testCaseSkip. isEmpty
120120 ? . none
121121 : . skip( _testCaseSkip)
@@ -197,11 +197,11 @@ public struct SwiftTestTool: SwiftCommand {
197197
198198 @OptionGroup ( )
199199 var options : TestToolOptions
200-
200+
201201 var shouldEnableCodeCoverage : Bool {
202202 swiftOptions. shouldEnableCodeCoverage
203203 }
204-
204+
205205 public func run( _ swiftTool: SwiftTool ) throws {
206206 // Validate commands arguments
207207 try self . validateArguments ( observabilityScope: swiftTool. observabilityScope)
@@ -501,25 +501,26 @@ public struct SwiftTestTool: SwiftCommand {
501501 /// - Returns: Array of TestSuite
502502 fileprivate func getTestSuites( fromTestAt path: AbsolutePath , swiftTool: SwiftTool ) throws -> [ TestSuite ] {
503503 // Run the correct tool.
504- #if os(macOS)
504+ #if os(macOS)
505505 let data : String = try withTemporaryFile { tempFile in
506506 let args = [ try xctestHelperPath ( swiftTool: swiftTool) . pathString, path. pathString, tempFile. path. pathString]
507507 var env = try constructTestEnvironment ( toolchain: try swiftTool. getToolchain ( ) , options: swiftOptions, buildParameters: swiftTool. buildParametersForTest ( ) )
508508 // Add the sdk platform path if we have it. If this is not present, we
509509 // might always end up failing.
510510 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)
513514 }
514515 try Process . checkNonZeroExit ( arguments: args, environment: env)
515516 // Read the temporary file's content.
516517 return try localFileSystem. readFileContents ( tempFile. path) . validDescription ?? " "
517518 }
518- #else
519+ #else
519520 let env = try constructTestEnvironment ( toolchain: try swiftTool. getToolchain ( ) , options: swiftOptions, buildParameters: swiftTool. buildParametersForTest ( ) )
520521 let args = [ path. description, " --dump-tests-json " ]
521522 let data = try Process . checkNonZeroExit ( arguments: args, environment: env)
522- #endif
523+ #endif
523524 // Parse json and return TestSuites.
524525 return try TestSuite . parse ( jsonString: data)
525526 }
@@ -542,12 +543,12 @@ public struct SwiftTestTool: SwiftCommand {
542543 throw ExitCode . failure
543544 }
544545 }
545-
546+
546547 if options. shouldGenerateLinuxMain {
547548 observabilityScope. emit ( warning: " '--generate-linuxmain' option is deprecated; tests are automatically discovered on all platforms " )
548549 }
549550 }
550-
551+
551552 public init ( ) { }
552553}
553554
@@ -1016,8 +1017,8 @@ fileprivate func constructTestEnvironment(
10161017 toolchain: UserToolchain ,
10171018 options: SwiftToolOptions ,
10181019 buildParameters: BuildParameters
1019- ) throws -> [ String : String ] {
1020- var env = ProcessEnv . vars
1020+ ) throws -> EnvironmentVariables {
1021+ var env = EnvironmentVariables . process ( )
10211022
10221023 // Add the code coverage related variables.
10231024 if options. shouldEnableCodeCoverage {
@@ -1034,7 +1035,7 @@ fileprivate func constructTestEnvironment(
10341035 #if !os(macOS)
10351036 #if os(Windows)
10361037 if let location = toolchain. configuration. xctestPath {
1037- env [ " Path " ] = " \( location. pathString) ; \( env [ " Path " ] ?? " " ) "
1038+ env. prependPath ( " Path " , value : location. pathString)
10381039 }
10391040 #endif
10401041 return env
0 commit comments