mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
who/stat/pinky: adjust tests to be compatible with running on macOS
A lot of tests depend on GNU's coreutils to be installed in order to obtain reference values during testing. In these cases testing is limited to `target_os = linux`. This PR installs GNU's coreutils on "github actions" and adjusts the tests for `who`, `stat` and `pinky` in order to be compatible with macOS. * `brew install coreutils` (prefix is 'g', e.g. `gwho`, `gstat`, etc. * switch paths for testing to something that's available on both OSs, e.g. `/boot` -> `/bin`, etc. * switch paths for testing to the macOS equivalent, e.g. `/dev/pts/ptmx` -> `/dev/ptmx`, etc. * exclude paths when no equivalent is available, e.g. `/proc`, `/etc/fstab`, etc. * refactor tests to make better use of the testing API * fix a warning in utmpx.rs to print to stderr instead of stdout * fix long_usage text in `who` * fix minor output formatting in `stat` * the `expected_result` function should be refactored to reduce duplicate code * more tests should be adjusted to not only run on `target_os = linux`
This commit is contained in:
parent
dc93f29fe3
commit
007e0a4e7f
6 changed files with 207 additions and 196 deletions
|
@ -1,28 +1,28 @@
|
|||
use crate::common::util::*;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||
#[test]
|
||||
fn test_count() {
|
||||
for opt in vec!["-q", "--count"] {
|
||||
new_ucmd!()
|
||||
.arg(opt)
|
||||
.succeeds()
|
||||
.stdout_is(expected_result(opt));
|
||||
.stdout_is(expected_result(&[opt]));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||
#[test]
|
||||
fn test_boot() {
|
||||
for opt in vec!["-b", "--boot"] {
|
||||
new_ucmd!()
|
||||
.arg(opt)
|
||||
.succeeds()
|
||||
.stdout_is(expected_result(opt));
|
||||
.stdout_is(expected_result(&[opt]));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||
#[test]
|
||||
fn test_heading() {
|
||||
for opt in vec!["-H", "--heading"] {
|
||||
|
@ -30,7 +30,7 @@ fn test_heading() {
|
|||
// * minor whitespace differences occur between platform built-in outputs;
|
||||
// specifically number of TABs between "TIME" and "COMMENT" may be variant
|
||||
let actual = new_ucmd!().arg(opt).succeeds().stdout_move_str();
|
||||
let expect = expected_result(opt);
|
||||
let expect = expected_result(&[opt]);
|
||||
println!("actual: {:?}", actual);
|
||||
println!("expect: {:?}", expect);
|
||||
let v_actual: Vec<&str> = actual.split_whitespace().collect();
|
||||
|
@ -39,205 +39,205 @@ fn test_heading() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||
#[test]
|
||||
fn test_short() {
|
||||
for opt in vec!["-s", "--short"] {
|
||||
new_ucmd!()
|
||||
.arg(opt)
|
||||
.succeeds()
|
||||
.stdout_is(expected_result(opt));
|
||||
.stdout_is(expected_result(&[opt]));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||
#[test]
|
||||
fn test_login() {
|
||||
for opt in vec!["-l", "--login"] {
|
||||
new_ucmd!()
|
||||
.arg(opt)
|
||||
.succeeds()
|
||||
.stdout_is(expected_result(opt));
|
||||
.stdout_is(expected_result(&[opt]));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||
#[test]
|
||||
fn test_m() {
|
||||
for opt in vec!["-m"] {
|
||||
new_ucmd!()
|
||||
.arg(opt)
|
||||
.succeeds()
|
||||
.stdout_is(expected_result(opt));
|
||||
.stdout_is(expected_result(&[opt]));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||
#[test]
|
||||
fn test_process() {
|
||||
for opt in vec!["-p", "--process"] {
|
||||
new_ucmd!()
|
||||
.arg(opt)
|
||||
.succeeds()
|
||||
.stdout_is(expected_result(opt));
|
||||
.stdout_is(expected_result(&[opt]));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||
#[test]
|
||||
fn test_runlevel() {
|
||||
for opt in vec!["-r", "--runlevel"] {
|
||||
new_ucmd!()
|
||||
.arg(opt)
|
||||
.succeeds()
|
||||
.stdout_is(expected_result(opt));
|
||||
.stdout_is(expected_result(&[opt]));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||
#[test]
|
||||
fn test_time() {
|
||||
for opt in vec!["-t", "--time"] {
|
||||
new_ucmd!()
|
||||
.arg(opt)
|
||||
.succeeds()
|
||||
.stdout_is(expected_result(opt));
|
||||
.stdout_is(expected_result(&[opt]));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||
#[test]
|
||||
fn test_mesg() {
|
||||
for opt in vec!["-w", "-T", "--users", "--message", "--writable"] {
|
||||
// -T, -w, --mesg
|
||||
// add user's message status as +, - or ?
|
||||
// --message
|
||||
// same as -T
|
||||
// --writable
|
||||
// same as -T
|
||||
for opt in vec!["-T", "-w", "--mesg", "--message", "--writable"] {
|
||||
new_ucmd!()
|
||||
.arg(opt)
|
||||
.succeeds()
|
||||
.stdout_is(expected_result(opt));
|
||||
.stdout_is(expected_result(&[opt]));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[test]
|
||||
fn test_arg1_arg2() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let args = ["am", "i"];
|
||||
|
||||
let expected = scene
|
||||
.cmd_keepenv(util_name!())
|
||||
.env("LANGUAGE", "C")
|
||||
.arg("am")
|
||||
.arg("i")
|
||||
.succeeds();
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("am")
|
||||
.arg("i")
|
||||
new_ucmd!()
|
||||
.args(&args)
|
||||
.succeeds()
|
||||
.stdout_is(expected.stdout_str());
|
||||
.stdout_is(expected_result(&args));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_too_many_args() {
|
||||
let expected =
|
||||
const EXPECTED: &str =
|
||||
"error: The value 'u' was provided to '<FILE>...', but it wasn't expecting any more values";
|
||||
|
||||
new_ucmd!()
|
||||
.arg("am")
|
||||
.arg("i")
|
||||
.arg("u")
|
||||
.fails()
|
||||
.stderr_contains(expected);
|
||||
let args = ["am", "i", "u"];
|
||||
new_ucmd!().args(&args).fails().stderr_contains(EXPECTED);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||
#[test]
|
||||
fn test_users() {
|
||||
for opt in vec!["-u", "--users"] {
|
||||
new_ucmd!()
|
||||
.arg(opt)
|
||||
.succeeds()
|
||||
.stdout_is(expected_result(opt));
|
||||
let actual = new_ucmd!().arg(opt).succeeds().stdout_move_str();
|
||||
let expect = expected_result(&[opt]);
|
||||
println!("actual: {:?}", actual);
|
||||
println!("expect: {:?}", expect);
|
||||
|
||||
let mut v_actual: Vec<&str> = actual.split_whitespace().collect();
|
||||
let mut v_expect: Vec<&str> = expect.split_whitespace().collect();
|
||||
|
||||
// TODO: `--users` differs from GNU's output on manOS running in CI
|
||||
// Diff < left / right > :
|
||||
// <"runner console 2021-05-20 22:03 00:08 196\n"
|
||||
// >"runner console 2021-05-20 22:03 old 196\n"
|
||||
if is_ci() && cfg!(target_os = "macos") {
|
||||
v_actual.remove(4);
|
||||
v_expect.remove(4);
|
||||
}
|
||||
|
||||
assert_eq!(v_actual, v_expect);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||
#[test]
|
||||
fn test_lookup() {
|
||||
for opt in vec!["--lookup"] {
|
||||
new_ucmd!()
|
||||
.arg(opt)
|
||||
.succeeds()
|
||||
.stdout_is(expected_result(opt));
|
||||
.stdout_is(expected_result(&[opt]));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||
#[test]
|
||||
fn test_dead() {
|
||||
for opt in vec!["-d", "--dead"] {
|
||||
new_ucmd!()
|
||||
.arg(opt)
|
||||
.succeeds()
|
||||
.stdout_is(expected_result(opt));
|
||||
.stdout_is(expected_result(&[opt]));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||
#[test]
|
||||
fn test_all_separately() {
|
||||
if is_ci() && cfg!(target_os = "macos") {
|
||||
// TODO: fix `-u`, see: test_users
|
||||
return;
|
||||
}
|
||||
|
||||
// -a, --all same as -b -d --login -p -r -t -T -u
|
||||
let args = ["-b", "-d", "--login", "-p", "-r", "-t", "-T", "-u"];
|
||||
let scene = TestScenario::new(util_name!());
|
||||
|
||||
let expected = scene
|
||||
.cmd_keepenv(util_name!())
|
||||
.env("LANGUAGE", "C")
|
||||
.arg("-b")
|
||||
.arg("-d")
|
||||
.arg("--login")
|
||||
.arg("-p")
|
||||
.arg("-r")
|
||||
.arg("-t")
|
||||
.arg("-T")
|
||||
.arg("-u")
|
||||
.succeeds();
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-b")
|
||||
.arg("-d")
|
||||
.arg("--login")
|
||||
.arg("-p")
|
||||
.arg("-r")
|
||||
.arg("-t")
|
||||
.arg("-T")
|
||||
.arg("-u")
|
||||
.args(&args)
|
||||
.succeeds()
|
||||
.stdout_is(expected.stdout_str());
|
||||
|
||||
.stdout_is(expected_result(&args));
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("--all")
|
||||
.succeeds()
|
||||
.stdout_is(expected.stdout_str());
|
||||
.stdout_is(expected_result(&args));
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||
#[test]
|
||||
fn test_all() {
|
||||
if is_ci() && cfg!(target_os = "macos") {
|
||||
// TODO: fix `-u`, see: test_users
|
||||
return;
|
||||
}
|
||||
|
||||
for opt in vec!["-a", "--all"] {
|
||||
new_ucmd!()
|
||||
.arg(opt)
|
||||
.succeeds()
|
||||
.stdout_is(expected_result(opt));
|
||||
.stdout_is(expected_result(&[opt]));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn expected_result(arg: &str) -> String {
|
||||
TestScenario::new(util_name!())
|
||||
.cmd_keepenv(util_name!())
|
||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
||||
fn expected_result(args: &[&str]) -> String {
|
||||
#[cfg(target_os = "linux")]
|
||||
let util_name = util_name!();
|
||||
#[cfg(target_vendor = "apple")]
|
||||
let util_name = format!("g{}", util_name!());
|
||||
|
||||
TestScenario::new(&util_name)
|
||||
.cmd_keepenv(util_name)
|
||||
.env("LANGUAGE", "C")
|
||||
.args(&[arg])
|
||||
.args(args)
|
||||
.succeeds()
|
||||
.stdout_move_str()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue