who: add tests

This commit is contained in:
Knight 2016-08-11 15:37:39 +08:00
parent 8c6cd72848
commit 7637115e51
3 changed files with 91 additions and 1 deletions

View file

@ -196,7 +196,8 @@ TEST_PROGS := \
unexpand \
uniq \
unlink \
wc
wc \
who
TESTS := \
$(sort $(filter $(UTILS),$(filter-out $(SKIP_UTILS),$(TEST_PROGS))))

88
tests/test_who.rs Normal file
View file

@ -0,0 +1,88 @@
use common::util::*;
static UTIL_NAME: &'static str = "who";
#[cfg(target_os = "linux")]
#[test]
fn test_count() {
for opt in ["-q", "--count"].into_iter() {
let scene = TestScenario::new(UTIL_NAME);
let args = [*opt];
scene.ucmd().args(&args).run().stdout_is(expected_result(&args));
}
}
#[cfg(target_os = "linux")]
#[test]
fn test_boot() {
for opt in ["-b", "--boot"].into_iter() {
let scene = TestScenario::new(UTIL_NAME);
let args = [*opt];
scene.ucmd().args(&args).run().stdout_is(expected_result(&args));
}
}
#[cfg(target_os = "linux")]
#[test]
fn test_heading() {
for opt in ["-H"].into_iter() {
let scene = TestScenario::new(UTIL_NAME);
let args = [*opt];
scene.ucmd().args(&args).run().stdout_is(expected_result(&args));
}
}
#[cfg(target_os = "linux")]
#[test]
fn test_short() {
for opt in ["-s", "--short"].into_iter() {
let scene = TestScenario::new(UTIL_NAME);
let args = [*opt];
scene.ucmd().args(&args).run().stdout_is(expected_result(&args));
}
}
#[cfg(target_os = "linux")]
#[test]
fn test_login() {
for opt in ["-l", "--login"].into_iter() {
let scene = TestScenario::new(UTIL_NAME);
let args = [*opt];
scene.ucmd().args(&args).run().stdout_is(expected_result(&args));
}
}
#[cfg(target_os = "linux")]
#[test]
fn test_m() {
for opt in ["-m"].into_iter() {
let scene = TestScenario::new(UTIL_NAME);
let args = [*opt];
scene.ucmd().args(&args).run().stdout_is(expected_result(&args));
}
}
#[cfg(target_os = "linux")]
#[test]
fn test_dead() {
for opt in ["-d", "--dead"].into_iter() {
let scene = TestScenario::new(UTIL_NAME);
let args = [*opt];
scene.ucmd().args(&args).run().stdout_is(expected_result(&args));
}
}
#[cfg(target_os = "linux")]
#[test]
fn test_all() {
for opt in ["-a", "--all"].into_iter() {
let scene = TestScenario::new(UTIL_NAME);
let args = [*opt];
scene.ucmd().args(&args).run().stdout_is(expected_result(&args));
}
}
#[cfg(target_os = "linux")]
fn expected_result(args: &[&str]) -> String {
TestScenario::new(UTIL_NAME).cmd_keepenv(UTIL_NAME).args(args).run().stdout
}

View file

@ -21,6 +21,7 @@ unix_only! {
"stdbuf", test_stdbuf;
"touch", test_touch;
"unlink", test_unlink;
"who", test_who;
// Be aware of the trailing semicolon after the last item
"stat", test_stat
}