Debian Codegraph @

tests/by-util/test_logname.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 regex::Regex;
7 use std::env;
8 use uutests::new_ucmd;
9 use uutests::util::is_ci;
10
11 #[test]
12 fn test_invalid_arg() {
13 new_ucmd!().arg("--definitely-invalid").fails_with_code(1);
14 }
15
16 #[test]
17 fn test_normal() {
18 let result = new_ucmd!().run();
19 println!("env::var(CI).is_ok() = {}", env::var("CI").is_ok());
20
21 for (key, value) in env::vars() {
22 println!("{key}: {value}");
23 }
24 if (is_ci() || uucore::os::is_wsl()) && result.stderr_str().contains("no login name") {
25 // ToDO: investigate WSL failure
26 // In the CI, some server are failing to return logname.
27 // As seems to be a configuration issue, ignoring it
28 return;
29 }
30
31 result.success();
32 assert!(!result.stdout_str().trim().is_empty());
33 }
34
35 #[test]
36 fn test_help() {
37 new_ucmd!()
38 .arg("--help")
39 .succeeds()
40 .stdout_contains("Print user's login name");
41 }
42
43 #[test]
44 fn test_output_format() {
45 let result = new_ucmd!().run();
46 if (is_ci() || uucore::os::is_wsl()) && result.stderr_str().contains("no login name") {
47 return;
48 }
49 result.success();
50 assert!(
51 Regex::new(r"^\w+\n$")
52 .unwrap()
53 .is_match(result.stdout_str()),
54 "unexpected logname output: {:?}",
55 result.stdout_str()
56 );
57 }