Skip to content

Commit 87a1538

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 - 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 87a1538

22 files changed

+251
-258
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: 67 additions & 55 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,
@@ -864,6 +864,7 @@ struct BuildCommandTestCases {
864864
}
865865

866866
@Test(
867+
.IssueWindowsLongPath,
867868
.tags(
868869
.Feature.BuildCache,
869870
),
@@ -874,43 +875,47 @@ struct BuildCommandTestCases {
874875
data: BuildData,
875876
) async throws {
876877
let buildSystem = data.buildSystem
877-
try await fixture(name: "DependencyResolution/Internal/Simple") { fixturePath in
878-
let buildCompleteRegex = try Regex(#"Build complete!\s?(\([0-9]*\.[0-9]*\s*s(econds)?\))?"#)
879-
do {
880-
let result = try await execute(
881-
packagePath: fixturePath,
882-
configuration: data.config,
883-
buildSystem: buildSystem,
884-
)
885-
// This test fails to match the 'Compiling' regex; rdar://101815761
886-
// XCTAssertMatch(result.stdout, .regex("\\[[1-9][0-9]*\\/[1-9][0-9]*\\] Compiling"))
887-
let lines = result.stdout.split(whereSeparator: { $0.isNewline })
888-
let lastLine = try #require(lines.last)
889-
#expect(lastLine.contains(buildCompleteRegex))
890-
}
878+
try await withKnownIssue(isIntermittent: true) {
879+
try await fixture(name: "DependencyResolution/Internal/Simple") { fixturePath in
880+
let buildCompleteRegex = try Regex(#"Build complete!\s?(\([0-9]*\.[0-9]*\s*s(econds)?\))?"#)
881+
do {
882+
let result = try await execute(
883+
packagePath: fixturePath,
884+
configuration: data.config,
885+
buildSystem: buildSystem,
886+
)
887+
// This test fails to match the 'Compiling' regex; rdar://101815761
888+
// XCTAssertMatch(result.stdout, .regex("\\[[1-9][0-9]*\\/[1-9][0-9]*\\] Compiling"))
889+
let lines = result.stdout.split(whereSeparator: { $0.isNewline })
890+
let lastLine = try #require(lines.last)
891+
#expect(lastLine.contains(buildCompleteRegex))
892+
}
891893

892-
do {
893-
// test second time, to stabilize the cache
894-
try await execute(
895-
packagePath: fixturePath,
896-
configuration: data.config,
897-
buildSystem: buildSystem,
898-
)
899-
}
894+
do {
895+
// test second time, to stabilize the cache
896+
try await execute(
897+
packagePath: fixturePath,
898+
configuration: data.config,
899+
buildSystem: buildSystem,
900+
)
901+
}
900902

901-
do {
902-
// test third time, to make sure message is presented even when nothing to build (cached)
903-
let result = try await execute(
904-
packagePath: fixturePath,
905-
configuration: data.config,
906-
buildSystem: buildSystem,
907-
)
908-
// This test fails to match the 'Compiling' regex; rdar://101815761
909-
// XCTAssertNoMatch(result.stdout, .regex("\\[[1-9][0-9]*\\/[1-9][0-9]*\\] Compiling"))
910-
let lines = result.stdout.split(whereSeparator: { $0.isNewline })
911-
let lastLine = try #require(lines.last)
912-
#expect(lastLine.contains(buildCompleteRegex))
903+
do {
904+
// test third time, to make sure message is presented even when nothing to build (cached)
905+
let result = try await execute(
906+
packagePath: fixturePath,
907+
configuration: data.config,
908+
buildSystem: buildSystem,
909+
)
910+
// This test fails to match the 'Compiling' regex; rdar://101815761
911+
// XCTAssertNoMatch(result.stdout, .regex("\\[[1-9][0-9]*\\/[1-9][0-9]*\\] Compiling"))
912+
let lines = result.stdout.split(whereSeparator: { $0.isNewline })
913+
let lastLine = try #require(lines.last)
914+
#expect(lastLine.contains(buildCompleteRegex))
915+
}
913916
}
917+
} when: {
918+
(buildSystem == .swiftbuild && ProcessInfo.hostOperatingSystem == .windows)
914919
}
915920
}
916921

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

@@ -1205,7 +1217,7 @@ struct BuildCommandTestCases {
12051217

12061218
try await withKnownIssue(
12071219
"https://github.com/swiftlang/swift-package-manager/issues/8659, SWIFT_EXEC override is not working",
1208-
isIntermittent: (buildSystem == .native && config == .release)
1220+
isIntermittent: true
12091221
){
12101222
// Build with a swiftc that returns version 1.0, we expect a successful build which compiles our one source
12111223
// file.
@@ -1300,7 +1312,7 @@ struct BuildCommandTestCases {
13001312
func getTaskAllowEntitlement(
13011313
buildSystem: BuildSystemProvider.Kind,
13021314
) async throws {
1303-
try await withKnownIssue(isIntermittent: (ProcessInfo.hostOperatingSystem == .linux)) {
1315+
try await withKnownIssue(isIntermittent: true) {
13041316
try await fixture(name: "ValidLayouts/SingleModule/ExecutableNew") { fixturePath in
13051317
#if os(macOS)
13061318
// try await building with default parameters. This should succeed. We build verbosely so we get full command
@@ -1512,7 +1524,7 @@ struct BuildCommandTestCases {
15121524
func parseAsLibraryCriteria(
15131525
buildData: BuildData,
15141526
) async throws {
1515-
try await withKnownIssue {
1527+
try await withKnownIssue(isIntermittent: true) {
15161528
try await fixture(name: "Miscellaneous/ParseAsLibrary") { fixturePath in
15171529
_ = try await executeSwiftBuild(
15181530
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)