chiark / gitweb /
apitest: Introduce OtterArgsSpec trait
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 21 May 2021 19:08:03 +0000 (20:08 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 21 May 2021 19:08:03 +0000 (20:08 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
apitest/apitest.rs
apitest/main.rs

index cac29c06e01523ea0bb6a3c42434edbfafddc2ee..c327ee18ef904ec8f79e2dd11b579f9c03230188 100644 (file)
@@ -741,6 +741,21 @@ impl Drop for OtterOutput {
   }
 }
 
+pub trait OtterArgsSpec {
+  fn to_args(&self) -> Vec<String>;
+}
+
+impl<S> OtterArgsSpec for [S] where for <'s> &'s S: Into<String> {
+  fn to_args(&self) -> Vec<String> {
+    self.iter().map(|s| s.into()).collect()
+  }
+}
+impl<S> OtterArgsSpec for Vec<S> where for <'s> &'s S: Into<String> {
+  fn to_args(&self) -> Vec<String> {
+    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<String>
+  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<String>
+  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<String> = 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()
index 6460d7dfb5e49bf12658b602884bb6b9228f48d7..6c8dd0ddb70879500187e4f3bafc56d473000e3b 100644 (file)
@@ -487,10 +487,10 @@ pub use GrabHow as GH;
 
 impl UsualCtx {
   #[throws(AE)]
-  pub fn otter<S:AsRef<str>>(&mut self, args: &[S]) -> OtterOutput {
+  pub fn otter(&mut self, args: &dyn OtterArgsSpec) -> OtterOutput {
     let args: Vec<String> =
       ["--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<S:AsRef<str>>(&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<String> {
+  fn some_library_add(&mut self, command: &dyn OtterArgsSpec) -> Vec<String> {
     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![];