Skip to content

Commit 6463516

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 1845c6e commit 6463516

28 files changed

+166
-228
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
@@ -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: 6 additions & 6 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,
@@ -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,

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,

Tests/CommandsTests/PackageCommandTests.swift

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ struct PackageCommandTests {
10441044
func describeJson(
10451045
data: BuildData,
10461046
) async throws {
1047-
try await withKnownIssue(isIntermittent: ProcessInfo.hostOperatingSystem == .windows) {
1047+
try await withKnownIssue(isIntermittent: true) {
10481048
try await fixture(name: "DependencyResolution/External/Simple/Bar") { fixturePath in
10491049
// Generate the JSON description.
10501050
let (jsonOutput, _) = try await execute(
@@ -1189,7 +1189,7 @@ struct PackageCommandTests {
11891189
withPrettyPrinting: Bool,
11901190
) async throws {
11911191
// try XCTSkipIf(buildSystemProvider == .native && (try? UserToolchain.default.getSymbolGraphExtract()) == nil, "skipping test because the `swift-symbolgraph-extract` tools isn't available")
1192-
try await withKnownIssue {
1192+
try await withKnownIssue(isIntermittent: true) {
11931193
try await fixture(
11941194
name: "DependencyResolution/Internal/Simple",
11951195
removeFixturePathOnDeinit: true
@@ -3069,9 +3069,7 @@ struct PackageCommandTests {
30693069
func purgeCacheWithoutPackage(
30703070
data: BuildData,
30713071
) async throws {
3072-
try await withKnownIssue(
3073-
isIntermittent: ProcessInfo.isHostAmazonLinux2() // rdar://134238535
3074-
) {
3072+
try await withKnownIssue(isIntermittent: true) {
30753073
// Create a temporary directory without Package.swift
30763074
try await fixture(name: "Miscellaneous") { fixturePath in
30773075
let tempDir = fixturePath.appending("empty-dir-for-purge-test")
@@ -3090,7 +3088,7 @@ struct PackageCommandTests {
30903088
}
30913089
}
30923090
} when: {
3093-
ProcessInfo.isHostAmazonLinux2()
3091+
ProcessInfo.isHostAmazonLinux2() //rdar://134238535
30943092
}
30953093
}
30963094

@@ -3434,7 +3432,7 @@ struct PackageCommandTests {
34343432
"""
34353433
)
34363434
}
3437-
try await withKnownIssue {
3435+
try await withKnownIssue(isIntermittent: true) {
34383436
try await testWithTemporaryDirectory { tmpPath in
34393437
let packageDir = tmpPath.appending(components: "library")
34403438
try localFileSystem.writeFileContents(
@@ -4422,7 +4420,7 @@ struct PackageCommandTests {
44224420
func buildToolPlugin(
44234421
data: BuildData,
44244422
) async throws {
4425-
try await withKnownIssue {
4423+
try await withKnownIssue(isIntermittent: true) {
44264424
try await testBuildToolPlugin(data: data, staticStdlib: false)
44274425
} when: {
44284426
ProcessInfo.hostOperatingSystem == .windows && data.buildSystem == .swiftbuild
@@ -4565,7 +4563,7 @@ struct PackageCommandTests {
45654563
buildSystem: data.buildSystem,
45664564
)
45674565
) { error in
4568-
withKnownIssue {
4566+
withKnownIssue(isIntermittent: true) {
45694567
#expect(error.stderr.contains("This is text from the plugin"))
45704568
#expect(error.stderr.contains("error: This is an error from the plugin"))
45714569
} when: {
@@ -5495,7 +5493,7 @@ struct PackageCommandTests {
54955493
) async throws {
54965494
let debugTarget = try buildData.buildSystem.binPath(for: .debug) + [executableName("placeholder")]
54975495
let releaseTarget = try buildData.buildSystem.binPath(for: .release) + [executableName("placeholder")]
5498-
try await withKnownIssue {
5496+
try await withKnownIssue(isIntermittent: true) {
54995497
// By default, a plugin-requested build produces a debug binary
55005498
try await fixture(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in
55015499
let _ = try await execute(
@@ -5530,7 +5528,7 @@ struct PackageCommandTests {
55305528
) async throws {
55315529
let debugTarget = try buildData.buildSystem.binPath(for: .debug) + [executableName("placeholder")]
55325530
let releaseTarget = try buildData.buildSystem.binPath(for: .release) + [executableName("placeholder")]
5533-
try await withKnownIssue {
5531+
try await withKnownIssue(isIntermittent: true) {
55345532
// If the plugin specifies a debug binary, that is what will be built, regardless of overall configuration
55355533
try await fixture(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in
55365534
let _ = try await execute(
@@ -5569,7 +5567,7 @@ struct PackageCommandTests {
55695567
) async throws {
55705568
let debugTarget = try buildData.buildSystem.binPath(for: .debug) + [executableName("placeholder")]
55715569
let releaseTarget = try buildData.buildSystem.binPath(for: .release) + [executableName("placeholder")]
5572-
try await withKnownIssue {
5570+
try await withKnownIssue(isIntermittent: true) {
55735571
// If the plugin requests a release binary, that is what will be built, regardless of overall configuration
55745572
try await fixture(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in
55755573
let _ = try await execute(
@@ -5607,7 +5605,7 @@ struct PackageCommandTests {
56075605
) async throws {
56085606
let debugTarget = try buildData.buildSystem.binPath(for: .debug) + [executableName("placeholder")]
56095607
let releaseTarget = try buildData.buildSystem.binPath(for: .release) + [executableName("placeholder")]
5610-
try await withKnownIssue {
5608+
try await withKnownIssue(isIntermittent: true) {
56115609
// If the plugin inherits the overall build configuration, that is what will be built
56125610
try await fixture(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in
56135611
let _ = try await execute(
@@ -5646,7 +5644,7 @@ struct PackageCommandTests {
56465644
data: BuildData,
56475645
) async throws {
56485646
// Plugin arguments: check-testability <targetName> <config> <shouldTestable>
5649-
try await withKnownIssue {
5647+
try await withKnownIssue(isIntermittent: true) {
56505648
// Overall configuration: debug, plugin build request: debug -> without testability
56515649
try await fixture(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in
56525650
let _ = await #expect(throws: Never.self) {
@@ -5674,7 +5672,7 @@ struct PackageCommandTests {
56745672
func commandPluginBuildTestabilityInternalModule_Release_False(
56755673
data: BuildData,
56765674
) async throws {
5677-
try await withKnownIssue {
5675+
try await withKnownIssue(isIntermittent: true) {
56785676
// Overall configuration: debug, plugin build request: release -> without testability
56795677
try await fixture(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in
56805678
let _ = await #expect(throws: Never.self) {
@@ -5705,7 +5703,7 @@ struct PackageCommandTests {
57055703
func commandPluginBuildTestabilityAllWithTests_Release_True(
57065704
data: BuildData,
57075705
) async throws {
5708-
try await withKnownIssue(isIntermittent: (ProcessInfo.hostOperatingSystem == .linux)) {
5706+
try await withKnownIssue(isIntermittent: true) {
57095707
// Overall configuration: release, plugin build request: release including tests -> with testability
57105708
try await fixture(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in
57115709
let _ = await #expect(throws: Never.self) {
@@ -5754,7 +5752,7 @@ struct PackageCommandTests {
57545752
// otherwise the logs may be different in subsequent tests.
57555753

57565754
// Check than nothing is echoed when echoLogs is false
5757-
try await withKnownIssue(isIntermittent: ProcessInfo.hostOperatingSystem == .windows) {
5755+
try await withKnownIssue(isIntermittent: true) {
57585756
try await fixture(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in
57595757
let (stdout, stderr) = try await execute( //got here
57605758
["print-diagnostics", "build"],
@@ -6500,7 +6498,7 @@ struct PackageCommandTests {
65006498
func commandPluginBuildingCallbacks(
65016499
data: BuildData,
65026500
) async throws {
6503-
try await withKnownIssue {
6501+
try await withKnownIssue(isIntermittent: true) {
65046502
try await testWithTemporaryDirectory { tmpPath in
65056503
let buildSystemProvider = data.buildSystem
65066504
// Create a sample package with a library, an executable, and a command plugin.
@@ -6676,7 +6674,7 @@ struct PackageCommandTests {
66766674
}
66776675

66786676
// SwiftBuild is currently not producing a static archive for static products unless they are linked into some other binary.
6679-
try await withKnownIssue {
6677+
try await withKnownIssue(isIntermittent: true) {
66806678
// Invoke the plugin with parameters choosing a verbose build of MyStaticLibrary for release.
66816679
do {
66826680
let (stdout, _) = try await execute(
@@ -6755,7 +6753,7 @@ struct PackageCommandTests {
67556753
arguments: [BuildSystemProvider.Kind.native, .swiftbuild],
67566754
)
67576755
func commandPluginBuildingCallbacksExcludeUnbuiltArtifacts(buildSystem: BuildSystemProvider.Kind) async throws {
6758-
try await withKnownIssue {
6756+
try await withKnownIssue(isIntermittent: true) {
67596757
try await fixture(name: "PartiallyUnusedDependency") { fixturePath in
67606758
let (stdout, _) = try await execute(
67616759
["dump-artifacts-plugin"],
@@ -6794,7 +6792,7 @@ struct PackageCommandTests {
67946792
func commandPluginTestingCallbacks(
67956793
data: BuildData,
67966794
) async throws {
6797-
try await withKnownIssue {
6795+
try await withKnownIssue(isIntermittent: true) {
67986796
try await testWithTemporaryDirectory { tmpPath in
67996797
// Create a sample package with a library, a command plugin, and a couple of tests.
68006798
let packageDir = tmpPath.appending(components: "MyPackage")
@@ -7496,7 +7494,7 @@ struct PackageCommandTests {
74967494
func commandPluginDynamicDependencies(
74977495
buildData: BuildData
74987496
) async throws {
7499-
try await withKnownIssue {
7497+
try await withKnownIssue(isIntermittent: true) {
75007498
try await testWithTemporaryDirectory { tmpPath in
75017499
// Create a sample package with a command plugin that has a dynamic dependency.
75027500
let packageDir = tmpPath.appending(components: "MyPackage")

0 commit comments

Comments
 (0)