From: Ian Jackson Date: Sat, 13 Mar 2021 13:30:31 +0000 (+0000) Subject: apitest: make macro to make wanted_tests() method on $c X-Git-Tag: otter-0.4.0~126 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=649c8dff5fe13a929b6e82409a5f8963e54d9617;p=otter.git apitest: make macro to make wanted_tests() method on $c Signed-off-by: Ian Jackson --- diff --git a/apitest.rs b/apitest.rs index 690df4b6..fd333209 100644 --- a/apitest.rs +++ b/apitest.rs @@ -223,6 +223,17 @@ impl Drop for TrackWantedTests { } } +#[macro_export] +macro_rules! usual_wanted_tests { + ($ctx:ty, $su:ident) => { + impl $ctx { + fn wanted_tests(&mut self) -> &mut TrackWantedTests { + &mut self.su.wanted_tests + } + } + } +} + #[macro_export] macro_rules! test { ($c:expr, $tname:expr, $s:stmt) => { diff --git a/apitest/at-otter.rs b/apitest/at-otter.rs index e2ce45a6..5af238c7 100644 --- a/apitest/at-otter.rs +++ b/apitest/at-otter.rs @@ -15,12 +15,7 @@ struct Ctx { bob: Player, } deref_to_field!{Ctx, SetupCore, su} - -impl Ctx { - fn wanted_tests(&mut self) -> &mut TrackWantedTests { - &mut self.su.wanted_tests - } -} +usual_wanted_tests!{Ctx, su} #[derive(Debug)] struct Player { diff --git a/wdriver/wdt-altergame.rs b/wdriver/wdt-altergame.rs index 90edfc4e..43dd916f 100644 --- a/wdriver/wdt-altergame.rs +++ b/wdriver/wdt-altergame.rs @@ -10,12 +10,9 @@ struct Ctx { su: Setup, alice: Window, } +usual_wanted_tests!{Ctx, su} impl Ctx { - fn wanted_tests(&mut self) -> &mut TrackWantedTests { - &mut self.su.wanted_tests - } - #[throws(AE)] fn check_link(&mut self, desc: &'static str, url: Option<&str>) { (||{ diff --git a/wdriver/wdt-hand.rs b/wdriver/wdt-hand.rs index 7c20e671..74575fdf 100644 --- a/wdriver/wdt-hand.rs +++ b/wdriver/wdt-hand.rs @@ -10,12 +10,7 @@ struct Ctx { bob: Window, } deref_to_field!{Ctx, Setup, su} - -impl Ctx { - fn wanted_tests(&mut self) -> &mut TrackWantedTests { - &mut self.su.wanted_tests - } -} +usual_wanted_tests!{Ctx, su} const HAND: &str = "6.1"; const ALICE: &str = "1#1"; diff --git a/wdriver/wdt-simple.rs b/wdriver/wdt-simple.rs index 24063b08..8116f7dd 100644 --- a/wdriver/wdt-simple.rs +++ b/wdriver/wdt-simple.rs @@ -11,12 +11,9 @@ struct Ctx { spec: GameSpec, } deref_to_field!{Ctx, Setup, su} +usual_wanted_tests!{Ctx, su} impl Ctx { - fn wanted_tests(&mut self) -> &mut TrackWantedTests { - &mut self.su.wanted_tests - } - #[throws(AE)] fn drag(&mut self){ let su = &mut self.su;