Skip to content

Commit 0644ac0

Browse files
daveinglisjakepetroules
authored andcommitted
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 - serializing some test that change cwd to hopefully fix the AL2 crashes where the CWD has been deleted and calls to get CWD returns nil
1 parent b60528e commit 0644ac0

26 files changed

+192
-247
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/Toolchain.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ package func resolveBinDir() throws -> AbsolutePath {
3737
#if os(macOS)
3838
return try macOSBundleRoot()
3939
#else
40-
return try AbsolutePath(validating: CommandLine.arguments[0], relativeTo: localFileSystem.currentWorkingDirectory!).parentDirectory
40+
guard let cwd = localFileSystem.currentWorkingDirectory else {
41+
fatalError("Current working directory unavailable!")
42+
}
43+
return try AbsolutePath(validating: CommandLine.arguments[0], relativeTo: cwd).parentDirectory
4144
#endif
4245
}
4346

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/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,

Tests/CommandsTests/PackageCommandTests.swift

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private func executeAddURLDependencyAndAssert(
9090
}
9191

9292
@Suite(
93-
.serializedIfOnWindows,
93+
.serialized,
9494
.tags(
9595
.TestSize.large,
9696
.Feature.Command.Package.General,
@@ -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(
@@ -4421,7 +4419,7 @@ struct PackageCommandTests {
44214419
func buildToolPlugin(
44224420
data: BuildData,
44234421
) async throws {
4424-
try await withKnownIssue {
4422+
try await withKnownIssue(isIntermittent: true) {
44254423
try await testBuildToolPlugin(data: data, staticStdlib: false)
44264424
} when: {
44274425
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(
@@ -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"],
@@ -6502,7 +6500,7 @@ struct PackageCommandTests {
65026500
func commandPluginBuildingCallbacks(
65036501
data: BuildData,
65046502
) async throws {
6505-
try await withKnownIssue {
6503+
try await withKnownIssue(isIntermittent: true) {
65066504
try await testWithTemporaryDirectory { tmpPath in
65076505
let buildSystemProvider = data.buildSystem
65086506
// Create a sample package with a library, an executable, and a command plugin.
@@ -6678,7 +6676,7 @@ struct PackageCommandTests {
66786676
}
66796677

66806678
// SwiftBuild is currently not producing a static archive for static products unless they are linked into some other binary.
6681-
try await withKnownIssue {
6679+
try await withKnownIssue(isIntermittent: true) {
66826680
// Invoke the plugin with parameters choosing a verbose build of MyStaticLibrary for release.
66836681
do {
66846682
let (stdout, _) = try await execute(
@@ -6757,7 +6755,7 @@ struct PackageCommandTests {
67576755
arguments: [BuildSystemProvider.Kind.native, .swiftbuild],
67586756
)
67596757
func commandPluginBuildingCallbacksExcludeUnbuiltArtifacts(buildSystem: BuildSystemProvider.Kind) async throws {
6760-
try await withKnownIssue {
6758+
try await withKnownIssue(isIntermittent: true) {
67616759
try await fixture(name: "PartiallyUnusedDependency") { fixturePath in
67626760
let (stdout, _) = try await execute(
67636761
["dump-artifacts-plugin"],
@@ -6796,7 +6794,7 @@ struct PackageCommandTests {
67966794
func commandPluginTestingCallbacks(
67976795
data: BuildData,
67986796
) async throws {
6799-
try await withKnownIssue {
6797+
try await withKnownIssue(isIntermittent: true) {
68006798
try await testWithTemporaryDirectory { tmpPath in
68016799
// Create a sample package with a library, a command plugin, and a couple of tests.
68026800
let packageDir = tmpPath.appending(components: "MyPackage")
@@ -7498,7 +7496,7 @@ struct PackageCommandTests {
74987496
func commandPluginDynamicDependencies(
74997497
buildData: BuildData
75007498
) async throws {
7501-
try await withKnownIssue {
7499+
try await withKnownIssue(isIntermittent: true) {
75027500
try await testWithTemporaryDirectory { tmpPath in
75037501
// Create a sample package with a command plugin that has a dynamic dependency.
75047502
let packageDir = tmpPath.appending(components: "MyPackage")

Tests/CommandsTests/RunCommandTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ struct RunCommandTests {
245245
func unreachableExecutable(
246246
buildSystem: BuildSystemProvider.Kind,
247247
) async throws {
248-
try await withKnownIssue {
248+
try await withKnownIssue(isIntermittent: true) {
249249
try await fixture(name: "Miscellaneous/UnreachableTargets") { fixturePath in
250250
let (output, _) = try await execute(["bexec"], packagePath: fixturePath.appending("A"), buildSystem: buildSystem)
251251
let outputLines = output.split(whereSeparator: { $0.isNewline })
@@ -265,7 +265,7 @@ struct RunCommandTests {
265265
func fileDeprecation(
266266
buildSystem: BuildSystemProvider.Kind,
267267
) async throws {
268-
try await withKnownIssue {
268+
try await withKnownIssue(isIntermittent: true) {
269269
try await fixture(name: "Miscellaneous/EchoExecutable") { fixturePath in
270270
let filePath = AbsolutePath(fixturePath, "Sources/secho/main.swift").pathString
271271
let cwd = try #require(localFileSystem.currentWorkingDirectory, "Current working directory should not be nil")
@@ -422,7 +422,7 @@ struct RunCommandTests {
422422
buildSystem: BuildSystemProvider.Kind,
423423
configuration: BuildConfiguration
424424
) async throws {
425-
try await withKnownIssue {
425+
try await withKnownIssue(isIntermittent: true) {
426426
// GIVEN we have a simple test package
427427
try await fixture(name: "Miscellaneous/SwiftRun") { fixturePath in
428428
//WHEN we run with the --quiet option

0 commit comments

Comments
 (0)