From: Ian Jackson Date: Sun, 21 Feb 2021 21:53:39 +0000 (+0000) Subject: apitest: Tests tracking: Encapsulate X-Git-Tag: otter-0.4.0~394 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=621c5a02c02920f9ffb0fda0fc443b41f98006a2;p=otter.git apitest: Tests tracking: Encapsulate NFC Signed-off-by: Ian Jackson --- diff --git a/apitest.rs b/apitest.rs index 3f2472b7..ba455266 100644 --- a/apitest.rs +++ b/apitest.rs @@ -126,13 +126,52 @@ pub struct Opts { pub pause: humantime::Duration, #[structopt(flatten)] - pub tests: WantedTests, + pub tests: WantedTestsOpt, } #[derive(Clone,Debug)] #[derive(StructOpt)] -pub struct WantedTests { - pub tests: Vec, +pub struct WantedTestsOpt { + tests: Vec, +} + +#[derive(Debug)] +pub struct TrackWantedTests { + wanted: WantedTestsOpt, + found: BTreeSet, +} + +impl WantedTestsOpt { + pub fn track(&self) -> TrackWantedTests { + TrackWantedTests { wanted: self.clone(), found: default() } + } +} + +impl TrackWantedTests { + pub fn wantp(&mut self, tname: &str) -> bool { + self.found.insert(tname.to_owned()); + let y = + self.wanted.tests.is_empty() || + self.wanted.tests.iter().any(|s| s==tname); + y + } +} + +impl Drop for TrackWantedTests { + fn drop(&mut self) { + let missing_tests = self.wanted.tests.iter().cloned() + .filter(|s| !self.found.contains(s)) + .collect::>(); + + if !missing_tests.is_empty() { + for f in &self.found { + eprintln!("fyi: test that exists: {}", f); + } + for m in &missing_tests { + eprintln!("warning: unknown test requested: {}", m); + } + } + } } #[derive(Clone,Debug)] diff --git a/wdriver.rs b/wdriver.rs index 6b80c3b1..0e19e4ae 100644 --- a/wdriver.rs +++ b/wdriver.rs @@ -47,7 +47,7 @@ pub struct Setup { pub mgmt_conn: MgmtChannel, pub opts: Opts, pub server_child: process::Child, - found_tests: BTreeSet, + wanted_tests: TrackWantedTests, driver: T4d, current_window: WindowState, screenshot_count: ScreenShotCount, @@ -359,11 +359,7 @@ macro_rules! ctx_with_setup { impl Setup { pub fn want_test(&mut self, tname: &str) -> bool { - self.found_tests.insert(tname.to_owned()); - let y = - self.opts.tests.tests.is_empty() || - self.opts.tests.tests.iter().any(|s| s==tname); - y + self.wanted_tests.wantp(tname) } #[throws(AE)] @@ -651,19 +647,6 @@ impl Drop for Setup { })() .context("screenshots, in Setup::drop") .just_warn(); - - let missing_tests = self.opts.tests.tests.iter().cloned() - .filter(|s| !self.found_tests.contains(s)) - .collect::>(); - - if !missing_tests.is_empty() { - for f in &self.found_tests { - eprintln!("fyi: test that exists: {}", f); - } - for m in &missing_tests { - eprintln!("warning: unknown test requested: {}", m); - } - } } } @@ -711,13 +694,15 @@ pub fn setup(exe_module_path: &str) -> (Setup, Instance) { let (driver, screenshot_count, windows_squirreled) = prepare_thirtyfour().always_context("prepare web session")?; + let wanted_tests = opts.tests.track(); + (Setup { ds, mgmt_conn, server_child, driver, opts, - found_tests: default(), + wanted_tests, screenshot_count, current_window: None, windows_squirreled,