From f5f8cf08e0836524ebdafedd9ad9b49a53b7c91f Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Sun, 31 Mar 2024 21:08:01 +0200 Subject: [PATCH] hostid: return correct exit code on error --- src/uu/hostid/src/hostid.rs | 2 +- tests/by-util/test_hostid.rs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/uu/hostid/src/hostid.rs b/src/uu/hostid/src/hostid.rs index a5c18d075..157cfc420 100644 --- a/src/uu/hostid/src/hostid.rs +++ b/src/uu/hostid/src/hostid.rs @@ -19,7 +19,7 @@ extern "C" { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - uu_app().get_matches_from(args); + uu_app().try_get_matches_from(args)?; hostid(); Ok(()) } diff --git a/tests/by-util/test_hostid.rs b/tests/by-util/test_hostid.rs index e9336116b..7525f5e08 100644 --- a/tests/by-util/test_hostid.rs +++ b/tests/by-util/test_hostid.rs @@ -10,3 +10,12 @@ fn test_normal() { let re = Regex::new(r"^[0-9a-f]{8}").unwrap(); new_ucmd!().succeeds().stdout_matches(&re); } + +#[test] +fn test_invalid_flag() { + new_ucmd!() + .arg("--invalid-argument") + .fails() + .no_stdout() + .code_is(1); +}