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 45024745845..ccc6c725041 100644 --- a/tests/by-util/test_chgrp.rs +++ b/tests/by-util/test_chgrp.rs @@ -478,16 +478,26 @@ 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"); - #[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") + 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("staff") + .arg("another_nonexistent_group") .arg("test_file") .fails() .stderr_is(err_msg);