Skip to content

Commit 3af203f

Browse files
authored
Don't rely on current working directory in BasicTests - use packagePath (#9500)
Don't rely on current working directory in BasicTests - use packagePath ### Motivation: Encountering race conditions with concurrent tests making use of current working directory. Removing usages.
1 parent bb754d8 commit 3af203f

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

Sources/Basics/Concurrency/AsyncProcess.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,12 @@ package final class AsyncProcess {
375375
environment: Environment = .current,
376376
outputRedirection: OutputRedirection = .collect,
377377
startNewProcessGroup: Bool = true,
378-
loggingHandler: LoggingHandler? = .none
378+
loggingHandler: LoggingHandler? = .none,
379+
workingDirectory: AbsolutePath? = nil
379380
) {
380381
self.arguments = arguments
381382
self.environment = environment
382-
self.workingDirectory = nil
383+
self.workingDirectory = workingDirectory
383384
self.outputRedirection = outputRedirection
384385
self.startNewProcessGroup = startNewProcessGroup
385386
self.loggingHandler = loggingHandler ?? AsyncProcess.loggingHandler
@@ -1126,13 +1127,15 @@ extension AsyncProcess {
11261127
package static func popen(
11271128
arguments: [String],
11281129
environment: Environment = .current,
1129-
loggingHandler: LoggingHandler? = .none
1130+
loggingHandler: LoggingHandler? = .none,
1131+
workingDirectory: AbsolutePath? = nil
11301132
) throws -> AsyncProcessResult {
11311133
let process = AsyncProcess(
11321134
arguments: arguments,
11331135
environment: environment,
11341136
outputRedirection: .collect,
1135-
loggingHandler: loggingHandler
1137+
loggingHandler: loggingHandler,
1138+
workingDirectory: workingDirectory
11361139
)
11371140
try process.launch()
11381141
return try process.waitUntilExit()

Sources/_IntegrationTestSupport/Helpers.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ public let xcodebuild: AbsolutePath = {
7474
package func sh(
7575
_ arguments: CustomStringConvertible...,
7676
env: [String: String] = [:],
77+
workingDirectory: AbsolutePath? = nil,
7778
sourceLocation: SourceLocation = #_sourceLocation,
7879
) throws -> ShReturnType {
79-
let result = try _sh(arguments, env: env)
80+
let result = try _sh(arguments, env: env, workingDirectory: workingDirectory)
8081
let stdout = try result.utf8Output()
8182
let stderr = try result.utf8stderrOutput()
8283

@@ -97,6 +98,7 @@ package func sh(
9798
package func _sh(
9899
_ arguments: [CustomStringConvertible],
99100
env: [String: String] = [:],
101+
workingDirectory: AbsolutePath? = nil
100102
) throws -> AsyncProcessResult {
101103
var environment = Environment()
102104

@@ -109,7 +111,7 @@ package func _sh(
109111
}
110112

111113
let result = try AsyncProcess.popen(
112-
arguments: arguments.map(\.description), environment: environment
114+
arguments: arguments.map(\.description), environment: environment, workingDirectory: workingDirectory
113115
)
114116
return result
115117
}

Tests/IntegrationTests/BasicTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ private struct BasicTests {
6969
#expect(dealerOutput.filter(\.isPlayingCardSuit).count == 10)
7070

7171
// Verify that the 'git status' is clean after a build.
72-
try localFileSystem.changeCurrentWorkingDirectory(to: packagePath)
73-
let gitOutput = try sh("git\(ProcessInfo.exeSuffix)", "status").stdout
72+
let gitOutput = try sh("git\(ProcessInfo.exeSuffix)", "status", workingDirectory: packagePath).stdout
7473
#expect(gitOutput.contains("nothing to commit, working tree clean"))
7574

7675
// Verify that another 'swift build' does nothing.

0 commit comments

Comments
 (0)