summaryrefslogtreecommitdiff
path: root/test/test_unistd.rs
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_unistd.rs')
-rw-r--r--test/test_unistd.rs37
1 files changed, 10 insertions, 27 deletions
diff --git a/test/test_unistd.rs b/test/test_unistd.rs
index d36a3d39..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;
@@ -14,8 +14,7 @@ use libc::{self, _exit, off_t};
#[test]
fn test_fork_and_waitpid() {
- #[allow(unused_variables)]
- let m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test");
// Safe: Child only calls `_exit`, which is signal-safe
match fork().expect("Error: Fork Failed") {
@@ -43,8 +42,7 @@ fn test_fork_and_waitpid() {
#[test]
fn test_wait() {
// Grab FORK_MTX so wait doesn't reap a different test's child process
- #[allow(unused_variables)]
- let m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test");
// Safe: Child only calls `_exit`, which is signal-safe
match fork().expect("Error: Fork Failed") {
@@ -129,15 +127,9 @@ 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");
- #[allow(unused_variables)]
- let m = ::GROUPS_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = ::GROUPS_MTX.lock().expect("Mutex got poisoned by another test");
// Save the existing groups
let old_groups = getgroups().unwrap();
@@ -159,15 +151,9 @@ 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");
- #[allow(unused_variables)]
- let m = ::GROUPS_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = ::GROUPS_MTX.lock().expect("Mutex got poisoned by another test");
// Save the existing groups
let old_groups = getgroups().unwrap();
@@ -195,8 +181,7 @@ macro_rules! execve_test_factory(
($test_name:ident, $syscall:ident, $exe: expr $(, $pathname:expr, $flags:expr)*) => (
#[test]
fn $test_name() {
- #[allow(unused_variables)]
- let m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test");
// The `exec`d process will write to `writer`, and we'll read that
// data from `reader`.
let (reader, writer) = pipe().unwrap();
@@ -280,8 +265,7 @@ cfg_if!{
#[test]
fn test_fchdir() {
// fchdir changes the process's cwd
- #[allow(unused_variables)]
- let m = ::CWD_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = ::CWD_MTX.lock().expect("Mutex got poisoned by another test");
let tmpdir = tempfile::tempdir().unwrap();
let tmpdir_path = tmpdir.path().canonicalize().unwrap();
@@ -296,8 +280,7 @@ fn test_fchdir() {
#[test]
fn test_getcwd() {
// chdir changes the process's cwd
- #[allow(unused_variables)]
- let m = ::CWD_MTX.lock().expect("Mutex got poisoned by another test");
+ let _m = ::CWD_MTX.lock().expect("Mutex got poisoned by another test");
let tmpdir = tempfile::tempdir().unwrap();
let tmpdir_path = tmpdir.path().canonicalize().unwrap();