mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
id/tests: fix tests if run on macOS
This commit is contained in:
parent
052202ca19
commit
54cbb69d37
4 changed files with 160 additions and 92 deletions
1
.github/workflows/CICD.yml
vendored
1
.github/workflows/CICD.yml
vendored
|
@ -235,6 +235,7 @@ jobs:
|
||||||
# { os, target, cargo-options, features, use-cross, toolchain }
|
# { os, target, cargo-options, features, use-cross, toolchain }
|
||||||
- { os: ubuntu-latest , target: arm-unknown-linux-gnueabihf , features: feat_os_unix_gnueabihf , use-cross: use-cross }
|
- { os: ubuntu-latest , target: arm-unknown-linux-gnueabihf , features: feat_os_unix_gnueabihf , use-cross: use-cross }
|
||||||
- { os: ubuntu-latest , target: aarch64-unknown-linux-gnu , features: feat_os_unix_gnueabihf , use-cross: use-cross }
|
- { os: ubuntu-latest , target: aarch64-unknown-linux-gnu , features: feat_os_unix_gnueabihf , use-cross: use-cross }
|
||||||
|
- { os: ubuntu-latest , target: x86_64-unknown-linux-gnu , features: feat_os_unix , use-cross: use-cross }
|
||||||
- { os: ubuntu-16.04 , target: x86_64-unknown-linux-gnu , features: feat_os_unix , use-cross: use-cross }
|
- { os: ubuntu-16.04 , target: x86_64-unknown-linux-gnu , features: feat_os_unix , use-cross: use-cross }
|
||||||
# - { os: ubuntu-18.04 , target: i586-unknown-linux-gnu , features: feat_os_unix , use-cross: use-cross } ## note: older windows platform; not required, dev-FYI only
|
# - { os: ubuntu-18.04 , target: i586-unknown-linux-gnu , features: feat_os_unix , use-cross: use-cross } ## note: older windows platform; not required, dev-FYI only
|
||||||
# - { os: ubuntu-18.04 , target: i586-unknown-linux-gnu , features: feat_os_unix , use-cross: use-cross } ## note: older windows platform; not required, dev-FYI only
|
# - { os: ubuntu-18.04 , target: i586-unknown-linux-gnu , features: feat_os_unix , use-cross: use-cross } ## note: older windows platform; not required, dev-FYI only
|
||||||
|
|
6
.github/workflows/GNU.yml
vendored
6
.github/workflows/GNU.yml
vendored
|
@ -45,8 +45,14 @@ jobs:
|
||||||
- name: Run GNU tests
|
- name: Run GNU tests
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
|
# bash uutils/util/run-gnu-test.sh
|
||||||
|
bash uutils/util/run-gnu-test.sh tests/id/context.sh # TODO: remove after debugging
|
||||||
|
sudo bash uutils/util/run-gnu-test.sh tests/id/setgid.sh # TODO: remove after debugging
|
||||||
|
bash uutils/util/run-gnu-test.sh tests/id/smack.sh # TODO: remove after debugging
|
||||||
bash uutils/util/run-gnu-test.sh tests/id/uid.sh # TODO: remove after debugging
|
bash uutils/util/run-gnu-test.sh tests/id/uid.sh # TODO: remove after debugging
|
||||||
bash uutils/util/run-gnu-test.sh tests/id/zero.sh # TODO: remove after debugging
|
bash uutils/util/run-gnu-test.sh tests/id/zero.sh # TODO: remove after debugging
|
||||||
|
bash uutils/util/run-gnu-test.sh tests/id/no-context.sh # TODO: remove after debugging
|
||||||
|
bash uutils/util/run-gnu-test.sh tests/id/gnu-zero-uids.sh # todo: remove after debugging
|
||||||
- name: Extract tests info
|
- name: Extract tests info
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
// * Help text based on BSD's `id`.
|
// * Help text based on BSD's `id`.
|
||||||
//
|
//
|
||||||
|
|
||||||
// spell-checker:ignore (ToDO) asid auditid auditinfo auid cstr egid emod euid getaudit getlogin gflag nflag pline rflag termid uflag gsflag zflag
|
// spell-checker:ignore (ToDO) asid auditid auditinfo auid cstr egid emod euid getaudit getlogin gflag nflag pline rflag termid uflag gsflag zflag testsuite
|
||||||
|
|
||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
@ -92,7 +92,7 @@ struct State {
|
||||||
rflag: bool, // --real
|
rflag: bool, // --real
|
||||||
zflag: bool, // --zero
|
zflag: bool, // --zero
|
||||||
ids: Option<Ids>,
|
ids: Option<Ids>,
|
||||||
// The behaviour for calling GNU's `id` and calling GNU's `id $USER` is similar but different.
|
// The behavior for calling GNU's `id` and calling GNU's `id $USER` is similar but different.
|
||||||
// * The SELinux context is only displayed without a specified user.
|
// * The SELinux context is only displayed without a specified user.
|
||||||
// * The `getgroups` system call is only used without a specified user, this causes
|
// * The `getgroups` system call is only used without a specified user, this causes
|
||||||
// the order of the displayed groups to be different between `id` and `id $USER`.
|
// the order of the displayed groups to be different between `id` and `id $USER`.
|
||||||
|
@ -336,12 +336,11 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let groups = entries::get_groups_gnu(Some(gid)).unwrap();
|
||||||
let groups = if state.user_specified {
|
let groups = if state.user_specified {
|
||||||
possible_pw
|
possible_pw.map(|p| p.belongs_to()).unwrap()
|
||||||
.map(|p| p.belongs_to())
|
|
||||||
.unwrap_or_else(|| entries::get_groups_gnu(Some(gid)).unwrap())
|
|
||||||
} else {
|
} else {
|
||||||
entries::get_groups_gnu(Some(gid)).unwrap()
|
groups.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
if state.gsflag {
|
if state.gsflag {
|
||||||
|
@ -517,7 +516,7 @@ fn id_print(state: &State, groups: Vec<u32>) {
|
||||||
.join(",")
|
.join(",")
|
||||||
);
|
);
|
||||||
|
|
||||||
// placeholder ("-Z" is NotImplemented):
|
// NOTE: placeholder ("-Z" is NotImplemented):
|
||||||
// if !state.user_specified {
|
// if !state.user_specified {
|
||||||
// // print SElinux context (does not depend on "-Z")
|
// // print SElinux context (does not depend on "-Z")
|
||||||
// print!(" context={}", get_selinux_contexts().join(":"));
|
// print!(" context={}", get_selinux_contexts().join(":"));
|
||||||
|
|
|
@ -12,11 +12,29 @@ use crate::common::util::*;
|
||||||
// whoami: "runner"
|
// whoami: "runner"
|
||||||
//
|
//
|
||||||
|
|
||||||
|
// spell-checker:ignore (ToDO) testsuite coreutil
|
||||||
|
|
||||||
|
const VERSION_EXPECTED: &str = "8.30"; // 8.32
|
||||||
|
const UUTILS_WARNING: &str = "uutils-tests-warning";
|
||||||
|
const UUTILS_INFO: &str = "uutils-tests-info";
|
||||||
|
|
||||||
|
macro_rules! unwrap_or_return {
|
||||||
|
( $e:expr ) => {
|
||||||
|
match $e {
|
||||||
|
Ok(x) => x,
|
||||||
|
Err(e) => {
|
||||||
|
println!("{}: test skipped: {}", UUTILS_INFO, e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
fn whoami() -> String {
|
fn whoami() -> String {
|
||||||
// Use environment variable to get current user instead of invoking `whoami`
|
// Use environment variable to get current user instead of
|
||||||
// and fall back to user "nobody" on error.
|
// invoking `whoami` and fall back to user "nobody" on error.
|
||||||
std::env::var("USER").unwrap_or_else(|e| {
|
std::env::var("USER").unwrap_or_else(|e| {
|
||||||
println!("warning: {}, using \"nobody\" instead", e);
|
println!("{}: {}, using \"nobody\" instead", UUTILS_WARNING, e);
|
||||||
"nobody".to_string()
|
"nobody".to_string()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -25,20 +43,23 @@ fn whoami() -> String {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn test_id_no_specified_user() {
|
fn test_id_no_specified_user() {
|
||||||
let result = new_ucmd!().run();
|
let result = new_ucmd!().run();
|
||||||
let expected_result = expected_result(&[]);
|
let exp_result = unwrap_or_return!(expected_result(&[]));
|
||||||
let mut exp_stdout = expected_result.stdout_str().to_string();
|
let mut _exp_stdout = exp_result.stdout_str().to_string();
|
||||||
|
|
||||||
// uu_id does not support selinux context. Remove 'context' part from exp_stdout:
|
#[cfg(target_os = "linux")]
|
||||||
let context_offset = expected_result
|
{
|
||||||
.stdout_str()
|
// NOTE: Strip 'context' part from exp_stdout (remove if SElinux gets added):
|
||||||
.find(" context")
|
let context_offset = exp_result
|
||||||
.unwrap_or(exp_stdout.len());
|
.stdout_str()
|
||||||
exp_stdout.replace_range(context_offset.., "\n");
|
.find(" context=")
|
||||||
|
.unwrap_or_else(|| _exp_stdout.len());
|
||||||
|
_exp_stdout.replace_range(context_offset.., "\n");
|
||||||
|
}
|
||||||
|
|
||||||
result
|
result
|
||||||
.stdout_is(exp_stdout)
|
.stdout_is(_exp_stdout)
|
||||||
.stderr_is(expected_result.stderr_str())
|
.stderr_is(exp_result.stderr_str())
|
||||||
.code_is(expected_result.code());
|
.code_is(exp_result.code());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -47,53 +68,53 @@ fn test_id_single_user() {
|
||||||
let test_users = [&whoami()[..]];
|
let test_users = [&whoami()[..]];
|
||||||
|
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
let mut exp_result = expected_result(&test_users);
|
let mut exp_result = unwrap_or_return!(expected_result(&test_users));
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&test_users)
|
.args(&test_users)
|
||||||
.run()
|
.run()
|
||||||
.stdout_is(exp_result.stdout_str())
|
.stdout_is(exp_result.stdout_str())
|
||||||
.stderr_is(exp_result.stderr_str())
|
.stderr_is(exp_result.stderr_str().replace(": Invalid argument", ""))
|
||||||
.code_is(exp_result.code());
|
.code_is(exp_result.code());
|
||||||
|
|
||||||
// u/g/G z/n
|
// u/g/G z/n
|
||||||
for &opt in &["--user", "--group", "--groups"] {
|
for &opt in &["--user", "--group", "--groups"] {
|
||||||
let mut args = vec![opt];
|
let mut args = vec![opt];
|
||||||
args.extend_from_slice(&test_users);
|
args.extend_from_slice(&test_users);
|
||||||
exp_result = expected_result(&args);
|
exp_result = unwrap_or_return!(expected_result(&args));
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&args)
|
.args(&args)
|
||||||
.run()
|
.run()
|
||||||
.stdout_is(exp_result.stdout_str())
|
.stdout_is(exp_result.stdout_str())
|
||||||
.stderr_is(exp_result.stderr_str())
|
.stderr_is(exp_result.stderr_str().replace(": Invalid argument", ""))
|
||||||
.code_is(exp_result.code());
|
.code_is(exp_result.code());
|
||||||
args.push("--zero");
|
args.push("--zero");
|
||||||
exp_result = expected_result(&args);
|
exp_result = unwrap_or_return!(expected_result(&args));
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&args)
|
.args(&args)
|
||||||
.run()
|
.run()
|
||||||
.stdout_is(exp_result.stdout_str())
|
.stdout_is(exp_result.stdout_str())
|
||||||
.stderr_is(exp_result.stderr_str())
|
.stderr_is(exp_result.stderr_str().replace(": Invalid argument", ""))
|
||||||
.code_is(exp_result.code());
|
.code_is(exp_result.code());
|
||||||
args.push("--name");
|
args.push("--name");
|
||||||
exp_result = expected_result(&args);
|
exp_result = unwrap_or_return!(expected_result(&args));
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&args)
|
.args(&args)
|
||||||
.run()
|
.run()
|
||||||
.stdout_is(exp_result.stdout_str())
|
.stdout_is(exp_result.stdout_str())
|
||||||
.stderr_is(exp_result.stderr_str())
|
.stderr_is(exp_result.stderr_str().replace(": Invalid argument", ""))
|
||||||
.code_is(exp_result.code());
|
.code_is(exp_result.code());
|
||||||
args.pop();
|
args.pop();
|
||||||
exp_result = expected_result(&args);
|
exp_result = unwrap_or_return!(expected_result(&args));
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&args)
|
.args(&args)
|
||||||
.run()
|
.run()
|
||||||
.stdout_is(exp_result.stdout_str())
|
.stdout_is(exp_result.stdout_str())
|
||||||
.stderr_is(exp_result.stderr_str())
|
.stderr_is(exp_result.stderr_str().replace(": Invalid argument", ""))
|
||||||
.code_is(exp_result.code());
|
.code_is(exp_result.code());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,11 +124,16 @@ fn test_id_single_user() {
|
||||||
fn test_id_single_user_non_existing() {
|
fn test_id_single_user_non_existing() {
|
||||||
let args = &["hopefully_non_existing_username"];
|
let args = &["hopefully_non_existing_username"];
|
||||||
let result = new_ucmd!().args(args).run();
|
let result = new_ucmd!().args(args).run();
|
||||||
let expected_result = expected_result(args);
|
let exp_result = unwrap_or_return!(expected_result(args));
|
||||||
|
|
||||||
|
// coreutils 8.32: $ LC_ALL=C id foobar
|
||||||
|
// macOS: stderr: "id: 'foobar': no such user: Invalid argument"
|
||||||
|
// linux: stderr: "id: 'foobar': no such user"
|
||||||
|
// It is unkown why the output on macOS is different.
|
||||||
result
|
result
|
||||||
.stdout_is(expected_result.stdout_str())
|
.stdout_is(exp_result.stdout_str())
|
||||||
.stderr_is(expected_result.stderr_str())
|
.stderr_is(exp_result.stderr_str().replace(": Invalid argument", ""))
|
||||||
.code_is(expected_result.code());
|
.code_is(exp_result.code());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -117,11 +143,11 @@ fn test_id_name() {
|
||||||
for &opt in &["--user", "--group", "--groups"] {
|
for &opt in &["--user", "--group", "--groups"] {
|
||||||
let args = [opt, "--name"];
|
let args = [opt, "--name"];
|
||||||
let result = scene.ucmd().args(&args).run();
|
let result = scene.ucmd().args(&args).run();
|
||||||
let expected_result = expected_result(&args);
|
let exp_result = unwrap_or_return!(expected_result(&args));
|
||||||
result
|
result
|
||||||
.stdout_is(expected_result.stdout_str())
|
.stdout_is(exp_result.stdout_str())
|
||||||
.stderr_is(expected_result.stderr_str())
|
.stderr_is(exp_result.stderr_str())
|
||||||
.code_is(expected_result.code());
|
.code_is(exp_result.code());
|
||||||
|
|
||||||
if opt == "--user" {
|
if opt == "--user" {
|
||||||
assert_eq!(result.stdout_str().trim_end(), whoami());
|
assert_eq!(result.stdout_str().trim_end(), whoami());
|
||||||
|
@ -136,11 +162,11 @@ fn test_id_real() {
|
||||||
for &opt in &["--user", "--group", "--groups"] {
|
for &opt in &["--user", "--group", "--groups"] {
|
||||||
let args = [opt, "--real"];
|
let args = [opt, "--real"];
|
||||||
let result = scene.ucmd().args(&args).run();
|
let result = scene.ucmd().args(&args).run();
|
||||||
let expected_result = expected_result(&args);
|
let exp_result = unwrap_or_return!(expected_result(&args));
|
||||||
result
|
result
|
||||||
.stdout_is(expected_result.stdout_str())
|
.stdout_is(exp_result.stdout_str())
|
||||||
.stderr_is(expected_result.stderr_str())
|
.stderr_is(exp_result.stderr_str())
|
||||||
.code_is(expected_result.code());
|
.code_is(exp_result.code());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +185,6 @@ fn test_id_pretty_print() {
|
||||||
// stdout =
|
// stdout =
|
||||||
// stderr = ', tests/common/util.rs:157:13
|
// stderr = ', tests/common/util.rs:157:13
|
||||||
println!("test skipped:");
|
println!("test skipped:");
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
result.success().stdout_contains(username);
|
result.success().stdout_contains(username);
|
||||||
}
|
}
|
||||||
|
@ -181,53 +206,53 @@ fn test_id_multiple_users() {
|
||||||
let test_users = ["root", "man", "postfix", "sshd", &whoami()];
|
let test_users = ["root", "man", "postfix", "sshd", &whoami()];
|
||||||
|
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
let mut exp_result = expected_result(&test_users);
|
let mut exp_result = unwrap_or_return!(expected_result(&test_users));
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&test_users)
|
.args(&test_users)
|
||||||
.run()
|
.run()
|
||||||
.stdout_is(exp_result.stdout_str())
|
.stdout_is(exp_result.stdout_str())
|
||||||
.stderr_is(exp_result.stderr_str())
|
.stderr_is(exp_result.stderr_str().replace(": Invalid argument", ""))
|
||||||
.code_is(exp_result.code());
|
.code_is(exp_result.code());
|
||||||
|
|
||||||
// u/g/G z/n
|
// u/g/G z/n
|
||||||
for &opt in &["--user", "--group", "--groups"] {
|
for &opt in &["--user", "--group", "--groups"] {
|
||||||
let mut args = vec![opt];
|
let mut args = vec![opt];
|
||||||
args.extend_from_slice(&test_users);
|
args.extend_from_slice(&test_users);
|
||||||
exp_result = expected_result(&args);
|
exp_result = unwrap_or_return!(expected_result(&args));
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&args)
|
.args(&args)
|
||||||
.run()
|
.run()
|
||||||
.stdout_is(exp_result.stdout_str())
|
.stdout_is(exp_result.stdout_str())
|
||||||
.stderr_is(exp_result.stderr_str())
|
.stderr_is(exp_result.stderr_str().replace(": Invalid argument", ""))
|
||||||
.code_is(exp_result.code());
|
.code_is(exp_result.code());
|
||||||
args.push("--zero");
|
args.push("--zero");
|
||||||
exp_result = expected_result(&args);
|
exp_result = unwrap_or_return!(expected_result(&args));
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&args)
|
.args(&args)
|
||||||
.run()
|
.run()
|
||||||
.stdout_is(exp_result.stdout_str())
|
.stdout_is(exp_result.stdout_str())
|
||||||
.stderr_is(exp_result.stderr_str())
|
.stderr_is(exp_result.stderr_str().replace(": Invalid argument", ""))
|
||||||
.code_is(exp_result.code());
|
.code_is(exp_result.code());
|
||||||
args.push("--name");
|
args.push("--name");
|
||||||
exp_result = expected_result(&args);
|
exp_result = unwrap_or_return!(expected_result(&args));
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&args)
|
.args(&args)
|
||||||
.run()
|
.run()
|
||||||
.stdout_is(exp_result.stdout_str())
|
.stdout_is(exp_result.stdout_str())
|
||||||
.stderr_is(exp_result.stderr_str())
|
.stderr_is(exp_result.stderr_str().replace(": Invalid argument", ""))
|
||||||
.code_is(exp_result.code());
|
.code_is(exp_result.code());
|
||||||
args.pop();
|
args.pop();
|
||||||
exp_result = expected_result(&args);
|
exp_result = unwrap_or_return!(expected_result(&args));
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&args)
|
.args(&args)
|
||||||
.run()
|
.run()
|
||||||
.stdout_is(exp_result.stdout_str())
|
.stdout_is(exp_result.stdout_str())
|
||||||
.stderr_is(exp_result.stderr_str())
|
.stderr_is(exp_result.stderr_str().replace(": Invalid argument", ""))
|
||||||
.code_is(exp_result.code());
|
.code_is(exp_result.code());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -249,53 +274,53 @@ fn test_id_multiple_users_non_existing() {
|
||||||
];
|
];
|
||||||
|
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
let mut exp_result = expected_result(&test_users);
|
let mut exp_result = unwrap_or_return!(expected_result(&test_users));
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&test_users)
|
.args(&test_users)
|
||||||
.run()
|
.run()
|
||||||
.stdout_is(exp_result.stdout_str())
|
.stdout_is(exp_result.stdout_str())
|
||||||
.stderr_is(exp_result.stderr_str())
|
.stderr_is(exp_result.stderr_str().replace(": Invalid argument", ""))
|
||||||
.code_is(exp_result.code());
|
.code_is(exp_result.code());
|
||||||
|
|
||||||
// u/g/G z/n
|
// u/g/G z/n
|
||||||
for &opt in &["--user", "--group", "--groups"] {
|
for &opt in &["--user", "--group", "--groups"] {
|
||||||
let mut args = vec![opt];
|
let mut args = vec![opt];
|
||||||
args.extend_from_slice(&test_users);
|
args.extend_from_slice(&test_users);
|
||||||
exp_result = expected_result(&args);
|
exp_result = unwrap_or_return!(expected_result(&args));
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&args)
|
.args(&args)
|
||||||
.run()
|
.run()
|
||||||
.stdout_is(exp_result.stdout_str())
|
.stdout_is(exp_result.stdout_str())
|
||||||
.stderr_is(exp_result.stderr_str())
|
.stderr_is(exp_result.stderr_str().replace(": Invalid argument", ""))
|
||||||
.code_is(exp_result.code());
|
.code_is(exp_result.code());
|
||||||
args.push("--zero");
|
args.push("--zero");
|
||||||
exp_result = expected_result(&args);
|
exp_result = unwrap_or_return!(expected_result(&args));
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&args)
|
.args(&args)
|
||||||
.run()
|
.run()
|
||||||
.stdout_is(exp_result.stdout_str())
|
.stdout_is(exp_result.stdout_str())
|
||||||
.stderr_is(exp_result.stderr_str())
|
.stderr_is(exp_result.stderr_str().replace(": Invalid argument", ""))
|
||||||
.code_is(exp_result.code());
|
.code_is(exp_result.code());
|
||||||
args.push("--name");
|
args.push("--name");
|
||||||
exp_result = expected_result(&args);
|
exp_result = unwrap_or_return!(expected_result(&args));
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&args)
|
.args(&args)
|
||||||
.run()
|
.run()
|
||||||
.stdout_is(exp_result.stdout_str())
|
.stdout_is(exp_result.stdout_str())
|
||||||
.stderr_is(exp_result.stderr_str())
|
.stderr_is(exp_result.stderr_str().replace(": Invalid argument", ""))
|
||||||
.code_is(exp_result.code());
|
.code_is(exp_result.code());
|
||||||
args.pop();
|
args.pop();
|
||||||
exp_result = expected_result(&args);
|
exp_result = unwrap_or_return!(expected_result(&args));
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&args)
|
.args(&args)
|
||||||
.run()
|
.run()
|
||||||
.stdout_is(exp_result.stdout_str())
|
.stdout_is(exp_result.stdout_str())
|
||||||
.stderr_is(exp_result.stderr_str())
|
.stderr_is(exp_result.stderr_str().replace(": Invalid argument", ""))
|
||||||
.code_is(exp_result.code());
|
.code_is(exp_result.code());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -311,12 +336,12 @@ fn test_id_default_format() {
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&args)
|
.args(&args)
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_only(expected_result(&args).stderr_str());
|
.stderr_only(unwrap_or_return!(expected_result(&args)).stderr_str());
|
||||||
for &opt2 in &["--user", "--group", "--groups"] {
|
for &opt2 in &["--user", "--group", "--groups"] {
|
||||||
// u/g/G n/r
|
// u/g/G n/r
|
||||||
let args = [opt2, opt1];
|
let args = [opt2, opt1];
|
||||||
let result = scene.ucmd().args(&args).run();
|
let result = scene.ucmd().args(&args).run();
|
||||||
let exp_result = expected_result(&args);
|
let exp_result = unwrap_or_return!(expected_result(&args));
|
||||||
result
|
result
|
||||||
.stdout_is(exp_result.stdout_str())
|
.stdout_is(exp_result.stdout_str())
|
||||||
.stderr_is(exp_result.stderr_str())
|
.stderr_is(exp_result.stderr_str())
|
||||||
|
@ -330,7 +355,7 @@ fn test_id_default_format() {
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&args)
|
.args(&args)
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_only(expected_result(&args).stdout_str());
|
.stdout_only(unwrap_or_return!(expected_result(&args)).stdout_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,7 +369,7 @@ fn test_id_zero() {
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&[z_flag])
|
.args(&[z_flag])
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_only(expected_result(&[z_flag]).stderr_str());
|
.stderr_only(unwrap_or_return!(expected_result(&[z_flag])).stderr_str());
|
||||||
for &opt1 in &["--name", "--real"] {
|
for &opt1 in &["--name", "--real"] {
|
||||||
// id: cannot print only names or real IDs in default format
|
// id: cannot print only names or real IDs in default format
|
||||||
let args = [opt1, z_flag];
|
let args = [opt1, z_flag];
|
||||||
|
@ -352,12 +377,12 @@ fn test_id_zero() {
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&args)
|
.args(&args)
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_only(expected_result(&args).stderr_str());
|
.stderr_only(unwrap_or_return!(expected_result(&args)).stderr_str());
|
||||||
for &opt2 in &["--user", "--group", "--groups"] {
|
for &opt2 in &["--user", "--group", "--groups"] {
|
||||||
// u/g/G n/r z
|
// u/g/G n/r z
|
||||||
let args = [opt2, z_flag, opt1];
|
let args = [opt2, z_flag, opt1];
|
||||||
let result = scene.ucmd().args(&args).run();
|
let result = scene.ucmd().args(&args).run();
|
||||||
let exp_result = expected_result(&args);
|
let exp_result = unwrap_or_return!(expected_result(&args));
|
||||||
result
|
result
|
||||||
.stdout_is(exp_result.stdout_str())
|
.stdout_is(exp_result.stdout_str())
|
||||||
.stderr_is(exp_result.stderr_str())
|
.stderr_is(exp_result.stderr_str())
|
||||||
|
@ -371,46 +396,83 @@ fn test_id_zero() {
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&args)
|
.args(&args)
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_only(expected_result(&args).stdout_str());
|
.stdout_only(unwrap_or_return!(expected_result(&args)).stdout_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::needless_borrow)]
|
#[allow(clippy::needless_borrow)]
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn expected_result(args: &[&str]) -> CmdResult {
|
fn expected_result(args: &[&str]) -> Result<CmdResult, String> {
|
||||||
|
// version for reference coreutil binary
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
let util_name = util_name!();
|
let util_name = util_name!();
|
||||||
#[cfg(all(unix, not(target_os = "linux")))]
|
#[cfg(all(unix, not(target_os = "linux")))]
|
||||||
let util_name = format!("g{}", util_name!());
|
let util_name = format!("g{}", util_name!());
|
||||||
|
|
||||||
let result = TestScenario::new(&util_name)
|
let scene = TestScenario::new(&util_name);
|
||||||
|
let version_check = scene
|
||||||
|
.cmd_keepenv(&util_name)
|
||||||
|
.env("LANGUAGE", "C")
|
||||||
|
.arg("--version")
|
||||||
|
.run();
|
||||||
|
let version_check_string: String = version_check
|
||||||
|
.stdout_str()
|
||||||
|
.split('\n')
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.get(0)
|
||||||
|
.map_or_else(
|
||||||
|
|| format!("{}: unexpected output format for reference coreutils '{} --version'", UUTILS_WARNING, util_name),
|
||||||
|
|s| {
|
||||||
|
if s.contains(&format!("(GNU coreutils) {}", VERSION_EXPECTED)) {
|
||||||
|
s.to_string()
|
||||||
|
} else if s.contains("(GNU coreutils)") {
|
||||||
|
// example: id (GNU coreutils) 8.32.162-4eda
|
||||||
|
let version_found = s.split_whitespace().last().unwrap()[..4].parse::<f32>().unwrap_or_default();
|
||||||
|
let version_expected = VERSION_EXPECTED.parse::<f32>().unwrap_or_default();
|
||||||
|
if version_found > version_expected {
|
||||||
|
format!("{}: version for the reference coreutil '{}' is higher than expected; expected: {}, found: {}", UUTILS_INFO, util_name, VERSION_EXPECTED, version_found)
|
||||||
|
} else {
|
||||||
|
format!("{}: version for the reference coreutil '{}' does not match; expected: {}, found: {}", UUTILS_WARNING, util_name, VERSION_EXPECTED, version_found) }
|
||||||
|
} else {
|
||||||
|
format!("{}: no coreutils version string found for reference coreutils '{} --version'", UUTILS_WARNING, util_name)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if version_check_string.starts_with(UUTILS_WARNING) {
|
||||||
|
return Err(version_check_string);
|
||||||
|
}
|
||||||
|
println!("{}", version_check_string);
|
||||||
|
|
||||||
|
let result = scene
|
||||||
.cmd_keepenv(&util_name)
|
.cmd_keepenv(&util_name)
|
||||||
.env("LANGUAGE", "C")
|
.env("LANGUAGE", "C")
|
||||||
.args(args)
|
.args(args)
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
let mut _o = 0;
|
// #[cfg(all(unix, not(target_os = "linux")))]
|
||||||
let mut _e = 0;
|
// if cfg!(target_os = "macos") {
|
||||||
#[cfg(all(unix, not(target_os = "linux")))]
|
let (stdout, stderr): (String, String) = if cfg!(target_os = "linux") {
|
||||||
{
|
(
|
||||||
_o = if result.stdout_str().starts_with(&util_name) {
|
result.stdout_str().to_string(),
|
||||||
1
|
result.stderr_str().to_string(),
|
||||||
} else {
|
)
|
||||||
0
|
} else {
|
||||||
};
|
// strip 'g' prefix from results:
|
||||||
_e = if result.stderr_str().starts_with(&util_name) {
|
let from = util_name.to_string() + ":";
|
||||||
1
|
let to = &from[1..];
|
||||||
} else {
|
(
|
||||||
0
|
result.stdout_str().replace(&from, to),
|
||||||
};
|
result.stderr_str().replace(&from, to),
|
||||||
}
|
)
|
||||||
|
};
|
||||||
|
|
||||||
CmdResult::new(
|
Ok(CmdResult::new(
|
||||||
Some(result.tmpd()),
|
Some(result.tmpd()),
|
||||||
Some(result.code()),
|
Some(result.code()),
|
||||||
result.succeeded(),
|
result.succeeded(),
|
||||||
&result.stdout()[_o..],
|
stdout.as_bytes(),
|
||||||
&result.stderr()[_e..],
|
stderr.as_bytes(),
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue