aboutsummaryrefslogtreecommitdiff
path: root/tests/test_cmd.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_cmd.rs')
-rw-r--r--tests/test_cmd.rs62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/test_cmd.rs b/tests/test_cmd.rs
new file mode 100644
index 0000000..16f639f
--- /dev/null
+++ b/tests/test_cmd.rs
@@ -0,0 +1,62 @@
+use assert_cmd::cargo::CommandCargoExt as _;
+use std::process::{Command, Stdio};
+
+const NULL: &str = "/dev/null";
+const TRICKY: &str = "testdata/tricky";
+const A: &str = "testdata/a";
+const B: &str = "testdata/b";
+const ANCESTOR: &str = "testdata/ancestor";
+const EXPECTED2: &str = "testdata/expected2";
+const EXPECTED3: &str = "testdata/expected3";
+
+fn merge_then_diff(args: &[&str], expected: &str) -> Result<(), Box<dyn std::error::Error>> {
+ let mut merge = Command::cargo_bin("zsh_history")?
+ .args(args)
+ .stdout(Stdio::piped())
+ .spawn()?;
+
+ let binary_stdout = merge.stdout.take().expect("Failed to capture stdout");
+
+ let mut diff = Command::new("diff")
+ .args(&["-u", expected, "-"])
+ .stdin(Stdio::from(binary_stdout))
+ .stdout(Stdio::inherit())
+ .stderr(Stdio::inherit())
+ .spawn()?;
+
+ let binary_status = merge.wait()?;
+ if !binary_status.success() {
+ return Err(format!("Merge failed with status {:?}", binary_status).into());
+ }
+
+ let diff_status = diff.wait()?;
+ if !diff_status.success() {
+ return Err(format!(
+ "Merging {} produced unexpected result (see diff above).",
+ args.join(" ")
+ )
+ .into());
+ }
+
+ Ok(())
+}
+
+#[test]
+fn test_pass_through() -> Result<(), Box<dyn std::error::Error>> {
+ for file in [NULL, TRICKY] {
+ merge_then_diff(&["merge", file, NULL], file)?;
+ merge_then_diff(&["merge", NULL, file], file)?;
+ merge_then_diff(&["merge", file, file], file)?;
+ }
+ Ok(())
+}
+
+#[test]
+fn test_merge() -> Result<(), Box<dyn std::error::Error>> {
+ merge_then_diff(&["merge", A, B], EXPECTED2)
+}
+
+#[test]
+fn test_merge_with_ancestor() -> Result<(), Box<dyn std::error::Error>> {
+ merge_then_diff(&["merge", A, B, ANCESTOR], EXPECTED3)
+}