From d2d9fcd6284a6959bee6ea24682ffbd23ca36cc3 Mon Sep 17 00:00:00 2001 From: Knight Date: Sun, 21 Aug 2016 17:05:05 +0800 Subject: [PATCH] chgrp: add tests --- tests/test_chgrp.rs | 102 ++++++++++++++++++++++++++++++++++++++++++++ tests/tests.rs | 1 + 2 files changed, 103 insertions(+) create mode 100644 tests/test_chgrp.rs diff --git a/tests/test_chgrp.rs b/tests/test_chgrp.rs new file mode 100644 index 000000000..29af80912 --- /dev/null +++ b/tests/test_chgrp.rs @@ -0,0 +1,102 @@ +use common::util::*; + +static UTIL_NAME: &'static str = "chgrp"; +fn new_ucmd() -> UCommand { + TestScenario::new(UTIL_NAME).ucmd() +} + +#[test] +fn test_invalid_option() { + new_ucmd() + .arg("-w") + .arg("/") + .fails(); +} + +static DIR: &'static str = "/tmp"; + +#[test] +fn test_invalid_group() { + new_ucmd() + .arg("nosuchgroup") + .arg("/") + .fails() + .stderr_is("chgrp: invalid group: nosuchgroup"); +} + +#[test] +fn test_1() { + new_ucmd() + .arg("bin") + .arg(DIR) + .fails() + .stderr_is("chgrp: changing group of '/tmp': Operation not permitted (os error 1)"); +} + +#[test] +fn test_fail_silently() { + for opt in &["-f", "--silent", "--quiet"] { + new_ucmd() + .arg(opt) + .arg("bin") + .arg(DIR) + .run() + .fails_silently(); + } +} + +#[test] +fn test_preserve_root() { + new_ucmd() + .arg("--preserve-root") + .arg("-R") + .arg("bin").arg("/") + .fails() + .stderr_is("chgrp: it is dangerous to operate recursively on '/'\nchgrp: use --no-preserve-root to override this failsafe"); +} + +#[test] +#[cfg(target_os = "linux")] +fn test_reference() { + new_ucmd() + .arg("-v") + .arg("--reference=/etc/passwd") + .arg("/etc") + .fails() + .stderr_is("chgrp: changing group of '/etc': Operation not permitted (os error 1)\n") + .stdout_is("failed to change group of /etc from root to root\n"); +} + +#[test] +#[cfg(target_os = "macos")] +fn test_reference() { + new_ucmd() + .arg("-v") + .arg("--reference=/etc/passwd") + .arg("/etc") + .succeeds(); +} + +#[test] +#[cfg(target_os = "linux")] +fn test_big_p() { + new_ucmd() + .arg("-RP") + .arg("bin") + .arg("/proc/self/cwd") + .fails() + .stderr_is("chgrp: changing group of '/proc/self/cwd': Operation not permitted (os error 1)\n"); +} + +#[test] +#[cfg(target_os = "linux")] +fn test_big_h() { + assert!(new_ucmd() + .arg("-RH") + .arg("bin") + .arg("/proc/self/fd") + .fails() + .stderr + .lines() + .fold(0, |acc, _| acc + 1) > 1); +} diff --git a/tests/tests.rs b/tests/tests.rs index 81336f5a6..3897935e2 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -14,6 +14,7 @@ macro_rules! unix_only { unix_only! { "chmod", test_chmod; "chown", test_chown; + "chgrp", test_chgrp; "install", test_install; "mv", test_mv; "pathchk", test_pathchk;