@@ -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