Skip to content

Commit 9a11616

Browse files
committed
Various fixes for tests on Windows
- also mark withKnownIssues tests as isIntermittent: true so that as we fix things in dependant packages (like swift-build) we dont break swiftPM CI
1 parent 84b3e6e commit 9a11616

27 files changed

+132
-194
lines changed

Sources/Commands/SwiftTestCommand.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import enum TSCBasic.JSON
4141
import var TSCBasic.stdoutStream
4242
import class TSCBasic.SynchronizedQueue
4343
import class TSCBasic.Thread
44+
import struct TSCBasic.Condition
4445

4546
#if os(Windows)
4647
import WinSDK // for ERROR_NOT_FOUND
@@ -1196,6 +1197,8 @@ final class ParallelTestRunner {
11961197
library: .xctest // swift-testing does not use ParallelTestRunner
11971198
)
11981199

1200+
var runningTests: [String] = []
1201+
let runningTestsLock = Condition()
11991202
// Enqueue all the tests.
12001203
try enqueueTests(tests)
12011204

@@ -1214,11 +1217,17 @@ final class ParallelTestRunner {
12141217
observabilityScope: self.observabilityScope,
12151218
library: .xctest // swift-testing does not use ParallelTestRunner
12161219
)
1220+
runningTestsLock.whileLocked() {
1221+
runningTests.append(test.specifier)
1222+
}
12171223
var output = ""
12181224
let outputLock = NSLock()
12191225
let start = DispatchTime.now()
12201226
let result = testRunner.test(outputHandler: { _output in outputLock.withLock{ output += _output }})
12211227
let duration = start.distance(to: .now())
1228+
runningTestsLock.whileLocked() {
1229+
runningTests = runningTests.filter { $0 != test.specifier }
1230+
}
12221231
if result == .failure {
12231232
self.ranSuccessfully = false
12241233
}
@@ -1249,6 +1258,9 @@ final class ParallelTestRunner {
12491258
if numCurrentTest == numTests {
12501259
break
12511260
}
1261+
runningTestsLock.whileLocked() {
1262+
print("\nRUNNING: \(runningTests)")
1263+
}
12521264
}
12531265

12541266
// Wait till all threads finish execution.

