| 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::at_and_ucmd; |
| 7 |
use uutests::new_ucmd; |
| 8 |
|
| 9 |
#[test] |
| 10 |
fn test_invalid_arg() { |
| 11 |
new_ucmd!().arg("--definitely-invalid").fails_with_code(1); |
| 12 |
} |
| 13 |
|
| 14 |
#[test] |
| 15 |
fn test_uname() { |
| 16 |
new_ucmd!().succeeds(); |
| 17 |
} |
| 18 |
|
| 19 |
#[test] |
| 20 |
fn test_uname_compatible() { |
| 21 |
new_ucmd!().arg("-a").succeeds(); |
| 22 |
} |
| 23 |
|
| 24 |
#[test] |
| 25 |
fn test_uname_name() { |
| 26 |
new_ucmd!().arg("-n").succeeds(); |
| 27 |
} |
| 28 |
|
| 29 |
#[test] |
| 30 |
fn test_uname_processor() { |
| 31 |
let result = new_ucmd!().arg("-p").succeeds(); |
| 32 |
assert_eq!(result.stdout_str().trim_end(), "unknown"); |
| 33 |
} |
| 34 |
|
| 35 |
#[test] |
| 36 |
fn test_uname_hardware_platform() { |
| 37 |
new_ucmd!() |
| 38 |
.arg("-i") |
| 39 |
.succeeds() |
| 40 |
.stdout_str_apply(str::trim_end) |
| 41 |
.stdout_only("unknown"); |
| 42 |
} |
| 43 |
|
| 44 |
#[test] |
| 45 |
fn test_uname_machine() { |
| 46 |
new_ucmd!().arg("-m").succeeds(); |
| 47 |
} |
| 48 |
|
| 49 |
#[test] |
| 50 |
fn test_uname_kernel_version() { |
| 51 |
new_ucmd!().arg("-v").succeeds(); |
| 52 |
} |
| 53 |
|
| 54 |
#[test] |
| 55 |
fn test_uname_kernel() { |
| 56 |
let (_, mut ucmd) = at_and_ucmd!(); |
| 57 |
|
| 58 |
#[cfg(target_os = "linux")] |
| 59 |
{ |
| 60 |
let result = ucmd.arg("-o").succeeds(); |
| 61 |
assert!(result.stdout_str().to_lowercase().contains("linux")); |
| 62 |
} |
| 63 |
|
| 64 |
#[cfg(not(target_os = "linux"))] |
| 65 |
ucmd.arg("-o").succeeds(); |
| 66 |
} |
| 67 |
|
| 68 |
#[test] |
| 69 |
fn test_uname_operating_system() { |
| 70 |
#[cfg(target_os = "android")] |
| 71 |
new_ucmd!() |
| 72 |
.arg("--operating-system") |
| 73 |
.succeeds() |
| 74 |
.stdout_is("Android\n"); |
| 75 |
#[cfg(target_vendor = "apple")] |
| 76 |
new_ucmd!() |
| 77 |
.arg("--operating-system") |
| 78 |
.succeeds() |
| 79 |
.stdout_is("Darwin\n"); |
| 80 |
#[cfg(target_os = "freebsd")] |
| 81 |
new_ucmd!() |
| 82 |
.arg("--operating-system") |
| 83 |
.succeeds() |
| 84 |
.stdout_is("FreeBSD\n"); |
| 85 |
#[cfg(target_os = "fuchsia")] |
| 86 |
new_ucmd!() |
| 87 |
.arg("--operating-system") |
| 88 |
.succeeds() |
| 89 |
.stdout_is("Fuchsia\n"); |
| 90 |
#[cfg(all(target_os = "linux", any(target_env = "gnu", target_env = "")))] |
| 91 |
new_ucmd!() |
| 92 |
.arg("--operating-system") |
| 93 |
.succeeds() |
| 94 |
.stdout_is("GNU/Linux\n"); |
| 95 |
#[cfg(all(target_os = "linux", not(any(target_env = "gnu", target_env = ""))))] |
| 96 |
new_ucmd!() |
| 97 |
.arg("--operating-system") |
| 98 |
.succeeds() |
| 99 |
.stdout_is("Linux\n"); |
| 100 |
#[cfg(target_os = "netbsd")] |
| 101 |
new_ucmd!() |
| 102 |
.arg("--operating-system") |
| 103 |
.succeeds() |
| 104 |
.stdout_is("NetBSD\n"); |
| 105 |
#[cfg(target_os = "openbsd")] |
| 106 |
new_ucmd!() |
| 107 |
.arg("--operating-system") |
| 108 |
.succeeds() |
| 109 |
.stdout_is("OpenBSD\n"); |
| 110 |
#[cfg(target_os = "redox")] |
| 111 |
new_ucmd!() |
| 112 |
.arg("--operating-system") |
| 113 |
.succeeds() |
| 114 |
.stdout_is("Redox\n"); |
| 115 |
#[cfg(windows)] |
| 116 |
{ |
| 117 |
let result = new_ucmd!().arg("--operating-system").succeeds(); |
| 118 |
println!("{:?}", result.stdout_str()); |
| 119 |
assert!(result.stdout_str().starts_with("MS/Windows")); |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
#[test] |
| 124 |
fn test_uname_help() { |
| 125 |
new_ucmd!() |
| 126 |
.arg("--help") |
| 127 |
.succeeds() |
| 128 |
.stdout_contains("system information"); |
| 129 |
} |
| 130 |
|
| 131 |
#[test] |
| 132 |
fn test_uname_output_for_invisible_chars() { |
| 133 |
// let re = regex::Regex::new("[^[[:print:]]]").unwrap(); // matches invisible (and emojis) |
| 134 |
let re = regex::Regex::new("[^[[:print:]]\\p{Other_Symbol}]").unwrap(); // matches invisible (not emojis) |
| 135 |
let result = new_ucmd!().arg("--all").succeeds(); |
| 136 |
assert_eq!(re.find(result.stdout_str().trim_end()), None); |
| 137 |
} |
| 138 |
|
| 139 |
#[test] |
| 140 |
fn test_uname_all_labeled() { |
| 141 |
let result = new_ucmd!().arg("-A").succeeds(); |
| 142 |
let stdout = result.stdout_str(); |
| 143 |
// One labeled "Label: value" line per item. Like GNU, an unknown processor or |
| 144 |
// hardware platform is omitted, and we never determine either one. |
| 145 |
assert_eq!(stdout.lines().count(), 6); |
| 146 |
for label in [ |
| 147 |
"Kernel name: ", |
| 148 |
"Node name: ", |
| 149 |
"Kernel release: ", |
| 150 |
"Kernel version: ", |
| 151 |
"Machine: ", |
| 152 |
"Operating system: ", |
| 153 |
] { |
| 154 |
assert!(stdout.contains(label), "missing {label:?}"); |
| 155 |
} |
| 156 |
assert!(!stdout.contains("Processor:")); |
| 157 |
assert!(!stdout.contains("Hardware platform:")); |
| 158 |
} |
| 159 |
|
| 160 |
#[test] |
| 161 |
fn test_uname_all_labeled_long_flag() { |
| 162 |
let short = new_ucmd!().arg("-A").succeeds(); |
| 163 |
new_ucmd!() |
| 164 |
.arg("--all-labeled") |
| 165 |
.succeeds() |
| 166 |
.stdout_is(short.stdout_str()); |
| 167 |
} |