From 57ac9ae893d7557ecfad81364991b116a8780234 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 21 May 2021 20:08:03 +0100 Subject: [PATCH] apitest: Introduce OtterArgsSpec trait Signed-off-by: Ian Jackson --- apitest/apitest.rs | 26 ++++++++++++++++++++------ apitest/main.rs | 11 ++++++----- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/apitest/apitest.rs b/apitest/apitest.rs index cac29c06..c327ee18 100644 --- a/apitest/apitest.rs +++ b/apitest/apitest.rs @@ -741,6 +741,21 @@ impl Drop for OtterOutput { } } +pub trait OtterArgsSpec { + fn to_args(&self) -> Vec; +} + +impl OtterArgsSpec for [S] where for <'s> &'s S: Into { + fn to_args(&self) -> Vec { + self.iter().map(|s| s.into()).collect() + } +} +impl OtterArgsSpec for Vec where for <'s> &'s S: Into { + fn to_args(&self) -> Vec { + self.iter().map(|s| s.into()).collect() + } +} + impl DirSubst { pub fn specs_dir(&self) -> String { format!("{}/specs" , &self.src) @@ -751,16 +766,15 @@ impl DirSubst { } #[throws(AE)] - pub fn otter<'s,S>(&self, xargs: &'s [S]) -> OtterOutput - where &'s S: Into + pub fn otter(&self, xargs: &dyn OtterArgsSpec) -> OtterOutput { self.otter_prctx(&default(), xargs)? } #[throws(AE)] - pub fn otter_prctx<'s,S>(&self, prctx: &PathResolveContext, xargs: &'s [S]) - -> OtterOutput - where &'s S: Into + pub fn otter_prctx(&self, prctx: &PathResolveContext, + xargs: &dyn OtterArgsSpec) + -> OtterOutput { let ds = self; let exe = ds.subst("@target@/debug/otter")?; @@ -768,7 +782,7 @@ impl DirSubst { let mut args: Vec = vec![]; args.push("--config" .to_owned()); args.push(prctx.resolve(&CONFIG)); args.push("--spec-dir".to_owned()); args.push(prctx.resolve(&specs) ); - args.extend(xargs.iter().map(|s| s.into())); + args.extend(xargs.to_args()); let dbg = format!("running {} {:?}", &exe, &args); let mut output = NamedTempFile::new_in( ds.subst("@abstmp@").unwrap() diff --git a/apitest/main.rs b/apitest/main.rs index 6460d7df..6c8dd0dd 100644 --- a/apitest/main.rs +++ b/apitest/main.rs @@ -487,10 +487,10 @@ pub use GrabHow as GH; impl UsualCtx { #[throws(AE)] - pub fn otter>(&mut self, args: &[S]) -> OtterOutput { + pub fn otter(&mut self, args: &dyn OtterArgsSpec) -> OtterOutput { let args: Vec = ["--account", "server:"].iter().cloned().map(Into::into) - .chain(args.iter().map(|s| s.as_ref().to_owned())) + .chain(args.to_args().into_iter()) .collect(); self.su().ds.otter_prctx(&self.prctx, &args)? } @@ -502,13 +502,14 @@ impl UsualCtx { } #[throws(AE)] - pub fn otter_resetting>(&mut self, args: &[S]) -> OtterOutput { + pub fn otter_resetting(&mut self, args: &dyn OtterArgsSpec) + -> OtterOutput { self.has_lib_markers = false; self.otter(args)? } #[throws(Explode)] - fn some_library_add(&mut self, command: &[String]) -> Vec { + fn some_library_add(&mut self, command: &dyn OtterArgsSpec) -> Vec { let mut session = if ! dbgc!(self.has_lib_markers) { let add_err = self.otter(command) .expect_err("library-add succeeded after reset!"); @@ -535,7 +536,7 @@ impl UsualCtx { self.connect_player(&self.alice)? }; - self.otter(&command) + self.otter(command) .expect("library-add failed after place!"); let mut added = vec![]; -- 2.30.2