1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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)
}
|