Skip to content

Commit f25397a

Browse files
authored
Rollup merge of #122786 - Enselic:remove_and_create_dir_all, r=onur-ozkan
compiletest: Introduce `remove_and_create_dir_all()` helper The code let _ = fs::remove_dir_all(&dir); create_dir_all(&dir).unwrap(); is duplicated in 7 places. Let's introduce a helper.
2 parents afdbad8 + c3cc6c1 commit f25397a

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/tools/compiletest/src/runtest.rs

+12-15
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ pub fn compute_stamp_hash(config: &Config) -> String {
198198
format!("{:x}", hash.finish())
199199
}
200200

201+
fn remove_and_create_dir_all(path: &Path) {
202+
let _ = fs::remove_dir_all(path);
203+
fs::create_dir_all(path).unwrap();
204+
}
205+
201206
#[derive(Copy, Clone)]
202207
struct TestCx<'test> {
203208
config: &'test Config,
@@ -998,8 +1003,7 @@ impl<'test> TestCx<'test> {
9981003
let mut rustc = Command::new(&self.config.rustc_path);
9991004

10001005
let out_dir = self.output_base_name().with_extension("pretty-out");
1001-
let _ = fs::remove_dir_all(&out_dir);
1002-
create_dir_all(&out_dir).unwrap();
1006+
remove_and_create_dir_all(&out_dir);
10031007

10041008
let target = if self.props.force_host { &*self.config.host } else { &*self.config.target };
10051009

@@ -2094,14 +2098,12 @@ impl<'test> TestCx<'test> {
20942098
let aux_dir = self.aux_output_dir_name();
20952099

20962100
if !self.props.aux_builds.is_empty() {
2097-
let _ = fs::remove_dir_all(&aux_dir);
2098-
create_dir_all(&aux_dir).unwrap();
2101+
remove_and_create_dir_all(&aux_dir);
20992102
}
21002103

21012104
if !self.props.aux_bins.is_empty() {
21022105
let aux_bin_dir = self.aux_bin_output_dir_name();
2103-
let _ = fs::remove_dir_all(&aux_bin_dir);
2104-
create_dir_all(&aux_bin_dir).unwrap();
2106+
remove_and_create_dir_all(&aux_bin_dir);
21052107
}
21062108

21072109
aux_dir
@@ -2469,8 +2471,7 @@ impl<'test> TestCx<'test> {
24692471
}
24702472

24712473
let mir_dump_dir = self.get_mir_dump_dir();
2472-
let _ = fs::remove_dir_all(&mir_dump_dir);
2473-
create_dir_all(mir_dump_dir.as_path()).unwrap();
2474+
remove_and_create_dir_all(&mir_dump_dir);
24742475
let mut dir_opt = "-Zdump-mir-dir=".to_string();
24752476
dir_opt.push_str(mir_dump_dir.to_str().unwrap());
24762477
debug!("dir_opt: {:?}", dir_opt);
@@ -2951,8 +2952,7 @@ impl<'test> TestCx<'test> {
29512952
assert!(self.revision.is_none(), "revisions not relevant here");
29522953

29532954
let out_dir = self.output_base_dir();
2954-
let _ = fs::remove_dir_all(&out_dir);
2955-
create_dir_all(&out_dir).unwrap();
2955+
remove_and_create_dir_all(&out_dir);
29562956

29572957
let proc_res = self.document(&out_dir);
29582958
if !proc_res.status.success() {
@@ -2986,9 +2986,7 @@ impl<'test> TestCx<'test> {
29862986
let suffix =
29872987
self.safe_revision().map_or("nightly".into(), |path| path.to_owned() + "-nightly");
29882988
let compare_dir = output_base_dir(self.config, self.testpaths, Some(&suffix));
2989-
// Don't give an error if the directory didn't already exist
2990-
let _ = fs::remove_dir_all(&compare_dir);
2991-
create_dir_all(&compare_dir).unwrap();
2989+
remove_and_create_dir_all(&compare_dir);
29922990

29932991
// We need to create a new struct for the lifetimes on `config` to work.
29942992
let new_rustdoc = TestCx {
@@ -3137,8 +3135,7 @@ impl<'test> TestCx<'test> {
31373135
assert!(self.revision.is_none(), "revisions not relevant here");
31383136

31393137
let out_dir = self.output_base_dir();
3140-
let _ = fs::remove_dir_all(&out_dir);
3141-
create_dir_all(&out_dir).unwrap();
3138+
remove_and_create_dir_all(&out_dir);
31423139

31433140
let proc_res = self.document(&out_dir);
31443141
if !proc_res.status.success() {

0 commit comments

Comments
 (0)