2023-08-24 10:07:48 +00:00
|
|
|
// This file is part of the uutils coreutils package.
|
|
|
|
//
|
|
|
|
// For the full copyright and license information, please view the LICENSE
|
|
|
|
// file that was distributed with this source code.
|
2021-04-17 20:29:07 +00:00
|
|
|
|
2023-03-20 15:26:31 +00:00
|
|
|
#[cfg(unix)]
|
|
|
|
use crate::common::util::expected_result;
|
|
|
|
use crate::common::util::{is_ci, whoami, TestScenario};
|
2020-05-15 12:19:40 +00:00
|
|
|
|
2022-09-10 16:38:14 +00:00
|
|
|
#[test]
|
|
|
|
fn test_invalid_arg() {
|
|
|
|
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
|
|
|
|
}
|
|
|
|
|
2020-05-15 12:19:40 +00:00
|
|
|
#[test]
|
2021-07-07 22:21:28 +00:00
|
|
|
#[cfg(unix)]
|
2020-05-15 12:19:40 +00:00
|
|
|
fn test_normal() {
|
2021-07-07 22:21:28 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let result = ts.ucmd().run();
|
|
|
|
let exp_result = unwrap_or_return!(expected_result(&ts, &[]));
|
|
|
|
|
|
|
|
result
|
|
|
|
.stdout_is(exp_result.stdout_str())
|
|
|
|
.stderr_is(exp_result.stderr_str())
|
|
|
|
.code_is(exp_result.code());
|
2020-05-15 12:19:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-07-07 22:21:28 +00:00
|
|
|
#[cfg(unix)]
|
2020-05-15 12:19:40 +00:00
|
|
|
fn test_normal_compare_id() {
|
2021-07-07 22:21:28 +00:00
|
|
|
let ts = TestScenario::new("id");
|
|
|
|
let id_un = unwrap_or_return!(expected_result(&ts, &["-un"]));
|
|
|
|
if id_un.succeeded() {
|
|
|
|
new_ucmd!().succeeds().stdout_is(id_un.stdout_str());
|
|
|
|
} else if is_ci() && id_un.stderr_str().contains("cannot find name for user ID") {
|
|
|
|
println!("test skipped:");
|
|
|
|
} else {
|
|
|
|
id_un.success();
|
2020-05-15 12:19:40 +00:00
|
|
|
}
|
2021-07-07 22:21:28 +00:00
|
|
|
}
|
2020-05-15 12:19:40 +00:00
|
|
|
|
2021-07-07 22:21:28 +00:00
|
|
|
#[test]
|
|
|
|
fn test_normal_compare_env() {
|
|
|
|
let whoami = whoami();
|
|
|
|
if whoami == "nobody" {
|
|
|
|
println!("test skipped:");
|
2021-07-07 23:32:39 +00:00
|
|
|
} else if !is_ci() {
|
2023-01-27 09:29:45 +00:00
|
|
|
new_ucmd!().succeeds().stdout_is(format!("{whoami}\n"));
|
2021-07-07 23:32:39 +00:00
|
|
|
} else {
|
|
|
|
println!("test skipped:");
|
2020-05-15 12:19:40 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-29 05:34:19 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_succeeds_on_all_platforms() {
|
|
|
|
new_ucmd!().succeeds().no_stderr();
|
|
|
|
}
|