File tree 1 file changed +25
-0
lines changed
mithril-common/src/test_utils
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -115,6 +115,7 @@ impl TempDir {
115
115
#[ cfg( test) ]
116
116
mod tests {
117
117
use super :: * ;
118
+ use std:: { fs, io:: Write , ops:: Not } ;
118
119
119
120
#[ test]
120
121
fn non_short_path_are_in_a_mithril_test_slash_module_folder_structure ( ) {
@@ -204,4 +205,28 @@ mod tests {
204
205
205
206
assert_ne ! ( path1, path2) ;
206
207
}
208
+
209
+ #[ test]
210
+ fn creating_temp_dir_remove_existing_content ( ) {
211
+ let builder = TempDir :: new ( "temp_dir" , "creating_temp_dir_remove_existing_content" ) ;
212
+ let ( existing_dir, existing_file) = {
213
+ let path = builder. build_path ( ) ;
214
+ ( path. join ( "existing_subdir" ) , path. join ( "existing_file.md" ) )
215
+ } ;
216
+
217
+ fs:: create_dir_all ( & existing_dir) . unwrap ( ) ;
218
+ let mut file = fs:: File :: create ( & existing_file) . unwrap ( ) ;
219
+ file. write_all ( b"file content" ) . unwrap ( ) ;
220
+
221
+ builder. build ( ) ;
222
+
223
+ assert ! (
224
+ existing_file. exists( ) . not( ) ,
225
+ "should have cleaned up existing files"
226
+ ) ;
227
+ assert ! (
228
+ existing_dir. exists( ) . not( ) ,
229
+ "should have cleaned up existing subdirectory"
230
+ ) ;
231
+ }
207
232
}
You can’t perform that action at this time.
0 commit comments