Skip to content

Commit

Permalink
Extract closure from match scrutinee
Browse files Browse the repository at this point in the history
  • Loading branch information
djc authored and rami3l committed Mar 13, 2024
1 parent f6dbe2e commit 86fdae1
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions tests/suite/cli_self_upd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,26 +267,29 @@ fn uninstall_doesnt_leave_gc_file() {
// 100ms, but during the contention of test suites can be substantially
// longer while still succeeding.

#[derive(thiserror::Error, Debug)]
#[error("garbage remaining: {:?}", .0)]
struct GcErr(Vec<String>);

match retry(Fibonacci::from_millis(1).map(jitter).take(23), || {
let garbage = fs::read_dir(parent)
.unwrap()
.map(|d| d.unwrap().path().to_string_lossy().to_string())
.collect::<Vec<_>>();
match garbage.len() {
0 => OperationResult::Ok(()),
_ => OperationResult::Retry(GcErr(garbage)),
}
}) {
let check = || ensure_empty(parent);
match retry(Fibonacci::from_millis(1).map(jitter).take(23), check) {
Ok(_) => (),
Err(e) => panic!("{e}"),
}
})
}

fn ensure_empty(dir: &Path) -> OperationResult<(), GcErr> {
let garbage = fs::read_dir(dir)
.unwrap()
.map(|d| d.unwrap().path().to_string_lossy().to_string())
.collect::<Vec<_>>();
match garbage.len() {
0 => OperationResult::Ok(()),
_ => OperationResult::Retry(GcErr(garbage)),
}
}

#[derive(thiserror::Error, Debug)]
#[error("garbage remaining: {:?}", .0)]
struct GcErr(Vec<String>);

#[test]
fn update_exact() {
let version = env!("CARGO_PKG_VERSION");
Expand Down

0 comments on commit 86fdae1

Please sign in to comment.