From 86fdae1aead9d0fa5d0e9d85049177735587d2da Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Wed, 13 Mar 2024 09:48:53 +0100 Subject: [PATCH] Extract closure from match scrutinee --- tests/suite/cli_self_upd.rs | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/tests/suite/cli_self_upd.rs b/tests/suite/cli_self_upd.rs index d67046c183..1dce5f813a 100644 --- a/tests/suite/cli_self_upd.rs +++ b/tests/suite/cli_self_upd.rs @@ -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); - - 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::>(); - 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::>(); + match garbage.len() { + 0 => OperationResult::Ok(()), + _ => OperationResult::Retry(GcErr(garbage)), + } +} + +#[derive(thiserror::Error, Debug)] +#[error("garbage remaining: {:?}", .0)] +struct GcErr(Vec); + #[test] fn update_exact() { let version = env!("CARGO_PKG_VERSION");