mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
test_who: refactor use expected_result from common/util.rs
This commit is contained in:
parent
805e024794
commit
735ec4014e
7 changed files with 98 additions and 87 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
// * 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.
|
||||||
|
|
||||||
use crate::common::util::*;
|
use crate::common::util::*;
|
||||||
|
|
||||||
const VERSION_MIN_MULTIPLE_USERS: &str = "8.31"; // this feature was introduced in GNU's coreutils 8.31
|
const VERSION_MIN_MULTIPLE_USERS: &str = "8.31"; // this feature was introduced in GNU's coreutils 8.31
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
use crate::common::util::*;
|
// * 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.
|
||||||
|
|
||||||
// spell-checker:ignore (ToDO) coreutil
|
// spell-checker:ignore (ToDO) coreutil
|
||||||
|
|
||||||
|
use crate::common::util::*;
|
||||||
|
|
||||||
const VERSION_MIN_MULTIPLE_USERS: &str = "8.31"; // this feature was introduced in GNU's coreutils 8.31
|
const VERSION_MIN_MULTIPLE_USERS: &str = "8.31"; // this feature was introduced in GNU's coreutils 8.31
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
// * 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.
|
||||||
|
|
||||||
extern crate uucore;
|
extern crate uucore;
|
||||||
|
|
||||||
use crate::common::util::*;
|
use crate::common::util::*;
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
// * 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.
|
||||||
|
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
|
|
||||||
use crate::common::util::*;
|
use crate::common::util::*;
|
||||||
|
|
|
@ -1,30 +1,33 @@
|
||||||
use crate::common::util::*;
|
// * 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.
|
||||||
|
|
||||||
// spell-checker:ignore (flags) runlevel mesg
|
// spell-checker:ignore (flags) runlevel mesg
|
||||||
|
|
||||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
use crate::common::util::*;
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_count() {
|
fn test_count() {
|
||||||
for opt in &["-q", "--count"] {
|
for opt in &["-q", "--count"] {
|
||||||
new_ucmd!()
|
let expected_stdout =
|
||||||
.arg(opt)
|
unwrap_or_return!(expected_result(util_name!(), &[opt])).stdout_move_str();
|
||||||
.succeeds()
|
new_ucmd!().arg(opt).succeeds().stdout_is(expected_stdout);
|
||||||
.stdout_is(expected_result(&[opt]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_boot() {
|
fn test_boot() {
|
||||||
for opt in &["-b", "--boot"] {
|
for opt in &["-b", "--boot"] {
|
||||||
new_ucmd!()
|
let expected_stdout =
|
||||||
.arg(opt)
|
unwrap_or_return!(expected_result(util_name!(), &[opt])).stdout_move_str();
|
||||||
.succeeds()
|
new_ucmd!().arg(opt).succeeds().stdout_is(expected_stdout);
|
||||||
.stdout_is(expected_result(&[opt]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_heading() {
|
fn test_heading() {
|
||||||
for opt in &["-H", "--heading"] {
|
for opt in &["-H", "--heading"] {
|
||||||
|
@ -32,7 +35,7 @@ fn test_heading() {
|
||||||
// * minor whitespace differences occur between platform built-in outputs;
|
// * minor whitespace differences occur between platform built-in outputs;
|
||||||
// specifically number of TABs between "TIME" and "COMMENT" may be variant
|
// specifically number of TABs between "TIME" and "COMMENT" may be variant
|
||||||
let actual = new_ucmd!().arg(opt).succeeds().stdout_move_str();
|
let actual = new_ucmd!().arg(opt).succeeds().stdout_move_str();
|
||||||
let expect = expected_result(&[opt]);
|
let expect = unwrap_or_return!(expected_result(util_name!(), &[opt])).stdout_move_str();
|
||||||
println!("actual: {:?}", actual);
|
println!("actual: {:?}", actual);
|
||||||
println!("expect: {:?}", expect);
|
println!("expect: {:?}", expect);
|
||||||
let v_actual: Vec<&str> = actual.split_whitespace().collect();
|
let v_actual: Vec<&str> = actual.split_whitespace().collect();
|
||||||
|
@ -41,76 +44,70 @@ fn test_heading() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_short() {
|
fn test_short() {
|
||||||
for opt in &["-s", "--short"] {
|
for opt in &["-s", "--short"] {
|
||||||
new_ucmd!()
|
let expected_stdout =
|
||||||
.arg(opt)
|
unwrap_or_return!(expected_result(util_name!(), &[opt])).stdout_move_str();
|
||||||
.succeeds()
|
new_ucmd!().arg(opt).succeeds().stdout_is(expected_stdout);
|
||||||
.stdout_is(expected_result(&[opt]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_login() {
|
fn test_login() {
|
||||||
for opt in &["-l", "--login"] {
|
for opt in &["-l", "--login"] {
|
||||||
new_ucmd!()
|
let expected_stdout =
|
||||||
.arg(opt)
|
unwrap_or_return!(expected_result(util_name!(), &[opt])).stdout_move_str();
|
||||||
.succeeds()
|
new_ucmd!().arg(opt).succeeds().stdout_is(expected_stdout);
|
||||||
.stdout_is(expected_result(&[opt]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_m() {
|
fn test_m() {
|
||||||
for opt in &["-m"] {
|
for opt in &["-m"] {
|
||||||
new_ucmd!()
|
let expected_stdout =
|
||||||
.arg(opt)
|
unwrap_or_return!(expected_result(util_name!(), &[opt])).stdout_move_str();
|
||||||
.succeeds()
|
new_ucmd!().arg(opt).succeeds().stdout_is(expected_stdout);
|
||||||
.stdout_is(expected_result(&[opt]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_process() {
|
fn test_process() {
|
||||||
for opt in &["-p", "--process"] {
|
for opt in &["-p", "--process"] {
|
||||||
new_ucmd!()
|
let expected_stdout =
|
||||||
.arg(opt)
|
unwrap_or_return!(expected_result(util_name!(), &[opt])).stdout_move_str();
|
||||||
.succeeds()
|
new_ucmd!().arg(opt).succeeds().stdout_is(expected_stdout);
|
||||||
.stdout_is(expected_result(&[opt]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_runlevel() {
|
fn test_runlevel() {
|
||||||
for opt in &["-r", "--runlevel"] {
|
for opt in &["-r", "--runlevel"] {
|
||||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
let expected_stdout =
|
||||||
new_ucmd!()
|
unwrap_or_return!(expected_result(util_name!(), &[opt])).stdout_move_str();
|
||||||
.arg(opt)
|
new_ucmd!().arg(opt).succeeds().stdout_is(expected_stdout);
|
||||||
.succeeds()
|
|
||||||
.stdout_is(expected_result(&[opt]));
|
|
||||||
|
|
||||||
#[cfg(not(target_os = "linux"))]
|
#[cfg(not(target_os = "linux"))]
|
||||||
new_ucmd!().arg(opt).succeeds().stdout_is("");
|
new_ucmd!().arg(opt).succeeds().stdout_is("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_time() {
|
fn test_time() {
|
||||||
for opt in &["-t", "--time"] {
|
for opt in &["-t", "--time"] {
|
||||||
new_ucmd!()
|
let expected_stdout =
|
||||||
.arg(opt)
|
unwrap_or_return!(expected_result(util_name!(), &[opt])).stdout_move_str();
|
||||||
.succeeds()
|
new_ucmd!().arg(opt).succeeds().stdout_is(expected_stdout);
|
||||||
.stdout_is(expected_result(&[opt]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_mesg() {
|
fn test_mesg() {
|
||||||
// -T, -w, --mesg
|
// -T, -w, --mesg
|
||||||
|
@ -120,21 +117,22 @@ fn test_mesg() {
|
||||||
// --writable
|
// --writable
|
||||||
// same as -T
|
// same as -T
|
||||||
for opt in &["-T", "-w", "--mesg", "--message", "--writable"] {
|
for opt in &["-T", "-w", "--mesg", "--message", "--writable"] {
|
||||||
new_ucmd!()
|
let expected_stdout =
|
||||||
.arg(opt)
|
unwrap_or_return!(expected_result(util_name!(), &[opt])).stdout_move_str();
|
||||||
.succeeds()
|
new_ucmd!().arg(opt).succeeds().stdout_is(expected_stdout);
|
||||||
.stdout_is(expected_result(&[opt]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_arg1_arg2() {
|
fn test_arg1_arg2() {
|
||||||
let args = ["am", "i"];
|
let args = ["am", "i"];
|
||||||
|
let expected_stdout = unwrap_or_return!(expected_result(util_name!(), &args)).stdout_move_str();
|
||||||
|
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&args)
|
.args(&args)
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_is(expected_result(&args));
|
.stdout_is(expected_stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -146,12 +144,12 @@ fn test_too_many_args() {
|
||||||
new_ucmd!().args(&args).fails().stderr_contains(EXPECTED);
|
new_ucmd!().args(&args).fails().stderr_contains(EXPECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_users() {
|
fn test_users() {
|
||||||
for opt in &["-u", "--users"] {
|
for opt in &["-u", "--users"] {
|
||||||
let actual = new_ucmd!().arg(opt).succeeds().stdout_move_str();
|
let actual = new_ucmd!().arg(opt).succeeds().stdout_move_str();
|
||||||
let expect = expected_result(&[opt]);
|
let expect = unwrap_or_return!(expected_result(util_name!(), &[opt])).stdout_move_str();
|
||||||
println!("actual: {:?}", actual);
|
println!("actual: {:?}", actual);
|
||||||
println!("expect: {:?}", expect);
|
println!("expect: {:?}", expect);
|
||||||
|
|
||||||
|
@ -170,28 +168,26 @@ fn test_users() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_lookup() {
|
fn test_lookup() {
|
||||||
let opt = "--lookup";
|
let opt = "--lookup";
|
||||||
new_ucmd!()
|
let expected_stdout =
|
||||||
.arg(opt)
|
unwrap_or_return!(expected_result(util_name!(), &[opt])).stdout_move_str();
|
||||||
.succeeds()
|
new_ucmd!().arg(opt).succeeds().stdout_is(expected_stdout);
|
||||||
.stdout_is(expected_result(&[opt]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_dead() {
|
fn test_dead() {
|
||||||
for opt in &["-d", "--dead"] {
|
for opt in &["-d", "--dead"] {
|
||||||
new_ucmd!()
|
let expected_stdout =
|
||||||
.arg(opt)
|
unwrap_or_return!(expected_result(util_name!(), &[opt])).stdout_move_str();
|
||||||
.succeeds()
|
new_ucmd!().arg(opt).succeeds().stdout_is(expected_stdout);
|
||||||
.stdout_is(expected_result(&[opt]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_all_separately() {
|
fn test_all_separately() {
|
||||||
if cfg!(target_os = "macos") {
|
if cfg!(target_os = "macos") {
|
||||||
|
@ -201,20 +197,23 @@ fn test_all_separately() {
|
||||||
|
|
||||||
// -a, --all same as -b -d --login -p -r -t -T -u
|
// -a, --all same as -b -d --login -p -r -t -T -u
|
||||||
let args = ["-b", "-d", "--login", "-p", "-r", "-t", "-T", "-u"];
|
let args = ["-b", "-d", "--login", "-p", "-r", "-t", "-T", "-u"];
|
||||||
|
let expected_stdout = unwrap_or_return!(expected_result(util_name!(), &args)).stdout_move_str();
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&args)
|
.args(&args)
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_is(expected_result(&args));
|
.stdout_is(expected_stdout);
|
||||||
|
let expected_stdout =
|
||||||
|
unwrap_or_return!(expected_result(util_name!(), &["--all"])).stdout_move_str();
|
||||||
scene
|
scene
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.arg("--all")
|
.arg("--all")
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_is(expected_result(&args));
|
.stdout_is(expected_stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_all() {
|
fn test_all() {
|
||||||
if cfg!(target_os = "macos") {
|
if cfg!(target_os = "macos") {
|
||||||
|
@ -223,26 +222,8 @@ fn test_all() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for opt in &["-a", "--all"] {
|
for opt in &["-a", "--all"] {
|
||||||
new_ucmd!()
|
let expected_stdout =
|
||||||
.arg(opt)
|
unwrap_or_return!(expected_result(util_name!(), &[opt])).stdout_move_str();
|
||||||
.succeeds()
|
new_ucmd!().arg(opt).succeeds().stdout_is(expected_stdout);
|
||||||
.stdout_is(expected_result(&[opt]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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!());
|
|
||||||
|
|
||||||
// note: clippy::needless_borrow *false positive*
|
|
||||||
#[allow(clippy::needless_borrow)]
|
|
||||||
TestScenario::new(&util_name)
|
|
||||||
.cmd_keepenv(util_name)
|
|
||||||
.env("LC_ALL", "C")
|
|
||||||
.args(args)
|
|
||||||
.succeeds()
|
|
||||||
.stdout_move_str()
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
// * 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.
|
||||||
|
|
||||||
/// Platform-independent helper for constructing a PathBuf from individual elements
|
/// Platform-independent helper for constructing a PathBuf from individual elements
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! path_concat {
|
macro_rules! path_concat {
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
// * 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.
|
||||||
|
|
||||||
//spell-checker: ignore (linux) rlimit prlimit Rlim coreutil
|
//spell-checker: ignore (linux) rlimit prlimit Rlim coreutil
|
||||||
|
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue