Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/SourceControl/Repository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public struct RepositorySpecifier: Hashable, Sendable {
if basename.hasSuffix(".git") {
basename = String(basename.dropLast(4))
}
if basename == "/" {
if basename == "/" || basename == "\\" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a single central variable that is an array of the possible path separators for the host.

See https://github.com/swiftlang/swift-build/blob/bc2e7d92d36caed0399f64594b9e5518b2f83731/Sources/SWBUtil/Path.swift#L69 for example.

There might already be one in the SwiftPM codebase somewhere, or in TSC.

Also, this part of the logic should probably be constrained to file URLs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, I couldn't find a central definition for path separators like whats in swift-build, and it looks like from this https://github.com/swiftlang/swift-package-manager/pull/6706/files we moved away from URL

return ""
}
return basename
Expand Down
6 changes: 2 additions & 4 deletions Tests/BasicsTests/AsyncProcessTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,14 @@ final class AsyncProcessTests: XCTestCase {
}

func testPopenWithBufferLargerThanAllocated() throws {
try XCTSkipOnWindows(because: "https://github.com/swiftlang/swift-package-manager/issues/9031: test fails on windows.")

// Test buffer larger than that allocated.
try withTemporaryFile { file in
let count = 10000
let stream = BufferedOutputByteStream()
stream.send(Format.asRepeating(string: "a", count: count))
try localFileSystem.writeFileContents(file.path, bytes: stream.bytes)
file.fileHandle.write(Data(stream.bytes.contents))
let actualStreamCount = stream.bytes.count
XCTAssertTrue(actualStreamCount == count, "Actual stream count (\(actualStreamCount)) is not as exxpected (\(count))")
XCTAssertTrue(actualStreamCount == count, "Actual stream count (\(actualStreamCount)) is not as expected (\(count))")
let outputCount = try AsyncProcess.popen(arguments: catExecutableArgs + [file.path.pathString]).utf8Output().count
XCTAssert(outputCount == count, "Actual count (\(outputCount)) is not as expected (\(count))")
}
Expand Down
12 changes: 6 additions & 6 deletions Tests/BasicsTests/FileSystem/InMemoryFilesSystemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ struct InMemoryFileSystemTests {

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

Expand All @@ -165,7 +165,7 @@ struct InMemoryFileSystemTests {

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

Expand All @@ -185,7 +185,7 @@ struct InMemoryFileSystemTests {

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

Expand All @@ -201,7 +201,7 @@ struct InMemoryFileSystemTests {

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

// WHEN we read the contents of a directory
// THEN we expect a failure to occur
withKnownIssue {
let _ = try fs.readFileContents(pathUnderTest.parentDirectory)
#expect(throws: (any Error).self) {
try fs.readFileContents(pathUnderTest.parentDirectory)
}
}
}
Expand Down
204 changes: 102 additions & 102 deletions Tests/BasicsTests/FileSystem/VFSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,108 +39,108 @@ func testWithTemporaryDirectory(
struct VFSTests {
@Test
func localBasics() throws {
try withKnownIssue("Permission issues on Windows") {
// tiny PE binary from: https://archive.is/w01DO
let contents: [UInt8] = [
0x4d, 0x5a, 0x00, 0x00, 0x50, 0x45, 0x00, 0x00, 0x4c, 0x01, 0x01, 0x00,
0x6a, 0x2a, 0x58, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x00, 0x03, 0x01, 0x0b, 0x01, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00,
0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x68, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02
]

let fs = localFileSystem
try withTemporaryFile { [contents] vfsPath in
try withTemporaryDirectory(removeTreeOnDeinit: true) { [contents] tempDirPath in
let file = tempDirPath.appending("best")
try fs.writeFileContents(file, string: "best")

let sym = tempDirPath.appending("hello")
try fs.createSymbolicLink(sym, pointingAt: file, relative: false)

let executable = tempDirPath.appending("exec-foo")
try fs.writeFileContents(executable, bytes: ByteString(contents))
#if !os(Windows)
try fs.chmod(.executable, path: executable, options: [])
#endif

let executableSym = tempDirPath.appending("exec-sym")
try fs.createSymbolicLink(executableSym, pointingAt: executable, relative: false)

try fs.createDirectory(tempDirPath.appending("dir"))
try fs.writeFileContents(tempDirPath.appending(components: ["dir", "file"]), bytes: [])

try VirtualFileSystem.serializeDirectoryTree(tempDirPath, into: AbsolutePath(vfsPath.path), fs: fs, includeContents: [executable])
}

let vfs = try VirtualFileSystem(path: vfsPath.path, fs: fs)

// exists()
#expect(vfs.exists(AbsolutePath("/")))
#expect(!vfs.exists(AbsolutePath("/does-not-exist")))

// isFile()
let filePath = AbsolutePath("/best")
#expect(vfs.exists(filePath))
#expect(vfs.isFile(filePath))
#expect(try vfs.getFileInfo(filePath).fileType == .typeRegular)
#expect(!vfs.isDirectory(filePath))
#expect(!vfs.isFile(AbsolutePath("/does-not-exist")))
#expect(!vfs.isSymlink(AbsolutePath("/does-not-exist")))
#expect(throws: (any Error).self) {
try vfs.getFileInfo(AbsolutePath("/does-not-exist"))
}

// isSymlink()
let symPath = AbsolutePath("/hello")
#expect(vfs.isSymlink(symPath))
#expect(vfs.isFile(symPath))
#expect(try vfs.getFileInfo(symPath).fileType == .typeSymbolicLink)
#expect(!vfs.isDirectory(symPath))

// isExecutableFile
let executablePath = AbsolutePath("/exec-foo")
let executableSymPath = AbsolutePath("/exec-sym")
#expect(vfs.isExecutableFile(executablePath))
#expect(vfs.isExecutableFile(executableSymPath))
#expect(vfs.isSymlink(executableSymPath))
#expect(!vfs.isExecutableFile(symPath))
#expect(!vfs.isExecutableFile(filePath))
#expect(!vfs.isExecutableFile(AbsolutePath("/does-not-exist")))
#expect(!vfs.isExecutableFile(AbsolutePath("/")))

// readFileContents
let execFileContents = try vfs.readFileContents(executablePath)
#expect(execFileContents == ByteString(contents))

// isDirectory()
#expect(vfs.isDirectory(AbsolutePath("/")))
#expect(!vfs.isDirectory(AbsolutePath("/does-not-exist")))

// getDirectoryContents()
let dirContents = try vfs.getDirectoryContents(AbsolutePath("/"))
#expect(dirContents.sorted() == ["best", "dir", "exec-foo", "exec-sym", "hello"])
#expect {try vfs.getDirectoryContents(AbsolutePath("/does-not-exist"))} throws: { error in
(error.localizedDescription == "no such file or directory: \(AbsolutePath("/does-not-exist"))")
}

let thisDirectoryContents = try vfs.getDirectoryContents(AbsolutePath("/"))
#expect(!thisDirectoryContents.contains(where: { $0 == "." }))
#expect(!thisDirectoryContents.contains(where: { $0 == ".." }))
#expect(thisDirectoryContents.sorted() == ["best", "dir", "exec-foo", "exec-sym", "hello"])

let contents = try vfs.getDirectoryContents(AbsolutePath("/dir"))
#expect(contents == ["file"])

let fileContents = try vfs.readFileContents(AbsolutePath("/dir/file"))
#expect(fileContents == "")
}
} when: {
ProcessInfo.hostOperatingSystem == .windows
// tiny PE binary from: https://archive.is/w01DO
let contents: [UInt8] = [
0x4d, 0x5a, 0x00, 0x00, 0x50, 0x45, 0x00, 0x00, 0x4c, 0x01, 0x01, 0x00,
0x6a, 0x2a, 0x58, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x00, 0x03, 0x01, 0x0b, 0x01, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00,
0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x68, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02
]

let fs = localFileSystem
let vfsPath = try withTemporaryFile(deleteOnClose: true) { $0 }
try withTemporaryDirectory(removeTreeOnDeinit: true) { [contents] tempDirPath in
let file = tempDirPath.appending("best")
try fs.writeFileContents(file, string: "best")

let sym = tempDirPath.appending("hello")
try fs.createSymbolicLink(sym, pointingAt: file, relative: false)

let executable = tempDirPath.appending("exec-foo")
try fs.writeFileContents(executable, bytes: ByteString(contents))
#if !os(Windows)
try fs.chmod(.executable, path: executable, options: [])
#endif

let executableSym = tempDirPath.appending("exec-sym")
try fs.createSymbolicLink(executableSym, pointingAt: executable, relative: false)

try fs.createDirectory(tempDirPath.appending("dir"))
try fs.writeFileContents(tempDirPath.appending(components: ["dir", "file"]), bytes: [])

#if os(Windows)
// Cannot open the file again on windows
try vfsPath.fileHandle.close()
#endif
try VirtualFileSystem.serializeDirectoryTree(tempDirPath, into: AbsolutePath(vfsPath.path), fs: fs, includeContents: [executable])
}

let vfs = try VirtualFileSystem(path: vfsPath.path, fs: fs)

// exists()
#expect(vfs.exists(AbsolutePath("/")))
#expect(!vfs.exists(AbsolutePath("/does-not-exist")))

// isFile()
let filePath = AbsolutePath("/best")
#expect(vfs.exists(filePath))
#expect(vfs.isFile(filePath))
#expect(try vfs.getFileInfo(filePath).fileType == .typeRegular)
#expect(!vfs.isDirectory(filePath))
#expect(!vfs.isFile(AbsolutePath("/does-not-exist")))
#expect(!vfs.isSymlink(AbsolutePath("/does-not-exist")))
#expect(throws: (any Error).self) {
try vfs.getFileInfo(AbsolutePath("/does-not-exist"))
}

// isSymlink()
let symPath = AbsolutePath("/hello")
#expect(vfs.isSymlink(symPath))
#expect(vfs.isFile(symPath))
#expect(try vfs.getFileInfo(symPath).fileType == .typeSymbolicLink)
#expect(!vfs.isDirectory(symPath))

// isExecutableFile
let executablePath = AbsolutePath("/exec-foo")
let executableSymPath = AbsolutePath("/exec-sym")
#if !os(Windows)
#expect(vfs.isExecutableFile(executablePath))
#expect(vfs.isExecutableFile(executableSymPath))
#endif
#expect(vfs.isSymlink(executableSymPath))
#expect(!vfs.isExecutableFile(symPath))
#expect(!vfs.isExecutableFile(filePath))
#expect(!vfs.isExecutableFile(AbsolutePath("/does-not-exist")))
#expect(!vfs.isExecutableFile(AbsolutePath("/")))
// readFileContents
let execFileContents = try vfs.readFileContents(executablePath)
#expect(execFileContents == ByteString(contents))

// isDirectory()
#expect(vfs.isDirectory(AbsolutePath("/")))
#expect(!vfs.isDirectory(AbsolutePath("/does-not-exist")))

// getDirectoryContents()
let dirContents = try vfs.getDirectoryContents(AbsolutePath("/"))
#expect(dirContents.sorted() == ["best", "dir", "exec-foo", "exec-sym", "hello"])
#expect {try vfs.getDirectoryContents(AbsolutePath("/does-not-exist"))} throws: { error in
(error.localizedDescription == "no such file or directory: \(AbsolutePath("/does-not-exist"))")
}

let thisDirectoryContents = try vfs.getDirectoryContents(AbsolutePath("/"))
#expect(!thisDirectoryContents.contains(where: { $0 == "." }))
#expect(!thisDirectoryContents.contains(where: { $0 == ".." }))
#expect(thisDirectoryContents.sorted() == ["best", "dir", "exec-foo", "exec-sym", "hello"])

let _contents = try vfs.getDirectoryContents(AbsolutePath("/dir"))
#expect(_contents == ["file"])

let fileContents = try vfs.readFileContents(AbsolutePath("/dir/file"))
#expect(fileContents == "")
}
}
6 changes: 2 additions & 4 deletions Tests/BasicsTests/Serialization/SerializedJSONTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,16 @@ final class SerializedJSONTests: XCTestCase {
}

func testPathInterpolationFailsOnWindows() throws {
try XCTSkipOnWindows(because: "Expectations are not met. Possibly related to https://github.com/swiftlang/swift-package-manager/issues/8511")

#if os(Windows)
var path = try AbsolutePath(validating: #"\\?\C:\Users"#)
var json: SerializedJSON = "\(path)"

XCTAssertEqual(json.underlying, #"C:\\Users"#)
XCTAssertEqual(json.underlying, #"\\\\?\\C:\\Users"#)

path = try AbsolutePath(validating: #"\\.\UNC\server\share\"#)
json = "\(path)"

XCTAssertEqual(json.underlying, #"\\.\\UNC\\server\\share"#)
XCTAssertEqual(json.underlying, #"\\\\.\\UNC\\server\\share"#)
#endif
}
}
5 changes: 2 additions & 3 deletions Tests/FunctionalTests/MiscellaneousTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ final class MiscellaneousTestCase: XCTestCase {
}

func testUnicode() async throws {
try XCTSkipOnWindows(because: "Filepath too long error")
try XCTSkipOnWindows(because: "fixture copy does not like the unicode files, needs investigation.")
#if !os(Linux) && !os(Android) // TODO: - Linux has trouble with this and needs investigation.
try await fixtureXCTest(name: "Miscellaneous/Unicode") { fixturePath in
// See the fixture manifest for an explanation of this string.
Expand Down Expand Up @@ -877,9 +877,8 @@ final class MiscellaneousTestCase: XCTestCase {
try await fixtureXCTest(name: "Miscellaneous/RootPackageWithConditionals") { path in
_ = try await executeSwiftBuild(
path,
extraArgs: ["--build-system=swiftbuild"],
env: ["SWIFT_DRIVER_SWIFTSCAN_LIB" : "/this/is/a/bad/path"],
buildSystem: .native,
buildSystem: .swiftbuild,
)
}
}
Expand Down
8 changes: 0 additions & 8 deletions Tests/FunctionalTests/ResourcesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ import XCTest

final class ResourcesTests: XCTestCase {
func testSimpleResources() async throws {
try XCTSkipOnWindows(
because: """
Invalid path. Possibly related to https://github.com/swiftlang/swift-package-manager/issues/8511 or https://github.com/swiftlang/swift-package-manager/issues/8602
""",
skipPlatformCi: true,
)

try await fixtureXCTest(name: "Resources/Simple") { fixturePath in
var executables = ["SwiftyResource"]

Expand Down Expand Up @@ -129,7 +122,6 @@ final class ResourcesTests: XCTestCase {
}

func testSwiftResourceAccessorDoesNotCauseInconsistentImportWarning() async throws {
try XCTSkipOnWindows(because: "fails to build, need investigation")
try await fixtureXCTest(name: "Resources/FoundationlessClient/UtilsWithFoundationPkg") { fixturePath in
await XCTAssertBuilds(
fixturePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ final class PackageGraphPerfTests: XCTestCasePerf {
}

func testRecursiveDependencies() throws {
try XCTSkipOnWindows()

var resolvedTarget = ResolvedModule.mock(packageIdentity: "pkg", name: "t0")
for i in 1..<1000 {
resolvedTarget = ResolvedModule.mock(packageIdentity: "pkg", name: "t\(i)", deps: resolvedTarget)
Expand Down
2 changes: 0 additions & 2 deletions Tests/PackageLoadingTests/PD_5_6_LoadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,6 @@ final class PackageDescription5_6LoadingTests: PackageDescriptionLoadingTests {

/// Tests access to the package's directory contents.
func testPackageContextDirectory() async throws {
try XCTSkipOnWindows(because: "Skipping since this tests does not fully work without the VFS overlay which is currently disabled on Windows")

let content = """
import PackageDescription
import Foundation
Expand Down
10 changes: 1 addition & 9 deletions Tests/PackageLoadingTests/PackageBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -583,13 +583,8 @@ struct PackageBuilderTests {
}
}

@Test(
.IssueWindowsLongPath,
.IssueWindowsPathLastConponent,
.IssueWindowsRelativePathAssert
)
@Test
func testTestManifestSearch() throws {
try withKnownIssue(isIntermittent: true) {
let fs = InMemoryFileSystem(emptyFiles:
"/pkg/foo.swift",
"/pkg/footests.swift"
Expand Down Expand Up @@ -620,9 +615,6 @@ struct PackageBuilderTests {
product.check(testEntryPointPath: nil)
}
}
} when: {
ProcessInfo.hostOperatingSystem == .windows
}
}

@Test
Expand Down
Loading