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

Conversation

compnerd
Copy link
Member

The path representation in AbsolutePath is incorrect and stores a relative path as an absolute path (paths with leading / or \ are drive relative, not absolute, absolute paths must start with [A-Z]: or \\[^\]+\[^\]+\). This adds a root directory so that the path to the manifest is not drive relative.

@compnerd
Copy link
Member Author

@swift-ci please smoke test

@@ -328,7 +328,7 @@ class SourceControlPackageContainerTests: XCTestCase {
func testPreReleaseVersions() 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.

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!

@compnerd
Copy link
Member Author

@swift-ci please smoke test

1 similar comment
@compnerd
Copy link
Member Author

@swift-ci please smoke test

@neonichu
Copy link
Contributor

neonichu commented Oct 4, 2023

@compnerd is this still relevant?

@compnerd
Copy link
Member Author

compnerd commented Oct 5, 2023

Yes, this is needed to repair the test suite on Windows.

@neonichu
Copy link
Contributor

neonichu commented Oct 5, 2023

Thanks, no rush, we were just looking at PRs that could potentially be stale this morning and weren't sure about this one.

The path representation in AbsolutePath is incorrect and stores a
relative path as an absolute path (paths with leading `/` or `\` are
drive relative, not absolute, absolute paths must start with `[A-Z]:` or
`\\[^\]+\[^\]+\`). This adds a root directory so that the path to the
manifest is not drive relative.
@compnerd compnerd force-pushed the relative-is-absolute branch from d19aa3a to 9a2f774 Compare November 20, 2023 19:05
@compnerd
Copy link
Member Author

@swift-ci please test

@compnerd
Copy link
Member Author

This is really needed for Windows - we cannot run the test suite without this.

Copy link
Contributor

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

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

Is there a way to use RelativePath here instead to avoid the hack in the first place?

@compnerd
Copy link
Member Author

compnerd commented Nov 20, 2023

I don't see an easy way to do that, as really what it amounts to is effectively saying all absolute paths are relative (as SPM only works with relative paths - /path is a relative path, not absolute, unlike on Unix). For example, we use that root for RepositorySpecifier.init where it would now need to change to take a relative path rather than absolute path as /path should be considered relative not absolute.

@MaxDesiatov
Copy link
Contributor

@swift-ci test

@compnerd
Copy link
Member Author

@swift-ci please test

@@ -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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants