2020-05-25 17:05:26 +00:00
|
|
|
use crate::common::util::*;
|
2016-08-11 07:37:39 +00:00
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[test]
|
|
|
|
fn test_count() {
|
2016-08-13 21:59:21 +00:00
|
|
|
for opt in vec!["-q", "--count"] {
|
2021-04-28 20:58:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg(opt)
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(expected_result(opt));
|
2016-08-11 07:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[test]
|
|
|
|
fn test_boot() {
|
2016-08-13 21:59:21 +00:00
|
|
|
for opt in vec!["-b", "--boot"] {
|
2021-04-28 20:58:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg(opt)
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(expected_result(opt));
|
2016-08-11 07:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[test]
|
|
|
|
fn test_heading() {
|
2021-04-28 20:58:28 +00:00
|
|
|
for opt in vec!["-H", "--heading"] {
|
2020-01-01 23:07:25 +00:00
|
|
|
// allow whitespace variation
|
2021-04-28 20:58:28 +00:00
|
|
|
// * 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();
|
2020-01-01 23:07:25 +00:00
|
|
|
let expect = expected_result(opt);
|
|
|
|
println!("actual: {:?}", actual);
|
|
|
|
println!("expect: {:?}", expect);
|
|
|
|
let v_actual: Vec<&str> = actual.split_whitespace().collect();
|
|
|
|
let v_expect: Vec<&str> = expect.split_whitespace().collect();
|
|
|
|
assert_eq!(v_actual, v_expect);
|
2016-08-11 07:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[test]
|
|
|
|
fn test_short() {
|
2016-08-13 21:59:21 +00:00
|
|
|
for opt in vec!["-s", "--short"] {
|
2021-04-28 20:58:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg(opt)
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(expected_result(opt));
|
2016-08-11 07:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[test]
|
|
|
|
fn test_login() {
|
2016-08-13 21:59:21 +00:00
|
|
|
for opt in vec!["-l", "--login"] {
|
2021-04-28 20:58:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg(opt)
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(expected_result(opt));
|
2016-08-11 07:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[test]
|
|
|
|
fn test_m() {
|
2016-08-13 21:59:21 +00:00
|
|
|
for opt in vec!["-m"] {
|
2021-04-28 20:58:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg(opt)
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(expected_result(opt));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[test]
|
|
|
|
fn test_process() {
|
|
|
|
for opt in vec!["-p", "--process"] {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg(opt)
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(expected_result(opt));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[test]
|
|
|
|
fn test_runlevel() {
|
|
|
|
for opt in vec!["-r", "--runlevel"] {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg(opt)
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(expected_result(opt));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[test]
|
|
|
|
fn test_time() {
|
|
|
|
for opt in vec!["-t", "--time"] {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg(opt)
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(expected_result(opt));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[test]
|
|
|
|
fn test_mesg() {
|
|
|
|
for opt in vec!["-w", "-T", "--users", "--message", "--writable"] {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg(opt)
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(expected_result(opt));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[test]
|
|
|
|
fn test_arg1_arg2() {
|
|
|
|
let scene = TestScenario::new(util_name!());
|
|
|
|
|
|
|
|
let expected = scene
|
|
|
|
.cmd_keepenv(util_name!())
|
|
|
|
.env("LANGUAGE", "C")
|
|
|
|
.arg("am")
|
|
|
|
.arg("i")
|
|
|
|
.succeeds();
|
|
|
|
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.arg("am")
|
|
|
|
.arg("i")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(expected.stdout_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_too_many_args() {
|
|
|
|
let expected =
|
|
|
|
"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);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[test]
|
|
|
|
fn test_users() {
|
|
|
|
for opt in vec!["-u", "--users"] {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg(opt)
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(expected_result(opt));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[test]
|
|
|
|
fn test_lookup() {
|
|
|
|
for opt in vec!["--lookup"] {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg(opt)
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(expected_result(opt));
|
2016-08-11 07:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[test]
|
|
|
|
fn test_dead() {
|
2016-08-13 21:59:21 +00:00
|
|
|
for opt in vec!["-d", "--dead"] {
|
2021-04-28 20:58:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg(opt)
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(expected_result(opt));
|
2016-08-11 07:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-28 20:58:28 +00:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[test]
|
|
|
|
fn test_all_separately() {
|
|
|
|
// -a, --all same as -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")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(expected.stdout_str());
|
|
|
|
|
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.arg("--all")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(expected.stdout_str());
|
|
|
|
}
|
|
|
|
|
2016-08-11 07:37:39 +00:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[test]
|
|
|
|
fn test_all() {
|
2016-08-13 21:59:21 +00:00
|
|
|
for opt in vec!["-a", "--all"] {
|
2021-04-28 20:58:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.arg(opt)
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(expected_result(opt));
|
2016-08-11 07:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
2016-08-13 21:59:21 +00:00
|
|
|
fn expected_result(arg: &str) -> String {
|
2020-04-13 18:36:03 +00:00
|
|
|
TestScenario::new(util_name!())
|
|
|
|
.cmd_keepenv(util_name!())
|
|
|
|
.env("LANGUAGE", "C")
|
|
|
|
.args(&[arg])
|
2021-04-28 20:58:28 +00:00
|
|
|
.succeeds()
|
2021-04-22 20:37:44 +00:00
|
|
|
.stdout_move_str()
|
2016-08-11 07:37:39 +00:00
|
|
|
}
|