From 81088abb3e257086f7dfc5810a363d28fea05706 Mon Sep 17 00:00:00 2001 From: Pascal Bach Date: Sun, 2 Sep 2018 23:46:10 +0200 Subject: Refactor skip_if_not_root into macro This macro can be used in tests to skip the test if it requires root to sucssfully run. --- test/test_unistd.rs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'test/test_unistd.rs') diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 39c0952e..54cbff8d 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -4,7 +4,7 @@ use nix::unistd::ForkResult::*; use nix::sys::signal::{SaFlags, SigAction, SigHandler, SigSet, Signal, sigaction}; use nix::sys::wait::*; use nix::sys::stat::{self, Mode, SFlag}; -use std::{self, env, iter}; +use std::{env, iter}; use std::ffi::CString; use std::fs::File; use std::io::Write; @@ -127,12 +127,7 @@ mod linux_android { #[cfg(not(any(target_os = "ios", target_os = "macos")))] fn test_setgroups() { // Skip this test when not run as root as `setgroups()` requires root. - if !Uid::current().is_root() { - let stderr = std::io::stderr(); - let mut handle = stderr.lock(); - writeln!(handle, "test_setgroups requires root privileges. Skipping test.").unwrap(); - return; - } + skip_if_not_root!("test_setgroups"); let _m = ::GROUPS_MTX.lock().expect("Mutex got poisoned by another test"); @@ -156,12 +151,7 @@ fn test_setgroups() { fn test_initgroups() { // Skip this test when not run as root as `initgroups()` and `setgroups()` // require root. - if !Uid::current().is_root() { - let stderr = std::io::stderr(); - let mut handle = stderr.lock(); - writeln!(handle, "test_initgroups requires root privileges. Skipping test.").unwrap(); - return; - } + skip_if_not_root!("test_initgroups"); let _m = ::GROUPS_MTX.lock().expect("Mutex got poisoned by another test"); -- cgit v1.2.3