2023-03-20 13:51:19 +00:00
|
|
|
use crate::common::util::TestScenario;
|
2020-04-30 22:24:06 +00:00
|
|
|
|
2022-09-10 16:38:14 +00:00
|
|
|
#[test]
|
|
|
|
fn test_invalid_arg() {
|
|
|
|
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
|
|
|
|
}
|
|
|
|
|
2021-07-06 22:40:38 +00:00
|
|
|
#[test]
|
|
|
|
fn test_uname() {
|
|
|
|
new_ucmd!().succeeds();
|
|
|
|
}
|
|
|
|
|
2020-04-30 22:24:06 +00:00
|
|
|
#[test]
|
|
|
|
fn test_uname_compatible() {
|
2021-04-17 23:28:06 +00:00
|
|
|
new_ucmd!().arg("-a").succeeds();
|
2020-04-30 22:24:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_uname_name() {
|
2021-04-17 23:28:06 +00:00
|
|
|
new_ucmd!().arg("-n").succeeds();
|
2020-04-30 22:24:06 +00:00
|
|
|
}
|
2020-05-05 13:52:17 +00:00
|
|
|
|
2020-12-11 21:46:36 +00:00
|
|
|
#[test]
|
|
|
|
fn test_uname_processor() {
|
2021-04-17 23:28:06 +00:00
|
|
|
let result = new_ucmd!().arg("-p").succeeds();
|
|
|
|
assert_eq!(result.stdout_str().trim_end(), "unknown");
|
2020-12-11 21:46:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-05-30 05:10:54 +00:00
|
|
|
fn test_uname_hardware_platform() {
|
2022-11-30 06:35:52 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg("-i")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_str_apply(str::trim_end)
|
|
|
|
.stdout_only("unknown");
|
2020-12-11 21:46:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_uname_machine() {
|
2021-04-17 23:28:06 +00:00
|
|
|
new_ucmd!().arg("-m").succeeds();
|
2020-12-11 21:46:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_uname_kernel_version() {
|
2021-04-17 23:28:06 +00:00
|
|
|
new_ucmd!().arg("-v").succeeds();
|
2020-12-11 21:46:36 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 13:52:17 +00:00
|
|
|
#[test]
|
|
|
|
fn test_uname_kernel() {
|
|
|
|
let (_, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
2021-05-02 07:41:04 +00:00
|
|
|
{
|
|
|
|
let result = ucmd.arg("-o").succeeds();
|
|
|
|
assert!(result.stdout_str().to_lowercase().contains("linux"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(target_os = "linux"))]
|
2021-05-18 23:04:24 +00:00
|
|
|
ucmd.arg("-o").succeeds();
|
2020-05-05 13:52:17 +00:00
|
|
|
}
|
2021-07-06 22:40:38 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_uname_operating_system() {
|
2022-02-09 18:08:28 +00:00
|
|
|
#[cfg(target_os = "android")]
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("--operating-system")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("Android\n");
|
2021-07-06 22:40:38 +00:00
|
|
|
#[cfg(target_vendor = "apple")]
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("--operating-system")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("Darwin\n");
|
|
|
|
#[cfg(target_os = "freebsd")]
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("--operating-system")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("FreeBSD\n");
|
|
|
|
#[cfg(target_os = "fuchsia")]
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("--operating-system")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("Fuchsia\n");
|
|
|
|
#[cfg(all(target_os = "linux", any(target_env = "gnu", target_env = "")))]
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("--operating-system")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("GNU/Linux\n");
|
|
|
|
#[cfg(all(target_os = "linux", not(any(target_env = "gnu", target_env = ""))))]
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("--operating-system")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("Linux\n");
|
|
|
|
#[cfg(target_os = "netbsd")]
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("--operating-system")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("NetBSD\n");
|
|
|
|
#[cfg(target_os = "openbsd")]
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("--operating-system")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("OpenBSD\n");
|
|
|
|
#[cfg(target_os = "redox")]
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("--operating-system")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("Redox\n");
|
|
|
|
#[cfg(target_os = "windows")]
|
2023-01-09 22:39:27 +00:00
|
|
|
{
|
|
|
|
let result = new_ucmd!().arg("--operating-system").succeeds();
|
|
|
|
println!("{:?}", result.stdout_str());
|
|
|
|
assert!(result.stdout_str().starts_with("MS/Windows"));
|
|
|
|
}
|
2021-07-06 22:40:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_uname_help() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("--help")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_contains("system information");
|
|
|
|
}
|
2023-01-10 04:31:48 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_uname_output_for_invisible_chars() {
|
|
|
|
// let re = regex::Regex::new("[^[[:print:]]]").unwrap(); // matches invisible (and emojis)
|
|
|
|
let re = regex::Regex::new("[^[[:print:]]\\p{Other_Symbol}]").unwrap(); // matches invisible (not emojis)
|
|
|
|
let result = new_ucmd!().arg("--all").succeeds();
|
|
|
|
assert_eq!(re.find(result.stdout_str().trim_end()), None);
|
|
|
|
}
|