Skip to content

Commit 45817dc

Browse files
committed
refactor(test): inline the uninstall GC cleanup check
Inline the single-use ensure_empty helper and replace GcErr with an inline error. Preserve the existing directory and GC filename filter.
1 parent e19437b commit 45817dc

1 file changed

Lines changed: 19 additions & 27 deletions

File tree

tests/suite/cli_self_upd.rs

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -395,39 +395,31 @@ async fn uninstall_doesnt_leave_gc_file() {
395395
// 100ms, but during the contention of test suites can be substantially
396396
// longer while still succeeding.
397397

398-
let check = || ensure_empty(parent);
398+
let check = || {
399+
let garbage = fs::read_dir(parent)
400+
.unwrap()
401+
.filter_map(|entry| {
402+
let path = entry.unwrap().path();
403+
let name = path.file_name()?.to_str()?;
404+
// On Windows, this binary is cleaned up on exit
405+
if !(name.starts_with("rustup-gc-") && name.ends_with(EXE_SUFFIX)) {
406+
return None;
407+
}
408+
Some(path.to_string_lossy().to_string())
409+
})
410+
.collect::<Vec<_>>();
411+
if garbage.is_empty() {
412+
Ok(())
413+
} else {
414+
Err(format!("garbage remaining: {garbage:?}"))
415+
}
416+
};
399417
match retry(Fibonacci::from_millis(1).map(jitter).take(23), check) {
400418
Ok(_) => (),
401419
Err(e) => panic!("{e}"),
402420
}
403421
}
404422

405-
#[cfg(windows)]
406-
fn ensure_empty(dir: &Path) -> Result<(), GcErr> {
407-
let garbage = fs::read_dir(dir)
408-
.unwrap()
409-
.filter_map(|entry| {
410-
let path = entry.unwrap().path();
411-
let name = path.file_name()?.to_str()?;
412-
// On Windows, this binary is cleaned up on exit
413-
if !(name.starts_with("rustup-gc-") && name.ends_with(EXE_SUFFIX)) {
414-
return None;
415-
}
416-
Some(path.to_string_lossy().to_string())
417-
})
418-
.collect::<Vec<_>>();
419-
if garbage.is_empty() {
420-
Ok(())
421-
} else {
422-
Err(GcErr(garbage))
423-
}
424-
}
425-
426-
#[derive(thiserror::Error, Debug)]
427-
#[error("garbage remaining: {:?}", .0)]
428-
#[cfg(windows)]
429-
struct GcErr(Vec<String>);
430-
431423
#[tokio::test]
432424
async fn update_exact() {
433425
let cx = SelfUpdateTestContext::new(TEST_VERSION).await;

0 commit comments

Comments
 (0)