mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
Merge pull request #6198 from BenWiederhake/dev-better-test-coverage
tests: test multi-call logic
This commit is contained in:
commit
9a6e0b7bef
1 changed files with 151 additions and 0 deletions
|
@ -92,3 +92,154 @@ fn util_name_single() {
|
||||||
scenario.fixtures.plus("uu-sort").display()
|
scenario.fixtures.plus("uu-sort").display()
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(any(unix, windows))]
|
||||||
|
fn util_invalid_name_help() {
|
||||||
|
use std::{
|
||||||
|
io::Write,
|
||||||
|
process::{Command, Stdio},
|
||||||
|
};
|
||||||
|
|
||||||
|
let scenario = TestScenario::new("invalid_name");
|
||||||
|
symlink_file(scenario.bin_path, scenario.fixtures.plus("invalid_name")).unwrap();
|
||||||
|
let child = Command::new(scenario.fixtures.plus("invalid_name"))
|
||||||
|
.arg("--help")
|
||||||
|
.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();
|
||||||
|
assert!(
|
||||||
|
output_str.contains("(multi-call binary)"),
|
||||||
|
"{:?}",
|
||||||
|
output_str
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
output_str.contains("Usage: invalid_name [function "),
|
||||||
|
"{:?}",
|
||||||
|
output_str
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
// The exact set of permitted filenames depends on many factors. Non-UTF-8 strings
|
||||||
|
// work on very few platforms, but linux works, especially because it also increases
|
||||||
|
// the likelihood that a filesystem is being used that supports non-UTF-8 filenames.
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
fn util_non_utf8_name_help() {
|
||||||
|
// Make sure we don't crash even if the util name is invalid UTF-8.
|
||||||
|
use std::{
|
||||||
|
ffi::OsStr,
|
||||||
|
io::Write,
|
||||||
|
os::unix::ffi::OsStrExt,
|
||||||
|
path::Path,
|
||||||
|
process::{Command, Stdio},
|
||||||
|
};
|
||||||
|
|
||||||
|
let scenario = TestScenario::new("invalid_name");
|
||||||
|
let non_utf8_path = scenario.fixtures.plus(OsStr::from_bytes(b"\xff"));
|
||||||
|
symlink_file(scenario.bin_path, &non_utf8_path).unwrap();
|
||||||
|
let child = Command::new(&non_utf8_path)
|
||||||
|
.arg("--help")
|
||||||
|
.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();
|
||||||
|
assert!(
|
||||||
|
output_str.contains("(multi-call binary)"),
|
||||||
|
"{:?}",
|
||||||
|
output_str
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
output_str.contains("Usage: <unknown binary name> [function "),
|
||||||
|
"{:?}",
|
||||||
|
output_str
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(any(unix, windows))]
|
||||||
|
fn util_invalid_name_invalid_command() {
|
||||||
|
use std::{
|
||||||
|
io::Write,
|
||||||
|
process::{Command, Stdio},
|
||||||
|
};
|
||||||
|
|
||||||
|
let scenario = TestScenario::new("invalid_name");
|
||||||
|
symlink_file(scenario.bin_path, scenario.fixtures.plus("invalid_name")).unwrap();
|
||||||
|
let child = Command::new(scenario.fixtures.plus("invalid_name"))
|
||||||
|
.arg("definitely_invalid")
|
||||||
|
.stdin(Stdio::piped())
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.stderr(Stdio::piped())
|
||||||
|
.spawn()
|
||||||
|
.unwrap();
|
||||||
|
let output = child.wait_with_output().unwrap();
|
||||||
|
assert_eq!(output.status.code(), Some(1));
|
||||||
|
assert_eq!(output.stderr, b"");
|
||||||
|
assert_eq!(
|
||||||
|
output.stdout,
|
||||||
|
b"definitely_invalid: function/utility not found\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn util_completion() {
|
||||||
|
use std::{
|
||||||
|
io::Write,
|
||||||
|
process::{Command, Stdio},
|
||||||
|
};
|
||||||
|
|
||||||
|
let scenario = TestScenario::new("completion");
|
||||||
|
let child = Command::new(scenario.bin_path)
|
||||||
|
.arg("completion")
|
||||||
|
.arg("true")
|
||||||
|
.arg("powershell")
|
||||||
|
.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();
|
||||||
|
assert!(
|
||||||
|
output_str.contains("using namespace System.Management.Automation"),
|
||||||
|
"{:?}",
|
||||||
|
output_str
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn util_manpage() {
|
||||||
|
use std::{
|
||||||
|
io::Write,
|
||||||
|
process::{Command, Stdio},
|
||||||
|
};
|
||||||
|
|
||||||
|
let scenario = TestScenario::new("completion");
|
||||||
|
let child = Command::new(scenario.bin_path)
|
||||||
|
.arg("manpage")
|
||||||
|
.arg("true")
|
||||||
|
.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();
|
||||||
|
assert!(output_str.contains("\n.TH true 1 "), "{:?}", output_str);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue