From 9177cb7b24a62a833e64aefa4609f4627f1dcaba Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Sat, 10 Sep 2022 18:38:14 +0200 Subject: [PATCH] all: add tests for usage error exit code --- tests/by-util/test_arch.rs | 5 +++++ tests/by-util/test_basename.rs | 5 +++++ tests/by-util/test_chgrp.rs | 5 +++++ tests/by-util/test_chmod.rs | 5 +++++ tests/by-util/test_chown.rs | 5 +++++ tests/by-util/test_chroot.rs | 5 +++++ tests/by-util/test_cksum.rs | 5 +++++ tests/by-util/test_comm.rs | 5 +++++ tests/by-util/test_csplit.rs | 5 +++++ tests/by-util/test_cut.rs | 5 +++++ tests/by-util/test_date.rs | 5 +++++ tests/by-util/test_dd.rs | 5 +++++ tests/by-util/test_df.rs | 5 +++++ tests/by-util/test_dircolors.rs | 5 +++++ tests/by-util/test_dirname.rs | 5 +++++ tests/by-util/test_du.rs | 5 +++++ tests/by-util/test_env.rs | 5 +++++ tests/by-util/test_expand.rs | 5 +++++ tests/by-util/test_factor.rs | 5 +++++ tests/by-util/test_fmt.rs | 5 +++++ tests/by-util/test_fold.rs | 5 +++++ tests/by-util/test_groups.rs | 6 ++++++ tests/by-util/test_hashsum.rs | 5 +++++ tests/by-util/test_head.rs | 5 +++++ tests/by-util/test_hostname.rs | 5 +++++ tests/by-util/test_id.rs | 5 +++++ tests/by-util/test_install.rs | 5 +++++ tests/by-util/test_join.rs | 5 +++++ tests/by-util/test_kill.rs | 5 +++++ tests/by-util/test_link.rs | 5 +++++ tests/by-util/test_ln.rs | 5 +++++ tests/by-util/test_logname.rs | 5 +++++ tests/by-util/test_mkdir.rs | 5 +++++ tests/by-util/test_mkfifo.rs | 5 +++++ tests/by-util/test_mknod.rs | 6 ++++++ tests/by-util/test_mv.rs | 5 +++++ tests/by-util/test_nl.rs | 5 +++++ tests/by-util/test_nohup.rs | 5 +++++ tests/by-util/test_nproc.rs | 5 +++++ tests/by-util/test_numfmt.rs | 5 +++++ tests/by-util/test_od.rs | 5 +++++ tests/by-util/test_paste.rs | 5 +++++ tests/by-util/test_pathchk.rs | 5 +++++ tests/by-util/test_pinky.rs | 5 +++++ tests/by-util/test_ptx.rs | 5 +++++ tests/by-util/test_pwd.rs | 5 +++++ tests/by-util/test_readlink.rs | 5 +++++ tests/by-util/test_rm.rs | 5 +++++ tests/by-util/test_rmdir.rs | 5 +++++ tests/by-util/test_seq.rs | 5 +++++ tests/by-util/test_shred.rs | 5 +++++ tests/by-util/test_shuf.rs | 5 +++++ tests/by-util/test_split.rs | 5 +++++ tests/by-util/test_stat.rs | 5 +++++ tests/by-util/test_stty.rs | 5 +++++ tests/by-util/test_sum.rs | 5 +++++ tests/by-util/test_sync.rs | 5 +++++ tests/by-util/test_tac.rs | 5 +++++ tests/by-util/test_tail.rs | 5 +++++ tests/by-util/test_tee.rs | 5 +++++ tests/by-util/test_timeout.rs | 5 +++++ tests/by-util/test_touch.rs | 5 +++++ tests/by-util/test_tr.rs | 5 +++++ tests/by-util/test_tsort.rs | 4 ++++ tests/by-util/test_uname.rs | 5 +++++ tests/by-util/test_unexpand.rs | 5 +++++ tests/by-util/test_uniq.rs | 5 +++++ tests/by-util/test_unlink.rs | 5 +++++ tests/by-util/test_uptime.rs | 5 +++++ tests/by-util/test_users.rs | 5 +++++ tests/by-util/test_wc.rs | 5 +++++ tests/by-util/test_who.rs | 5 +++++ tests/by-util/test_whoami.rs | 5 +++++ tests/by-util/test_yes.rs | 5 +++++ 74 files changed, 371 insertions(+) diff --git a/tests/by-util/test_arch.rs b/tests/by-util/test_arch.rs index 909e0ee80..2945a0937 100644 --- a/tests/by-util/test_arch.rs +++ b/tests/by-util/test_arch.rs @@ -12,3 +12,8 @@ fn test_arch_help() { .succeeds() .stdout_contains("architecture name"); } + +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} diff --git a/tests/by-util/test_basename.rs b/tests/by-util/test_basename.rs index 0e8d65657..f5bb5c96a 100644 --- a/tests/by-util/test_basename.rs +++ b/tests/by-util/test_basename.rs @@ -192,3 +192,8 @@ fn test_simple_format() { .code_is(1) .stderr_contains("extra operand 'c'"); } + +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} diff --git a/tests/by-util/test_chgrp.rs b/tests/by-util/test_chgrp.rs index 33ec2c6c9..d2be150cd 100644 --- a/tests/by-util/test_chgrp.rs +++ b/tests/by-util/test_chgrp.rs @@ -8,6 +8,11 @@ fn test_invalid_option() { new_ucmd!().arg("-w").arg("/").fails(); } +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + static DIR: &str = "/dev"; // we should always get both arguments, regardless of whether --reference was used diff --git a/tests/by-util/test_chmod.rs b/tests/by-util/test_chmod.rs index ea296de1c..9eb576f34 100644 --- a/tests/by-util/test_chmod.rs +++ b/tests/by-util/test_chmod.rs @@ -561,6 +561,11 @@ fn test_no_operands() { .usage_error("missing operand"); } +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_mode_after_dash_dash() { let (at, ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_chown.rs b/tests/by-util/test_chown.rs index ef3fc0d33..c51d5ba69 100644 --- a/tests/by-util/test_chown.rs +++ b/tests/by-util/test_chown.rs @@ -78,6 +78,11 @@ fn test_invalid_option() { new_ucmd!().arg("-w").arg("-q").arg("/").fails(); } +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_chown_only_owner() { // test chown username file.txt diff --git a/tests/by-util/test_chroot.rs b/tests/by-util/test_chroot.rs index 6c9237ac3..93eb9fc6c 100644 --- a/tests/by-util/test_chroot.rs +++ b/tests/by-util/test_chroot.rs @@ -2,6 +2,11 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(125); +} + #[test] fn test_missing_operand() { let result = new_ucmd!().run(); diff --git a/tests/by-util/test_cksum.rs b/tests/by-util/test_cksum.rs index 66bdba9e3..523715126 100644 --- a/tests/by-util/test_cksum.rs +++ b/tests/by-util/test_cksum.rs @@ -2,6 +2,11 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_single_file() { new_ucmd!() diff --git a/tests/by-util/test_comm.rs b/tests/by-util/test_comm.rs index de75839de..9fc175c7f 100644 --- a/tests/by-util/test_comm.rs +++ b/tests/by-util/test_comm.rs @@ -2,6 +2,11 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn ab_no_args() { new_ucmd!() diff --git a/tests/by-util/test_csplit.rs b/tests/by-util/test_csplit.rs index 7eeb584eb..d44b4aca5 100644 --- a/tests/by-util/test_csplit.rs +++ b/tests/by-util/test_csplit.rs @@ -7,6 +7,11 @@ fn generate(from: u32, to: u32) -> String { (from..to).fold(String::new(), |acc, v| format!("{}{}\n", acc, v)) } +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_stdin() { let (at, mut ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_cut.rs b/tests/by-util/test_cut.rs index 457ba7096..bcdd9eaf0 100644 --- a/tests/by-util/test_cut.rs +++ b/tests/by-util/test_cut.rs @@ -39,6 +39,11 @@ static COMPLEX_SEQUENCE: &TestedSequence = &TestedSequence { sequence: "9-,6-7,-2,4", }; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_byte_sequence() { for param in ["-b", "--bytes", "--byt"] { diff --git a/tests/by-util/test_date.rs b/tests/by-util/test_date.rs index 81b176ce9..41fd54798 100644 --- a/tests/by-util/test_date.rs +++ b/tests/by-util/test_date.rs @@ -5,6 +5,11 @@ use crate::common::util::*; #[cfg(all(unix, not(target_os = "macos")))] use rust_users::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_date_email() { for param in ["--rfc-email", "--rfc-e", "-R"] { diff --git a/tests/by-util/test_dd.rs b/tests/by-util/test_dd.rs index 40a54d7d2..89699426c 100644 --- a/tests/by-util/test_dd.rs +++ b/tests/by-util/test_dd.rs @@ -75,6 +75,11 @@ fn build_ascii_block(n: usize) -> Vec { (0..=127).cycle().take(n).collect() } +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + // Sanity Tests #[test] fn version() { diff --git a/tests/by-util/test_df.rs b/tests/by-util/test_df.rs index 76df27b58..78f353062 100644 --- a/tests/by-util/test_df.rs +++ b/tests/by-util/test_df.rs @@ -3,6 +3,11 @@ use std::collections::HashSet; use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_df_compatible_no_size_arg() { new_ucmd!().arg("-a").succeeds(); diff --git a/tests/by-util/test_dircolors.rs b/tests/by-util/test_dircolors.rs index 2a93cbfa9..7e9578020 100644 --- a/tests/by-util/test_dircolors.rs +++ b/tests/by-util/test_dircolors.rs @@ -4,6 +4,11 @@ use crate::common::util::*; extern crate dircolors; use self::dircolors::{guess_syntax, OutputFmt, StrUtils}; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_shell_syntax() { use std::env; diff --git a/tests/by-util/test_dirname.rs b/tests/by-util/test_dirname.rs index 026ac22bb..952f715e8 100644 --- a/tests/by-util/test_dirname.rs +++ b/tests/by-util/test_dirname.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_path_with_trailing_slashes() { new_ucmd!() diff --git a/tests/by-util/test_du.rs b/tests/by-util/test_du.rs index 4eea79d45..09bb36e05 100644 --- a/tests/by-util/test_du.rs +++ b/tests/by-util/test_du.rs @@ -41,6 +41,11 @@ fn _du_basics(s: &str) { assert_eq!(s, answer); } +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_du_basics_subdir() { let ts = TestScenario::new(util_name!()); diff --git a/tests/by-util/test_env.rs b/tests/by-util/test_env.rs index 395e6d157..6e29cbf79 100644 --- a/tests/by-util/test_env.rs +++ b/tests/by-util/test_env.rs @@ -5,6 +5,11 @@ use std::env; use std::path::Path; use tempfile::tempdir; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(125); +} + #[test] fn test_env_help() { new_ucmd!() diff --git a/tests/by-util/test_expand.rs b/tests/by-util/test_expand.rs index 555671707..ac9eb1fad 100644 --- a/tests/by-util/test_expand.rs +++ b/tests/by-util/test_expand.rs @@ -2,6 +2,11 @@ use crate::common::util::*; use uucore::display::Quotable; // spell-checker:ignore (ToDO) taaaa tbbbb tcccc +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_with_tab() { new_ucmd!() diff --git a/tests/by-util/test_factor.rs b/tests/by-util/test_factor.rs index 7c1e540b6..3e576cd04 100644 --- a/tests/by-util/test_factor.rs +++ b/tests/by-util/test_factor.rs @@ -27,6 +27,11 @@ use self::sieve::Sieve; const NUM_PRIMES: usize = 10000; const NUM_TESTS: usize = 100; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_parallel() { use hex_literal::hex; diff --git a/tests/by-util/test_fmt.rs b/tests/by-util/test_fmt.rs index 0d6d9bb24..02d205466 100644 --- a/tests/by-util/test_fmt.rs +++ b/tests/by-util/test_fmt.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_fmt() { let result = new_ucmd!().arg("one-word-per-line.txt").run(); diff --git a/tests/by-util/test_fold.rs b/tests/by-util/test_fold.rs index 1acdadac1..049535422 100644 --- a/tests/by-util/test_fold.rs +++ b/tests/by-util/test_fold.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_default_80_column_wrap() { new_ucmd!() diff --git a/tests/by-util/test_groups.rs b/tests/by-util/test_groups.rs index 73837235f..1432e8c9c 100644 --- a/tests/by-util/test_groups.rs +++ b/tests/by-util/test_groups.rs @@ -9,6 +9,12 @@ use crate::common::util::*; const VERSION_MIN_MULTIPLE_USERS: &str = "8.31"; // this feature was introduced in GNU's coreutils 8.31 +#[test] +#[cfg(unix)] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] #[cfg(unix)] fn test_groups() { diff --git a/tests/by-util/test_hashsum.rs b/tests/by-util/test_hashsum.rs index 06d039d59..5fdc6e648 100644 --- a/tests/by-util/test_hashsum.rs +++ b/tests/by-util/test_hashsum.rs @@ -116,3 +116,8 @@ fn test_check_sha1() { .stdout_is("testf: OK\n") .stderr_is(""); } + +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} diff --git a/tests/by-util/test_head.rs b/tests/by-util/test_head.rs index 20bec7589..cefb5c0ae 100644 --- a/tests/by-util/test_head.rs +++ b/tests/by-util/test_head.rs @@ -9,6 +9,11 @@ use crate::common::util::*; static INPUT: &str = "lorem_ipsum.txt"; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_stdin_default() { new_ucmd!() diff --git a/tests/by-util/test_hostname.rs b/tests/by-util/test_hostname.rs index 45acff1b5..474be8b3e 100644 --- a/tests/by-util/test_hostname.rs +++ b/tests/by-util/test_hostname.rs @@ -28,3 +28,8 @@ fn test_hostname_full() { .succeeds() .stdout_contains(ls_short_res.stdout_str().trim()); } + +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} diff --git a/tests/by-util/test_id.rs b/tests/by-util/test_id.rs index b791dbfd0..b7b36c58d 100644 --- a/tests/by-util/test_id.rs +++ b/tests/by-util/test_id.rs @@ -9,6 +9,11 @@ use crate::common::util::*; const VERSION_MIN_MULTIPLE_USERS: &str = "8.31"; // this feature was introduced in GNU's coreutils 8.31 +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] #[cfg(unix)] fn test_id_no_specified_user() { diff --git a/tests/by-util/test_install.rs b/tests/by-util/test_install.rs index 3b68eb38c..252aeb1b7 100644 --- a/tests/by-util/test_install.rs +++ b/tests/by-util/test_install.rs @@ -9,6 +9,11 @@ use std::process::Command; #[cfg(any(target_os = "linux", target_os = "android"))] use std::thread::sleep; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_install_basic() { let (at, mut ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_join.rs b/tests/by-util/test_join.rs index d5da873f6..10af26ec5 100644 --- a/tests/by-util/test_join.rs +++ b/tests/by-util/test_join.rs @@ -8,6 +8,11 @@ use std::{ffi::OsStr, os::unix::ffi::OsStrExt}; #[cfg(windows)] use std::{ffi::OsString, os::windows::ffi::OsStringExt}; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn empty_files() { new_ucmd!() diff --git a/tests/by-util/test_kill.rs b/tests/by-util/test_kill.rs index 7581086a0..43e281155 100644 --- a/tests/by-util/test_kill.rs +++ b/tests/by-util/test_kill.rs @@ -45,6 +45,11 @@ impl Drop for Target { } } +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_kill_list_all_signals() { // Check for a few signals. Do not try to be comprehensive. diff --git a/tests/by-util/test_link.rs b/tests/by-util/test_link.rs index 9f6a2ee5f..a1f4f2c3f 100644 --- a/tests/by-util/test_link.rs +++ b/tests/by-util/test_link.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[cfg(not(target_os = "android"))] #[test] fn test_link_existing_file() { diff --git a/tests/by-util/test_ln.rs b/tests/by-util/test_ln.rs index 74af0acc6..cb4729adf 100644 --- a/tests/by-util/test_ln.rs +++ b/tests/by-util/test_ln.rs @@ -1,6 +1,11 @@ use crate::common::util::*; use std::path::PathBuf; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_symlink_existing_file() { let (at, mut ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_logname.rs b/tests/by-util/test_logname.rs index 0e8125191..43fce6851 100644 --- a/tests/by-util/test_logname.rs +++ b/tests/by-util/test_logname.rs @@ -1,6 +1,11 @@ use crate::common::util::*; use std::env; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_normal() { let result = new_ucmd!().run(); diff --git a/tests/by-util/test_mkdir.rs b/tests/by-util/test_mkdir.rs index be7a95af2..0a9d9f4d4 100644 --- a/tests/by-util/test_mkdir.rs +++ b/tests/by-util/test_mkdir.rs @@ -20,6 +20,11 @@ static TEST_DIR11: &str = "mkdir_test11/.."; #[cfg(not(windows))] static TEST_DIR12: &str = "mkdir_test12"; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_mkdir_mkdir() { new_ucmd!().arg(TEST_DIR1).succeeds(); diff --git a/tests/by-util/test_mkfifo.rs b/tests/by-util/test_mkfifo.rs index 318a2ea5d..18d1d53d1 100644 --- a/tests/by-util/test_mkfifo.rs +++ b/tests/by-util/test_mkfifo.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_create_fifo_missing_operand() { new_ucmd!().fails().stderr_is("mkfifo: missing operand"); diff --git a/tests/by-util/test_mknod.rs b/tests/by-util/test_mknod.rs index 3b22ef835..291b56b72 100644 --- a/tests/by-util/test_mknod.rs +++ b/tests/by-util/test_mknod.rs @@ -1,5 +1,11 @@ use crate::common::util::*; +#[test] +#[cfg(not(windows))] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[cfg(not(windows))] #[test] fn test_mknod_help() { diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index f22c8f7ca..a171b6ba9 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -4,6 +4,11 @@ extern crate time; use self::filetime::*; use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_mv_rename_dir() { let (at, mut ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_nl.rs b/tests/by-util/test_nl.rs index 1ed46c313..cd59a745c 100644 --- a/tests/by-util/test_nl.rs +++ b/tests/by-util/test_nl.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_stdin_no_newline() { new_ucmd!() diff --git a/tests/by-util/test_nohup.rs b/tests/by-util/test_nohup.rs index 8d848131c..8ef0bc9c9 100644 --- a/tests/by-util/test_nohup.rs +++ b/tests/by-util/test_nohup.rs @@ -5,6 +5,11 @@ use std::thread::sleep; // because stdin/stdout is not attached to a TTY. // All that can be tested is the side-effects. +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(125); +} + #[test] #[cfg(any( target_os = "linux", diff --git a/tests/by-util/test_nproc.rs b/tests/by-util/test_nproc.rs index 330f327cb..3260e46e7 100644 --- a/tests/by-util/test_nproc.rs +++ b/tests/by-util/test_nproc.rs @@ -1,6 +1,11 @@ // spell-checker:ignore incorrectnumber use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_nproc() { let nproc: u8 = new_ucmd!().succeeds().stdout_str().trim().parse().unwrap(); diff --git a/tests/by-util/test_numfmt.rs b/tests/by-util/test_numfmt.rs index 721e3e5a4..b12ea2d50 100644 --- a/tests/by-util/test_numfmt.rs +++ b/tests/by-util/test_numfmt.rs @@ -2,6 +2,11 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_should_not_round_floats() { new_ucmd!() diff --git a/tests/by-util/test_od.rs b/tests/by-util/test_od.rs index e68881309..a5dc49554 100644 --- a/tests/by-util/test_od.rs +++ b/tests/by-util/test_od.rs @@ -24,6 +24,11 @@ static ALPHA_OUT: &str = " // XXX We could do a better job of ensuring that we have a fresh temp dir to ourselves, // not a general one full of other process leftovers. +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + // Test that od can read one file and dump with default format #[test] fn test_file() { diff --git a/tests/by-util/test_paste.rs b/tests/by-util/test_paste.rs index b4d23868a..088a27eae 100644 --- a/tests/by-util/test_paste.rs +++ b/tests/by-util/test_paste.rs @@ -128,6 +128,11 @@ static EXAMPLE_DATA: &[TestData] = &[ }, ]; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_combine_pairs_of_lines() { for s in ["-s", "--serial"] { diff --git a/tests/by-util/test_pathchk.rs b/tests/by-util/test_pathchk.rs index 8ba3b9033..9b16fe738 100644 --- a/tests/by-util/test_pathchk.rs +++ b/tests/by-util/test_pathchk.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_default_mode() { // test the default mode diff --git a/tests/by-util/test_pinky.rs b/tests/by-util/test_pinky.rs index 1da93ee42..26af822cd 100644 --- a/tests/by-util/test_pinky.rs +++ b/tests/by-util/test_pinky.rs @@ -12,6 +12,11 @@ use self::uucore::entries::{Locate, Passwd}; extern crate pinky; pub use self::pinky::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_capitalize() { assert_eq!("Zbnmasd", "zbnmasd".capitalize()); // spell-checker:disable-line diff --git a/tests/by-util/test_ptx.rs b/tests/by-util/test_ptx.rs index 75c96e42e..7372bb5cc 100644 --- a/tests/by-util/test_ptx.rs +++ b/tests/by-util/test_ptx.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn gnu_ext_disabled_rightward_no_ref() { new_ucmd!() diff --git a/tests/by-util/test_pwd.rs b/tests/by-util/test_pwd.rs index 950a148a3..0ae63c895 100644 --- a/tests/by-util/test_pwd.rs +++ b/tests/by-util/test_pwd.rs @@ -4,6 +4,11 @@ use std::path::PathBuf; use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_default() { let (at, mut ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_readlink.rs b/tests/by-util/test_readlink.rs index 5707913b2..2bc983b02 100644 --- a/tests/by-util/test_readlink.rs +++ b/tests/by-util/test_readlink.rs @@ -8,6 +8,11 @@ static NOT_A_DIRECTORY: &str = "Not a directory"; #[cfg(windows)] static NOT_A_DIRECTORY: &str = "The directory name is invalid."; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_resolve() { let scene = TestScenario::new(util_name!()); diff --git a/tests/by-util/test_rm.rs b/tests/by-util/test_rm.rs index c5c150371..472d12bed 100644 --- a/tests/by-util/test_rm.rs +++ b/tests/by-util/test_rm.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_rm_one_file() { let (at, mut ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_rmdir.rs b/tests/by-util/test_rmdir.rs index c8f22aa6c..4cee34bf8 100644 --- a/tests/by-util/test_rmdir.rs +++ b/tests/by-util/test_rmdir.rs @@ -20,6 +20,11 @@ const NOT_A_DIRECTORY: &str = "The directory name is invalid."; #[cfg(not(windows))] const NOT_A_DIRECTORY: &str = "Not a directory"; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_rmdir_empty_directory_no_parents() { let (at, mut ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_seq.rs b/tests/by-util/test_seq.rs index a18cbc2ad..c3ca61081 100644 --- a/tests/by-util/test_seq.rs +++ b/tests/by-util/test_seq.rs @@ -2,6 +2,11 @@ use crate::common::util::*; use std::io::Read; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_hex_rejects_sign_after_identifier() { new_ucmd!() diff --git a/tests/by-util/test_shred.rs b/tests/by-util/test_shred.rs index b29b9bfec..0780411f6 100644 --- a/tests/by-util/test_shred.rs +++ b/tests/by-util/test_shred.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_shred_remove() { let scene = TestScenario::new(util_name!()); diff --git a/tests/by-util/test_shuf.rs b/tests/by-util/test_shuf.rs index 682b0dab6..39a7a640b 100644 --- a/tests/by-util/test_shuf.rs +++ b/tests/by-util/test_shuf.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_output_is_random_permutation() { let input_seq = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; diff --git a/tests/by-util/test_split.rs b/tests/by-util/test_split.rs index 854225d18..c57e6bd6e 100644 --- a/tests/by-util/test_split.rs +++ b/tests/by-util/test_split.rs @@ -119,6 +119,11 @@ impl RandomFile { } } +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_split_default() { let (at, mut ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_stat.rs b/tests/by-util/test_stat.rs index 92af7118d..365ac3df3 100644 --- a/tests/by-util/test_stat.rs +++ b/tests/by-util/test_stat.rs @@ -10,6 +10,11 @@ use crate::common::util::*; extern crate stat; pub use self::stat::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_scanners() { assert_eq!(Some((-5, 2)), "-5zxc".scan_num::()); diff --git a/tests/by-util/test_stty.rs b/tests/by-util/test_stty.rs index 730ccdf37..d15052591 100644 --- a/tests/by-util/test_stty.rs +++ b/tests/by-util/test_stty.rs @@ -2,6 +2,11 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] #[ignore = "Fails because cargo test does not run in a tty"] fn runs() { diff --git a/tests/by-util/test_sum.rs b/tests/by-util/test_sum.rs index 0248c05cf..68432a647 100644 --- a/tests/by-util/test_sum.rs +++ b/tests/by-util/test_sum.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_bsd_single_file() { new_ucmd!() diff --git a/tests/by-util/test_sync.rs b/tests/by-util/test_sync.rs index 033651910..97259cdda 100644 --- a/tests/by-util/test_sync.rs +++ b/tests/by-util/test_sync.rs @@ -3,6 +3,11 @@ extern crate tempfile; use std::fs; use tempfile::tempdir; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_sync_default() { new_ucmd!().succeeds(); diff --git a/tests/by-util/test_tac.rs b/tests/by-util/test_tac.rs index 323aa5149..6f8a72989 100644 --- a/tests/by-util/test_tac.rs +++ b/tests/by-util/test_tac.rs @@ -1,6 +1,11 @@ // spell-checker:ignore axxbxx bxxaxx axxx axxxx xxaxx xxax xxxxa axyz zyax zyxa use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_stdin_default() { new_ucmd!() diff --git a/tests/by-util/test_tail.rs b/tests/by-util/test_tail.rs index 442c07979..cbb05ba9d 100644 --- a/tests/by-util/test_tail.rs +++ b/tests/by-util/test_tail.rs @@ -30,6 +30,11 @@ static FOLLOW_NAME_SHORT_EXP: &str = "follow_name_short.expected"; #[cfg(target_os = "linux")] static FOLLOW_NAME_EXP: &str = "follow_name.expected"; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] #[cfg(all(unix, not(target_os = "android")))] // FIXME: fix this test for Android fn test_stdin_default() { diff --git a/tests/by-util/test_tee.rs b/tests/by-util/test_tee.rs index 7fd4d77b0..54b77d3b4 100644 --- a/tests/by-util/test_tee.rs +++ b/tests/by-util/test_tee.rs @@ -6,6 +6,11 @@ use crate::common::util::*; // spell-checker:ignore nopipe +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_tee_processing_multiple_operands() { // POSIX says: "Processing of at least 13 file operands shall be supported." diff --git a/tests/by-util/test_timeout.rs b/tests/by-util/test_timeout.rs index 5d77e1fa0..2dc8da8fe 100644 --- a/tests/by-util/test_timeout.rs +++ b/tests/by-util/test_timeout.rs @@ -1,6 +1,11 @@ // spell-checker:ignore dont use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(125); +} + // FIXME: this depends on the system having true and false in PATH // the best solution is probably to generate some test binaries that we can call for any // utility that requires executing another program (kill, for instance) diff --git a/tests/by-util/test_touch.rs b/tests/by-util/test_touch.rs index bdef1e1e5..a89e808de 100644 --- a/tests/by-util/test_touch.rs +++ b/tests/by-util/test_touch.rs @@ -59,6 +59,11 @@ fn str_to_filetime(format: &str, s: &str) -> FileTime { FileTime::from_unix_time(offset_dt.unix_timestamp(), tm.nanosecond()) } +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_touch_default() { let (at, mut ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_tr.rs b/tests/by-util/test_tr.rs index bf550a109..7f60f88a1 100644 --- a/tests/by-util/test_tr.rs +++ b/tests/by-util/test_tr.rs @@ -1,6 +1,11 @@ // spell-checker:ignore aabbaa aabbcc aabc abbb abcc abcdefabcdef abcdefghijk abcdefghijklmn abcdefghijklmnop ABCDEFGHIJKLMNOPQRS abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFZZ abcxyz ABCXYZ abcxyzabcxyz ABCXYZABCXYZ acbdef alnum amzamz AMZXAMZ bbbd cclass cefgm cntrl compl dabcdef dncase Gzabcdefg PQRST upcase wxyzz xdigit xycde xyyye xyyz xyzzzzxyzzzz ZABCDEF Zamz Cdefghijkl Cdefghijklmn use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_to_upper() { new_ucmd!() diff --git a/tests/by-util/test_tsort.rs b/tests/by-util/test_tsort.rs index 0da6f44e4..e424fe651 100644 --- a/tests/by-util/test_tsort.rs +++ b/tests/by-util/test_tsort.rs @@ -1,5 +1,9 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} #[test] fn test_sort_call_graph() { new_ucmd!() diff --git a/tests/by-util/test_uname.rs b/tests/by-util/test_uname.rs index 5e78ddc13..7cd165d0f 100644 --- a/tests/by-util/test_uname.rs +++ b/tests/by-util/test_uname.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_uname() { new_ucmd!().succeeds(); diff --git a/tests/by-util/test_unexpand.rs b/tests/by-util/test_unexpand.rs index c208b624c..1639ee1bc 100644 --- a/tests/by-util/test_unexpand.rs +++ b/tests/by-util/test_unexpand.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn unexpand_init_0() { new_ucmd!() diff --git a/tests/by-util/test_uniq.rs b/tests/by-util/test_uniq.rs index 5b22622d3..22a56c0e2 100644 --- a/tests/by-util/test_uniq.rs +++ b/tests/by-util/test_uniq.rs @@ -9,6 +9,11 @@ static SKIP_CHARS: &str = "skip-chars.txt"; static SKIP_FIELDS: &str = "skip-fields.txt"; static SORTED_ZERO_TERMINATED: &str = "sorted-zero-terminated.txt"; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_stdin_default() { new_ucmd!() diff --git a/tests/by-util/test_unlink.rs b/tests/by-util/test_unlink.rs index 6b4fc41da..38b1cf2ba 100644 --- a/tests/by-util/test_unlink.rs +++ b/tests/by-util/test_unlink.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_unlink_file() { let (at, mut ucmd) = at_and_ucmd!(); diff --git a/tests/by-util/test_uptime.rs b/tests/by-util/test_uptime.rs index 4dc90eb31..946bb30fa 100644 --- a/tests/by-util/test_uptime.rs +++ b/tests/by-util/test_uptime.rs @@ -2,6 +2,11 @@ extern crate regex; use self::regex::Regex; use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_uptime() { TestScenario::new(util_name!()) diff --git a/tests/by-util/test_users.rs b/tests/by-util/test_users.rs index c074f3e40..747995d99 100644 --- a/tests/by-util/test_users.rs +++ b/tests/by-util/test_users.rs @@ -1,5 +1,10 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_users_no_arg() { new_ucmd!().succeeds(); diff --git a/tests/by-util/test_wc.rs b/tests/by-util/test_wc.rs index d9166cb92..9b4f053ac 100644 --- a/tests/by-util/test_wc.rs +++ b/tests/by-util/test_wc.rs @@ -2,6 +2,11 @@ use crate::common::util::*; // spell-checker:ignore (flags) lwmcL clmwL ; (path) bogusfile emptyfile manyemptylines moby notrailingnewline onelongemptyline onelongword weirdchars +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_count_bytes_large_stdin() { for n in [ diff --git a/tests/by-util/test_who.rs b/tests/by-util/test_who.rs index 580d9ea6f..1f0554f92 100644 --- a/tests/by-util/test_who.rs +++ b/tests/by-util/test_who.rs @@ -7,6 +7,11 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[cfg(unix)] #[test] #[ignore = "issue #3219"] diff --git a/tests/by-util/test_whoami.rs b/tests/by-util/test_whoami.rs index 340c1434f..a64dbb7cd 100644 --- a/tests/by-util/test_whoami.rs +++ b/tests/by-util/test_whoami.rs @@ -5,6 +5,11 @@ use crate::common::util::*; +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] #[cfg(unix)] fn test_normal() { diff --git a/tests/by-util/test_yes.rs b/tests/by-util/test_yes.rs index 20561ced6..dd455a933 100644 --- a/tests/by-util/test_yes.rs +++ b/tests/by-util/test_yes.rs @@ -28,6 +28,11 @@ fn run(args: &[&str], expected: &[u8]) { assert_eq!(buf.as_slice(), expected); } +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails().code_is(1); +} + #[test] fn test_simple() { run(&[], b"y\ny\ny\ny\n");