mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
uucore: fix order of group IDs returned from entries::get_groups()
As discussed here: https://github.com/uutils/coreutils/pull/2361 the group IDs returned for GNU's 'group' and GNU's 'id --groups' starts with the effective group ID. This implements a wrapper for `entris::get_groups()` which mimics GNU's behaviour. * add tests for `id` * add tests for `groups` * fix `id --groups --real` to no longer ignore `--real`
This commit is contained in:
parent
a3b520abde
commit
26ad05cbb4
6 changed files with 162 additions and 66 deletions
|
@ -1,41 +1,53 @@
|
|||
use crate::common::util::*;
|
||||
|
||||
#[test]
|
||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||
fn test_groups() {
|
||||
let result = new_ucmd!().run();
|
||||
println!("result.stdout = {}", result.stdout_str());
|
||||
println!("result.stderr = {}", result.stderr_str());
|
||||
if is_ci() && result.stdout_str().trim().is_empty() {
|
||||
// In the CI, some server are failing to return the group.
|
||||
// As seems to be a configuration issue, ignoring it
|
||||
return;
|
||||
if !is_ci() {
|
||||
new_ucmd!().succeeds().stdout_is(expected_result(&[]));
|
||||
} else {
|
||||
// TODO: investigate how this could be tested in CI
|
||||
// stderr = groups: cannot find name for group ID 116
|
||||
println!("test skipped:");
|
||||
}
|
||||
result.success();
|
||||
assert!(!result.stdout_str().trim().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_groups_arg() {
|
||||
// get the username with the "id -un" command
|
||||
let result = TestScenario::new("id").ucmd_keepenv().arg("-un").run();
|
||||
println!("result.stdout = {}", result.stdout_str());
|
||||
println!("result.stderr = {}", result.stderr_str());
|
||||
let s1 = String::from(result.stdout_str().trim());
|
||||
if is_ci() && s1.parse::<f64>().is_ok() {
|
||||
// In the CI, some server are failing to return id -un.
|
||||
// So, if we are getting a uid, just skip this test
|
||||
// As seems to be a configuration issue, ignoring it
|
||||
#[cfg(any(target_os = "linux"))]
|
||||
#[ignore = "fixme: 'groups USERNAME' needs more debugging"]
|
||||
fn test_groups_username() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let whoami_result = scene.cmd("whoami").run();
|
||||
|
||||
let username = if whoami_result.succeeded() {
|
||||
whoami_result.stdout_move_str()
|
||||
} else if is_ci() {
|
||||
String::from("docker")
|
||||
} else {
|
||||
println!("test skipped:");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
println!("result.stdout = {}", result.stdout_str());
|
||||
println!("result.stderr = {}", result.stderr_str());
|
||||
result.success();
|
||||
assert!(!result.stdout_str().is_empty());
|
||||
let username = result.stdout_str().trim();
|
||||
// TODO: stdout should be in the form: "username : group1 group2 group3"
|
||||
|
||||
// call groups with the user name to check that we
|
||||
// are getting something
|
||||
new_ucmd!().arg(username).succeeds();
|
||||
assert!(!result.stdout_str().is_empty());
|
||||
scene
|
||||
.ucmd()
|
||||
.arg(&username)
|
||||
.succeeds()
|
||||
.stdout_is(expected_result(&[&username]));
|
||||
}
|
||||
|
||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||
fn expected_result(args: &[&str]) -> String {
|
||||
#[cfg(target_os = "linux")]
|
||||
let util_name = util_name!();
|
||||
#[cfg(target_vendor = "apple")]
|
||||
let util_name = format!("g{}", util_name!());
|
||||
|
||||
TestScenario::new(&util_name)
|
||||
.cmd_keepenv(util_name)
|
||||
.env("LANGUAGE", "C")
|
||||
.args(args)
|
||||
.succeeds()
|
||||
.stdout_move_str()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue