diff options
author | Kamal Marhubi <kamal@marhubi.com> | 2015-12-25 08:07:49 +0400 |
---|---|---|
committer | Carl Lerche <me@carllerche.com> | 2016-01-13 09:31:54 -0800 |
commit | b40046e9852c43540a120ac60e0207e365e52547 (patch) | |
tree | 4fb51bdd23c72bbf0da7b7413b7bcfae0ee1f99d | |
parent | 3154b7da011bba35a2615d00160676bdb7c41cb5 (diff) | |
download | nix-b40046e9852c43540a120ac60e0207e365e52547.zip |
Fix compiler warnings in tests
-rw-r--r-- | test/sys/test_select.rs | 4 | ||||
-rw-r--r-- | test/test_signalfd.rs | 2 | ||||
-rw-r--r-- | test/test_stat.rs | 24 |
3 files changed, 16 insertions, 14 deletions
diff --git a/test/sys/test_select.rs b/test/sys/test_select.rs index 6b7eac9a..74b390f9 100644 --- a/test/sys/test_select.rs +++ b/test/sys/test_select.rs @@ -1,6 +1,6 @@ use nix::sys::select::{FdSet, FD_SETSIZE, select}; use nix::sys::time::TimeVal; -use nix::unistd::{read, write, pipe}; +use nix::unistd::{write, pipe}; #[test] fn test_fdset() { @@ -35,7 +35,7 @@ fn test_fdset() { fn test_select() { let (r1, w1) = pipe().unwrap(); write(w1, b"hi!").unwrap(); - let (r2, w2) = pipe().unwrap(); + let (r2, _w2) = pipe().unwrap(); let mut fd_set = FdSet::new(); fd_set.insert(r1); diff --git a/test/test_signalfd.rs b/test/test_signalfd.rs index fb28e2ad..ee14d69a 100644 --- a/test/test_signalfd.rs +++ b/test/test_signalfd.rs @@ -1,7 +1,5 @@ extern crate nix; -use nix::unistd; - #[cfg(feature = "signalfd")] use nix::sys::signalfd::*; diff --git a/test/test_stat.rs b/test/test_stat.rs index 900459a4..aa3f7818 100644 --- a/test/test_stat.rs +++ b/test/test_stat.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::os::unix::fs::symlink; use std::str; use libc::consts::os::posix88; @@ -11,6 +11,16 @@ use nix::fcntl::{O_CREAT, O_RDONLY}; use nix::sys::stat::{FileStat, S_IWUSR, S_IRUSR}; use nix::Result; +#[allow(unused_comparisons)] +// uid and gid are signed on Windows, but not on other platforms. This function +// allows warning free compiles on all platforms, and can be removed when +// expression-level #[allow] is available. +fn valid_uid_gid(stat: FileStat) -> bool { + // uid could be 0 for the `root` user. This quite possible when + // the tests are being run on a rooted Android device. + stat.st_uid >= 0 && stat.st_gid >= 0 +} + fn assert_stat_results(stat_result: Result<FileStat>) { match stat_result { Ok(stats) => { @@ -18,10 +28,7 @@ fn assert_stat_results(stat_result: Result<FileStat>) { assert!(stats.st_ino > 0); // inode is positive integer, exact number machine dependent assert!(stats.st_mode > 0); // must be positive integer assert!(stats.st_nlink == 1); // there links created, must be 1 - // uid could be 0 for the `root` user. This quite possible when - // the tests are being run on a rooted Android device. - assert!(stats.st_uid >= 0); // must be positive integer - assert!(stats.st_gid >= 0); // must be positive integer + assert!(valid_uid_gid(stats)); // must be positive integers assert!(stats.st_size == 0); // size is 0 because we did not write anything to the file assert!(stats.st_blksize > 0); // must be positive integer, exact number machine dependent assert!(stats.st_blocks <= 16); // Up to 16 blocks can be allocated for a blank file @@ -43,10 +50,7 @@ fn assert_lstat_results(stat_result: Result<FileStat>) { assert!((stats.st_mode as usize) & (posix88::S_IFMT as usize) == posix88::S_IFLNK as usize); // should be a link assert!(stats.st_nlink == 1); // there links created, must be 1 - // uid could be 0 for the `root` user. This quite possible when - // the tests are being run on a rooted Android device. - assert!(stats.st_uid >= 0); // must be positive integer - assert!(stats.st_gid >= 0); // must be positive integer + assert!(valid_uid_gid(stats)); // must be positive integers assert!(stats.st_size > 0); // size is > 0 because it points to another file assert!(stats.st_blksize > 0); // must be positive integer, exact number machine dependent @@ -80,7 +84,7 @@ fn test_stat_fstat_lstat() { let linkname = b"target/barlink".as_ref(); open(filename, O_CREAT, S_IWUSR | S_IRUSR).unwrap(); // create empty file - fs::soft_link("bar.txt", str::from_utf8(linkname).unwrap()).unwrap(); + symlink("bar.txt", str::from_utf8(linkname).unwrap()).unwrap(); let fd = open(linkname, O_RDONLY, S_IRUSR).unwrap(); // should be the same result as calling stat, |