From 2d071f6c82de9eb1eb1a564ac070fd4cef3ccbf3 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 4 Apr 2021 20:28:39 +0100 Subject: [PATCH] tests: Rename always_context to did and use it a lot more Signed-off-by: Ian Jackson --- apitest/apitest.rs | 4 ++-- wdriver/wdriver.rs | 8 ++++---- wdriver/wdt-altergame.rs | 9 +++++---- wdriver/wdt-hand.rs | 12 ++++++------ wdriver/wdt-simple.rs | 16 ++++++++-------- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/apitest/apitest.rs b/apitest/apitest.rs index a8ecaef4..e28ff950 100644 --- a/apitest/apitest.rs +++ b/apitest/apitest.rs @@ -257,7 +257,7 @@ macro_rules! test { #[ext(pub)] impl Result { - fn always_context(self, msg: &'static str) -> anyhow::Result + fn did(self, msg: &'static str) -> anyhow::Result where Self: anyhow::Context { let x = self.context(msg); @@ -886,7 +886,7 @@ pub fn setup_core(module_paths: &[&str], early_args: EarlyArgPredicate) -> let ds = prepare_tmpdir(&opts, ¤t_exe)?; let (mgmt_conn, server_child) = - prepare_gameserver(&cln, &ds).always_context("setup game server")?; + prepare_gameserver(&cln, &ds).did("setup game server")?; let mgmt_conn = mgmt_conn.for_game( TABLE.parse()?, diff --git a/wdriver/wdriver.rs b/wdriver/wdriver.rs index 3ec5e80b..3bef8500 100644 --- a/wdriver/wdriver.rs +++ b/wdriver/wdriver.rs @@ -757,13 +757,13 @@ pub fn setup(exe_module_path: &str) -> (Setup, Instance) { &mut |s: &OsStr| s.to_str().unwrap().starts_with("--test=") )?; - prepare_xserver(&cln, &core.ds).always_context("setup X server")?; + prepare_xserver(&cln, &core.ds).did("setup X server")?; let final_hook = FinalInfoCollection; - prepare_geckodriver(&opts, &cln).always_context("setup webdriver server")?; + prepare_geckodriver(&opts, &cln).did("setup webdriver server")?; let (driver, screenshot_count, windows_squirreled) = - prepare_thirtyfour(&core.ds).always_context("prepare web session")?; + prepare_thirtyfour(&core.ds).did("prepare web session")?; (Setup { core, @@ -806,7 +806,7 @@ pub struct UsualSetup { impl UsualSetup { #[throws(AE)] pub fn new(exe_module_path: &str) -> UsualSetup { - let (mut su, inst) = setup(exe_module_path).always_context("setup")?; + let (mut su, inst) = setup(exe_module_path).did("usual setup")?; let [alice, bob] : [Window; 2] = su.setup_static_users(&inst)?.try_into().unwrap(); let spec = su.ds.game_spec_data()?; diff --git a/wdriver/wdt-altergame.rs b/wdriver/wdt-altergame.rs index 5cd66929..02627500 100644 --- a/wdriver/wdt-altergame.rs +++ b/wdriver/wdt-altergame.rs @@ -36,7 +36,7 @@ impl Ctx { } Ok::<_,AE>(()) })() - .context(desc).context("check link")? + .context(desc).did("check link")? } #[throws(AE)] @@ -51,7 +51,7 @@ impl Ctx { self.check_link(desc, Some(url))?; Ok::<_,AE>(()) })() - .context(desc).context("test link")? + .context(desc).did("test link")? } #[throws(AE)] @@ -61,7 +61,7 @@ impl Ctx { self.check_link(desc, None)?; Ok::<_,AE>(()) })() - .context(desc).context("test remove link")? + .context(desc).did("test remove link")? } } @@ -117,7 +117,8 @@ fn tests(UsualSetup { su, alice, ..}: UsualSetup) { .click_and_hold() .move_w(&alice, p2)? .release() - .perform()?; + .perform() + .did("click and hold while paused")?; let got_p2 = p.posg()?; assert_eq!(p2, got_p2); diff --git a/wdriver/wdt-hand.rs b/wdriver/wdt-hand.rs index 008e5aa6..9a0014b9 100644 --- a/wdriver/wdt-hand.rs +++ b/wdriver/wdt-hand.rs @@ -57,20 +57,20 @@ impl Ctx { .move_pos(&hand)? .click() .perform() - .context("select hand")?; + .did("select hand")?; w.synch()?; w.action_chain() .key_down('C') .key_up('C') .perform() - .context("claim hand")?; + .did("claim hand")?; w.synch()?; w.action_chain() .click() .perform() - .context("deselect")?; + .did("deselect")?; chk(&mut w, HAND, Some(ALICE))?; @@ -112,19 +112,19 @@ impl Ctx { .move_pos(&hand)? .click() .perform() - .context("select hand")?; + .did("select hand")?; w.synch()?; w.action_chain() .key_down('C') .key_up('C') .perform() - .context("unclaim hand")?; + .did("unclaim hand")?; w.action_chain() .click() .perform() - .context("deselect")?; + .did("deselect")?; chk(&mut w, HAND, None)?; } diff --git a/wdriver/wdt-simple.rs b/wdriver/wdt-simple.rs index 8c8f487c..896d8644 100644 --- a/wdriver/wdt-simple.rs +++ b/wdriver/wdt-simple.rs @@ -71,7 +71,7 @@ impl Ctx { .key_down('l') .key_up('l') .perform() - .always_context("rotate")?; + .did("rotate")?; chk(&w)?; w.synch()?; @@ -111,7 +111,7 @@ impl Ctx { .move_w(&w, try_end)? .release() .perform() - .always_context("drag off")?; + .did("drag off")?; w.synch()?; chk(&w, exp_end)?; @@ -145,7 +145,7 @@ impl Ctx { .click() .release() .perform() - .always_context("unselect by clicking elsewhere")?; + .did("unselect by clicking elsewhere")?; chk(&w)?; w.synch()?; @@ -190,7 +190,7 @@ impl Ctx { .click() .click() .perform() - .context("select and release")?; + .did("select and release")?; w.synch()?; @@ -219,7 +219,7 @@ impl Ctx { .release() .perform() - .context("conflicting drag")?; + .did("conflicting drag")?; } paused.resume()?; @@ -275,9 +275,9 @@ fn tests(UsualSetup { su, alice, bob, spec, ..}: UsualSetup) { 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")?; + let pc = c.rotate().did("rotate")?; + c.drag_off(pc).did("drag off")?; + c.unselect(pc).did("unselect")?; }); test!(c, "conflict", c.conflict()?); -- 2.30.2