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.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/test.rs') diff --git a/test/test.rs b/test/test.rs index a72dc44a..14f63e26 100644 --- a/test/test.rs +++ b/test/test.rs @@ -9,6 +9,21 @@ extern crate libc; extern crate rand; extern crate tempfile; +macro_rules! skip_if_not_root { + ($name:expr) => { + use nix::unistd::Uid; + use std; + use std::io::Write; + + if !Uid::current().is_root() { + let stderr = std::io::stderr(); + let mut handle = stderr.lock(); + writeln!(handle, "{} requires root privileges. Skipping test.", $name).unwrap(); + return; + } + }; +} + mod sys; mod test_dir; mod test_fcntl; -- cgit v1.2.3