mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
Merge pull request #8127 from MarcusGrass/mg/coreutils-version
feat: add `--version` argument to print main binary version
This commit is contained in:
commit
db229ea6d5
2 changed files with 30 additions and 0 deletions
|
@ -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
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue