Skip to content

Implemented initial version of whereis #287

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 15 commits into
base: main
Choose a base branch
from
Open

Implemented initial version of whereis #287

wants to merge 15 commits into from

Conversation

spud0
Copy link

@spud0 spud0 commented Apr 8, 2025

This PR focuses on basic functionality of the whereis utility.

Current Issues with the current implementation:

  • The order of the output doesn't exactly match the original whereis C utility.
  • I am not sure how to handle errors in WhDirList::add_sub_dirs
  • How would I make the tests cover more cases?
  • Could there be some use of a shell script to compare the output of the original commands with the re-implemented commands to check for correctness?

Future work could include:

  • Improving matching for partial results, and clearing up some issues in the uu_app function where naming is concerned.

I am happy to iterate further based on feedback!

assert!(stdout.contains("/usr/bin/gcc"));

assert!(stdout.contains("/usr/lib/gcc"));
assert!(stdout.contains("/usr/share/gcc"));
Copy link
Contributor

Choose a reason for hiding this comment

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

This assert fails on my machine as there is no such folder.


// Store the metadata for a file
#[derive(Serialize, Clone, Debug)]
pub struct WhDir {
Copy link
Contributor

Choose a reason for hiding this comment

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

What does Wh mean?

Copy link
Author

Choose a reason for hiding this comment

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

The Wh is taken from the C source code. I suspect it just means WhereisDirectory since in the C source the list of paths is hardcoded. I think its there for significance of the paths that are used. https://github.com/util-linux/util-linux/blob/master/misc-utils/whereis.c

On Line 94 is the definition of the structure.

@sylvestre sylvestre requested a review from Copilot April 22, 2025 08:24
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements the initial version of the whereis utility with basic functionality to locate binaries, source, and man pages.

  • Basic implementation of whereis including tests and documentation
  • Addition of test cases for various lookup options (binary, man, source)
  • Updates to Cargo.toml files to include whereis in the workspace

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/tests.rs Added mod inclusion for test_whereis in tests
tests/by-util/test_whereis.rs Added several tests to verify whereis output
src/uu/whereis/whereis.md Added documentation for the whereis utility
src/uu/whereis/src/main.rs Bootstraps the whereis utility using uucore macro
src/uu/whereis/src/constants.rs Defines constant arrays for directories used by whereis
src/uu/whereis/Cargo.toml Defines the Cargo package for the whereis utility
Cargo.toml Updated workspace dependencies to include whereis

.arg("-s")
.arg("dig")
.succeeds()
.stdout_contains("");
Copy link
Preview

Copilot AI Apr 22, 2025

Choose a reason for hiding this comment

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

The assertion in the test_src_only test is ineffective because checking for an empty string always passes. Consider verifying against an expected output or removing the check if it is not necessary.

Suggested change
.stdout_contains("");
.stdout_is("");

Copilot uses AI. Check for mistakes.

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.

2 participants