Add collection methods to RunfilesSubject

Open
#72 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Domain
testing

Research direction

Start at RunfilesSubject and inspect how its existing APIs represent Runfiles.file, empty_filenames, symlinks, and root_symlinks. Done means exposing the requested subject accessors plus paths() and path_map(), with collection matching and Bazel-compatible handling of overlapping file and symlink paths.

Written by the indexing model from the issue text.

Description

enhancement

While asserting some runfiles, I needed to do something like:

target.runfiles().contains_at_least([
  <ends with "/foo">,
  <ends with "/foo.exe">
])

Unfortunately, there isn't a great way to do this.

At the least, I think these convenience methods need to be added:

  • .paths() -> CollectionSubject[str]: returns all the runfiles paths that are represented.
  • .path_map() -> DictSubject[str, File|None]: returns a mapping of path to File (or None, in the case of .empty_filenames). Unfortunately, this is, potentially, a lossy operation -- a symlink could have the same path as a regular file entry. So we would want to match Bazel's behavior for how it handles such cases as best we can.

And these two lower-level accessors need to be added:

  • .files() -> DepsetFileSubject: returns the Runfiles.file value as a subject
  • .empty_filenames() -> CollectionSubject[str]: Returns Runfiles.empty_filenames as a subject
  • .symlinks() -> DepsetSubject[SymlinkEntry]: Returns Runfiles.symlinks as a subject
  • .root_symlinks() -> DepsetSubject[SymlinKEntry]: Returns Runfiles.root_symlinks as a subject

I'm not sure how to best directly expose other methods because a runfiles object is a heterogenous collection -- Files, symlink entries, and str (empty file names). I think matching on the str paths is about the best we can do -- its the common denominator. For a more specific check, the other accessors can be used (e.g. to check that something is a symlink).

Dominant language
Starlark
Stars
29
Forks
11
Avg merge
15h 15m
Merged PRs (30d)
3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bazelbuild/rules_testing

All issues in bazelbuild/rules_testing

Similar issues

More Testing & QA issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.