Skip to content

Commit c8505d4

Browse files
authored
Merge pull request #7836 from cakebaker/id_fix_7835
id: adapt error message to match the one from GNU `id`
2 parents b151e03 + 48c4c82 commit c8505d4

File tree

2 files changed

+36
-31
lines changed

2 files changed

+36
-31
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: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ fn test_invalid_arg() {
1818
}
1919

2020
#[test]
21-
#[cfg(unix)]
2221
#[allow(unused_mut)]
2322
fn test_id_no_specified_user() {
2423
let ts = TestScenario::new(util_name!());
@@ -44,7 +43,6 @@ fn test_id_no_specified_user() {
4443
}
4544

4645
#[test]
47-
#[cfg(unix)]
4846
fn test_id_single_user() {
4947
let test_users = [&whoami()[..]];
5048

@@ -96,7 +94,6 @@ fn test_id_single_user() {
9694
}
9795

9896
#[test]
99-
#[cfg(unix)]
10097
fn test_id_single_user_non_existing() {
10198
let args = &["hopefully_non_existing_username"];
10299
let ts = TestScenario::new(util_name!());
@@ -114,7 +111,6 @@ fn test_id_single_user_non_existing() {
114111
}
115112

116113
#[test]
117-
#[cfg(unix)]
118114
fn test_id_name() {
119115
let ts = TestScenario::new(util_name!());
120116
for opt in ["--user", "--group", "--groups"] {
@@ -133,7 +129,6 @@ fn test_id_name() {
133129
}
134130

135131
#[test]
136-
#[cfg(unix)]
137132
fn test_id_real() {
138133
let ts = TestScenario::new(util_name!());
139134
for opt in ["--user", "--group", "--groups"] {
@@ -148,7 +143,7 @@ fn test_id_real() {
148143
}
149144

150145
#[test]
151-
#[cfg(all(unix, not(any(target_os = "linux", target_os = "android"))))]
146+
#[cfg(not(any(target_os = "linux", target_os = "android")))]
152147
fn test_id_pretty_print() {
153148
// `-p` is BSD only and not supported on GNU's `id`
154149
let username = whoami();
@@ -157,7 +152,7 @@ fn test_id_pretty_print() {
157152
}
158153

159154
#[test]
160-
#[cfg(all(unix, not(any(target_os = "linux", target_os = "android"))))]
155+
#[cfg(not(any(target_os = "linux", target_os = "android")))]
161156
fn test_id_password_style() {
162157
// `-P` is BSD only and not supported on GNU's `id`
163158
let username = whoami();
@@ -166,7 +161,6 @@ fn test_id_password_style() {
166161
}
167162

168163
#[test]
169-
#[cfg(unix)]
170164
fn test_id_multiple_users() {
171165
unwrap_or_return!(check_coreutil_version(
172166
util_name!(),
@@ -224,7 +218,6 @@ fn test_id_multiple_users() {
224218
}
225219

226220
#[test]
227-
#[cfg(unix)]
228221
fn test_id_multiple_users_non_existing() {
229222
unwrap_or_return!(check_coreutil_version(
230223
util_name!(),
@@ -292,16 +285,19 @@ fn test_id_multiple_users_non_existing() {
292285
}
293286

294287
#[test]
295-
#[cfg(unix)]
288+
fn test_id_name_or_real_with_default_format() {
289+
for flag in ["-n", "--name", "-r", "--real"] {
290+
new_ucmd!()
291+
.arg(flag)
292+
.fails()
293+
.stderr_only("id: printing only names or real IDs requires -u, -g, or -G\n");
294+
}
295+
}
296+
297+
#[test]
296298
fn test_id_default_format() {
297299
let ts = TestScenario::new(util_name!());
298300
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());
305301
for opt2 in ["--user", "--group", "--groups"] {
306302
// u/g/G n/r
307303
let args = [opt2, opt1];
@@ -329,22 +325,32 @@ fn test_id_default_format() {
329325
}
330326

331327
#[test]
332-
#[cfg(unix)]
328+
fn test_id_zero_with_default_format() {
329+
for z_flag in ["-z", "--zero"] {
330+
new_ucmd!()
331+
.arg(z_flag)
332+
.fails()
333+
.stderr_only("id: option --zero not permitted in default format\n");
334+
}
335+
}
336+
337+
#[test]
338+
fn test_id_zero_with_name_or_real() {
339+
for z_flag in ["-z", "--zero"] {
340+
for flag in ["-n", "--name", "-r", "--real"] {
341+
new_ucmd!()
342+
.args(&[z_flag, flag])
343+
.fails()
344+
.stderr_only("id: printing only names or real IDs requires -u, -g, or -G\n");
345+
}
346+
}
347+
}
348+
349+
#[test]
333350
fn test_id_zero() {
334351
let ts = TestScenario::new(util_name!());
335352
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());
341353
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());
348354
for opt2 in ["--user", "--group", "--groups"] {
349355
// u/g/G n/r z
350356
let args = [opt2, z_flag, opt1];
@@ -429,7 +435,6 @@ fn test_id_context() {
429435
}
430436

431437
#[test]
432-
#[cfg(unix)]
433438
fn test_id_no_specified_user_posixly() {
434439
// gnu/tests/id/no-context.sh
435440

@@ -456,7 +461,7 @@ fn test_id_no_specified_user_posixly() {
456461
}
457462

458463
#[test]
459-
#[cfg(all(unix, not(target_os = "android")))]
464+
#[cfg(not(target_os = "android"))]
460465
fn test_id_pretty_print_password_record() {
461466
// `-p` is BSD only and not supported on GNU's `id`.
462467
// `-P` is our own extension, and not supported by either GNU nor BSD.

0 commit comments

Comments
 (0)