Skip to content

Commit 2652bd7

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 2652bd7

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Foundation
1616
import Basics
1717

1818
import Testing
19+
import _InternalTestSupport
1920

2021
struct EnvironmentTests {
2122
@Test
@@ -144,6 +145,20 @@ struct EnvironmentTests {
144145
#expect(Environment.current[key] == nil)
145146
}
146147

148+
/// Important: This test is inherently race-prone, if it is proven to be
149+
/// flaky, it should run in a singled threaded environment/removed entirely.
150+
@Test
151+
func makeCustomPathEnv() async throws {
152+
try XCTSkipOnWindows(because: "Fails in CI due to parallel running tests", skipPlatformCi: true, skipSelfHostedCI: true)
153+
let customEnvironment: Environment = .current
154+
let origPath = customEnvironment[.path]
155+
156+
try Environment.makeCustom(["PATH": "/foo/bar"]) {
157+
#expect(Environment.current[.path] == "/foo/bar")
158+
}
159+
#expect(Environment.current[.path] == origPath)
160+
}
161+
147162
/// Important: This test is inherently race-prone, if it is proven to be
148163
/// flaky, it should run in a singled threaded environment/removed entirely.
149164
@Test

Tests/FunctionalTests/TraitTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,7 @@ final class TraitTests: XCTestCase {
328328
error: Disabled default traits by package 'disablingemptydefaultsexample' on package 'Package11' that declares no traits. This is prohibited to allow packages to adopt traits initially without causing an API break.
329329
330330
"""
331-
XCTAssertTrue(stderr.contains(expectedErr))
332-
331+
XCTAssertMatch(stderr, .contains(expectedErr))
333332
}
334333
}
335334
}

0 commit comments

Comments
 (0)