Skip to content

Commit ccbf01f

Browse files
authored
Fix issue with running test on windows w/no-parallel (#8676)
The AsyncProcess Tests were using a TSCTestSupport method to temporarily 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 switches it to using the similar method that is in SwiftPM Environment.swift
1 parent 5fe143f commit ccbf01f

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
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: 14 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,19 @@ 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(.disabled(if: isInCiEnvironment, "This test can disrupt other tests running in parallel."))
151+
func makeCustomPathEnv() async throws {
152+
let customEnvironment: Environment = .current
153+
let origPath = customEnvironment[.path]
154+
155+
try Environment.makeCustom(["PATH": "/foo/bar"]) {
156+
#expect(Environment.current[.path] == "/foo/bar")
157+
}
158+
#expect(Environment.current[.path] == origPath)
159+
}
160+
147161
/// Important: This test is inherently race-prone, if it is proven to be
148162
/// flaky, it should run in a singled threaded environment/removed entirely.
149163
@Test

Tests/CommandsTests/RunCommandTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ class RunCommandTestCase: CommandsBuildProviderTestCase {
142142
}
143143

144144
func testSwiftRunSIGINT() throws {
145-
try XCTSkipIfPlatformCI()
146-
try XCTSkipOnWindows(because: "fails due to possible timing issues, need investigation")
145+
try XCTSkipIfPlatformCI(because: "This seems to be flaky in CI")
146+
try XCTSkipIfselfHostedCI(because: "This seems to be flaky in CI")
147147
try fixture(name: "Miscellaneous/SwiftRun") { fixturePath in
148148
let mainFilePath = fixturePath.appending("main.swift")
149149
try localFileSystem.removeFileTree(mainFilePath)

Tests/FunctionalTests/PluginTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,8 @@ final class PluginTests: XCTestCase {
665665
}
666666

667667
func testCommandPluginCancellation() async throws {
668+
try XCTSkipOnWindows(because: "This hangs intermittently on windows in CI", skipSelfHostedCI: true)
669+
668670
// Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require).
669671
try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency")
670672

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)