Skip to content

Commit

Permalink
Ajust the test paths
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed Jan 23, 2024
1 parent 7939749 commit a10ef62
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 105 deletions.
63 changes: 35 additions & 28 deletions src/context_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down Expand Up @@ -400,29 +401,29 @@ 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() {
panic!("{:?}", output);
}
//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);
}
}
Expand All @@ -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] {
Expand Down Expand Up @@ -473,29 +475,30 @@ 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() {
panic!("{:?}", output);
}
//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);
}
}
Expand All @@ -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] {
Expand Down Expand Up @@ -549,29 +553,30 @@ 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() {
panic!("{:?}", output);
}
//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);
}
}
Expand All @@ -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] {
Expand Down Expand Up @@ -628,29 +634,30 @@ 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() {
panic!("{:?}", output);
}
//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);
}
}
Expand Down
31 changes: 17 additions & 14 deletions src/ed_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
}
Expand All @@ -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] {
Expand Down Expand Up @@ -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;
Expand All @@ -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] {
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
}
Expand Down
Loading

0 comments on commit a10ef62

Please sign in to comment.