Show usage when invoked without argments

* exit with code 1 when no arguments
* add a test for no arguments.
* Update test_sed.rs
* cargo fmt
* pass -n for missing script arguments test

Issue: #274
PR: #409
This commit is contained in:
Devel
2026-06-02 18:37:35 +03:00
committed by GitHub
parent c45b2f5516
commit 508d74fe4a
2 changed files with 18 additions and 0 deletions
+9
View File
@@ -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);
+9
View File
@@ -54,11 +54,20 @@ fn test_silent_alias() {
#[test]
fn test_missing_script_argument() {
new_ucmd!()
.args(&["-n"])
.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);