Skip to content

Commit 34cc3f7

Browse files
committed
tests: Break out prep() and its strudt
We are going to want to add another test that reuses this. No functional change. Signed-off-by: Ian Jackson <[email protected]>
1 parent 6c9d685 commit 34cc3f7

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/portable.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ mod test {
2525
use crate::remove_dir_all;
2626
use crate::remove_dir_contents;
2727
use std::fs::{self, File};
28+
use std::path::PathBuf;
2829
use std::io;
2930

3031
fn expect_failure<T>(k: io::ErrorKind, r: io::Result<T>) -> io::Result<()> {
@@ -38,23 +39,34 @@ mod test {
3839
}
3940
}
4041

41-
#[test]
42-
fn mkdir_rm() -> Result<(), io::Error> {
42+
struct Prep {
43+
_tmp: TempDir,
44+
ours: PathBuf,
45+
file: PathBuf,
46+
}
47+
48+
fn prep() -> Result<Prep, io::Error> {
4349
let tmp = TempDir::new()?;
4450
let ours = tmp.path().join("t.mkdir");
4551
let file = ours.join("file");
4652
fs::create_dir(&ours)?;
4753
File::create(&file)?;
4854
File::open(&file)?;
55+
Ok(Prep { _tmp: tmp, ours, file })
56+
}
57+
58+
#[test]
59+
fn mkdir_rm() -> Result<(), io::Error> {
60+
let p = prep()?;
4961

50-
expect_failure(io::ErrorKind::Other, remove_dir_contents(&file))?;
62+
expect_failure(io::ErrorKind::Other, remove_dir_contents(&p.file))?;
5163

52-
remove_dir_contents(&ours)?;
53-
expect_failure(io::ErrorKind::NotFound, File::open(&file))?;
64+
remove_dir_contents(&p.ours)?;
65+
expect_failure(io::ErrorKind::NotFound, File::open(&p.file))?;
5466

55-
remove_dir_contents(&ours)?;
56-
remove_dir_all(&ours)?;
57-
expect_failure(io::ErrorKind::NotFound, remove_dir_contents(&ours))?;
67+
remove_dir_contents(&p.ours)?;
68+
remove_dir_all(&p.ours)?;
69+
expect_failure(io::ErrorKind::NotFound, remove_dir_contents(&p.ours))?;
5870
Ok(())
5971
}
6072
}

0 commit comments

Comments
 (0)