From 0c687c5a86a6072b4664264a9280d3383a339bba Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Tue, 21 Jul 2026 15:56:52 +0200 Subject: [PATCH 1/3] chgrp: use "nobody", not "staff", as group in test because "staff" doesn't exist on Arch Linux and so test_from_with_invalid_group fails there --- tests/by-util/test_chgrp.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/by-util/test_chgrp.rs b/tests/by-util/test_chgrp.rs index 45024745845..93a2873fd0e 100644 --- a/tests/by-util/test_chgrp.rs +++ b/tests/by-util/test_chgrp.rs @@ -487,7 +487,7 @@ fn test_from_with_invalid_group() { ucmd.arg("--from") .arg("nonexistent_group") - .arg("staff") + .arg("nobody") // assumption: group exists .arg("test_file") .fails() .stderr_is(err_msg); From 02524cfcba08dc293157683367e0630d73165872 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Tue, 21 Jul 2026 16:06:03 +0200 Subject: [PATCH 2/3] chgrp: remove unreachable code on Android in test --- tests/by-util/test_chgrp.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/by-util/test_chgrp.rs b/tests/by-util/test_chgrp.rs index 93a2873fd0e..406f83dc118 100644 --- a/tests/by-util/test_chgrp.rs +++ b/tests/by-util/test_chgrp.rs @@ -480,10 +480,8 @@ fn test_from_option() { fn test_from_with_invalid_group() { let (at, mut ucmd) = at_and_ucmd!(); at.touch("test_file"); - #[cfg(not(target_os = "android"))] + let err_msg = "chgrp: invalid user: 'nonexistent_group'\n"; - #[cfg(target_os = "android")] - let err_msg = "chgrp: invalid user: 'staff'\n"; ucmd.arg("--from") .arg("nonexistent_group") From 62ba3ee94e3c4f2bc7952a12f5655855d6146c26 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Tue, 21 Jul 2026 16:14:15 +0200 Subject: [PATCH 3/3] chgrp: fix error msg for "--from nonexisting" and show the same msg for "--from nonexisting GROUP", independent of whether GROUP exists --- src/uu/chgrp/src/chgrp.rs | 4 ++-- tests/by-util/test_chgrp.rs | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/uu/chgrp/src/chgrp.rs b/src/uu/chgrp/src/chgrp.rs index 0e41a67601b..b09fd929658 100644 --- a/src/uu/chgrp/src/chgrp.rs +++ b/src/uu/chgrp/src/chgrp.rs @@ -67,8 +67,6 @@ fn get_dest_gid(matches: &ArgMatches) -> UResult<(Option, String)> { } fn parse_gid_and_uid(matches: &ArgMatches) -> UResult { - let (dest_gid, raw_group) = get_dest_gid(matches)?; - // Handle --from option let filter = if let Some(from_group) = matches.get_one::(options::FROM) { match parse_gid_from_str(from_group) { @@ -84,6 +82,8 @@ fn parse_gid_and_uid(matches: &ArgMatches) -> UResult { IfFrom::All }; + let (dest_gid, raw_group) = get_dest_gid(matches)?; + Ok(GidUidOwnerFilter { dest_gid, dest_uid: None, diff --git a/tests/by-util/test_chgrp.rs b/tests/by-util/test_chgrp.rs index 406f83dc118..ccc6c725041 100644 --- a/tests/by-util/test_chgrp.rs +++ b/tests/by-util/test_chgrp.rs @@ -478,17 +478,29 @@ fn test_from_option() { #[test] #[cfg(not(any(target_os = "android", target_os = "macos")))] fn test_from_with_invalid_group() { - let (at, mut ucmd) = at_and_ucmd!(); + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; at.touch("test_file"); let err_msg = "chgrp: invalid user: 'nonexistent_group'\n"; - ucmd.arg("--from") + scene + .ucmd() + .arg("--from") .arg("nonexistent_group") .arg("nobody") // assumption: group exists .arg("test_file") .fails() .stderr_is(err_msg); + + scene + .ucmd() + .arg("--from") + .arg("nonexistent_group") + .arg("another_nonexistent_group") + .arg("test_file") + .fails() + .stderr_is(err_msg); } #[test]