diff --git a/Makefile b/Makefile index 38a9e3ec3..e67a262ad 100644 --- a/Makefile +++ b/Makefile @@ -196,7 +196,8 @@ TEST_PROGS := \ unexpand \ uniq \ unlink \ - wc + wc \ + who TESTS := \ $(sort $(filter $(UTILS),$(filter-out $(SKIP_UTILS),$(TEST_PROGS)))) diff --git a/tests/test_who.rs b/tests/test_who.rs new file mode 100644 index 000000000..f50e50551 --- /dev/null +++ b/tests/test_who.rs @@ -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 +} diff --git a/tests/tests.rs b/tests/tests.rs index 86f489fa0..81336f5a6 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -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 }