diff --git a/src/uucore/src/lib/features/perms.rs b/src/uucore/src/lib/features/perms.rs index 2823b35b1a2..82df03ebd5b 100644 --- a/src/uucore/src/lib/features/perms.rs +++ b/src/uucore/src/lib/features/perms.rs @@ -163,7 +163,7 @@ pub fn wrap_chown>( format!( "group of {} retained as {}", path.quote(), - entries::gid2grp(dest_gid).unwrap_or_default() + entries::gid2grp(dest_gid).unwrap_or_else(|_| dest_gid.to_string()) ) } else { format!( diff --git a/tests/by-util/test_chgrp.rs b/tests/by-util/test_chgrp.rs index cc0727dd3eb..d6f671baea5 100644 --- a/tests/by-util/test_chgrp.rs +++ b/tests/by-util/test_chgrp.rs @@ -8,7 +8,6 @@ use std::os::unix::ffi::OsStringExt; use uucore::process::getegid; use uutests::{at_and_ucmd, new_ucmd}; -#[cfg(not(target_vendor = "apple"))] use uutests::{util::TestScenario, util_name}; #[test] @@ -640,3 +639,25 @@ fn test_chgrp_recursive_on_file() { current_gid ); } + +#[test] +fn test_chgrp_verbose_for_unmapped_gid() { + // To be able to change the gid we need root privileges so we skip if the user running the test + // suite does not have root privileges + if getegid() == 0 { + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + + at.touch("tmp"); + + scene.ucmd().arg("1337").arg("tmp").succeeds().no_stderr(); + + scene + .ucmd() + .arg("-v") + .arg("1337") + .arg("tmp") + .succeeds() + .stderr_contains("chgrp: group of 'tmp' retained as 1337"); + } +}