1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

id: add more tests for '--zero'

* fix clippy warnings
This commit is contained in:
Jan Scheer 2021-06-09 13:24:28 +02:00
parent babf6ecae4
commit 026570ff9c
2 changed files with 75 additions and 26 deletions

View file

@ -177,6 +177,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
crash!(1, "cannot print only names or real IDs in default format"); crash!(1, "cannot print only names or real IDs in default format");
} }
if (zflag) && !(uflag || gflag || gsflag) { if (zflag) && !(uflag || gflag || gsflag) {
// GNU testsuite "id/zero.sh" needs this stderr output
crash!(1, "option --zero not permitted in default format"); crash!(1, "option --zero not permitted in default format");
} }

View file

@ -6,8 +6,12 @@ use crate::common::util::*;
// //
// From the Logs: "Build (ubuntu-18.04, x86_64-unknown-linux-gnu, feat_os_unix, use-cross)" // From the Logs: "Build (ubuntu-18.04, x86_64-unknown-linux-gnu, feat_os_unix, use-cross)"
// stderr: "whoami: cannot find name for user ID 1001" // stderr: "whoami: cannot find name for user ID 1001"
// Maybe: "adduser --uid 1001 username" can put things right? // stderr: "id: Could not find uid 1001: No such id: 1001"
// stderr = id: Could not find uid 1001: No such id: 1001 //
// However, when running "id" from within "/bin/bash" it looks fine:
// id: "uid=1001(runner) gid=118(docker) groups=118(docker),4(adm),101(systemd-journal)"
// whoami: "runner"
//
fn skipping_test_is_okay(result: &CmdResult, needle: &str) -> bool { fn skipping_test_is_okay(result: &CmdResult, needle: &str) -> bool {
if !result.succeeded() { if !result.succeeded() {
println!("result.stdout = {}", result.stdout_str()); println!("result.stdout = {}", result.stdout_str());
@ -191,53 +195,97 @@ fn test_id_password_style() {
#[test] #[test]
#[cfg(any(target_vendor = "apple", target_os = "linux"))] #[cfg(any(target_vendor = "apple", target_os = "linux"))]
fn test_id_default_format() { fn test_id_default_format() {
// These are the same tests like in test_id_zero but without --zero flag.
let scene = TestScenario::new(util_name!()); let scene = TestScenario::new(util_name!());
// -ugG for &opt1 in &["--name", "--real"] {
for flag in &["--name", "--real"] { // id: cannot print only names or real IDs in default format
let args = [opt1];
scene scene
.ucmd() .ucmd()
.arg(flag) .args(&args)
.fails() .fails()
.stderr_is(expected_result(&[flag], true)); .stderr_only(expected_result(&args, true));
for &opt in &["--user", "--group", "--groups"] { for &opt2 in &["--user", "--group", "--groups"] {
if is_ci() && *flag == "--name" { // u/g/G n/r
let args = [opt2, opt1];
let result = scene.ucmd().args(&args).run();
if !result.succeeded() && is_ci()
// && (result.stderr_str().contains("cannot find name for")
// || result.stdout_str().contains("cannot find name for"))
{
// '--name' does not work on CICD ubuntu-16/ubuntu-18 // '--name' does not work on CICD ubuntu-16/ubuntu-18
// id: cannot find name for user ID 1001 // id: cannot find name for user ID 1001
// id: cannot find name for group ID 116 // id: cannot find name for group ID 116
println!("test skipped"); scene
continue; .ucmd()
.args(&args)
.fails()
.stderr_only(expected_result(&args, true));
} else {
result.stdout_only(expected_result(&args, false));
} }
let args = [opt, flag]; }
}
// u/g/G
for &opt2 in &["--user", "--group", "--groups"] {
let args = [opt2];
scene scene
.ucmd() .ucmd()
.args(&args) .args(&args)
.succeeds() .succeeds()
.stdout_is(expected_result(&args, false)); .stdout_only(expected_result(&args, false));
}
} }
} }
#[test] #[test]
#[cfg(any(target_vendor = "apple", target_os = "linux"))] #[cfg(any(target_vendor = "apple", target_os = "linux"))]
fn test_id_zero() { fn test_id_zero() {
let scene = TestScenario::new(util_name!());
for z_flag in &["-z", "--zero"] { for z_flag in &["-z", "--zero"] {
for &opt in &["-n", "--name", "-r", "--real"] { for &opt1 in &["--name", "--real"] {
let args = [opt, z_flag]; // id: cannot print only names or real IDs in default format
new_ucmd!() let args = [opt1, z_flag];
scene
.ucmd()
.args(&args) .args(&args)
.fails() .fails()
.stderr_is(expected_result(&args, true)); .stderr_only(expected_result(&args, true));
for &opt2 in &["--user", "--group", "--groups"] {
// u/g/G n/r z
let args = [opt2, z_flag, opt1];
let result = scene.ucmd().args(&args).run();
if !result.succeeded() && is_ci()
// && (result.stderr_str().contains("cannot find name for")
// || result.stdout_str().contains("cannot find name for"))
{
// '--name' does not work on CICD ubuntu-16/ubuntu-18
// id: cannot find name for user ID 1001
// id: cannot find name for group ID 116
scene
.ucmd()
.args(&args)
.fails()
.stderr_only(expected_result(&args, true));
} else {
result.stdout_only(expected_result(&args, false));
} }
for &opt in &["-u", "--user", "-g", "--group", "-G", "--groups"] { }
let args = [opt, z_flag]; }
new_ucmd!() // u/g/G z
for &opt2 in &["--user", "--group", "--groups"] {
let args = [opt2, z_flag];
scene
.ucmd()
.args(&args) .args(&args)
.succeeds() .succeeds()
.stdout_is(expected_result(&args, false)); .stdout_only(expected_result(&args, false));
} }
} }
} }
#[allow(clippy::needless_borrow)]
#[cfg(any(target_vendor = "apple", target_os = "linux"))] #[cfg(any(target_vendor = "apple", target_os = "linux"))]
fn expected_result(args: &[&str], exp_fail: bool) -> String { fn expected_result(args: &[&str], exp_fail: bool) -> String {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
@ -260,9 +308,9 @@ fn expected_result(args: &[&str], exp_fail: bool) -> String {
.fails() .fails()
.stderr_move_str() .stderr_move_str()
}; };
return if cfg!(target_os = "macos") && result.starts_with("gid") { if cfg!(target_os = "macos") && result.starts_with("gid") {
result[1..].to_string() result[1..].to_string()
} else { } else {
result result
}; }
} }