diff --git a/src/process.rs b/src/process.rs index fe26648..35ef174 100644 --- a/src/process.rs +++ b/src/process.rs @@ -13,7 +13,10 @@ use std::process::Stdio; use tokio::process::Command; #[cfg(not(test))] -pub async fn script_exit_code(executable: &str, args: &[impl AsRef]) -> Result { +pub async fn script_exit_code>( + executable: P, + args: &[impl AsRef], +) -> Result { // Run given script and return the exit code let output = Command::new(executable) .args(args) @@ -25,14 +28,17 @@ pub async fn script_exit_code(executable: &str, args: &[impl AsRef]) -> R } #[cfg(test)] -pub async fn script_exit_code(executable: &str, args: &[impl AsRef]) -> Result { +pub async fn script_exit_code>( + executable: P, + args: &[impl AsRef], +) -> Result { let test = crate::testing::current(); let args: Vec<&OsStr> = args.iter().map(|arg| arg.as_ref()).collect(); let cb = test.process_cb.get(); - cb(executable, args.as_ref()).map(|(res, _)| res) + cb(executable.as_ref(), args.as_ref()).map(|(res, _)| res) } -pub async fn run_script(executable: &str, args: &[impl AsRef]) -> Result<()> { +pub async fn run_script>(executable: P, args: &[impl AsRef]) -> Result<()> { // Run given script to get exit code and return true on success. // Return Err on failure, but also print an error if needed match script_exit_code(executable, args).await { @@ -43,7 +49,10 @@ pub async fn run_script(executable: &str, args: &[impl AsRef]) -> Result< } #[cfg(not(test))] -pub async fn script_output(executable: &str, args: &[impl AsRef]) -> Result { +pub async fn script_output>( + executable: P, + args: &[impl AsRef], +) -> Result { // Run given command and return the output given let output = Command::new(executable).args(args).output(); @@ -54,11 +63,14 @@ pub async fn script_output(executable: &str, args: &[impl AsRef]) -> Resu } #[cfg(test)] -pub async fn script_output(executable: &str, args: &[impl AsRef]) -> Result { +pub async fn script_output>( + executable: P, + args: &[impl AsRef], +) -> Result { let test = crate::testing::current(); let args: Vec<&OsStr> = args.iter().map(|arg| arg.as_ref()).collect(); let cb = test.process_cb.get(); - cb(executable, args.as_ref()).map(|(_, res)| res) + cb(executable.as_ref(), args.as_ref()).map(|(_, res)| res) } #[cfg(test)] @@ -66,15 +78,15 @@ pub(crate) mod test { use super::*; use crate::testing; - pub fn ok(_: &str, _: &[&OsStr]) -> Result<(i32, String)> { + pub fn ok(_: &OsStr, _: &[&OsStr]) -> Result<(i32, String)> { Ok((0, String::from("ok"))) } - pub fn code(_: &str, _: &[&OsStr]) -> Result<(i32, String)> { + pub fn code(_: &OsStr, _: &[&OsStr]) -> Result<(i32, String)> { Ok((1, String::from("code"))) } - pub fn exit(_: &str, _: &[&OsStr]) -> Result<(i32, String)> { + pub fn exit(_: &OsStr, _: &[&OsStr]) -> Result<(i32, String)> { Err(anyhow!("oops!")) } diff --git a/src/testing.rs b/src/testing.rs index 5a66052..cc1fe8e 100644 --- a/src/testing.rs +++ b/src/testing.rs @@ -89,7 +89,7 @@ pub struct MockDBus { pub struct Test { base: TempDir, - pub process_cb: Cell Result<(i32, String)>>, + pub process_cb: Cell Result<(i32, String)>>, pub mock_dbus: Cell>, pub dbus_address: Mutex>, }