From: Ian Jackson Date: Sun, 14 Feb 2021 19:19:41 +0000 (+0000) Subject: wdt: Refactor UsualSetup X-Git-Tag: otter-0.4.0~492 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=ea6ab3e3be153093314eb362360a9454a7841abb;p=otter.git wdt: Refactor UsualSetup Signed-off-by: Ian Jackson --- diff --git a/wdriver.rs b/wdriver.rs index 68edf468..44753ea9 100644 --- a/wdriver.rs +++ b/wdriver.rs @@ -1369,3 +1369,29 @@ impl Setup { .collect::,AE>>()? } } + +pub struct UsualSetup { + pub su: Setup, + pub inst: Instance, + pub alice: Window, + pub bob: Window, + pub spec: otter::spec::GameSpec, +} + +impl UsualSetup { + #[throws(AE)] + pub fn new() -> UsualSetup { + let (mut su, inst) = setup(module_path!()).always_context("setup")?; + let [alice, bob] : [Window; 2] = + su.setup_static_users(&inst)?.try_into().unwrap(); + let spec = su.ds.game_spec_data()?; + UsualSetup { su, inst, alice, bob, spec } + } +} + +#[throws(AE)] +pub fn as_usual Result<(), AE>>(f: F) { + let usual = UsualSetup::new()?; + f(usual)?; + info!("ok"); +} diff --git a/wdriver/wdt-simple.rs b/wdriver/wdt-simple.rs index d500409b..707ea4a8 100644 --- a/wdriver/wdt-simple.rs +++ b/wdriver/wdt-simple.rs @@ -279,27 +279,21 @@ impl Ctx { } #[throws(AE)] -fn main(){ - { - let (mut su, inst) = setup(module_path!()).always_context("setup")?; - let [alice, bob] : [Window; 2] = - su.setup_static_users(&inst)?.try_into().unwrap(); - let spec = su.ds.game_spec_data()?; - debug!("ok {:?} {:?}", alice, bob); +fn tests(UsualSetup { su, alice, bob, spec, ..}: UsualSetup) { + let mut c = Ctx { su, alice, bob, spec }; - let mut c = Ctx { su, alice, bob, spec }; + test!(c, "drag", c.drag()?); - test!(c, "drag", c.drag()?); + test!(c, "drag-rotate-unselect", { + let pc = c.rotate().always_context("rotate")?; + c.drag_off(pc).always_context("drag off")?; + c.unselect(pc).always_context("unselect")?; + }); - test!(c, "drag-rotate-unselect", { - let pc = c.rotate().always_context("rotate")?; - c.drag_off(pc).always_context("drag off")?; - c.unselect(pc).always_context("unselect")?; - }); + test!(c, "conflict", c.conflict()?); - test!(c, "conflict", c.conflict()?); - - debug!("finishing"); - } - info!("ok"); + debug!("finishing"); } + +#[throws(AE)] +fn main() { as_usual(tests)? }