Skip to content

Commit

Permalink
Test remove file after read
Browse files Browse the repository at this point in the history
  • Loading branch information
LokiSharp committed Dec 15, 2023
1 parent e5faf13 commit 00de205
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ mod test {

#[cfg(unix)]
use crate::advice::{Advice, UncheckedAdvice};
use std::fs::{File, OpenOptions};
use std::fs::{self, File, OpenOptions};
use std::io::{Read, Write};
use std::mem;
#[cfg(unix)]
Expand Down Expand Up @@ -1571,6 +1571,30 @@ mod test {
assert_eq!(write, &read);
}

#[test]
fn file_remove() {
let tempdir = tempfile::tempdir().unwrap();
let path = tempdir.path().join("mmap");

let mut file = OpenOptions::new()
.read(true)
.write(true)
.create(true)
.open(path.clone())
.unwrap();
file.set_len(128).unwrap();

let mmap = unsafe { Mmap::map(&file) };

assert!(mmap.is_ok());

let remove_res = fs::remove_file(path.clone());
if remove_res.is_err() {
println!("remove_res: {:?}", remove_res);
}
assert!(remove_res.is_ok());
}

#[test]
fn flush_range() {
let tempdir = tempfile::tempdir().unwrap();
Expand Down

0 comments on commit 00de205

Please sign in to comment.