mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
env: reject program with --null, error stderr
This commit is contained in:
parent
75249e1e5d
commit
2d2042c8fc
3 changed files with 23 additions and 7 deletions
22
src/env/env.rs
vendored
22
src/env/env.rs
vendored
|
@ -103,14 +103,14 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
let var = iter.next();
|
||||
|
||||
match var {
|
||||
None => println!("{}: this option requires an argument: {}", NAME, opt),
|
||||
None => eprintln!("{}: this option requires an argument: {}", NAME, opt),
|
||||
Some(s) => opts.unsets.push(s.to_owned()),
|
||||
}
|
||||
}
|
||||
|
||||
_ => {
|
||||
println!("{}: invalid option \"{}\"", NAME, *opt);
|
||||
println!("Type \"{} --help\" for detailed informations", NAME);
|
||||
eprintln!("{}: invalid option \"{}\"", NAME, *opt);
|
||||
eprintln!("Type \"{} --help\" for detailed information", NAME);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -134,13 +134,13 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
let var = iter.next();
|
||||
|
||||
match var {
|
||||
None => println!("{}: this option requires an argument: {}", NAME, opt),
|
||||
None => eprintln!("{}: this option requires an argument: {}", NAME, opt),
|
||||
Some(s) => opts.unsets.push(s.to_owned()),
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
println!("{}: illegal option -- {}", NAME, c);
|
||||
println!("Type \"{} --help\" for detailed informations", NAME);
|
||||
eprintln!("{}: illegal option -- {}", NAME, c);
|
||||
eprintln!("Type \"{} --help\" for detailed information", NAME);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -159,6 +159,11 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
}
|
||||
// no, its a program-like opt
|
||||
_ => {
|
||||
if opts.null {
|
||||
eprintln!("{}: cannot specify --null (-0) with command", NAME);
|
||||
eprintln!("Type \"{} --help\" for detailed information", NAME);
|
||||
return 1;
|
||||
}
|
||||
opts.program.push(opt.clone());
|
||||
break;
|
||||
}
|
||||
|
@ -170,6 +175,11 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
|
||||
// read program arguments
|
||||
for opt in iter {
|
||||
if opts.null {
|
||||
eprintln!("{}: cannot specify --null (-0) with command", NAME);
|
||||
eprintln!("Type \"{} --help\" for detailed information", NAME);
|
||||
return 1;
|
||||
}
|
||||
opts.program.push(opt.clone())
|
||||
}
|
||||
|
||||
|
|
|
@ -606,7 +606,7 @@ impl UCommand {
|
|||
}
|
||||
|
||||
/// Spawns the command, feeds the stdin if any, waits for the result,
|
||||
/// asserts success, and returns a command result.
|
||||
/// asserts failure, and returns a command result.
|
||||
pub fn fails(&mut self) -> CmdResult {
|
||||
let cmd_result = self.run();
|
||||
cmd_result.failure();
|
||||
|
|
|
@ -81,3 +81,9 @@ fn test_unset_variable() {
|
|||
|
||||
assert_eq!(out.lines().any(|line| line.starts_with("HOME=")), false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fail_null_with_program() {
|
||||
let out = new_ucmd!().arg("--null").arg("cd").fails().stderr;
|
||||
assert!(out.contains("cannot specify --null (-0) with command"));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue