diff --git a/src/bin/coreutils.rs b/src/bin/coreutils.rs index 2821988c2..da318d741 100644 --- a/src/bin/coreutils.rs +++ b/src/bin/coreutils.rs @@ -145,6 +145,10 @@ fn main() { } process::exit(0); } + "--version" | "-V" => { + println!("{binary_as_util} {VERSION} (multi-call binary)"); + process::exit(0); + } // Not a special command: fallthrough to calling a util _ => {} } diff --git a/tests/test_util_name.rs b/tests/test_util_name.rs index cd0356edc..efa8fe08a 100644 --- a/tests/test_util_name.rs +++ b/tests/test_util_name.rs @@ -251,3 +251,29 @@ fn util_manpage() { let output_str = String::from_utf8(output.stdout).unwrap(); assert!(output_str.contains("\n.TH true 1 "), "{output_str:?}"); } + +#[test] +fn util_version() { + use std::process::{Command, Stdio}; + + let scenario = TestScenario::new("--version"); + if !scenario.bin_path.exists() { + println!("Skipping test: Binary not found at {:?}", scenario.bin_path); + return; + } + for arg in ["-V", "--version"] { + let child = Command::new(&scenario.bin_path) + .arg(arg) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .unwrap(); + let output = child.wait_with_output().unwrap(); + assert_eq!(output.status.code(), Some(0)); + assert_eq!(output.stderr, b""); + let output_str = String::from_utf8(output.stdout).unwrap(); + let ver = std::env::var("CARGO_PKG_VERSION").unwrap(); + assert_eq!(format!("coreutils {ver} (multi-call binary)\n"), output_str); + } +}