chiark / gitweb /
path resolution tests: Plumb rctx to various places and use it
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 3 May 2021 11:45:50 +0000 (12:45 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 3 May 2021 11:47:44 +0000 (12:47 +0100)
* 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 <ijackson@chiark.greenend.org.uk>
apitest/apitest.rs
apitest/at-otter.rs

index 442d1156cd81c7c13b339467fb287938e4ac0920..fac1f0273e22e3d6765a61dc76c3081c5cb19b62 100644 (file)
@@ -638,14 +638,23 @@ impl DirSubst {
   }
 
   #[throws(AE)]
-  pub fn otter<S:AsRef<str>>(&self, xargs: &[S]) {
+  pub fn otter<'s,S>(&self, xargs: &'s [S])
+  where &'s S: Into<String>
+  {
+    self.otter_rctx(&default(), xargs)?
+  }
+
+  #[throws(AE)]
+  pub fn otter_rctx<'s,S>(&self, rctx: &ResolveContext, xargs: &'s [S])
+  where &'s S: Into<String>
+  {
     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<String> = 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<O>(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();
 
index a96baa0987ccda6d04c8e2ee99f73326f2a22716..8d82797b2ed1c48839d52cb7929ccbc9aba49bed 100644 (file)
@@ -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");
 }