2023-08-24 12:07:48 +02: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-07-07 16:19:58 +02:00
|
|
|
|
2021-07-08 01:32:39 +02:00
|
|
|
//spell-checker: ignore coreutil
|
|
|
|
|
|
2025-03-28 09:51:51 +01:00
|
|
|
use uutests::new_ucmd;
|
|
|
|
|
use uutests::unwrap_or_return;
|
|
|
|
|
use uutests::util::{TestScenario, check_coreutil_version, expected_result, whoami};
|
|
|
|
|
use uutests::util_name;
|
2020-06-02 22:14:35 +02:00
|
|
|
|
2021-06-21 20:55:57 +02:00
|
|
|
const VERSION_MIN_MULTIPLE_USERS: &str = "8.31"; // this feature was introduced in GNU's coreutils 8.31
|
|
|
|
|
|
2022-09-10 18:38:14 +02:00
|
|
|
#[test]
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
fn test_invalid_arg() {
|
2025-03-01 15:29:11 +01:00
|
|
|
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);
|
2022-09-10 18:38:14 +02:00
|
|
|
}
|
|
|
|
|
|
2020-06-02 22:14:35 +02:00
|
|
|
#[test]
|
2021-06-08 22:53:48 +02:00
|
|
|
#[cfg(unix)]
|
2020-06-02 22:14:35 +02:00
|
|
|
fn test_groups() {
|
2021-07-07 22:46:16 +02:00
|
|
|
let ts = TestScenario::new(util_name!());
|
2025-03-09 16:53:56 +01:00
|
|
|
let result = ts.ucmd().succeeds();
|
2021-07-07 22:46:16 +02:00
|
|
|
let exp_result = unwrap_or_return!(expected_result(&ts, &[]));
|
2021-06-21 20:55:57 +02:00
|
|
|
|
|
|
|
|
result
|
|
|
|
|
.stdout_is(exp_result.stdout_str())
|
|
|
|
|
.stderr_is(exp_result.stderr_str())
|
|
|
|
|
.code_is(exp_result.code());
|
2020-06-02 22:14:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2021-06-08 22:53:48 +02:00
|
|
|
#[cfg(unix)]
|
2021-06-07 19:52:49 +02:00
|
|
|
fn test_groups_username() {
|
2021-06-21 20:55:57 +02:00
|
|
|
let test_users = [&whoami()[..]];
|
2021-06-07 19:52:49 +02:00
|
|
|
|
2021-07-07 22:46:16 +02:00
|
|
|
let ts = TestScenario::new(util_name!());
|
2025-03-09 16:53:56 +01:00
|
|
|
let result = ts.ucmd().args(&test_users).succeeds();
|
2021-07-07 22:46:16 +02:00
|
|
|
let exp_result = unwrap_or_return!(expected_result(&ts, &test_users));
|
2021-06-21 20:55:57 +02:00
|
|
|
|
|
|
|
|
result
|
|
|
|
|
.stdout_is(exp_result.stdout_str())
|
|
|
|
|
.stderr_is(exp_result.stderr_str())
|
|
|
|
|
.code_is(exp_result.code());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
fn test_groups_username_multiple() {
|
2021-07-07 15:52:56 +02:00
|
|
|
unwrap_or_return!(check_coreutil_version(
|
|
|
|
|
util_name!(),
|
|
|
|
|
VERSION_MIN_MULTIPLE_USERS
|
|
|
|
|
));
|
2021-06-21 20:55:57 +02:00
|
|
|
let test_users = ["root", "man", "postfix", "sshd", &whoami()];
|
|
|
|
|
|
2021-07-07 22:46:16 +02:00
|
|
|
let ts = TestScenario::new(util_name!());
|
2025-03-09 16:53:56 +01:00
|
|
|
let result = ts.ucmd().args(&test_users).fails();
|
2021-07-07 22:46:16 +02:00
|
|
|
let exp_result = unwrap_or_return!(expected_result(&ts, &test_users));
|
2021-06-21 20:55:57 +02:00
|
|
|
|
|
|
|
|
result
|
|
|
|
|
.stdout_is(exp_result.stdout_str())
|
|
|
|
|
.stderr_is(exp_result.stderr_str())
|
|
|
|
|
.code_is(exp_result.code());
|
|
|
|
|
}
|