diff --git a/src/tests.rs b/src/tests.rs index c9fefa0..3d46f37 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -188,32 +188,24 @@ mod tests { #[test] fn test_list_items() { with_temp_env(|data_dir| { - // Set the data directory for this test + // Create test items with the common environment setup + create_test_items(data_dir, |input, tag| { + // Set the data directory for this test + let env = format!("KEEP_DIR={} cargo run --", data_dir.display()); + + // Create a command that pipes input to keep with the specified environment + let cmd = format!("echo {} | {} {}", input, env, tag); + let output = run_sh(cmd.as_str()); + assert!( + output.status.success(), + "Command failed: {} RC={}", + cmd, + output.status + ); + }); + let env = format!("KEEP_DIR={} cargo run --", data_dir.display()); - // Save an item with some content - let input_a = "test content A"; - let input_b = "test content B"; - - // Create a command that pipes input to keep with the specified environment - let cmd = format!("echo {} A | {} tag tag_a", input_a, env); - let output = run_sh(cmd.as_str()); - assert!( - output.status.success(), - "Command failed: {} RC={}", - cmd, - output.status - ); - - let cmd = format!("echo {} | {} tag tag_b", input_b, env); - let output = run_sh(cmd.as_str()); - assert!( - output.status.success(), - "Command failed: {} RC={}", - cmd, - output.status - ); - let cmd = format!("{} --list", env); let output = run_sh(cmd.as_str()); assert!( @@ -227,7 +219,7 @@ mod tests { let output = run_sh(cmd.as_str()); assert!( output.status.success(), - "Command failed with status: {} RC={}", + "Command failed: {} RC={}", cmd, output.status ); @@ -236,7 +228,7 @@ mod tests { let output = run_sh(cmd.as_str()); assert!( output.status.success(), - "Command failed with status: {} RC={}", + "Command failed: {} RC={}", cmd, output.status );