Skip to content

Commit 8c9336b

Browse files
committed
Various fixes for tests on Windows
1 parent fae1549 commit 8c9336b

File tree

15 files changed

+128
-191
lines changed

15 files changed

+128
-191
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

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
@@ -145,7 +145,7 @@ struct InMemoryFileSystemTests {
145145

146146
// WHEN we write contents to the file
147147
// THEn we expect an error to occus
148-
withKnownIssue {
148+
#expect(throws: (any Error).self) {
149149
try fs.writeFileContents(pathUnderTest, bytes: expectedContents)
150150
}
151151

@@ -165,7 +165,7 @@ struct InMemoryFileSystemTests {
165165

166166
// WHEN we write contents to the file
167167
// THEN we expect an error to occur
168-
withKnownIssue {
168+
#expect(throws: (any Error).self) {
169169
try fs.writeFileContents(pathUnderTest, bytes: expectedContents)
170170
}
171171

@@ -185,7 +185,7 @@ struct InMemoryFileSystemTests {
185185

186186
// WHEN we write contents to the file
187187
// THEN we expect an error to occur
188-
withKnownIssue {
188+
#expect(throws: (any Error).self) {
189189
try fs.writeFileContents(pathUnderTest, bytes: expectedContents)
190190
}
191191

@@ -201,7 +201,7 @@ struct InMemoryFileSystemTests {
201201

202202
// WHEN we read a non-existing file
203203
// THEN an error occurs
204-
withKnownIssue {
204+
#expect(throws: (any Error).self) {
205205
let _ = try fs.readFileContents("/file/does/not/exists")
206206
}
207207
}
@@ -317,8 +317,8 @@ struct InMemoryFileSystemTests {
317317

318318
// WHEN we read the contents of a directory
319319
// THEN we expect a failure to occur
320-
withKnownIssue {
321-
let _ = try fs.readFileContents(pathUnderTest.parentDirectory)
320+
#expect(throws: (any Error).self) {
321+
try fs.readFileContents(pathUnderTest.parentDirectory)
322322
}
323323
}
324324
}

Tests/BasicsTests/FileSystem/VFSTests.swift

Lines changed: 102 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -39,108 +39,108 @@ func testWithTemporaryDirectory(
3939
struct VFSTests {
4040
@Test
4141
func localBasics() throws {
42-
try withKnownIssue("Permission issues on Windows") {
43-
// tiny PE binary from: https://archive.is/w01DO
44-
let contents: [UInt8] = [
45-
0x4d, 0x5a, 0x00, 0x00, 0x50, 0x45, 0x00, 0x00, 0x4c, 0x01, 0x01, 0x00,
46-
0x6a, 0x2a, 0x58, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
47-
0x04, 0x00, 0x03, 0x01, 0x0b, 0x01, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00,
48-
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
49-
0x04, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00,
50-
0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
51-
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
52-
0x68, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
53-
0x02
54-
]
55-
56-
let fs = localFileSystem
57-
try withTemporaryFile { [contents] vfsPath in
58-
try withTemporaryDirectory(removeTreeOnDeinit: true) { [contents] tempDirPath in
59-
let file = tempDirPath.appending("best")
60-
try fs.writeFileContents(file, string: "best")
61-
62-
let sym = tempDirPath.appending("hello")
63-
try fs.createSymbolicLink(sym, pointingAt: file, relative: false)
64-
65-
let executable = tempDirPath.appending("exec-foo")
66-
try fs.writeFileContents(executable, bytes: ByteString(contents))
67-
#if !os(Windows)
68-
try fs.chmod(.executable, path: executable, options: [])
69-
#endif
70-
71-
let executableSym = tempDirPath.appending("exec-sym")
72-
try fs.createSymbolicLink(executableSym, pointingAt: executable, relative: false)
73-
74-
try fs.createDirectory(tempDirPath.appending("dir"))
75-
try fs.writeFileContents(tempDirPath.appending(components: ["dir", "file"]), bytes: [])
76-
77-
try VirtualFileSystem.serializeDirectoryTree(tempDirPath, into: AbsolutePath(vfsPath.path), fs: fs, includeContents: [executable])
78-
}
79-
80-
let vfs = try VirtualFileSystem(path: vfsPath.path, fs: fs)
81-
82-
// exists()
83-
#expect(vfs.exists(AbsolutePath("/")))
84-
#expect(!vfs.exists(AbsolutePath("/does-not-exist")))
85-
86-
// isFile()
87-
let filePath = AbsolutePath("/best")
88-
#expect(vfs.exists(filePath))
89-
#expect(vfs.isFile(filePath))
90-
#expect(try vfs.getFileInfo(filePath).fileType == .typeRegular)
91-
#expect(!vfs.isDirectory(filePath))
92-
#expect(!vfs.isFile(AbsolutePath("/does-not-exist")))
93-
#expect(!vfs.isSymlink(AbsolutePath("/does-not-exist")))
94-
#expect(throws: (any Error).self) {
95-
try vfs.getFileInfo(AbsolutePath("/does-not-exist"))
96-
}
97-
98-
// isSymlink()
99-
let symPath = AbsolutePath("/hello")
100-
#expect(vfs.isSymlink(symPath))
101-
#expect(vfs.isFile(symPath))
102-
#expect(try vfs.getFileInfo(symPath).fileType == .typeSymbolicLink)
103-
#expect(!vfs.isDirectory(symPath))
104-
105-
// isExecutableFile
106-
let executablePath = AbsolutePath("/exec-foo")
107-
let executableSymPath = AbsolutePath("/exec-sym")
108-
#expect(vfs.isExecutableFile(executablePath))
109-
#expect(vfs.isExecutableFile(executableSymPath))
110-
#expect(vfs.isSymlink(executableSymPath))
111-
#expect(!vfs.isExecutableFile(symPath))
112-
#expect(!vfs.isExecutableFile(filePath))
113-
#expect(!vfs.isExecutableFile(AbsolutePath("/does-not-exist")))
114-
#expect(!vfs.isExecutableFile(AbsolutePath("/")))
115-
116-
// readFileContents
117-
let execFileContents = try vfs.readFileContents(executablePath)
118-
#expect(execFileContents == ByteString(contents))
119-
120-
// isDirectory()
121-
#expect(vfs.isDirectory(AbsolutePath("/")))
122-
#expect(!vfs.isDirectory(AbsolutePath("/does-not-exist")))
123-
124-
// getDirectoryContents()
125-
let dirContents = try vfs.getDirectoryContents(AbsolutePath("/"))
126-
#expect(dirContents.sorted() == ["best", "dir", "exec-foo", "exec-sym", "hello"])
127-
#expect {try vfs.getDirectoryContents(AbsolutePath("/does-not-exist"))} throws: { error in
128-
(error.localizedDescription == "no such file or directory: \(AbsolutePath("/does-not-exist"))")
129-
}
130-
131-
let thisDirectoryContents = try vfs.getDirectoryContents(AbsolutePath("/"))
132-
#expect(!thisDirectoryContents.contains(where: { $0 == "." }))
133-
#expect(!thisDirectoryContents.contains(where: { $0 == ".." }))
134-
#expect(thisDirectoryContents.sorted() == ["best", "dir", "exec-foo", "exec-sym", "hello"])
135-
136-
let contents = try vfs.getDirectoryContents(AbsolutePath("/dir"))
137-
#expect(contents == ["file"])
138-
139-
let fileContents = try vfs.readFileContents(AbsolutePath("/dir/file"))
140-
#expect(fileContents == "")
141-
}
142-
} when: {
143-
ProcessInfo.hostOperatingSystem == .windows
42+
// tiny PE binary from: https://archive.is/w01DO
43+
let contents: [UInt8] = [
44+
0x4d, 0x5a, 0x00, 0x00, 0x50, 0x45, 0x00, 0x00, 0x4c, 0x01, 0x01, 0x00,
45+
0x6a, 0x2a, 0x58, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
46+
0x04, 0x00, 0x03, 0x01, 0x0b, 0x01, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00,
47+
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
48+
0x04, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00,
49+
0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
50+
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
51+
0x68, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
52+
0x02
53+
]
54+
55+
let fs = localFileSystem
56+
let vfsPath = try withTemporaryFile(deleteOnClose: true) { $0 }
57+
try withTemporaryDirectory(removeTreeOnDeinit: true) { [contents] tempDirPath in
58+
let file = tempDirPath.appending("best")
59+
try fs.writeFileContents(file, string: "best")
60+
61+
let sym = tempDirPath.appending("hello")
62+
try fs.createSymbolicLink(sym, pointingAt: file, relative: false)
63+
64+
let executable = tempDirPath.appending("exec-foo")
65+
try fs.writeFileContents(executable, bytes: ByteString(contents))
66+
#if !os(Windows)
67+
try fs.chmod(.executable, path: executable, options: [])
68+
#endif
69+
70+
let executableSym = tempDirPath.appending("exec-sym")
71+
try fs.createSymbolicLink(executableSym, pointingAt: executable, relative: false)
72+
73+
try fs.createDirectory(tempDirPath.appending("dir"))
74+
try fs.writeFileContents(tempDirPath.appending(components: ["dir", "file"]), bytes: [])
75+
76+
#if os(Windows)
77+
// Cannot open the file again on windows
78+
try vfsPath.fileHandle.close()
79+
#endif
80+
try VirtualFileSystem.serializeDirectoryTree(tempDirPath, into: AbsolutePath(vfsPath.path), fs: fs, includeContents: [executable])
14481
}
82+
83+
let vfs = try VirtualFileSystem(path: vfsPath.path, fs: fs)
84+
85+
// exists()
86+
#expect(vfs.exists(AbsolutePath("/")))
87+
#expect(!vfs.exists(AbsolutePath("/does-not-exist")))
88+
89+
// isFile()
90+
let filePath = AbsolutePath("/best")
91+
#expect(vfs.exists(filePath))
92+
#expect(vfs.isFile(filePath))
93+
#expect(try vfs.getFileInfo(filePath).fileType == .typeRegular)
94+
#expect(!vfs.isDirectory(filePath))
95+
#expect(!vfs.isFile(AbsolutePath("/does-not-exist")))
96+
#expect(!vfs.isSymlink(AbsolutePath("/does-not-exist")))
97+
#expect(throws: (any Error).self) {
98+
try vfs.getFileInfo(AbsolutePath("/does-not-exist"))
99+
}
100+
101+
// isSymlink()
102+
let symPath = AbsolutePath("/hello")
103+
#expect(vfs.isSymlink(symPath))
104+
#expect(vfs.isFile(symPath))
105+
#expect(try vfs.getFileInfo(symPath).fileType == .typeSymbolicLink)
106+
#expect(!vfs.isDirectory(symPath))
107+
108+
// isExecutableFile
109+
let executablePath = AbsolutePath("/exec-foo")
110+
let executableSymPath = AbsolutePath("/exec-sym")
111+
#if !os(Windows)
112+
#expect(vfs.isExecutableFile(executablePath))
113+
#expect(vfs.isExecutableFile(executableSymPath))
114+
#endif
115+
#expect(vfs.isSymlink(executableSymPath))
116+
#expect(!vfs.isExecutableFile(symPath))
117+
#expect(!vfs.isExecutableFile(filePath))
118+
#expect(!vfs.isExecutableFile(AbsolutePath("/does-not-exist")))
119+
#expect(!vfs.isExecutableFile(AbsolutePath("/")))
120+
// readFileContents
121+
let execFileContents = try vfs.readFileContents(executablePath)
122+
#expect(execFileContents == ByteString(contents))
123+
124+
// isDirectory()
125+
#expect(vfs.isDirectory(AbsolutePath("/")))
126+
#expect(!vfs.isDirectory(AbsolutePath("/does-not-exist")))
127+
128+
// getDirectoryContents()
129+
let dirContents = try vfs.getDirectoryContents(AbsolutePath("/"))
130+
#expect(dirContents.sorted() == ["best", "dir", "exec-foo", "exec-sym", "hello"])
131+
#expect {try vfs.getDirectoryContents(AbsolutePath("/does-not-exist"))} throws: { error in
132+
(error.localizedDescription == "no such file or directory: \(AbsolutePath("/does-not-exist"))")
133+
}
134+
135+
let thisDirectoryContents = try vfs.getDirectoryContents(AbsolutePath("/"))
136+
#expect(!thisDirectoryContents.contains(where: { $0 == "." }))
137+
#expect(!thisDirectoryContents.contains(where: { $0 == ".." }))
138+
#expect(thisDirectoryContents.sorted() == ["best", "dir", "exec-foo", "exec-sym", "hello"])
139+
140+
let _contents = try vfs.getDirectoryContents(AbsolutePath("/dir"))
141+
#expect(_contents == ["file"])
142+
143+
let fileContents = try vfs.readFileContents(AbsolutePath("/dir/file"))
144+
#expect(fileContents == "")
145145
}
146146
}

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/FunctionalTests/MiscellaneousTests.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ final class MiscellaneousTestCase: XCTestCase {
448448
}
449449

