diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index b1df1aca4..e27dbfc18 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -58,7 +58,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app().override_usage(&usage[..]).get_matches_from(args); - let files = matches.values_of_os(ARG_FILES).unwrap(); + let files = matches.values_of_os(ARG_FILES).ok_or_else(|| { + USimpleError::new( + 1, + r##"missing file operand +Try 'touch --help' for more information."##, + ) + })?; let (mut atime, mut mtime) = if let Some(reference) = matches.value_of_os(options::sources::REFERENCE) { diff --git a/tests/by-util/test_touch.rs b/tests/by-util/test_touch.rs index e661907cc..dd4a0b6cc 100644 --- a/tests/by-util/test_touch.rs +++ b/tests/by-util/test_touch.rs @@ -530,3 +530,12 @@ fn test_touch_permission_denied_error_msg() { &full_path )); } + +#[test] +fn test_touch_no_args() { + let mut ucmd = new_ucmd!(); + ucmd.fails().stderr_only( + r##"touch: missing file operand +Try 'touch --help' for more information."##, + ); +}