From 80203a7a024cd916755eb0c7a83b96ac44feab07 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Mon, 11 May 2020 00:18:23 +0200 Subject: [PATCH 1/2] fix(more) Return a proper error message when no argument is provided Fix #1509 --- src/uu/more/src/more.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/uu/more/src/more.rs b/src/uu/more/src/more.rs index 44a61dc20..32350e58e 100644 --- a/src/uu/more/src/more.rs +++ b/src/uu/more/src/more.rs @@ -41,6 +41,12 @@ static VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> i32 { let mut opts = Options::new(); + // FixME: fail without panic for now; but `more` should work with no arguments (ie, for piped input) + if args.len() < 2 { + println!("{}: incorrect usage", args[0]); + return 1; + } + opts.optflag("h", "help", "display this help and exit"); opts.optflag("v", "version", "output version information and exit"); From 62901490e14fbcf6268e6fc1f451e5b39612dc11 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Mon, 11 May 2020 10:44:12 +0200 Subject: [PATCH 2/2] test(more): add a test for more when called without arg --- tests/test_more.rs | 8 ++++++++ tests/tests.rs | 1 + 2 files changed, 9 insertions(+) create mode 100644 tests/test_more.rs diff --git a/tests/test_more.rs b/tests/test_more.rs new file mode 100644 index 000000000..9d4835769 --- /dev/null +++ b/tests/test_more.rs @@ -0,0 +1,8 @@ +use common::util::*; + +#[test] +fn test_more_no_arg() { + let (_, mut ucmd) = at_and_ucmd!(); + let result = ucmd.run(); + assert!(!result.success); +} diff --git a/tests/tests.rs b/tests/tests.rs index ead3b68f9..a99c7cc26 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -75,6 +75,7 @@ generic! { "ls", test_ls; "mkdir", test_mkdir; "mktemp", test_mktemp; + "more", test_more; "mv", test_mv; "numfmt", test_numfmt; "nl", test_nl;