mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
Test for unimplemented command line arguments
We check if the user has given one of the (many) not yet implemented command line arguments. Upon catching this, we display the specific transgressor to stderr and exit with return code 2. This behaviour is tested in one new integration test.
This commit is contained in:
+46
-1
@@ -50,6 +50,11 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||
let usage = opts.usage("Copy SOURCE to DEST or multiple SOURCE(s) to the existing\n \
|
||||
DIRECTORY, while setting permission modes and owner/group");
|
||||
|
||||
if let Err(s) = check_unimplemented(&matches) {
|
||||
show_error!("Unimplemented feature: {}", s);
|
||||
return 2;
|
||||
}
|
||||
|
||||
let behaviour = match behaviour(&matches) {
|
||||
Ok(x) => x,
|
||||
Err(ret) => {
|
||||
@@ -100,7 +105,7 @@ fn opts() -> getopts::Options {
|
||||
components of the specified directories");
|
||||
|
||||
|
||||
// TODO implement flagd
|
||||
// TODO implement flag
|
||||
opts.optflag("D", "", "create all leading components of DEST except the last, then copy\n \
|
||||
SOURCE to DEST");
|
||||
|
||||
@@ -150,6 +155,46 @@ fn opts() -> getopts::Options {
|
||||
opts
|
||||
}
|
||||
|
||||
fn check_unimplemented(matches: &getopts::Matches) -> Result<(), &str> {
|
||||
if matches.opt_present("backup") {
|
||||
Err("--backup")
|
||||
} else if matches.opt_present("b") {
|
||||
Err("-b")
|
||||
} else if matches.opt_present("compare") {
|
||||
Err("--compare, -C")
|
||||
} else if matches.opt_present("directory") {
|
||||
Err("--directory, -d")
|
||||
} else if matches.opt_present("D") {
|
||||
Err("-D")
|
||||
} else if matches.opt_present("group") {
|
||||
Err("--group, -g")
|
||||
} else if matches.opt_present("mode") {
|
||||
Err("--mode, -m")
|
||||
} else if matches.opt_present("owner") {
|
||||
Err("--owner, -o")
|
||||
} else if matches.opt_present("preserve-timestamps") {
|
||||
Err("--preserve-timestamps, -p")
|
||||
} else if matches.opt_present("strip") {
|
||||
Err("--strip, -s")
|
||||
} else if matches.opt_present("strip-program") {
|
||||
Err("--strip-program")
|
||||
} else if matches.opt_present("suffix") {
|
||||
Err("--suffix, -S")
|
||||
} else if matches.opt_present("target-directory") {
|
||||
Err("--target-directory, -t")
|
||||
} else if matches.opt_present("no-target-directory") {
|
||||
Err("--no-target-directory, -T")
|
||||
} else if matches.opt_present("verbose") {
|
||||
Err("--verbose, -v")
|
||||
} else if matches.opt_present("preserve-context") {
|
||||
Err("--preserve-context, -P")
|
||||
} else if matches.opt_present("context") {
|
||||
Err("--context, -Z")
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn behaviour(matches: &getopts::Matches) -> Result<Behaviour, i32> {
|
||||
let main_function = if matches.opt_present("version") {
|
||||
MainFunction::Version
|
||||
|
||||
+19
-2
@@ -17,13 +17,13 @@ fn test_install_help() {
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
|
||||
// assert!(result.stdout.contains("Usage:"));
|
||||
assert!(result.stdout.contains("Usage:"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_install_basic() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let dir = "test_install_target_dir_dir";
|
||||
let dir = "test_install_target_dir_dir_a";
|
||||
let file = "test_install_target_dir_file_a";
|
||||
|
||||
at.touch(file);
|
||||
@@ -36,3 +36,20 @@ fn test_install_basic() {
|
||||
assert!(!at.file_exists(file));
|
||||
assert!(at.file_exists(&format!("{}/{}", dir, file)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_install_unimplemented_arg() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let dir = "test_install_target_dir_dir_b";
|
||||
let file = "test_install_target_dir_file_b";
|
||||
let context_arg = "--context";
|
||||
|
||||
at.touch(file);
|
||||
at.mkdir(dir);
|
||||
let result = ucmd.arg(context_arg).arg(file).arg(dir).run();
|
||||
|
||||
assert!(!result.success);
|
||||
assert!(result.stderr.contains("Unimplemented"));
|
||||
|
||||
assert!(!at.file_exists(&format!("{}/{}", dir, file)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user