mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 11:48:30 +00:00
Avoid double panics when using TempDir
in tests
This commit is contained in:
parent
df368ae457
commit
84c0c9d20d
@ -8,6 +8,7 @@ pub mod test {
|
|||||||
use crate::env;
|
use crate::env;
|
||||||
use crate::fs;
|
use crate::fs;
|
||||||
use crate::path::{Path, PathBuf};
|
use crate::path::{Path, PathBuf};
|
||||||
|
use crate::thread;
|
||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
|
|
||||||
pub struct TempDir(PathBuf);
|
pub struct TempDir(PathBuf);
|
||||||
@ -29,7 +30,12 @@ pub mod test {
|
|||||||
// Gee, seeing how we're testing the fs module I sure hope that we
|
// Gee, seeing how we're testing the fs module I sure hope that we
|
||||||
// at least implement this correctly!
|
// at least implement this correctly!
|
||||||
let TempDir(ref p) = *self;
|
let TempDir(ref p) = *self;
|
||||||
fs::remove_dir_all(p).unwrap();
|
let result = fs::remove_dir_all(p);
|
||||||
|
// Avoid panicking while panicking as this causes the process to
|
||||||
|
// immediately abort, without displaying test results.
|
||||||
|
if !thread::panicking() {
|
||||||
|
result.unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user