mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 11:07:44 +00:00
refactor/uucore ~ correct implementation of executable!() for multicall
- Use an atomic bool to track whether the utility name is the second or the first argument. - Add tests
This commit is contained in:
parent
38f3d13f7f
commit
44981cab01
6 changed files with 117 additions and 43 deletions
81
tests/test_util_name.rs
Normal file
81
tests/test_util_name.rs
Normal file
|
@ -0,0 +1,81 @@
|
|||
mod common;
|
||||
|
||||
use common::util::TestScenario;
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "ls")]
|
||||
fn execution_phrase_double() {
|
||||
use std::process::Command;
|
||||
|
||||
let scenario = TestScenario::new("ls");
|
||||
let output = Command::new(&scenario.bin_path)
|
||||
.arg("ls")
|
||||
.arg("--some-invalid-arg")
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(String::from_utf8(output.stderr)
|
||||
.unwrap()
|
||||
.contains(&format!("USAGE:\n {} ls", scenario.bin_path.display(),)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "ls")]
|
||||
fn execution_phrase_single() {
|
||||
use std::process::Command;
|
||||
|
||||
let scenario = TestScenario::new("ls");
|
||||
std::fs::copy(scenario.bin_path, scenario.fixtures.plus("uu-ls")).unwrap();
|
||||
let output = Command::new(scenario.fixtures.plus("uu-ls"))
|
||||
.arg("--some-invalid-arg")
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(String::from_utf8(output.stderr).unwrap().contains(&format!(
|
||||
"USAGE:\n {}",
|
||||
scenario.fixtures.plus("uu-ls").display()
|
||||
)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "sort")]
|
||||
fn util_name_double() {
|
||||
use std::{
|
||||
io::Write,
|
||||
process::{Command, Stdio},
|
||||
};
|
||||
|
||||
let scenario = TestScenario::new("sort");
|
||||
let mut child = Command::new(&scenario.bin_path)
|
||||
.arg("sort")
|
||||
.stdin(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap();
|
||||
// input invalid utf8 to cause an error
|
||||
child.stdin.take().unwrap().write_all(&[255]).unwrap();
|
||||
let output = child.wait_with_output().unwrap();
|
||||
assert!(String::from_utf8(output.stderr).unwrap().contains("sort: "));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "sort")]
|
||||
fn util_name_single() {
|
||||
use std::{
|
||||
io::Write,
|
||||
process::{Command, Stdio},
|
||||
};
|
||||
|
||||
let scenario = TestScenario::new("sort");
|
||||
std::fs::copy(scenario.bin_path, scenario.fixtures.plus("uu-sort")).unwrap();
|
||||
let mut child = Command::new(scenario.fixtures.plus("uu-sort"))
|
||||
.stdin(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap();
|
||||
// input invalid utf8 to cause an error
|
||||
child.stdin.take().unwrap().write_all(&[255]).unwrap();
|
||||
let output = child.wait_with_output().unwrap();
|
||||
assert!(String::from_utf8(output.stderr).unwrap().contains(&format!(
|
||||
"{}: ",
|
||||
scenario.fixtures.plus("uu-sort").display()
|
||||
)));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue