Skip to content

Added better filesystem layout testing harness #15874

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ranger-ross
Copy link
Contributor

What does this PR try to resolve?

The goal is to make filesystem layout tests easier to understand and review.
The build-dir test's have a helper fns that have imperative checks. While this works, its not easy to see what its validating at a glance.

My thought is to reuse the snapbox infrastructure we already have for the cargo ui tests.
The prototype in this PR generates a file tree (like the unix tree command) and uses snapbox to compare against a snapshot. This makes the layout tests much easier to read and failures are much more obvious what what went wrong.


However there are some problems with the current implementation that limit the usefulness of it.

  1. Different platforms have different files which cause some tests to fail
    • Examples
      • lib prefix/suffixes based on platform
      • dSYM on macos
    • One idea I have would be to have a cfg suffix after file name in the tree like so
      • └── foo-[HASH].dSYM [cfg(target_os = "macos")]
      • This would also require rethinking the "tree lines" (, , ) to handle optional files.
  2. When dealing with build scripts there are multiple target/<profile>/build/pkg-[HASH] directories. The hash changes the order of the directories when generating the tree making snapshots inconsistent.
    • We have redactions to handle replacing the hash with a placeholder [HASH], but this does not help with the order.

@rustbot rustbot added the A-testing-cargo-itself Area: cargo's tests label Aug 21, 2025
@weihanglo
Copy link
Member

Haven't look at the change, but thanks a lot for improving the test infrastructure!

// Match multi-part hashes like 06/b451d0d6f88b1d used in directory paths
subs.insert("[HASH]", regex!(r"/(?<redacted>[a-f0-9]{2}\/[0-9a-f]{14})"))
.unwrap();
subs.insert("[HASH]", regex!(r"[a-z0-9]+-(?<redacted>[a-f0-9]{16})"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Whats this redaction covering?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is handling the hashes in file/dir names in the fingerprint/build dirs

└── debug
    ├── .cargo-lock
    ├── .fingerprint
    │   └── foo-[HASH]
    │       ├── bin-foo
    │       ├── bin-foo.json
    │       ├── dep-bin-foo
    │       └── invoked.timestamp

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a corresponding comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

although I think the first multi-part hash is incorrect now. (I added that when I was still experimenting with a flat file paths)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testing-cargo-itself Area: cargo's tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants