Ajust the test paths

This commit is contained in:
Sylvestre Ledru
2024-01-23 09:52:49 +01:00
parent 7939749338
commit a10ef621c8
4 changed files with 128 additions and 105 deletions
+35 -28
View File
@@ -356,7 +356,8 @@ pub fn diff(
#[test]
fn test_permutations() {
// test all possible six-line files.
let _ = std::fs::create_dir("target");
let target = "target/context-diff/";
let _ = std::fs::create_dir(target);
for &a in &[0, 1, 2] {
for &b in &[0, 1, 2] {
for &c in &[0, 1, 2] {
@@ -400,21 +401,21 @@ fn test_permutations() {
}
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff = diff(&alef, "a/alef", &bet, "target/alef", 2);
File::create("target/ab.diff")
let diff = diff(&alef, "a/alef", &bet, &format!("{}/alef", target), 2);
File::create(&format!("{}/ab.diff", target))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create("target/alef").unwrap();
let mut fa = File::create(&format!("{}/alef", target)).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create("target/bet").unwrap();
let mut fb = File::create(&format!("{}/bet", target)).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.arg("--context")
.stdin(File::open("target/ab.diff").unwrap())
.stdin(File::open(&format!("{}/ab.diff", target)).unwrap())
.output()
.unwrap();
if !output.status.success() {
@@ -422,7 +423,7 @@ fn test_permutations() {
}
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read("target/alef").unwrap();
let alef = fs::read(&format!("{}/alef", target)).unwrap();
assert_eq!(alef, bet);
}
}
@@ -434,8 +435,9 @@ fn test_permutations() {
#[test]
fn test_permutations_empty_lines() {
let target = "target/context-diff/";
// test all possible six-line files with missing newlines.
let _ = std::fs::create_dir("target");
let _ = std::fs::create_dir(target);
for &a in &[0, 1, 2] {
for &b in &[0, 1, 2] {
for &c in &[0, 1, 2] {
@@ -473,21 +475,22 @@ fn test_permutations_empty_lines() {
}
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff = diff(&alef, "a/alef_", &bet, "target/alef_", 2);
File::create("target/ab_.diff")
let diff =
diff(&alef, "a/alef_", &bet, &format!("{}/alef_", target), 2);
File::create(&format!("{}/ab_.diff", target))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create("target/alef_").unwrap();
let mut fa = File::create(&format!("{}/alef_", target)).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create("target/bet_").unwrap();
let mut fb = File::create(&format!("{}/bet_", target)).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.arg("--context")
.stdin(File::open("target/ab_.diff").unwrap())
.stdin(File::open(&format!("{}/ab_.diff", target)).unwrap())
.output()
.unwrap();
if !output.status.success() {
@@ -495,7 +498,7 @@ fn test_permutations_empty_lines() {
}
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read("target/alef_").unwrap();
let alef = fs::read(&format!("{}/alef_", target)).unwrap();
assert_eq!(alef, bet);
}
}
@@ -507,8 +510,9 @@ fn test_permutations_empty_lines() {
#[test]
fn test_permutations_missing_lines() {
let target = "target/context-diff/";
// test all possible six-line files.
let _ = std::fs::create_dir("target");
let _ = std::fs::create_dir(target);
for &a in &[0, 1, 2] {
for &b in &[0, 1, 2] {
for &c in &[0, 1, 2] {
@@ -549,21 +553,22 @@ fn test_permutations_missing_lines() {
};
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff = diff(&alef, "a/alefx", &bet, "target/alefx", 2);
File::create("target/abx.diff")
let diff =
diff(&alef, "a/alefx", &bet, &format!("{}/alefx", target), 2);
File::create(&format!("{}/abx.diff", target))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create("target/alefx").unwrap();
let mut fa = File::create(&format!("{}/alefx", target)).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create("target/betx").unwrap();
let mut fb = File::create(&format!("{}/betx", target)).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.arg("--context")
.stdin(File::open("target/abx.diff").unwrap())
.stdin(File::open(&format!("{}/abx.diff", target)).unwrap())
.output()
.unwrap();
if !output.status.success() {
@@ -571,7 +576,7 @@ fn test_permutations_missing_lines() {
}
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read("target/alefx").unwrap();
let alef = fs::read(&format!("{}/alefx", target)).unwrap();
assert_eq!(alef, bet);
}
}
@@ -583,8 +588,9 @@ fn test_permutations_missing_lines() {
#[test]
fn test_permutations_reverse() {
let target = "target/context-diff/";
// test all possible six-line files.
let _ = std::fs::create_dir("target");
let _ = std::fs::create_dir(target);
for &a in &[0, 1, 2] {
for &b in &[0, 1, 2] {
for &c in &[0, 1, 2] {
@@ -628,21 +634,22 @@ fn test_permutations_reverse() {
}
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff = diff(&alef, "a/alefr", &bet, "target/alefr", 2);
File::create("target/abr.diff")
let diff =
diff(&alef, "a/alefr", &bet, &format!("{}/alefr", target), 2);
File::create(&format!("{}/abr.diff", target))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create("target/alefr").unwrap();
let mut fa = File::create(&format!("{}/alefr", target)).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create("target/betr").unwrap();
let mut fb = File::create(&format!("{}/betr", target)).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.arg("--context")
.stdin(File::open("target/abr.diff").unwrap())
.stdin(File::open(&format!("{}/abr.diff", target)).unwrap())
.output()
.unwrap();
if !output.status.success() {
@@ -650,7 +657,7 @@ fn test_permutations_reverse() {
}
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read("target/alefr").unwrap();
let alef = fs::read(&format!("{}/alefr", target)).unwrap();
assert_eq!(alef, bet);
}
}
+17 -14
View File
@@ -154,8 +154,9 @@ pub fn diff_w(expected: &[u8], actual: &[u8], filename: &str) -> Result<Vec<u8>,
#[test]
fn test_permutations() {
let target = "target/ed-diff/";
// test all possible six-line files.
let _ = std::fs::create_dir("target");
let _ = std::fs::create_dir(target);
for &a in &[0, 1, 2] {
for &b in &[0, 1, 2] {
for &c in &[0, 1, 2] {
@@ -199,19 +200,19 @@ fn test_permutations() {
}
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff = diff_w(&alef, &bet, "target/alef").unwrap();
let diff = diff_w(&alef, &bet, &format!("{}/alef", target)).unwrap();
File::create("target/ab.ed")
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create("target/alef").unwrap();
let mut fa = File::create(&format!("{}/alef", target)).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create("target/bet").unwrap();
let mut fb = File::create(&format!("{}/bet", target)).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("ed")
.arg("target/alef")
.arg(&format!("{}/alef", target))
.stdin(File::open("target/ab.ed").unwrap())
.output()
.unwrap();
@@ -220,7 +221,7 @@ fn test_permutations() {
}
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read("target/alef").unwrap();
let alef = fs::read(&format!("{}/alef", target)).unwrap();
assert_eq!(alef, bet);
}
}
@@ -232,8 +233,9 @@ fn test_permutations() {
#[test]
fn test_permutations_empty_lines() {
let target = "target/ed-diff/";
// test all possible six-line files with missing newlines.
let _ = std::fs::create_dir("target");
let _ = std::fs::create_dir(target);
for &a in &[0, 1, 2] {
for &b in &[0, 1, 2] {
for &c in &[0, 1, 2] {
@@ -278,7 +280,7 @@ fn test_permutations_empty_lines() {
.unwrap();
let mut fa = File::create("target/alef_").unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create("target/bet_").unwrap();
let mut fb = File::create(&format!("{}/bet_", target)).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
@@ -304,8 +306,9 @@ fn test_permutations_empty_lines() {
#[test]
fn test_permutations_reverse() {
let target = "target/ed-diff/";
// test all possible six-line files.
let _ = std::fs::create_dir("target");
let _ = std::fs::create_dir(target);
for &a in &[0, 1, 2] {
for &b in &[0, 1, 2] {
for &c in &[0, 1, 2] {
@@ -349,19 +352,19 @@ fn test_permutations_reverse() {
}
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff = diff_w(&alef, &bet, "target/alefr").unwrap();
let diff = diff_w(&alef, &bet, &format!("{}/alefr", target)).unwrap();
File::create("target/abr.ed")
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create("target/alefr").unwrap();
let mut fa = File::create(&format!("{}/alefr", target)).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create("target/betr").unwrap();
let mut fb = File::create(&format!("{}/betr", target)).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("ed")
.arg("target/alefr")
.arg(&format!("{}/alefr", target))
.stdin(File::open("target/abr.ed").unwrap())
.output()
.unwrap();
@@ -370,7 +373,7 @@ fn test_permutations_reverse() {
}
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read("target/alefr").unwrap();
let alef = fs::read(&format!("{}/alefr", target)).unwrap();
assert_eq!(alef, bet);
}
}
+32 -28
View File
@@ -170,8 +170,9 @@ pub fn diff(expected: &[u8], actual: &[u8]) -> Vec<u8> {
#[test]
fn test_permutations() {
let target = "target/normal-diff/";
// test all possible six-line files.
let _ = std::fs::create_dir("target");
let _ = std::fs::create_dir(target);
for &a in &[0, 1, 2] {
for &b in &[0, 1, 2] {
for &c in &[0, 1, 2] {
@@ -216,20 +217,20 @@ fn test_permutations() {
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff = diff(&alef, &bet);
File::create("target/ab.diff")
File::create(&format!("{}/ab.diff", target))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create("target/alef").unwrap();
let mut fa = File::create(&format!("{}/alef", target)).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create("target/bet").unwrap();
let mut fb = File::create(&format!("{}/bet", target)).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.arg("target/alef")
.stdin(File::open("target/ab.diff").unwrap())
.arg(&format!("{}/alef", target))
.stdin(File::open(&format!("{}/ab.diff", target)).unwrap())
.output()
.unwrap();
if !output.status.success() {
@@ -237,7 +238,7 @@ fn test_permutations() {
}
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read("target/alef").unwrap();
let alef = fs::read(&format!("{}/alef", target)).unwrap();
assert_eq!(alef, bet);
}
}
@@ -249,8 +250,9 @@ fn test_permutations() {
#[test]
fn test_permutations_missing_line_ending() {
let target = "target/normal-diff/";
// test all possible six-line files with missing newlines.
let _ = std::fs::create_dir("target");
let _ = std::fs::create_dir(target);
for &a in &[0, 1, 2] {
for &b in &[0, 1, 2] {
for &c in &[0, 1, 2] {
@@ -309,21 +311,21 @@ fn test_permutations_missing_line_ending() {
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff = diff(&alef, &bet);
File::create("target/abn.diff")
File::create(&format!("{}/abn.diff", target))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create("target/alefn").unwrap();
let mut fa = File::create(&format!("{}/alefn", target)).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create("target/betn").unwrap();
let mut fb = File::create(&format!("{}/betn", target)).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.arg("--normal")
.arg("target/alefn")
.stdin(File::open("target/abn.diff").unwrap())
.arg(&format!("{}/alefn", target))
.stdin(File::open(&format!("{}/abn.diff", target)).unwrap())
.output()
.unwrap();
if !output.status.success() {
@@ -331,7 +333,7 @@ fn test_permutations_missing_line_ending() {
}
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read("target/alefn").unwrap();
let alef = fs::read(&format!("{}/alefn", target)).unwrap();
assert_eq!(alef, bet);
}
}
@@ -344,8 +346,9 @@ fn test_permutations_missing_line_ending() {
#[test]
fn test_permutations_empty_lines() {
let target = "target/normal-diff/";
// test all possible six-line files with missing newlines.
let _ = std::fs::create_dir("target");
let _ = std::fs::create_dir(target);
for &a in &[0, 1, 2] {
for &b in &[0, 1, 2] {
for &c in &[0, 1, 2] {
@@ -384,20 +387,20 @@ fn test_permutations_empty_lines() {
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff = diff(&alef, &bet);
File::create("target/ab_.diff")
File::create(&format!("{}/ab_.diff", target))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create("target/alef_").unwrap();
let mut fa = File::create(&format!("{}/alef_", target)).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create("target/bet_").unwrap();
let mut fb = File::create(&format!("{}/bet_", target)).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.arg("target/alef_")
.stdin(File::open("target/ab_.diff").unwrap())
.arg(&format!("{}/alef_", target))
.stdin(File::open(&format!("{}/ab_.diff", target)).unwrap())
.output()
.unwrap();
if !output.status.success() {
@@ -405,7 +408,7 @@ fn test_permutations_empty_lines() {
}
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read("target/alef_").unwrap();
let alef = fs::read(&format!("{}/alef_", target)).unwrap();
assert_eq!(alef, bet);
}
}
@@ -417,8 +420,9 @@ fn test_permutations_empty_lines() {
#[test]
fn test_permutations_reverse() {
let target = "target/normal-diff/";
// test all possible six-line files.
let _ = std::fs::create_dir("target");
let _ = std::fs::create_dir(target);
for &a in &[0, 1, 2] {
for &b in &[0, 1, 2] {
for &c in &[0, 1, 2] {
@@ -463,20 +467,20 @@ fn test_permutations_reverse() {
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff = diff(&alef, &bet);
File::create("target/abr.diff")
File::create(&format!("{}/abr.diff", target))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create("target/alefr").unwrap();
let mut fa = File::create(&format!("{}/alefr", target)).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create("target/betr").unwrap();
let mut fb = File::create(&format!("{}/betr", target)).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.arg("target/alefr")
.stdin(File::open("target/abr.diff").unwrap())
.arg(&format!("{}/alefr", target))
.stdin(File::open(&format!("{}/abr.diff", target)).unwrap())
.output()
.unwrap();
if !output.status.success() {
@@ -484,7 +488,7 @@ fn test_permutations_reverse() {
}
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read("target/alefr").unwrap();
let alef = fs::read(&format!("{}/alefr", target)).unwrap();
assert_eq!(alef, bet);
}
}
+44 -35
View File
@@ -384,8 +384,9 @@ pub fn diff(
#[test]
fn test_permutations() {
let target = "target/unified-diff/";
// test all possible six-line files.
let _ = std::fs::create_dir("target");
let _ = std::fs::create_dir(target);
for &a in &[0, 1, 2] {
for &b in &[0, 1, 2] {
for &c in &[0, 1, 2] {
@@ -429,20 +430,20 @@ fn test_permutations() {
}
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff = diff(&alef, "a/alef", &bet, "target/alef", 2);
File::create("target/ab.diff")
let diff = diff(&alef, "a/alef", &bet, &format!("{}/alef", target), 2);
File::create(&format!("{}/ab.diff", target))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create("target/alef").unwrap();
let mut fa = File::create(&format!("{}/alef", target)).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create("target/bet").unwrap();
let mut fb = File::create(&format!("{}/bet", target)).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.stdin(File::open("target/ab.diff").unwrap())
.stdin(File::open(&format!("{}/ab.diff", target)).unwrap())
.output()
.unwrap();
if !output.status.success() {
@@ -450,7 +451,7 @@ fn test_permutations() {
}
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read("target/alef").unwrap();
let alef = fs::read(&format!("{}/alef", target)).unwrap();
assert_eq!(alef, bet);
}
}
@@ -462,8 +463,9 @@ fn test_permutations() {
#[test]
fn test_permutations_missing_line_ending() {
let target = "target/unified-diff/";
// test all possible six-line files with missing newlines.
let _ = std::fs::create_dir("target");
let _ = std::fs::create_dir(target);
for &a in &[0, 1, 2] {
for &b in &[0, 1, 2] {
for &c in &[0, 1, 2] {
@@ -521,20 +523,21 @@ fn test_permutations_missing_line_ending() {
}
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff = diff(&alef, "a/alefn", &bet, "target/alefn", 2);
File::create("target/abn.diff")
let diff =
diff(&alef, "a/alefn", &bet, &format!("{}/alefn", target), 2);
File::create(&format!("{}/abn.diff", target))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create("target/alefn").unwrap();
let mut fa = File::create(&format!("{}/alefn", target)).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create("target/betn").unwrap();
let mut fb = File::create(&format!("{}/betn", target)).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.stdin(File::open("target/abn.diff").unwrap())
.stdin(File::open(&format!("{}/abn.diff", target)).unwrap())
.output()
.unwrap();
if !output.status.success() {
@@ -542,7 +545,7 @@ fn test_permutations_missing_line_ending() {
}
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read("target/alefn").unwrap();
let alef = fs::read(&format!("{}/alefn", target)).unwrap();
assert_eq!(alef, bet);
}
}
@@ -555,8 +558,9 @@ fn test_permutations_missing_line_ending() {
#[test]
fn test_permutations_empty_lines() {
let target = "target/unified-diff/";
// test all possible six-line files with missing newlines.
let _ = std::fs::create_dir("target");
let _ = std::fs::create_dir(target);
for &a in &[0, 1, 2] {
for &b in &[0, 1, 2] {
for &c in &[0, 1, 2] {
@@ -609,20 +613,21 @@ fn test_permutations_empty_lines() {
}
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff = diff(&alef, "a/alef_", &bet, "target/alef_", 2);
File::create("target/ab_.diff")
let diff =
diff(&alef, "a/alef_", &bet, &format!("{}/alef_", target), 2);
File::create(&format!("{}/ab_.diff", target))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create("target/alef_").unwrap();
let mut fa = File::create(&format!("{}/alef_", target)).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create("target/bet_").unwrap();
let mut fb = File::create(&format!("{}/bet_", target)).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.stdin(File::open("target/ab_.diff").unwrap())
.stdin(File::open(&format!("{}/ab_.diff", target)).unwrap())
.output()
.unwrap();
if !output.status.success() {
@@ -630,7 +635,7 @@ fn test_permutations_empty_lines() {
}
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read("target/alef_").unwrap();
let alef = fs::read(&format!("{}/alef_", target)).unwrap();
assert_eq!(alef, bet);
}
}
@@ -643,8 +648,9 @@ fn test_permutations_empty_lines() {
#[test]
fn test_permutations_missing_lines() {
let target = "target/unified-diff/";
// test all possible six-line files.
let _ = std::fs::create_dir("target");
let _ = std::fs::create_dir(target);
for &a in &[0, 1, 2] {
for &b in &[0, 1, 2] {
for &c in &[0, 1, 2] {
@@ -682,20 +688,21 @@ fn test_permutations_missing_lines() {
}
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff = diff(&alef, "a/alefx", &bet, "target/alefx", 2);
File::create("target/abx.diff")
let diff =
diff(&alef, "a/alefx", &bet, &format!("{}/alefx", target), 2);
File::create(&format!("{}/abx.diff", target))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create("target/alefx").unwrap();
let mut fa = File::create(&format!("{}/alefx", target)).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create("target/betx").unwrap();
let mut fb = File::create(&format!("{}/betx", target)).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.stdin(File::open("target/abx.diff").unwrap())
.stdin(File::open(&format!("{}/abx.diff", target)).unwrap())
.output()
.unwrap();
if !output.status.success() {
@@ -703,7 +710,7 @@ fn test_permutations_missing_lines() {
}
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read("target/alefx").unwrap();
let alef = fs::read(&format!("{}/alefx", target)).unwrap();
assert_eq!(alef, bet);
}
}
@@ -715,8 +722,9 @@ fn test_permutations_missing_lines() {
#[test]
fn test_permutations_reverse() {
let target = "target/unified-diff/";
// test all possible six-line files.
let _ = std::fs::create_dir("target");
let _ = std::fs::create_dir(target);
for &a in &[0, 1, 2] {
for &b in &[0, 1, 2] {
for &c in &[0, 1, 2] {
@@ -760,20 +768,21 @@ fn test_permutations_reverse() {
}
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff = diff(&alef, "a/alefr", &bet, "target/alefr", 2);
File::create("target/abr.diff")
let diff =
diff(&alef, "a/alefr", &bet, &format!("{}/alefr", target), 2);
File::create(&format!("{}/abr.diff", target))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create("target/alefr").unwrap();
let mut fa = File::create(&format!("{}/alefr", target)).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create("target/betr").unwrap();
let mut fb = File::create(&format!("{}/betr", target)).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.stdin(File::open("target/abr.diff").unwrap())
.stdin(File::open(&format!("{}/abr.diff", target)).unwrap())
.output()
.unwrap();
if !output.status.success() {
@@ -781,7 +790,7 @@ fn test_permutations_reverse() {
}
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read("target/alefr").unwrap();
let alef = fs::read(&format!("{}/alefr", target)).unwrap();
assert_eq!(alef, bet);
}
}