diff --git a/src/tests.rs b/src/tests.rs index 3cda72d..0ff423c 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -6,11 +6,11 @@ mod tests { use tempfile::tempdir; - // Helper function to run the keep command with given arguments - fn run_keep(args: &[&str]) -> std::process::Output { - let output = Command::new("cargo") - .args(["run", "--",]) - .args(args) + // Helper function to run a command in sh -c + fn run_sh(cmd: &str) -> std::process::Output { + let output = Command::new("sh") + .arg("-c") + .arg(cmd) .output() .expect("Failed to execute command"); output @@ -56,14 +56,8 @@ mod tests { // Save an item with some content let input = "test content"; // Create a command that pipes input to keep with the specified environment - let mut cmd = Command::new("sh"); - cmd.arg("-c") - .arg(format!("echo {} | {}", input, env)); - - cmd.spawn() - .expect("Failed to spawn process") - .wait() - .expect("Failed to wait for child process"); + let cmd = format!("echo {} | {}", input, env); + run_sh(cmd.as_str()).expect("Failed to execute command"); // Verify the item was saved let output = Command::new("sh") @@ -232,15 +226,8 @@ mod tests { // Save an item with some content and tags let input = "test content"; // Create a command that pipes input to keep with the specified environment and tags - let mut cmd = Command::new("sh"); - cmd.arg("-c") - .arg(format!("echo {} | {}", input, env)) - .arg("cargo run -- --save tag1 tag2"); - - cmd.spawn() - .expect("Failed to spawn process") - .wait() - .expect("Failed to wait for child process"); + let cmd = format!("echo {} | {}", input, env); + run_sh(cmd.as_str()).expect("Failed to execute command"); // List items with a specific tag let output = Command::new("sh") @@ -263,15 +250,8 @@ mod tests { // Save an item with some content and compression let input = "test content"; // Create a command that pipes input to keep with the specified environment and compression - let mut cmd = Command::new("sh"); - cmd.arg("-c") - .arg(format!("echo {} | {}", input, env)) - .arg("cargo run -- --save --compression gzip"); - - cmd.spawn() - .expect("Failed to spawn process") - .wait() - .expect("Failed to wait for child process"); + let cmd = format!("echo {} | {}", input, env); + run_sh(cmd.as_str()).expect("Failed to execute command"); // Get the item ID let list_output = Command::new("sh")