From dff051ec4457c31709cd36d42285384fe19bd83b Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 3 May 2021 12:45:50 +0100 Subject: [PATCH] path resolution tests: Plumb rctx to various places and use it * otter_rctx * rctx in at-otter Ctx * rctx passed to prepare_game No functional change since this is always default() for the moment. Signed-off-by: Ian Jackson --- apitest/apitest.rs | 30 ++++++++++++++++++++---------- apitest/at-otter.rs | 9 +++++---- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/apitest/apitest.rs b/apitest/apitest.rs index 442d1156..fac1f027 100644 --- a/apitest/apitest.rs +++ b/apitest/apitest.rs @@ -638,14 +638,23 @@ impl DirSubst { } #[throws(AE)] - pub fn otter>(&self, xargs: &[S]) { + pub fn otter<'s,S>(&self, xargs: &'s [S]) + where &'s S: Into + { + self.otter_rctx(&default(), xargs)? + } + + #[throws(AE)] + pub fn otter_rctx<'s,S>(&self, rctx: &ResolveContext, xargs: &'s [S]) + where &'s S: Into + { let ds = self; let exe = ds.subst("@target@/debug/otter")?; let specs = self.subst("@src@/specs")?; - let mut args: Vec<&str> = vec![]; - args.extend(&["--config", CONFIG]); - args.extend(&["--spec-dir", &specs]); - args.extend(xargs.iter().map(AsRef::as_ref)); + let mut args: Vec = vec![]; + args.push("--config" .to_owned()); args.push(rctx.resolve(&CONFIG)); + args.push("--spec-dir".to_owned()); args.push(rctx.resolve(&specs) ); + args.extend(xargs.iter().map(|s| s.into())); let dbg = format!("running {} {:?}", &exe, &args); debug!("{}", &dbg); (||{ @@ -685,13 +694,14 @@ impl DirSubst { } #[throws(AE)] -pub fn prepare_game(ds: &DirSubst, table: &str) -> InstanceName { +pub fn prepare_game(ds: &DirSubst, rctx: &ResolveContext, table: &str) + -> InstanceName { let game_spec = ds.game_spec_path()?; let subst = ds.also(&[ - ("table", table), - ("game_spec", &game_spec), + ("table", table.to_owned()), + ("game_spec", rctx.resolve(&game_spec)), ]); - ds.otter(&subst.ss( + ds.otter_rctx(rctx, &subst.ss( "--account server: \ reset \ --reset-table @specs@/test.table.toml \ @@ -901,7 +911,7 @@ pub fn setup_core(module_paths: &[&str], early_args: EarlyArgPredicate) -> ); let instance_name = - prepare_game(&ds, TABLE).context("setup game")?; + prepare_game(&ds, &default(), TABLE).context("setup game")?; let wanted_tests = opts.tests.track(); diff --git a/apitest/at-otter.rs b/apitest/at-otter.rs index a96baa09..8d82797b 100644 --- a/apitest/at-otter.rs +++ b/apitest/at-otter.rs @@ -18,6 +18,7 @@ struct Ctx { spec: GameSpec, alice: Player, bob: Player, + rctx: ResolveContext, } impl Ctx { @@ -477,12 +478,12 @@ impl Ctx { ["--account", "server:"].iter().cloned().map(Into::into) .chain(args.iter().map(|s| s.as_ref().to_owned())) .collect(); - self.su().ds.otter(&args)?; + self.su().ds.otter_rctx(&self.rctx, &args)?; } #[throws(AE)] fn library_load(&mut self) { - prepare_game(&self.su().ds, TABLE)?; + prepare_game(&self.su().ds, &self.rctx, TABLE)?; let command = self.su().ds.ss( "library-add @table@ wikimedia chess-blue-?" @@ -526,7 +527,7 @@ impl Ctx { #[throws(AE)] fn hidden_hand(&mut self) { - prepare_game(&self.su().ds, TABLE)?; + prepare_game(&self.su().ds, &default(), TABLE)?; let mut alice = self.connect_player(&self.alice)?; let mut bob = self.connect_player(&self.bob)?; self.su_mut().mgmt_conn().fakerng_load(&[&"1",&"0"])?; @@ -703,7 +704,7 @@ fn main() { drop(mc); let su_rc = Rc::new(RefCell::new(su)); - tests(Ctx { opts, spec, su_rc, alice, bob })?; + tests(Ctx { opts, spec, su_rc, alice, bob, rctx: default() })?; } info!("ok"); } -- 2.30.2