Skip to content

Commit 13c0be3

Browse files
committed
Various fixes for tests on Windows
- also mark withKnownIssues tests as isIntermittent: true so that as we fix things in dependent packages (like swift-build) we don't break swiftPM CI
1 parent 96d7b55 commit 13c0be3

26 files changed

+195
-252
lines changed

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

Sources/_InternalTestSupport/misc.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public enum TestError: Error {
212212
do {
213213
// Make a suitable test directory name from the fixture subpath.
214214
let fixtureSubpath = try RelativePath(validating: name)
215-
let copyName = fixtureSubpath.components.joined(separator: "_")
215+
let copyName = fixtureSubpath.components.last!
216216

217217
// Create a temporary directory for the duration of the block.
218218
return try await withTemporaryDirectory(prefix: copyName) { tmpDirPath in
@@ -252,7 +252,7 @@ public enum TestError: Error {
252252
do {
253253
// Make a suitable test directory name from the fixture subpath.
254254
let fixtureSubpath = try RelativePath(validating: name)
255-
let copyName = fixtureSubpath.components.joined(separator: "_")
255+
let copyName = fixtureSubpath.components.last!
256256

257257
// Create a temporary directory for the duration of the block.
258258
return try await withTemporaryDirectory(

Tests/BasicsTests/AsyncProcessTests.swift

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

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

Tests/BasicsTests/FileSystem/InMemoryFilesSystemTests.swift

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

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

@@ -172,7 +172,7 @@ struct InMemoryFileSystemTests {
172172

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

@@ -192,7 +192,7 @@ struct InMemoryFileSystemTests {
192192

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

@@ -208,7 +208,7 @@ struct InMemoryFileSystemTests {
208208

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

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

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: 28 additions & 21 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,
@@ -1148,24 +1148,31 @@ struct BuildCommandTestCases {
11481148
func swiftDriverRawOutputGetsNewlines(
11491149
buildSystem: BuildSystemProvider.Kind,
11501150
) async throws {
1151-
try await fixture(name: "DependencyResolution/Internal/Simple") { fixturePath in
1152-
// Building with `-wmo` should result in a `remark: Incremental compilation has been disabled: it is not
1153-
// compatible with whole module optimization` message, which should have a trailing newline. Since that
1154-
// message won't be there at all when the legacy compiler driver is used, we gate this check on whether the
1155-
// remark is there in the first place.
1156-
let result = try await execute(
1157-
["-Xswiftc", "-wmo"],
1158-
packagePath: fixturePath,
1159-
configuration: .release,
1160-
buildSystem: buildSystem,
1161-
)
1162-
if result.stdout.contains(
1163-
"remark: Incremental compilation has been disabled: it is not compatible with whole module optimization"
1164-
) {
1165-
#expect(result.stdout.contains("optimization\n"))
1166-
#expect(!result.stdout.contains("optimization["))
1167-
#expect(!result.stdout.contains("optimizationremark"))
1151+
try await withKnownIssue(
1152+
"error produced for this fixture",
1153+
isIntermittent: true,
1154+
) {
1155+
try await fixture(name: "DependencyResolution/Internal/Simple") { fixturePath in
1156+
// Building with `-wmo` should result in a `remark: Incremental compilation has been disabled: it is not
1157+
// compatible with whole module optimization` message, which should have a trailing newline. Since that
1158+
// message won't be there at all when the legacy compiler driver is used, we gate this check on whether the
1159+
// remark is there in the first place.
1160+
let result = try await execute(
1161+
["-Xswiftc", "-wmo"],
1162+
packagePath: fixturePath,
1163+
configuration: .release,
1164+
buildSystem: buildSystem,
1165+
)
1166+
if result.stdout.contains(
1167+
"remark: Incremental compilation has been disabled: it is not compatible with whole module optimization"
1168+
) {
1169+
#expect(result.stdout.contains("optimization\n"))
1170+
#expect(!result.stdout.contains("optimization["))
1171+
#expect(!result.stdout.contains("optimizationremark"))
1172+
}
11681173
}
1174+
} when: {
1175+
ProcessInfo.hostOperatingSystem == .windows && buildSystem == .swiftbuild
11691176
}
11701177
}
11711178

@@ -1205,7 +1212,7 @@ struct BuildCommandTestCases {
12051212

12061213
try await withKnownIssue(
12071214
"https://github.com/swiftlang/swift-package-manager/issues/8659, SWIFT_EXEC override is not working",
1208-
isIntermittent: (buildSystem == .native && config == .release)
1215+
isIntermittent: true
12091216
){
12101217
// Build with a swiftc that returns version 1.0, we expect a successful build which compiles our one source
12111218
// file.
@@ -1300,7 +1307,7 @@ struct BuildCommandTestCases {
13001307
func getTaskAllowEntitlement(
13011308
buildSystem: BuildSystemProvider.Kind,
13021309
) async throws {
1303-
try await withKnownIssue(isIntermittent: (ProcessInfo.hostOperatingSystem == .linux)) {
1310+
try await withKnownIssue(isIntermittent: true) {
13041311
try await fixture(name: "ValidLayouts/SingleModule/ExecutableNew") { fixturePath in
13051312
#if os(macOS)
13061313
// try await building with default parameters. This should succeed. We build verbosely so we get full command
@@ -1512,7 +1519,7 @@ struct BuildCommandTestCases {
15121519
func parseAsLibraryCriteria(
15131520
buildData: BuildData,
15141521
) async throws {
1515-
try await withKnownIssue {
1522+
try await withKnownIssue(isIntermittent: true) {
15161523
try await fixture(name: "Miscellaneous/ParseAsLibrary") { fixturePath in
15171524
_ = try await executeSwiftBuild(
15181525
fixturePath,

Tests/CommandsTests/CoverageTests.swift

Lines changed: 3 additions & 3 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,
@@ -157,7 +157,7 @@ struct CoverageTests {
157157
try #require(!localFileSystem.exists(coveragePath))
158158

159159
// WHEN we test with coverage enabled
160-
try await withKnownIssue {
160+
try await withKnownIssue(isIntermittent: true) {
161161
try await executeSwiftTest(
162162
path,
163163
configuration: buildData.config,

0 commit comments

Comments
 (0)