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

id: fix error message & simplify tests

This commit is contained in:
Daniel Hofstetter 2025-04-24 14:52:34 +02:00
parent b151e039ae
commit 2b5391e6eb
2 changed files with 33 additions and 18 deletions

View file

@ -157,7 +157,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
if (state.nflag || state.rflag) && default_format && !state.cflag { if (state.nflag || state.rflag) && default_format && !state.cflag {
return Err(USimpleError::new( return Err(USimpleError::new(
1, 1,
"cannot print only names or real IDs in default format", "printing only names or real IDs requires -u, -g, or -G",
)); ));
} }
if state.zflag && default_format && !state.cflag { if state.zflag && default_format && !state.cflag {

View file

@ -291,17 +291,21 @@ fn test_id_multiple_users_non_existing() {
} }
} }
#[test]
fn test_id_name_or_real_with_default_format() {
for flag in ["-n", "--name", "-r", "--real"] {
new_ucmd!()
.arg(flag)
.fails()
.stderr_only("id: printing only names or real IDs requires -u, -g, or -G\n");
}
}
#[test] #[test]
#[cfg(unix)] #[cfg(unix)]
fn test_id_default_format() { fn test_id_default_format() {
let ts = TestScenario::new(util_name!()); let ts = TestScenario::new(util_name!());
for opt1 in ["--name", "--real"] { for opt1 in ["--name", "--real"] {
// id: cannot print only names or real IDs in default format
let args = [opt1];
ts.ucmd()
.args(&args)
.fails()
.stderr_only(unwrap_or_return!(expected_result(&ts, &args)).stderr_str());
for opt2 in ["--user", "--group", "--groups"] { for opt2 in ["--user", "--group", "--groups"] {
// u/g/G n/r // u/g/G n/r
let args = [opt2, opt1]; let args = [opt2, opt1];
@ -328,23 +332,34 @@ fn test_id_default_format() {
} }
} }
#[test]
fn test_id_zero_with_default_format() {
for z_flag in ["-z", "--zero"] {
new_ucmd!()
.arg(z_flag)
.fails()
.stderr_only("id: option --zero not permitted in default format\n");
}
}
#[test]
fn test_id_zero_with_name_or_real() {
for z_flag in ["-z", "--zero"] {
for flag in ["-n", "--name", "-r", "--real"] {
new_ucmd!()
.args(&[z_flag, flag])
.fails()
.stderr_only("id: printing only names or real IDs requires -u, -g, or -G\n");
}
}
}
#[test] #[test]
#[cfg(unix)] #[cfg(unix)]
fn test_id_zero() { fn test_id_zero() {
let ts = TestScenario::new(util_name!()); let ts = TestScenario::new(util_name!());
for z_flag in ["-z", "--zero"] { for z_flag in ["-z", "--zero"] {
// id: option --zero not permitted in default format
ts.ucmd()
.args(&[z_flag])
.fails()
.stderr_only(unwrap_or_return!(expected_result(&ts, &[z_flag])).stderr_str());
for opt1 in ["--name", "--real"] { for opt1 in ["--name", "--real"] {
// id: cannot print only names or real IDs in default format
let args = [opt1, z_flag];
ts.ucmd()
.args(&args)
.fails()
.stderr_only(unwrap_or_return!(expected_result(&ts, &args)).stderr_str());
for opt2 in ["--user", "--group", "--groups"] { for opt2 in ["--user", "--group", "--groups"] {
// u/g/G n/r z // u/g/G n/r z
let args = [opt2, z_flag, opt1]; let args = [opt2, z_flag, opt1];