450450
func testUnicode() async throws {
451-
try XCTSkipOnWindows(because: "Filepath too long error")
451+
try XCTSkipOnWindows(because: "fixture copy does not like the unicode files, needs investigation.")
452452
#if !os(Linux) && !os(Android) // TODO: - Linux has trouble with this and needs investigation.
453453
try await fixtureXCTest(name: "Miscellaneous/Unicode") { fixturePath in
454454
// See the fixture manifest for an explanation of this string.
@@ -877,9 +877,8 @@ final class MiscellaneousTestCase: XCTestCase {
877877
try await fixtureXCTest(name: "Miscellaneous/RootPackageWithConditionals") { path in
878878
_ = try await executeSwiftBuild(
879879
path,
880-
extraArgs: ["--build-system=swiftbuild"],
881880
env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"],
882-
buildSystem: .native,
881+
buildSystem: .swiftbuild,
883882
)
884883
}
885884
}

Tests/FunctionalTests/ResourcesTests.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ import XCTest
1717

1818
final class ResourcesTests: XCTestCase {
1919
func testSimpleResources() async throws {
20-
try XCTSkipOnWindows(
21-
because: """
22-
Invalid path. Possibly related to https://github.com/swiftlang/swift-package-manager/issues/8511 or https://github.com/swiftlang/swift-package-manager/issues/8602
23-
""",
24-
skipPlatformCi: true,
25-
)
26-
2720
try await fixtureXCTest(name: "Resources/Simple") { fixturePath in
2821
var executables = ["SwiftyResource"]
2922

@@ -129,7 +122,6 @@ final class ResourcesTests: XCTestCase {
129122
}
130123

131124
func testSwiftResourceAccessorDoesNotCauseInconsistentImportWarning() async throws {
132-
try XCTSkipOnWindows(because: "fails to build, need investigation")
133125
try await fixtureXCTest(name: "Resources/FoundationlessClient/UtilsWithFoundationPkg") { fixturePath in
134126
await XCTAssertBuilds(
135127
fixturePath,

Tests/PackageGraphPerformanceTests/PackageGraphPerfTests.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,6 @@ final class PackageGraphPerfTests: XCTestCasePerf {
167167
}
168168

169169
func testRecursiveDependencies() throws {
170-
try XCTSkipOnWindows()
171-
172170
var resolvedTarget = ResolvedModule.mock(packageIdentity: "pkg", name: "t0")
173171
for i in 1..<1000 {
174172
resolvedTarget = ResolvedModule.mock(packageIdentity: "pkg", name: "t\(i)", deps: resolvedTarget)

Tests/PackageLoadingTests/PD_5_6_LoadingTests.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,6 @@ final class PackageDescription5_6LoadingTests: PackageDescriptionLoadingTests {
240240

241241
/// Tests access to the package's directory contents.
242242
func testPackageContextDirectory() async throws {
243-
try XCTSkipOnWindows(because: "Skipping since this tests does not fully work without the VFS overlay which is currently disabled on Windows")
244-
245243
let content = """
246244
import PackageDescription
247245
import Foundation

Tests/PackageLoadingTests/PackageBuilderTests.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,6 @@ struct PackageBuilderTests {
589589
.IssueWindowsRelativePathAssert
590590
)
591591
func testTestManifestSearch() throws {
592-
try withKnownIssue(isIntermittent: true) {
593592
let fs = InMemoryFileSystem(emptyFiles:
594593
"/pkg/foo.swift",
595594
"/pkg/footests.swift"
@@ -620,9 +619,6 @@ struct PackageBuilderTests {
620619
product.check(testEntryPointPath: nil)
621620
}
622621
}
623-
} when: {
624-
ProcessInfo.hostOperatingSystem == .windows
625-
}
626622
}
627623

628624
@Test

0 commit comments

Comments
 (0)