Skip to content

Commit b092abe

Browse files
authored
Tests: Merge Windows helper function and update GH issues (#8569)
Update the GitHub issue reference on some skipped tests, and also merge the skipIfOnWindowsBecause..() and XCTSkipOnWindows() helper functions to make aid with discoverability. Also, update the Git Tests to be skipped only in the self hosted pipelines, as that is the environment where the tests are hanging.
1 parent bc72d82 commit b092abe

30 files changed

+123
-118
lines changed

Sources/_InternalTestSupport/XCTAssertHelpers.swift

+23-6
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,34 @@ public func XCTAssertEqual<T:Equatable, U:Equatable> (_ lhs:(T,U), _ rhs:(T,U),
4444
TSCTestSupport.XCTAssertEqual(lhs, rhs, file: file, line: line)
4545
}
4646

47-
public func XCTSkipIfCI(file: StaticString = #filePath, line: UInt = #line) throws {
47+
public func XCTSkipIfPlatformCI(because reason: String? = nil, file: StaticString = #filePath, line: UInt = #line) throws {
4848
// TODO: is this actually the right variable now?
4949
if isInCiEnvironment {
50-
throw XCTSkip("Skipping because the test is being run on CI", file: file, line: line)
50+
let failureCause = reason ?? "Skipping because the test is being run on CI"
51+
throw XCTSkip(failureCause, file: file, line: line)
5152
}
5253
}
5354

54-
public func XCTSkipIfWindowsCI(file: StaticString = #filePath, line: UInt = #line) throws {
55+
public func XCTSkipIfselfHostedCI(because reason: String, file: StaticString = #filePath, line: UInt = #line) throws {
56+
// TODO: is this actually the right variable now?
57+
if isSelfHostedCiEnvironment {
58+
throw XCTSkip(reason, file: file, line: line)
59+
}
60+
}
61+
62+
public func XCTSkipOnWindows(because reason: String? = nil, skipPlatformCi: Bool = false, skipSelfHostedCI: Bool = false , file: StaticString = #filePath, line: UInt = #line) throws {
5563
#if os(Windows)
56-
if ProcessInfo.processInfo.environment["SWIFTCI_IS_SELF_HOSTED"] != nil {
57-
throw XCTSkip("Skipping because the test is being run on CI", file: file, line: line)
64+
let failureCause: String
65+
if let reason {
66+
failureCause = " because \(reason.description)"
67+
} else {
68+
failureCause = ""
69+
}
70+
if (skipPlatformCi || skipSelfHostedCI) {
71+
try XCTSkipIfPlatformCI(because: "Test is run in Platform CI. Skipping\(failureCause)", file: file, line: line)
72+
try XCTSkipIfselfHostedCI(because: "Test is run in Self hosted CI. Skipping\(failureCause)", file: file, line: line)
73+
} else {
74+
throw XCTSkip("Skipping test\(failureCause)", file: file, line: line)
5875
}
5976
#endif
6077
}
@@ -276,7 +293,7 @@ public struct CommandExecutionError: Error {
276293
/// - seealso: https://github.com/swiftlang/swift-package-manager/issues/8560
277294
public func XCTSkipIfWorkingDirectoryUnsupported() throws {
278295
func unavailable() throws {
279-
throw XCTSkip("Thread-safe process working directory support is unavailable on this platform.")
296+
throw XCTSkip("https://github.com/swiftlang/swift-package-manager/issues/8560: Thread-safe process working directory support is unavailable on this platform.")
280297
}
281298
#if os(Linux)
282299
if FileManager.default.contents(atPath: "/etc/system-release").map({ String(decoding: $0, as: UTF8.self) == "Amazon Linux release 2 (Karoo)\n" }) ?? false {

Sources/_InternalTestSupport/misc.swift

+1-12
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import enum TSCUtility.Git
4040
@_exported import enum TSCTestSupport.StringPattern
4141

4242
public let isInCiEnvironment = ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] != nil
43+
public let isSelfHostedCiEnvironment = ProcessInfo.processInfo.environment["SWIFTCI_IS_SELF_HOSTED"] != nil
4344

4445
/// Test helper utility for executing a block with a temporary directory.
4546
public func testWithTemporaryDirectory(
@@ -288,18 +289,6 @@ public func executeSwiftBuild(
288289
return try await SwiftPM.Build.execute(args, packagePath: packagePath, env: env)
289290
}
290291

291-
public func skipOnWindowsAsTestCurrentlyFails(because reason: String? = nil) throws {
292-
#if os(Windows)
293-
let failureCause: String
294-
if let reason {
295-
failureCause = " because \(reason.description)"
296-
} else {
297-
failureCause = ""
298-
}
299-
throw XCTSkip("Skipping tests on windows\(failureCause)")
300-
#endif
301-
}
302-
303292
@discardableResult
304293
public func executeSwiftRun(
305294
_ packagePath: AbsolutePath?,

Tests/BasicsTests/AsyncProcessTests.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ final class AsyncProcessTests: XCTestCase {
144144
}
145145

146146
func testFindExecutable() throws {
147-
try skipOnWindowsAsTestCurrentlyFails(because: "https://github.com/swiftlang/swift-package-manager/issues/8547: Assertion failure when trying to find ls executable")
147+
try XCTSkipOnWindows(because: "https://github.com/swiftlang/swift-package-manager/issues/8547: Assertion failure when trying to find ls executable")
148148

149149
try testWithTemporaryDirectory { tmpdir in
150150
// This process should always work.
@@ -426,8 +426,8 @@ final class AsyncProcessTests: XCTestCase {
426426

427427
func testAsyncStream() async throws {
428428
// rdar://133548796
429-
try XCTSkipIfCI()
430-
try skipOnWindowsAsTestCurrentlyFails(because: "https://github.com/swiftlang/swift-package-manager/issues/8547: 'swift test' was hanging.")
429+
try XCTSkipIfPlatformCI()
430+
try XCTSkipOnWindows(because: "https://github.com/swiftlang/swift-package-manager/issues/8547: 'swift test' was hanging.")
431431

432432
let (stdoutStream, stdoutContinuation) = AsyncProcess.ReadableStream.makeStream()
433433
let (stderrStream, stderrContinuation) = AsyncProcess.ReadableStream.makeStream()
@@ -484,8 +484,8 @@ final class AsyncProcessTests: XCTestCase {
484484

485485
func testAsyncStreamHighLevelAPI() async throws {
486486
// rdar://133548796
487-
try XCTSkipIfCI()
488-
try skipOnWindowsAsTestCurrentlyFails(because: "https://github.com/swiftlang/swift-package-manager/issues/8547: 'swift test' was hanging.")
487+
try XCTSkipIfPlatformCI()
488+
try XCTSkipOnWindows(because: "https://github.com/swiftlang/swift-package-manager/issues/8547: 'swift test' was hanging.")
489489

490490
let result = try await AsyncProcess.popen(
491491
scriptName: "echo\(ProcessInfo.batSuffix)", // maps to 'processInputs/echo' script

Tests/BasicsTests/FileSystem/PathTests.swift

+17-17
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Basics
1212
import Foundation
1313
import XCTest
1414

15-
import _InternalTestSupport // for skipOnWindowsAsTestCurrentlyFails()
15+
import _InternalTestSupport // for XCTSkipOnWindows()
1616

1717
#if os(Windows)
1818
private var windows: Bool { true }
@@ -57,7 +57,7 @@ class PathTests: XCTestCase {
5757
}
5858

5959
func testRepeatedPathSeparators() throws {
60-
try skipOnWindowsAsTestCurrentlyFails(because: "all assertions fail")
60+
try XCTSkipOnWindows(because: "all assertions fail")
6161

6262
XCTAssertEqual(AbsolutePath("/ab//cd//ef").pathString, windows ? #"\ab\cd\ef"# : "/ab/cd/ef")
6363
XCTAssertEqual(AbsolutePath("/ab///cd//ef").pathString, windows ? #"\ab\cd\ef"# : "/ab/cd/ef")
@@ -66,7 +66,7 @@ class PathTests: XCTestCase {
6666
}
6767

6868
func testTrailingPathSeparators() throws {
69-
try skipOnWindowsAsTestCurrentlyFails(because: "trailing path seperator is not removed from pathString")
69+
try XCTSkipOnWindows(because: "trailing path seperator is not removed from pathString")
7070

7171
XCTAssertEqual(AbsolutePath("/ab/cd/ef/").pathString, windows ? #"\ab\cd\ef"# : "/ab/cd/ef")
7272
XCTAssertEqual(AbsolutePath("/ab/cd/ef//").pathString, windows ? #"\ab\cd\ef"# : "/ab/cd/ef")
@@ -75,7 +75,7 @@ class PathTests: XCTestCase {
7575
}
7676

7777
func testDotPathComponents() throws {
78-
try skipOnWindowsAsTestCurrentlyFails()
78+
try XCTSkipOnWindows()
7979

8080
XCTAssertEqual(AbsolutePath("/ab/././cd//ef").pathString, "/ab/cd/ef")
8181
XCTAssertEqual(AbsolutePath("/ab/./cd//ef/.").pathString, "/ab/cd/ef")
@@ -84,7 +84,7 @@ class PathTests: XCTestCase {
8484
}
8585

8686
func testDotDotPathComponents() throws {
87-
try skipOnWindowsAsTestCurrentlyFails()
87+
try XCTSkipOnWindows()
8888

8989
XCTAssertEqual(AbsolutePath("/..").pathString, windows ? #"\"# : "/")
9090
XCTAssertEqual(AbsolutePath("/../../../../..").pathString, windows ? #"\"# : "/")
@@ -102,7 +102,7 @@ class PathTests: XCTestCase {
102102
}
103103

104104
func testCombinationsAndEdgeCases() throws {
105-
try skipOnWindowsAsTestCurrentlyFails()
105+
try XCTSkipOnWindows()
106106

107107
XCTAssertEqual(AbsolutePath("///").pathString, windows ? #"\"# : "/")
108108
XCTAssertEqual(AbsolutePath("/./").pathString, windows ? #"\"# : "/")
@@ -133,7 +133,7 @@ class PathTests: XCTestCase {
133133
}
134134

135135
func testDirectoryNameExtraction() throws {
136-
try skipOnWindowsAsTestCurrentlyFails()
136+
try XCTSkipOnWindows()
137137

138138
XCTAssertEqual(AbsolutePath("/").dirname, windows ? #"\"# : "/")
139139
XCTAssertEqual(AbsolutePath("/a").dirname, windows ? #"\"# : "/")
@@ -152,7 +152,7 @@ class PathTests: XCTestCase {
152152
}
153153

154154
func testBaseNameExtraction() throws {
155-
try skipOnWindowsAsTestCurrentlyFails()
155+
try XCTSkipOnWindows()
156156

157157
XCTAssertEqual(AbsolutePath("/").basename, windows ? #"\"# : "/")
158158
XCTAssertEqual(AbsolutePath("/a").basename, "a")
@@ -170,7 +170,7 @@ class PathTests: XCTestCase {
170170
}
171171

172172
func testBaseNameWithoutExt() throws{
173-
try skipOnWindowsAsTestCurrentlyFails()
173+
try XCTSkipOnWindows()
174174

175175
XCTAssertEqual(AbsolutePath("/").basenameWithoutExt, windows ? #"\"# : "/")
176176
XCTAssertEqual(AbsolutePath("/a").basenameWithoutExt, "a")
@@ -195,7 +195,7 @@ class PathTests: XCTestCase {
195195
}
196196

197197
func testSuffixExtraction() throws {
198-
try skipOnWindowsAsTestCurrentlyFails(because: "expected nil is not the actual")
198+
try XCTSkipOnWindows(because: "expected nil is not the actual")
199199

200200
XCTAssertEqual(RelativePath("a").suffix, nil)
201201
XCTAssertEqual(RelativePath("a").extension, nil)
@@ -222,7 +222,7 @@ class PathTests: XCTestCase {
222222
}
223223

224224
func testParentDirectory() throws {
225-
try skipOnWindowsAsTestCurrentlyFails()
225+
try XCTSkipOnWindows()
226226

227227
XCTAssertEqual(AbsolutePath("/").parentDirectory, AbsolutePath("/"))
228228
XCTAssertEqual(AbsolutePath("/").parentDirectory.parentDirectory, AbsolutePath("/"))
@@ -233,7 +233,7 @@ class PathTests: XCTestCase {
233233

234234
@available(*, deprecated)
235235
func testConcatenation() throws {
236-
try skipOnWindowsAsTestCurrentlyFails()
236+
try XCTSkipOnWindows()
237237

238238
XCTAssertEqual(AbsolutePath(AbsolutePath("/"), RelativePath("")).pathString, windows ? #"\"# : "/")
239239
XCTAssertEqual(AbsolutePath(AbsolutePath("/"), RelativePath(".")).pathString, windows ? #"\"# : "/")
@@ -272,7 +272,7 @@ class PathTests: XCTestCase {
272272
}
273273

274274
func testPathComponents() throws {
275-
try skipOnWindowsAsTestCurrentlyFails()
275+
try XCTSkipOnWindows()
276276

277277
XCTAssertEqual(AbsolutePath("/").components, ["/"])
278278
XCTAssertEqual(AbsolutePath("/.").components, ["/"])
@@ -302,7 +302,7 @@ class PathTests: XCTestCase {
302302
}
303303

304304
func testRelativePathFromAbsolutePaths() throws {
305-
try skipOnWindowsAsTestCurrentlyFails()
305+
try XCTSkipOnWindows()
306306

307307
XCTAssertEqual(AbsolutePath("/").relative(to: AbsolutePath("/")), RelativePath("."));
308308
XCTAssertEqual(AbsolutePath("/a/b/c/d").relative(to: AbsolutePath("/")), RelativePath("a/b/c/d"));
@@ -345,7 +345,7 @@ class PathTests: XCTestCase {
345345
}
346346

347347
func testAbsolutePathValidation() throws {
348-
try skipOnWindowsAsTestCurrentlyFails()
348+
try XCTSkipOnWindows()
349349

350350
XCTAssertNoThrow(try AbsolutePath(validating: "/a/b/c/d"))
351351

@@ -359,7 +359,7 @@ class PathTests: XCTestCase {
359359
}
360360

361361
func testRelativePathValidation() throws {
362-
try skipOnWindowsAsTestCurrentlyFails()
362+
try XCTSkipOnWindows()
363363

364364
XCTAssertNoThrow(try RelativePath(validating: "a/b/c/d"))
365365

@@ -374,7 +374,7 @@ class PathTests: XCTestCase {
374374
}
375375

376376
func testCodable() throws {
377-
try skipOnWindowsAsTestCurrentlyFails()
377+
try XCTSkipOnWindows()
378378

379379
struct Foo: Codable, Equatable {
380380
var path: AbsolutePath

Tests/BasicsTests/FileSystem/VFSTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import XCTest
1616

1717
import struct TSCBasic.ByteString
1818

19-
import _InternalTestSupport // for skipOnWindowsAsTestCurrentlyFails
19+
import _InternalTestSupport // for XCTSkipOnWindows
2020

2121
func testWithTemporaryDirectory(
2222
function: StaticString = #function,
@@ -38,7 +38,7 @@ func testWithTemporaryDirectory(
3838

3939
class VFSTests: XCTestCase {
4040
func testLocalBasics() throws {
41-
try skipOnWindowsAsTestCurrentlyFails()
41+
try XCTSkipOnWindows()
4242

4343
// tiny PE binary from: https://archive.is/w01DO
4444
let contents: [UInt8] = [

Tests/BasicsTests/HTTPClientTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ final class HTTPClientTests: XCTestCase {
226226
}
227227

228228
func testExponentialBackoff() async throws {
229-
try skipOnWindowsAsTestCurrentlyFails(because: "https://github.com/swiftlang/swift-package-manager/issues/8501")
229+
try XCTSkipOnWindows(because: "https://github.com/swiftlang/swift-package-manager/issues/8501")
230230

231231
let counter = SendableBox(0)
232232
let lastCall = SendableBox<Date>()

Tests/BasicsTests/LegacyHTTPClientTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ final class LegacyHTTPClientTests: XCTestCase {
350350
}
351351

352352
func testExponentialBackoff() throws {
353-
try skipOnWindowsAsTestCurrentlyFails(because: "https://github.com/swiftlang/swift-package-manager/issues/8501")
353+
try XCTSkipOnWindows(because: "https://github.com/swiftlang/swift-package-manager/issues/8501")
354354

355355
let count = ThreadSafeBox<Int>(0)
356356
let lastCall = ThreadSafeBox<Date>()

Tests/BasicsTests/Serialization/SerializedJSONTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
@testable import Basics
1414
import XCTest
15-
import _InternalTestSupport // for skipOnWindowsAsTestCurrentlyFails
15+
import _InternalTestSupport // for XCTSkipOnWindows
1616

1717
final class SerializedJSONTests: XCTestCase {
1818
func testPathInterpolation() throws {
@@ -34,7 +34,7 @@ final class SerializedJSONTests: XCTestCase {
3434
}
3535

3636
func testPathInterpolationFailsOnWindows() throws {
37-
try skipOnWindowsAsTestCurrentlyFails(because: "Expectations are not met. Possibly related to https://github.com/swiftlang/swift-package-manager/issues/8511")
37+
try XCTSkipOnWindows(because: "Expectations are not met. Possibly related to https://github.com/swiftlang/swift-package-manager/issues/8511")
3838

3939
#if os(Windows)
4040
var path = try AbsolutePath(validating: #"\\?\C:\Users"#)

Tests/BasicsTests/URLSessionHTTPClientTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ final class URLSessionHTTPClientTest: XCTestCase {
356356
// https://github.com/apple/swift-corelibs-foundation/pull/2593 tries to address the latter part
357357
try XCTSkipIf(true, "test is only supported on macOS")
358358
#endif
359-
try XCTSkipIfCI()
359+
try XCTSkipIfPlatformCI()
360360
let netrcContent = "default login default password default"
361361
let netrc = try NetrcAuthorizationWrapper(underlying: NetrcParser.parse(netrcContent))
362362
let authData = Data("default:default".utf8)

Tests/BuildTests/BuildPlanTests.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
620620
}
621621

622622
func testPackageNameFlag() async throws {
623-
try XCTSkipIfCI() // test is disabled because it isn't stable, see rdar://118239206
623+
try XCTSkipIfPlatformCI() // test is disabled because it isn't stable, see rdar://118239206
624624
let isFlagSupportedInDriver = try DriverSupport.checkToolchainDriverFlags(
625625
flags: ["package-name"],
626626
toolchain: UserToolchain.default,
@@ -2040,7 +2040,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
20402040
}
20412041

20422042
func test_symbolGraphExtract_arguments() async throws {
2043-
try skipOnWindowsAsTestCurrentlyFails()
2043+
try XCTSkipOnWindows()
20442044

20452045
// ModuleGraph:
20462046
// .
@@ -4701,7 +4701,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
47014701
}
47024702

47034703
func testUserToolchainCompileFlags() async throws {
4704-
try skipOnWindowsAsTestCurrentlyFails()
4704+
try XCTSkipOnWindows()
47054705

47064706
let fs = InMemoryFileSystem(
47074707
emptyFiles:
@@ -4955,7 +4955,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
49554955
}
49564956

49574957
func testUserToolchainWithToolsetCompileFlags() async throws {
4958-
try skipOnWindowsAsTestCurrentlyFails(because: "Path delimiters donw's work well on Windows")
4958+
try XCTSkipOnWindows(because: "Path delimiters donw's work well on Windows")
49594959

49604960
let fileSystem = InMemoryFileSystem(
49614961
emptyFiles:
@@ -5125,7 +5125,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
51255125
}
51265126

51275127
func testUserToolchainWithSDKSearchPaths() async throws {
5128-
try skipOnWindowsAsTestCurrentlyFails()
5128+
try XCTSkipOnWindows()
51295129

51305130
let fileSystem = InMemoryFileSystem(
51315131
emptyFiles:

Tests/BuildTests/BuildSystemDelegateTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class BuildSystemDelegateTests: XCTestCase {
3030
}
3131

3232
func testFilterNonFatalCodesignMessages() async throws {
33-
try skipOnWindowsAsTestCurrentlyFails(because: "https://github.com/swiftlang/swift-package-manager/issues/8540: Package fails to build when the test is being executed")
33+
try XCTSkipOnWindows(because: "https://github.com/swiftlang/swift-package-manager/issues/8540: Package fails to build when the test is being executed")
3434

3535
try XCTSkipIf(!UserToolchain.default.supportsSDKDependentTests(), "skipping because test environment doesn't support this test")
3636
// Note: we can re-use the `TestableExe` fixture here since we just need an executable.

Tests/BuildTests/PluginsBuildPlanTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import PackageModel
1818

1919
final class PluginsBuildPlanTests: XCTestCase {
2020
func testBuildToolsDatabasePath() async throws {
21-
try skipOnWindowsAsTestCurrentlyFails()
21+
try XCTSkipOnWindows()
2222

2323
try await fixture(name: "Miscellaneous/Plugins/MySourceGenPlugin") { fixturePath in
2424
let (stdout, _) = try await executeSwiftBuild(fixturePath)

0 commit comments

Comments
 (0)