1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

env: reject program with --null, error stderr

This commit is contained in:
Reto Habluetzel 2019-04-28 11:12:37 +02:00 committed by Reto Habluetzel
parent 75249e1e5d
commit 2d2042c8fc
3 changed files with 23 additions and 7 deletions

22
src/env/env.rs vendored
View file

@ -103,14 +103,14 @@ pub fn uumain(args: Vec<String>) -> i32 {
let var = iter.next(); let var = iter.next();
match var { 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()), Some(s) => opts.unsets.push(s.to_owned()),
} }
} }
_ => { _ => {
println!("{}: invalid option \"{}\"", NAME, *opt); eprintln!("{}: invalid option \"{}\"", NAME, *opt);
println!("Type \"{} --help\" for detailed informations", NAME); eprintln!("Type \"{} --help\" for detailed information", NAME);
return 1; return 1;
} }
} }
@ -134,13 +134,13 @@ pub fn uumain(args: Vec<String>) -> i32 {
let var = iter.next(); let var = iter.next();
match var { 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()), Some(s) => opts.unsets.push(s.to_owned()),
} }
} }
_ => { _ => {
println!("{}: illegal option -- {}", NAME, c); eprintln!("{}: illegal option -- {}", NAME, c);
println!("Type \"{} --help\" for detailed informations", NAME); eprintln!("Type \"{} --help\" for detailed information", NAME);
return 1; return 1;
} }
} }
@ -159,6 +159,11 @@ pub fn uumain(args: Vec<String>) -> i32 {
} }
// no, its a program-like opt // 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()); opts.program.push(opt.clone());
break; break;
} }
@ -170,6 +175,11 @@ pub fn uumain(args: Vec<String>) -> i32 {
// read program arguments // read program arguments
for opt in iter { 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()) opts.program.push(opt.clone())
} }

View file

@ -606,7 +606,7 @@ impl UCommand {
} }
/// Spawns the command, feeds the stdin if any, waits for the result, /// 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 { pub fn fails(&mut self) -> CmdResult {
let cmd_result = self.run(); let cmd_result = self.run();
cmd_result.failure(); cmd_result.failure();

View file

@ -81,3 +81,9 @@ fn test_unset_variable() {
assert_eq!(out.lines().any(|line| line.starts_with("HOME=")), false); 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"));
}