Skip to content

Commit e10bdbc

Browse files
committed
Fix issue with running test on windows w/no-parallel
The AsyncProcess Tests were using a TSCTestSupport method to temporarly change the PATH env but seems to have a bug where it removes the variable instead of restoring resulting in any future test needing PATH to fail. This switch it to using the same method that is in SwiftPM Environment.swft
1 parent 0c47332 commit e10bdbc

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

Tests/BasicsTests/AsyncProcessTests.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import struct TSCBasic.ByteString
2020
import struct TSCBasic.Format
2121
import class TSCBasic.Thread
2222
import func TSCBasic.withTemporaryFile
23-
import func TSCTestSupport.withCustomEnv
2423

2524
#if os(Windows)
2625
let catExecutable = "type"
@@ -168,7 +167,7 @@ final class AsyncProcessTests: XCTestCase {
168167
#endif
169168
try localFileSystem.writeFileContents(tempExecutable, bytes: exitScriptContent)
170169

171-
try withCustomEnv(["PATH": tmpdir.pathString]) {
170+
try Environment.makeCustom(["PATH": tmpdir.pathString]) {
172171
XCTAssertEqual(AsyncProcess.findExecutable("nonExecutableProgram"), nil)
173172
}
174173
}
@@ -184,7 +183,7 @@ final class AsyncProcessTests: XCTestCase {
184183
185184
""")
186185

187-
try withCustomEnv(["PATH": tmpdir.pathString]) {
186+
try Environment.makeCustom(["PATH": tmpdir.pathString]) {
188187
do {
189188
let process = AsyncProcess(args: "nonExecutableProgram")
190189
try process.launch()

Tests/BasicsTests/Environment/EnvironmentTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,19 @@ struct EnvironmentTests {
144144
#expect(Environment.current[key] == nil)
145145
}
146146

147+
@Test
148+
func makeCustomPathEnv() async throws {
149+
let value = "TestValue"
150+
151+
var customEnvironment: Environment = .current
152+
let origPath = customEnvironment[.path]
153+
154+
try Environment.makeCustom(["PATH": "/foo/bar"]) {
155+
#expect(Environment.current[.path] == "/foo/bar")
156+
}
157+
#expect(Environment.current[.path] == origPath)
158+
}
159+
147160
/// Important: This test is inherently race-prone, if it is proven to be
148161
/// flaky, it should run in a singled threaded environment/removed entirely.
149162
@Test

0 commit comments

Comments
 (0)