@@ -45,7 +45,9 @@ impl Drop for ShallowTempDir {
4545
4646 if should_clean_up {
4747 if let Err ( e) = std:: fs:: remove_dir_all ( & self . path ) {
48- eprintln ! ( "Failed to remove temp directory: {:?}" , e) ;
48+ if !std:: thread:: panicking ( ) {
49+ panic ! ( "Failed to remove ShallowTempDir: {}" , e) ;
50+ }
4951 }
5052 }
5153 }
@@ -125,12 +127,31 @@ mod tests {
125127 env:: remove_var ( DB_CLEAN_UP_ENV_VAR ) ;
126128 }
127129
130+ fn shallow_temp_dir__panics_while_dropping_if_not_panicking ( ) {
131+ // given
132+ env:: set_var ( DB_CLEAN_UP_ENV_VAR , "true" ) ;
133+
134+ let result = std:: panic:: catch_unwind ( || {
135+ let _ = ShallowTempDir :: new ( ) ;
136+ // when: out of scope, tries to drop
137+ // it will panic when trying to drop, since there
138+ // are no other panics
139+ } ) ;
140+
141+ // then
142+ assert ! ( result. is_err( ) ) ;
143+
144+ // clean up
145+ env:: remove_var ( DB_CLEAN_UP_ENV_VAR ) ;
146+ }
147+
128148 #[ test]
129149 fn test_shallow_temp_dir_behaviour ( ) {
130150 // run tests sequentially to avoid conflicts due to env var usage
131151 shallow_temp_dir__drops_if_env_var_is_set ( ) ;
132152 shallow_temp_dir__does_not_drop_if_env_var_is_set ( ) ;
133153 shallow_temp_dir__drops_if_env_var_is_not_set ( ) ;
134154 shallow_temp_dir__drops_if_env_var_malformed ( ) ;
155+ shallow_temp_dir__panics_while_dropping_if_not_panicking ( ) ;
135156 }
136157}
0 commit comments