@@ -18,32 +18,9 @@ use std::thread;
1818
1919use tempfile:: { Builder , TempDir } ;
2020
21- macro_rules! t {
22- ( $e: expr) => {
23- match $e {
24- Ok ( n) => n,
25- Err ( e) => panic!( "error: {}" , e) ,
26- }
27- } ;
28- }
29-
30- trait PathExt {
31- fn exists ( & self ) -> bool ;
32- fn is_dir ( & self ) -> bool ;
33- }
34-
35- impl PathExt for Path {
36- fn exists ( & self ) -> bool {
37- fs:: metadata ( self ) . is_ok ( )
38- }
39- fn is_dir ( & self ) -> bool {
40- fs:: metadata ( self ) . map ( |m| m. is_dir ( ) ) . unwrap_or ( false )
41- }
42- }
43-
4421fn test_tempdir ( ) {
4522 let path = {
46- let p = t ! ( Builder :: new( ) . prefix( "foobar" ) . tempdir_in( Path :: new ( "." ) ) ) ;
23+ let p = Builder :: new ( ) . prefix ( "foobar" ) . tempdir_in ( "." ) . unwrap ( ) ;
4724 let p = p. path ( ) ;
4825 assert ! ( p. to_str( ) . unwrap( ) . contains( "foobar" ) ) ;
4926 p. to_path_buf ( )
@@ -73,15 +50,15 @@ fn test_customnamed() {
7350fn test_rm_tempdir ( ) {
7451 let ( tx, rx) = channel ( ) ;
7552 let f = move || {
76- let tmp = t ! ( TempDir :: new( ) ) ;
53+ let tmp = TempDir :: new ( ) . unwrap ( ) ;
7754 tx. send ( tmp. path ( ) . to_path_buf ( ) ) . unwrap ( ) ;
7855 panic ! ( "panic to unwind past `tmp`" ) ;
7956 } ;
8057 let _ = thread:: spawn ( f) . join ( ) ;
8158 let path = rx. recv ( ) . unwrap ( ) ;
8259 assert ! ( !path. exists( ) ) ;
8360
84- let tmp = t ! ( TempDir :: new( ) ) ;
61+ let tmp = TempDir :: new ( ) . unwrap ( ) ;
8562 let path = tmp. path ( ) . to_path_buf ( ) ;
8663 let f = move || {
8764 let _tmp = tmp;
@@ -92,7 +69,7 @@ fn test_rm_tempdir() {
9269
9370 let path;
9471 {
95- let f = move || t ! ( TempDir :: new( ) ) ;
72+ let f = move || TempDir :: new ( ) . unwrap ( ) ;
9673
9774 let tmp = thread:: spawn ( f) . join ( ) . unwrap ( ) ;
9875 path = tmp. path ( ) . to_path_buf ( ) ;
@@ -102,54 +79,54 @@ fn test_rm_tempdir() {
10279
10380 let path;
10481 {
105- let tmp = t ! ( TempDir :: new( ) ) ;
82+ let tmp = TempDir :: new ( ) . unwrap ( ) ;
10683 path = tmp. into_path ( ) ;
10784 }
10885 assert ! ( path. exists( ) ) ;
109- t ! ( fs:: remove_dir_all( & path) ) ;
86+ fs:: remove_dir_all ( & path) . unwrap ( ) ;
11087 assert ! ( !path. exists( ) ) ;
11188}
11289
11390fn test_rm_tempdir_close ( ) {
11491 let ( tx, rx) = channel ( ) ;
11592 let f = move || {
116- let tmp = t ! ( TempDir :: new( ) ) ;
93+ let tmp = TempDir :: new ( ) . unwrap ( ) ;
11794 tx. send ( tmp. path ( ) . to_path_buf ( ) ) . unwrap ( ) ;
118- t ! ( tmp. close( ) ) ;
95+ tmp. close ( ) . unwrap ( ) ;
11996 panic ! ( "panic when unwinding past `tmp`" ) ;
12097 } ;
12198 let _ = thread:: spawn ( f) . join ( ) ;
12299 let path = rx. recv ( ) . unwrap ( ) ;
123100 assert ! ( !path. exists( ) ) ;
124101
125- let tmp = t ! ( TempDir :: new( ) ) ;
102+ let tmp = TempDir :: new ( ) . unwrap ( ) ;
126103 let path = tmp. path ( ) . to_path_buf ( ) ;
127104 let f = move || {
128105 let tmp = tmp;
129- t ! ( tmp. close( ) ) ;
106+ tmp. close ( ) . unwrap ( ) ;
130107 panic ! ( "panic when unwinding past `tmp`" ) ;
131108 } ;
132109 let _ = thread:: spawn ( f) . join ( ) ;
133110 assert ! ( !path. exists( ) ) ;
134111
135112 let path;
136113 {
137- let f = move || t ! ( TempDir :: new( ) ) ;
114+ let f = move || TempDir :: new ( ) . unwrap ( ) ;
138115
139116 let tmp = thread:: spawn ( f) . join ( ) . unwrap ( ) ;
140117 path = tmp. path ( ) . to_path_buf ( ) ;
141118 assert ! ( path. exists( ) ) ;
142- t ! ( tmp. close( ) ) ;
119+ tmp. close ( ) . unwrap ( ) ;
143120 }
144121 assert ! ( !path. exists( ) ) ;
145122
146123 let path;
147124 {
148- let tmp = t ! ( TempDir :: new( ) ) ;
125+ let tmp = TempDir :: new ( ) . unwrap ( ) ;
149126 path = tmp. into_path ( ) ;
150127 }
151128 assert ! ( path. exists( ) ) ;
152- t ! ( fs:: remove_dir_all( & path) ) ;
129+ fs:: remove_dir_all ( & path) . unwrap ( ) ;
153130 assert ! ( !path. exists( ) ) ;
154131}
155132
@@ -158,7 +135,7 @@ fn dont_double_panic() {
158135 let tmpdir = TempDir :: new ( ) . unwrap ( ) ;
159136 // Remove the temporary directory so that TempDir sees
160137 // an error on drop
161- t ! ( fs:: remove_dir( tmpdir. path( ) ) ) ;
138+ fs:: remove_dir ( tmpdir. path ( ) ) . unwrap ( ) ;
162139 // Panic. If TempDir panics *again* due to the rmdir
163140 // error then the process will abort.
164141 panic ! ( ) ;
@@ -171,14 +148,14 @@ fn in_tmpdir<F>(f: F)
171148where
172149 F : FnOnce ( ) ,
173150{
174- let tmpdir = t ! ( TempDir :: new( ) ) ;
151+ let tmpdir = TempDir :: new ( ) . unwrap ( ) ;
175152 assert ! ( env:: set_current_dir( tmpdir. path( ) ) . is_ok( ) ) ;
176153
177154 f ( ) ;
178155}
179156
180- pub fn pass_as_asref_path ( ) {
181- let tempdir = t ! ( TempDir :: new( ) ) ;
157+ fn pass_as_asref_path ( ) {
158+ let tempdir = TempDir :: new ( ) . unwrap ( ) ;
182159 takes_asref_path ( & tempdir) ;
183160
184161 fn takes_asref_path < T : AsRef < Path > > ( path : T ) {
0 commit comments