Sources/SourceControl/Repository.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public struct RepositorySpecifier: Hashable, Sendable {
4747
if basename.hasSuffix(".git") {
4848
basename = String(basename.dropLast(4))
4949
}
50-
if basename == "/" {
50+
if basename == "/" || basename == "\\" {
5151
return ""
5252
}
5353
return basename

Tests/BasicsTests/AsyncProcessTests.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,14 @@ final class AsyncProcessTests: XCTestCase {
5353
}
5454

5555
func testPopenWithBufferLargerThanAllocated() throws {
56-
try XCTSkipOnWindows(because: "https://github.com/swiftlang/swift-package-manager/issues/9031: test fails on windows.")
57-
5856
// Test buffer larger than that allocated.
5957
try withTemporaryFile { file in
6058
let count = 10000
6159
let stream = BufferedOutputByteStream()
6260
stream.send(Format.asRepeating(string: "a", count: count))
63-
try localFileSystem.writeFileContents(file.path, bytes: stream.bytes)
61+
file.fileHandle.write(Data(stream.bytes.contents))
6462
let actualStreamCount = stream.bytes.count
65-
XCTAssertTrue(actualStreamCount == count, "Actual stream count (\(actualStreamCount)) is not as exxpected (\(count))")
63+
XCTAssertTrue(actualStreamCount == count, "Actual stream count (\(actualStreamCount)) is not as expected (\(count))")
6664
let outputCount = try AsyncProcess.popen(arguments: catExecutableArgs + [file.path.pathString]).utf8Output().count
6765
XCTAssert(outputCount == count, "Actual count (\(outputCount)) is not as expected (\(count))")
6866
}

Tests/BasicsTests/FileSystem/InMemoryFilesSystemTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ struct InMemoryFileSystemTests {
151151

152152
// WHEN we write contents to the file
153153
// THEn we expect an error to occus
154-
withKnownIssue {
154+
#expect(throws: (any Error).self) {
155155
try fs.writeFileContents(pathUnderTest, bytes: expectedContents)
156156
}
157157

@@ -171,7 +171,7 @@ struct InMemoryFileSystemTests {
171171

172172
// WHEN we write contents to the file
173173
// THEN we expect an error to occur
174-
withKnownIssue {
174+
#expect(throws: (any Error).self) {
175175
try fs.writeFileContents(pathUnderTest, bytes: expectedContents)
176176
}
177177

@@ -191,7 +191,7 @@ struct InMemoryFileSystemTests {
191191

192192
// WHEN we write contents to the file
193193
// THEN we expect an error to occur
194-
withKnownIssue {
194+
#expect(throws: (any Error).self) {
195195
try fs.writeFileContents(pathUnderTest, bytes: expectedContents)
196196
}
197197

@@ -207,7 +207,7 @@ struct InMemoryFileSystemTests {
207207

208208
// WHEN we read a non-existing file
209209
// THEN an error occurs
210-
withKnownIssue {
210+
#expect(throws: (any Error).self) {
211211
let _ = try fs.readFileContents("/file/does/not/exists")
212212
}
213213
}
@@ -323,8 +323,8 @@ struct InMemoryFileSystemTests {
323323

324324
// WHEN we read the contents of a directory
325325
// THEN we expect a failure to occur
326-
withKnownIssue {
327-
let _ = try fs.readFileContents(pathUnderTest.parentDirectory)
326+
#expect(throws: (any Error).self) {
327+
try fs.readFileContents(pathUnderTest.parentDirectory)
328328
}
329329
}
330330
}

Tests/BasicsTests/Serialization/SerializedJSONTests.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,16 @@ final class SerializedJSONTests: XCTestCase {
3434
}
3535

3636
func testPathInterpolationFailsOnWindows() throws {
37-
try XCTSkipOnWindows(because: "Expectations are not met. Possibly related to https://github.com/swiftlang/swift-package-manager/issues/8511")
38-
3937
#if os(Windows)
4038
var path = try AbsolutePath(validating: #"\\?\C:\Users"#)
4139
var json: SerializedJSON = "\(path)"
4240

43-
XCTAssertEqual(json.underlying, #"C:\\Users"#)
41+
XCTAssertEqual(json.underlying, #"\\\\?\\C:\\Users"#)
4442

4543
path = try AbsolutePath(validating: #"\\.\UNC\server\share\"#)
4644
json = "\(path)"
4745

48-
XCTAssertEqual(json.underlying, #"\\.\\UNC\\server\\share"#)
46+
XCTAssertEqual(json.underlying, #"\\\\.\\UNC\\server\\share"#)
4947
#endif
5048
}
5149
}

Tests/CommandsTests/BuildCommandTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ struct BuildCommandTestCases {
782782
) async throws {
783783
let buildSystem = data.buildSystem
784784
try await fixture(name: "Miscellaneous/ParseableInterfaces") { fixturePath in
785-
try await withKnownIssue(isIntermittent: ProcessInfo.hostOperatingSystem == .windows) {
785+
try await withKnownIssue(isIntermittent: true) {
786786
let result = try await build(
787787
["--enable-parseable-module-interfaces"],
788788
packagePath: fixturePath,
@@ -818,7 +818,7 @@ struct BuildCommandTestCases {
818818
data: BuildData,
819819
) async throws {
820820
let buildSystem = data.buildSystem
821-
try await withKnownIssue {
821+
try await withKnownIssue(isIntermittent: true) {
822822
try await fixture(name: "Miscellaneous/LibraryEvolution") { fixturePath in
823823
let result = try await build(
824824
[],
@@ -857,7 +857,7 @@ struct BuildCommandTestCases {
857857
data: BuildData,
858858
) async throws {
859859
let buildSystem = data.buildSystem
860-
try await withKnownIssue {
860+
try await withKnownIssue(isIntermittent: true) {
861861
try await fixture(name: "DependencyResolution/Internal/Simple") { fixturePath in
862862
let buildCompleteRegex = try Regex(#"Build complete!\s?(\([0-9]*\.[0-9]*\s*s(econds)?\))?"#)
863863
do {
@@ -1137,7 +1137,7 @@ struct BuildCommandTestCases {
11371137
) async throws {
11381138
try await withKnownIssue(
11391139
"error produced for this fixture",
1140-
isIntermittent: ProcessInfo.hostOperatingSystem == .linux,
1140+
isIntermittent: true,
11411141
) {
11421142
try await fixture(name: "DependencyResolution/Internal/Simple") { fixturePath in
11431143
// Building with `-wmo` should result in a `remark: Incremental compilation has been disabled: it is not
@@ -1199,7 +1199,7 @@ struct BuildCommandTestCases {
11991199

12001200
try await withKnownIssue(
12011201
"https://github.com/swiftlang/swift-package-manager/issues/8659, SWIFT_EXEC override is not working",
1202-
isIntermittent: (buildSystem == .native && config == .release)
1202+
isIntermittent: true
12031203
){
12041204
// Build with a swiftc that returns version 1.0, we expect a successful build which compiles our one source
12051205
// file.
@@ -1294,7 +1294,7 @@ struct BuildCommandTestCases {
12941294
func getTaskAllowEntitlement(
12951295
buildSystem: BuildSystemProvider.Kind,
12961296
) async throws {
1297-
try await withKnownIssue(isIntermittent: (ProcessInfo.hostOperatingSystem == .linux)) {
1297+
try await withKnownIssue(isIntermittent: true) {
12981298
try await fixture(name: "ValidLayouts/SingleModule/ExecutableNew") { fixturePath in
12991299
#if os(macOS)
13001300
// try await building with default parameters. This should succeed. We build verbosely so we get full command
@@ -1506,7 +1506,7 @@ struct BuildCommandTestCases {
15061506
func parseAsLibraryCriteria(
15071507
buildData: BuildData,
15081508
) async throws {
1509-
try await withKnownIssue {
1509+
try await withKnownIssue(isIntermittent: true) {
15101510
try await fixture(name: "Miscellaneous/ParseAsLibrary") { fixturePath in
15111511
_ = try await executeSwiftBuild(
15121512
fixturePath,
@@ -1571,7 +1571,7 @@ struct BuildCommandTestCases {
15711571
) async throws {
15721572
let buildSystem = data.buildSystem
15731573
let configuration = data.config
1574-
try await withKnownIssue {
1574+
try await withKnownIssue(isIntermittent: true) {
15751575
// GIVEN we have a simple test package
15761576
try await fixture(name: "Miscellaneous/SwiftBuild") { fixturePath in
15771577
//WHEN we build with the --quiet option

Tests/CommandsTests/CoverageTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct CoverageTests {
4141
buildSystem: BuildSystemProvider.Kind,
4242
) async throws {
4343
let config = BuildConfiguration.debug
44-
try await withKnownIssue(isIntermittent: (ProcessInfo.hostOperatingSystem == .linux && buildSystem == .swiftbuild)) {
44+
try await withKnownIssue(isIntermittent: true) {
4545
try await fixture(name: "Miscellaneous/TestDiscovery/Simple") { path in
4646
_ = try await executeSwiftBuild(
4747
path,
@@ -96,7 +96,7 @@ struct CoverageTests {
9696
let codeCovPath = try AbsolutePath(validating: codeCovPathString)
9797

9898
// WHEN we build with coverage enabled
99-
try await withKnownIssue {
99+
try await withKnownIssue(isIntermittent: true) {
100100
try await executeSwiftBuild(
101101
path,
102102
configuration: config,

0 commit comments

Comments
 (0)