Skip to content

tests: add a workaround for SPM tests #6853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 7 additions & 4 deletions Tests/WorkspaceTests/SourceControlPackageContainerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class SourceControlPackageContainerTests: XCTestCase {
func testVprefixVersions() throws {
let fs = InMemoryFileSystem()

let repoPath = AbsolutePath.root
let repoPath = AbsolutePath.root.appending("SourceCache")
let filePath = repoPath.appending("Package.swift")

let specifier = RepositorySpecifier(path: repoPath)
Expand Down Expand Up @@ -234,7 +234,7 @@ class SourceControlPackageContainerTests: XCTestCase {
func testVersions() throws {
let fs = InMemoryFileSystem()

let repoPath = AbsolutePath.root
let repoPath = AbsolutePath.root.appending("SourceCache")
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Should we use withTemporaryDirectory here instead? Untested e.g

func testVersions() throws {
    try withTemporaryDirectory(removeTreeOnDeinit: true) { repoPath in
        let filePath = repoPath.appending("Package.swift")

        //....

    }
}

This way, we won't risk corrupting the host drive folder.

Copy link
Member Author

@compnerd compnerd Mar 14, 2025

Choose a reason for hiding this comment

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

We can do that in place of the InMemoryFileSystem. I think that the test issues do often arise from the use of InMemoryFileSystem. Note that I care little what solution we go with as long as we can get SPM tests correctly testing SPM on Windows as well :)

let filePath = repoPath.appending("Package.swift")

let specifier = RepositorySpecifier(path: repoPath)
Expand Down Expand Up @@ -327,7 +327,10 @@ class SourceControlPackageContainerTests: XCTestCase {
func testPreReleaseVersions() throws {
let fs = InMemoryFileSystem()

let repoPath = AbsolutePath.root
// Insert an arc in the path prior to the repository root to prevent
// `\Package.swift` being the path that is used. The
// intermediate arc allows processing the tools versions.
let repoPath = AbsolutePath.root.appending("SourceCache")
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I can connect the description of the PR to the actual change here. It mentions relative path, but only an absolute is stored here. How does adding a SourceCache component make this better for Windows?

Copy link
Member Author

Choose a reason for hiding this comment

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

The path to Package.swift is now no longer \Package.swift, as the \SourceCache adds an arc between the root of the package and the drive root. Its a horrible workaround, but I don't have a good solution here.

Copy link
Contributor

@MaxDesiatov MaxDesiatov Aug 25, 2023

Choose a reason for hiding this comment

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

Please add this as a comment in code so that it's visible when reviewed in the future by someone else and not "cleaned up" by accident.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

let filePath = repoPath.appending("Package.swift")

let specifier = RepositorySpecifier(path: repoPath)
Expand Down Expand Up @@ -371,7 +374,7 @@ class SourceControlPackageContainerTests: XCTestCase {
func testSimultaneousVersions() throws {
let fs = InMemoryFileSystem()

let repoPath = AbsolutePath.root
let repoPath = AbsolutePath.root.appending("SourceCache")
let filePath = repoPath.appending("Package.swift")

let specifier = RepositorySpecifier(path: repoPath)
Expand Down