From 6f4080b591135cb0aa35fa75b94c6c47522e7144 Mon Sep 17 00:00:00 2001 From: Devel08 Date: Sun, 3 May 2026 04:27:52 +0300 Subject: [PATCH 1/4] exit with code 1 when no arguments --- src/sed/mod.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/sed/mod.rs b/src/sed/mod.rs index 1206140c..70cf1b4e 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); From 6e454cebe6c4f76d3d7e46eda21ea72b8243a50a Mon Sep 17 00:00:00 2001 From: Devel08 Date: Sun, 3 May 2026 09:54:47 +0300 Subject: [PATCH 2/4] add a test for no arguments. --- tests/by-util/test_sed.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/by-util/test_sed.rs b/tests/by-util/test_sed.rs index 13a65767..49246340 100644 --- a/tests/by-util/test_sed.rs +++ b/tests/by-util/test_sed.rs @@ -54,14 +54,18 @@ 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_positional_script_ok() { - new_ucmd!().arg("l").succeeds().code_is(0); +fn test_no_arguments() { + new_ucmd!() + .fails() + .code_is(1) + .stdout_contains("Stream editor for filtering and transforming text"); } #[test] From e85c2672a000c2d49c2e99a61bde9601a156d311 Mon Sep 17 00:00:00 2001 From: Devel08 Date: Sun, 3 May 2026 10:15:26 +0300 Subject: [PATCH 3/4] Update test_sed.rs --- tests/by-util/test_sed.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/by-util/test_sed.rs b/tests/by-util/test_sed.rs index 49246340..ec9c441c 100644 --- a/tests/by-util/test_sed.rs +++ b/tests/by-util/test_sed.rs @@ -68,6 +68,11 @@ fn test_no_arguments() { .stdout_contains("Stream editor for filtering and transforming text"); } +#[test] +fn test_positional_script_ok() { + new_ucmd!().arg("l").succeeds().code_is(0); +} + #[test] fn test_empty_positional_script_ok() { new_ucmd!().arg("").succeeds().code_is(0); From 477b2a38be1896ea075e72ce22dca6ed914f112f Mon Sep 17 00:00:00 2001 From: Devel08 Date: Sun, 3 May 2026 10:46:18 +0300 Subject: [PATCH 4/4] cargo fmt --- src/sed/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sed/mod.rs b/src/sed/mod.rs index 70cf1b4e..7605f522 100644 --- a/src/sed/mod.rs +++ b/src/sed/mod.rs @@ -44,7 +44,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let _ = uu_app().print_help(); std::process::exit(1); } - + let (scripts, files) = get_scripts_files(&matches)?; let mut context = build_context(&matches);