mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
--version should just print the command name, not the path (#8921)
* --version should just print the command name, not the path This will fix the parsing for old autoconf Closes: #8880 * Update tests/by-util/test_mkdir.rs Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com> --------- Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
This commit is contained in:
co-authored by
Daniel Hofstetter
parent
ca8eb4d161
commit
3d6b0b2ea4
@@ -328,7 +328,14 @@ static UTIL_NAME: LazyLock<String> = LazyLock::new(|| {
|
||||
let is_man = usize::from(ARGV[base_index].eq("manpage"));
|
||||
let argv_index = base_index + is_man;
|
||||
|
||||
ARGV[argv_index].to_string_lossy().into_owned()
|
||||
// Strip directory path to show only utility name
|
||||
// (e.g., "mkdir" instead of "./target/debug/mkdir")
|
||||
// in version output, error messages, and other user-facing output
|
||||
std::path::Path::new(&ARGV[argv_index])
|
||||
.file_name()
|
||||
.unwrap_or(&ARGV[argv_index])
|
||||
.to_string_lossy()
|
||||
.into_owned()
|
||||
});
|
||||
|
||||
/// Derive the utility name.
|
||||
|
||||
@@ -24,6 +24,42 @@ fn test_invalid_arg() {
|
||||
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_version_no_path() {
|
||||
use std::process::Command;
|
||||
use uutests::get_tests_binary;
|
||||
|
||||
// This test verifies that when an individual utility binary is invoked with its full path,
|
||||
// the version output shows just "mkdir", not the full path like "/path/to/mkdir".
|
||||
//
|
||||
// Note: The multicall binary (coreutils) doesn't have this issue because it reads
|
||||
// the utility name from ARGV[1], not ARGV[0]. This bug only affects individual binaries.
|
||||
|
||||
let tests_binary = get_tests_binary!();
|
||||
let mkdir_binary_path = std::path::Path::new(tests_binary)
|
||||
.parent()
|
||||
.unwrap()
|
||||
.join("mkdir");
|
||||
|
||||
// If the individual mkdir binary exists, test it
|
||||
let output = if mkdir_binary_path.exists() {
|
||||
// Invoke the individual mkdir binary with its full path
|
||||
Command::new(&mkdir_binary_path)
|
||||
.arg("--version")
|
||||
.output()
|
||||
.expect("Failed to execute mkdir binary")
|
||||
} else {
|
||||
// If only multicall binary exists, test that (it should already pass)
|
||||
Command::new(tests_binary)
|
||||
.args(["mkdir", "--version"])
|
||||
.output()
|
||||
.expect("Failed to execute mkdir via multicall binary")
|
||||
};
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
assert!(stdout.starts_with("mkdir (uutils coreutils)"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_no_arg() {
|
||||
new_ucmd!()
|
||||
|
||||
Reference in New Issue
Block a user