Skip to content

Commit

Permalink
Add a test for world_accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
tbu- committed Jul 21, 2018
1 parent c07ec4b commit 6c169c1
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/namedtempfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,33 @@ fn test_customnamed() {
assert_eq!(name.len(), 18);
}

#[test]
fn test_world_accessible() {
#[cfg(unix)]
fn assert_filemode(file: &File, world_accessible: bool) {
use std::os::unix::fs::PermissionsExt;

const MASK: u32 = 0o644;
let value = if world_accessible { 0o644 } else { 0o600 };
let mode = file.metadata().unwrap().permissions().mode();
assert!(mode & MASK == value,
"mode & MASK != value: 0o{:o} & 0o{:o} != 0o{:o}",
mode, MASK, value);
}
#[cfg(not(unix))]
fn assert_filemode(file: &File, world_accessible: bool) {
let _ = (file, world_accessible);
}
for &world_accessible in &[None, Some(false), Some(true)] {
let mut builder = Builder::new();
if let Some(wa) = world_accessible {
builder.world_accessible(wa);
}
let tempfile = builder.tempfile().unwrap();
assert_filemode(tempfile.as_file(), world_accessible.unwrap_or(false));
}
}

#[test]
fn test_reopen() {
let source = NamedTempFile::new().unwrap();
Expand Down

0 comments on commit 6c169c1

Please sign in to comment.