diff --git a/src/sed/mod.rs b/src/sed/mod.rs index 1206140..7605f52 100644 --- a/src/sed/mod.rs +++ b/src/sed/mod.rs @@ -36,6 +36,15 @@ const USAGE: &str = "sed [OPTION]... [script] [file]..."; #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app().try_get_matches_from(args)?; + + // Don't use arg_required_else_help when declaring command + // as it exits with code 2 and we use it to check + // default matches in tests. + if !matches.args_present() { + let _ = uu_app().print_help(); + std::process::exit(1); + } + let (scripts, files) = get_scripts_files(&matches)?; let mut context = build_context(&matches); diff --git a/tests/by-util/test_sed.rs b/tests/by-util/test_sed.rs index 13a6576..ec9c441 100644 --- a/tests/by-util/test_sed.rs +++ b/tests/by-util/test_sed.rs @@ -54,11 +54,20 @@ fn test_silent_alias() { #[test] fn test_missing_script_argument() { new_ucmd!() + .args(&["-i", "file.txt"]) .fails() .code_is(1) .stderr_contains("missing script"); } +#[test] +fn test_no_arguments() { + new_ucmd!() + .fails() + .code_is(1) + .stdout_contains("Stream editor for filtering and transforming text"); +} + #[test] fn test_positional_script_ok() { new_ucmd!().arg("l").succeeds().code_is(0);