Skip to content

Commit 2b5391e

Browse files
committed
id: fix error message & simplify tests
1 parent b151e03 commit 2b5391e

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

src/uu/id/src/id.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
157157
if (state.nflag || state.rflag) && default_format && !state.cflag {
158158
return Err(USimpleError::new(
159159
1,
160-
"cannot print only names or real IDs in default format",
160+
"printing only names or real IDs requires -u, -g, or -G",
161161
));
162162
}
163163
if state.zflag && default_format && !state.cflag {

tests/by-util/test_id.rs

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -291,17 +291,21 @@ fn test_id_multiple_users_non_existing() {
291291
}
292292
}
293293

294+
#[test]
295+
fn test_id_name_or_real_with_default_format() {
296+
for flag in ["-n", "--name", "-r", "--real"] {
297+
new_ucmd!()
298+
.arg(flag)
299+
.fails()
300+
.stderr_only("id: printing only names or real IDs requires -u, -g, or -G\n");
301+
}
302+
}
303+
294304
#[test]
295305
#[cfg(unix)]
296306
fn test_id_default_format() {
297307
let ts = TestScenario::new(util_name!());
298308
for opt1 in ["--name", "--real"] {
299-
// id: cannot print only names or real IDs in default format
300-
let args = [opt1];
301-
ts.ucmd()
302-
.args(&args)
303-
.fails()
304-
.stderr_only(unwrap_or_return!(expected_result(&ts, &args)).stderr_str());
305309
for opt2 in ["--user", "--group", "--groups"] {
306310
// u/g/G n/r
307311
let args = [opt2, opt1];
@@ -328,23 +332,34 @@ fn test_id_default_format() {
328332
}
329333
}
330334

335+
#[test]
336+
fn test_id_zero_with_default_format() {
337+
for z_flag in ["-z", "--zero"] {
338+
new_ucmd!()
339+
.arg(z_flag)
340+
.fails()
341+
.stderr_only("id: option --zero not permitted in default format\n");
342+
}
343+
}
344+
345+
#[test]
346+
fn test_id_zero_with_name_or_real() {
347+
for z_flag in ["-z", "--zero"] {
348+
for flag in ["-n", "--name", "-r", "--real"] {
349+
new_ucmd!()
350+
.args(&[z_flag, flag])
351+
.fails()
352+
.stderr_only("id: printing only names or real IDs requires -u, -g, or -G\n");
353+
}
354+
}
355+
}
356+
331357
#[test]
332358
#[cfg(unix)]
333359
fn test_id_zero() {
334360
let ts = TestScenario::new(util_name!());
335361
for z_flag in ["-z", "--zero"] {
336-
// id: option --zero not permitted in default format
337-
ts.ucmd()
338-
.args(&[z_flag])
339-
.fails()
340-
.stderr_only(unwrap_or_return!(expected_result(&ts, &[z_flag])).stderr_str());
341362
for opt1 in ["--name", "--real"] {
342-
// id: cannot print only names or real IDs in default format
343-
let args = [opt1, z_flag];
344-
ts.ucmd()
345-
.args(&args)
346-
.fails()
347-
.stderr_only(unwrap_or_return!(expected_result(&ts, &args)).stderr_str());
348363
for opt2 in ["--user", "--group", "--groups"] {
349364
// u/g/G n/r z
350365
let args = [opt2, z_flag, opt1];

0 commit comments

Comments
 (0)