Debian Codegraph @

tests/by-util/test_whoami.rs

raw
1 // This file is part of the uutils coreutils package.
2 //
3 // For the full copyright and license information, please view the LICENSE
4 // file that was distributed with this source code.
5
6 use uutests::new_ucmd;
7 #[cfg(unix)]
8 use uutests::unwrap_or_return;
9 #[cfg(unix)]
10 use uutests::util::{TestScenario, expected_result};
11 use uutests::util::{is_ci, whoami};
12
13 #[test]
14 fn test_invalid_arg() {
15 new_ucmd!().arg("--definitely-invalid").fails_with_code(1);
16 }
17
18 #[test]
19 #[cfg(unix)]
20 fn test_normal() {
21 use uutests::util_name;
22
23 let ts = TestScenario::new(util_name!());
24 let exp_result = unwrap_or_return!(expected_result(&ts, &[]));
25
26 ts.ucmd()
27 .succeeds()
28 .stdout_is(exp_result.stdout_str())
29 .stderr_is(exp_result.stderr_str());
30 }
31
32 #[test]
33 #[cfg(unix)]
34 fn test_normal_compare_id() {
35 let ts = TestScenario::new("id");
36 let id_un = unwrap_or_return!(expected_result(&ts, &["-un"]));
37
38 if id_un.succeeded() {
39 new_ucmd!().succeeds().stdout_is(id_un.stdout_str());
40 } else if is_ci() && id_un.stderr_str().contains("cannot find name for user ID") {
41 println!("test skipped:");
42 } else {
43 id_un.success();
44 }
45 }
46
47 #[test]
48 fn test_normal_compare_env() {
49 let whoami = whoami();
50
51 if whoami == "nobody" {
52 println!("test skipped:");
53 } else if !is_ci() {
54 new_ucmd!().succeeds().stdout_is(format!("{whoami}\n"));
55 } else {
56 println!("test skipped:");
57 }
58 }
59
60 #[test]
61 fn test_succeeds_on_all_platforms() {
62 new_ucmd!().succeeds().no_stderr();
63 }