summaryrefslogtreecommitdiff
path: root/test/test.rs
diff options
context:
space:
mode:
authorPascal Bach <pascal.bach@nextrem.ch>2018-09-02 23:46:10 +0200
committerPascal Bach <pascal.bach@nextrem.ch>2018-09-05 21:59:45 +0200
commit81088abb3e257086f7dfc5810a363d28fea05706 (patch)
tree4e26c4a32ef3625cca7be2d635251cc3dbb09453 /test/test.rs
parent57603c62922980d1d8e624700b8aa24d59bebc76 (diff)
downloadnix-81088abb3e257086f7dfc5810a363d28fea05706.zip
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.
Diffstat (limited to 'test/test.rs')
-rw-r--r--test/test.rs15
1 files changed, 15 insertions, 0 deletions
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;