diff --git a/src/tests.rs b/src/tests.rs index c49ea8a..99fa30d 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -4,6 +4,10 @@ mod tests { use std::path::Path; use std::process::Command; + // Global test input values + const INPUT_A: &str = "test content A"; + const INPUT_B: &str = "test content B"; + use tempfile::tempdir; // Helper function to run a command in sh -c @@ -36,9 +40,6 @@ mod tests { // Helper function to create test items with specific content and tags fn create_test_items(dir: &Path) { - // Create the test items - let input_a = "test content A"; - let input_b = "test content B"; // Set the data directory for this test let env = format!("KEEP_DIR={} cargo run -- --verbose", dir.display()); @@ -108,7 +109,7 @@ mod tests { output.status ); let output_str = String::from_utf8_lossy(&output.stdout).to_string(); - assert!(output_str.contains(input_a), "Command output does not contain expected string. Command: {} Output: {} Expected: \"{}\"", cmd, output_str, input_a); + assert!(output_str.contains(INPUT_A), "Command output does not contain expected string. Command: {} Output: {} Expected: \"{}\"", cmd, output_str, INPUT_A); let cmd = format!("{} -g 1", env); let output = run_sh(cmd.as_str()); @@ -119,7 +120,7 @@ mod tests { output.status ); let output_str = String::from_utf8_lossy(&output.stdout).to_string(); - assert!(output_str.contains(input_a), "Command output does not contain expected string. Command: {} Output: {} Expected: \"{}\"", cmd, output_str, input_a); + assert!(output_str.contains(INPUT_A), "Command output does not contain expected string. Command: {} Output: {} Expected: \"{}\"", cmd, output_str, INPUT_A); let cmd = format!("{} 1", env); let output = run_sh(cmd.as_str()); @@ -130,7 +131,7 @@ mod tests { output.status ); let output_str = String::from_utf8_lossy(&output.stdout).to_string(); - assert!(output_str.contains(input_a), "Command output does not contain expected string. Command: {} Output: {} Expected: \"{}\"", cmd, output_str, input_a); + assert!(output_str.contains(INPUT_A), "Command output does not contain expected string. Command: {} Output: {} Expected: \"{}\"", cmd, output_str, INPUT_A); let cmd = format!("{} --get", env); let output = run_sh(cmd.as_str()); @@ -141,7 +142,7 @@ mod tests { output.status ); let output_str = String::from_utf8_lossy(&output.stdout).to_string(); - assert!(output_str.contains(input_b), "Command output does not contain expected string. Command: {} Output: {} Expected: \"{}\"", cmd, output_str, input_b); + assert!(output_str.contains(INPUT_B), "Command output does not contain expected string. Command: {} Output: {} Expected: \"{}\"", cmd, output_str, INPUT_B); let cmd = format!("{} --get tag_a", env); let output = run_sh(cmd.as_str()); @@ -152,7 +153,7 @@ mod tests { output.status ); let output_str = String::from_utf8_lossy(&output.stdout).to_string(); - assert!(output_str.contains(input_a), "Command output does not contain expected string. Command: {} Output: {} Expected: \"{}\"", cmd, output_str, input_a); + assert!(output_str.contains(INPUT_A), "Command output does not contain expected string. Command: {} Output: {} Expected: \"{}\"", cmd, output_str, INPUT_A); let cmd = format!("{} --get tag_b", env); let output = run_sh(cmd.as_str()); @@ -163,7 +164,7 @@ mod tests { output.status ); let output_str = String::from_utf8_lossy(&output.stdout).to_string(); - assert!(output_str.contains(input_b), "Command output does not contain expected string. Command: {} Output: {} Expected: \"{}\"", cmd, output_str, input_b); + assert!(output_str.contains(INPUT_B), "Command output does not contain expected string. Command: {} Output: {} Expected: \"{}\"", cmd, output_str, INPUT_B); let cmd = format!("{} --get tag", env); let output = run_sh(cmd.as_str()); @@ -174,7 +175,7 @@ mod tests { output.status ); let output_str = String::from_utf8_lossy(&output.stdout).to_string(); - assert!(output_str.contains(input_b), "Command output does not contain expected string. Command: {} Output: {} Expected: \"{}\"", cmd, output_str, input_b); + assert!(output_str.contains(INPUT_B), "Command output does not contain expected string. Command: {} Output: {} Expected: \"{}\"", cmd, output_str, INPUT_B); }); } @@ -282,9 +283,9 @@ mod tests { output.status ); let output_str = String::from_utf8_lossy(&output.stdout).to_string(); - assert!(output_str.contains(input_a), "Command output does not contain expected string. Command: {} Output: {} Expected: \"{}\"", cmd, output_str, input_a); + assert!(output_str.contains(INPUT_A), "Command output does not contain expected string. Command: {} Output: {} Expected: \"{}\"", cmd, output_str, INPUT_A); let output_str = String::from_utf8_lossy(&output.stdout).to_string(); - assert!(output_str.contains(input_b), "Command output does not contain expected string. Command: {} Output: {} Expected: \"{}\"", cmd, output_str, input_b); + assert!(output_str.contains(INPUT_B), "Command output does not contain expected string. Command: {} Output: {} Expected: \"{}\"", cmd, output_str, INPUT_B); let cmd = format!("{} --diff tag_a tag_b", env); let output = run_sh(cmd.as_str());