Skip to content

Commit d73fa83

Browse files
marc-hbsylvestre
authored andcommitted
tests: fix "old" names in generated patch files
Fixes #223. Very simple reproduction ``` cd diffutils mkdir a touch a/alef a/alefn a/alef_ a/alefx a/alefr a/fuzz.file cargo test ``` => fail https://www.gnu.org/software/diffutils/manual/html_node/Multiple-Patches.html states that the "old" file name has precedence over the "new" filename. I hit this problem because some other (and unfortunately: unknown for now) test issue left bogus `a/alef*` file(s) behind in my workspace. I didn't bother cleaning them up because I assumed some test would keep recreating them and that cost me a lot of time. This issue seems to have existed since the very first commit. Interestingly, there as a previous attempt in 2024 to fix this in commit a3a372f ! So I was apparently not the only affected. BUT that fix was immediately reverted by commit ba7cb0a in the same PR. Admittedly, that fix seemed somewhat off-topic in #33. So here it is again.
1 parent be90f75 commit d73fa83

3 files changed

Lines changed: 31 additions & 21 deletions

File tree

fuzz/fuzz_targets/fuzz_patch.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ fuzz_target!(|x: (Vec<u8>, Vec<u8>, u8)| {
2222
return
2323
}*/
2424
fs::create_dir_all("target").unwrap();
25+
let patched = "target/fuzz.file";
2526
let diff = unified_diff::diff(
2627
&from,
2728
&to,
2829
&Params {
29-
from: "a/fuzz.file".into(),
30-
to: "target/fuzz.file".into(),
30+
from: patched.into(),
31+
to: patched.into(),
3132
context_count: context as usize,
3233
..Default::default()
33-
}
34+
},
3435
);
3536
File::create("target/fuzz.file.original")
3637
.unwrap()

src/context_diff.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,13 @@ mod tests {
429429
}
430430
// This test diff is intentionally reversed.
431431
// We want it to turn the alef into bet.
432+
let patched = &format!("{target}/alef");
432433
let diff = diff(
433434
&alef,
434435
&bet,
435436
&Params {
436-
from: "a/alef".into(),
437-
to: (&format!("{target}/alef")).into(),
437+
from: patched.into(),
438+
to: patched.into(),
438439
context_count: 2,
439440
..Default::default()
440441
},
@@ -510,12 +511,13 @@ mod tests {
510511
}
511512
// This test diff is intentionally reversed.
512513
// We want it to turn the alef into bet.
514+
let patched = &format!("{target}/alef_");
513515
let diff = diff(
514516
&alef,
515517
&bet,
516518
&Params {
517-
from: "a/alef_".into(),
518-
to: (&format!("{target}/alef_")).into(),
519+
from: patched.into(),
520+
to: patched.into(),
519521
context_count: 2,
520522
..Default::default()
521523
},
@@ -594,12 +596,13 @@ mod tests {
594596
};
595597
// This test diff is intentionally reversed.
596598
// We want it to turn the alef into bet.
599+
let patched = &format!("{target}/alefx");
597600
let diff = diff(
598601
&alef,
599602
&bet,
600603
&Params {
601-
from: "a/alefx".into(),
602-
to: (&format!("{target}/alefx")).into(),
604+
from: patched.into(),
605+
to: patched.into(),
603606
context_count: 2,
604607
..Default::default()
605608
},
@@ -681,12 +684,13 @@ mod tests {
681684
}
682685
// This test diff is intentionally reversed.
683686
// We want it to turn the alef into bet.
687+
let alefr_path = &format!("{target}/alefr");
684688
let diff = diff(
685689
&alef,
686690
&bet,
687691
&Params {
688-
from: "a/alefr".into(),
689-
to: (&format!("{target}/alefr")).into(),
692+
from: alefr_path.into(),
693+
to: alefr_path.into(),
690694
context_count: 2,
691695
..Default::default()
692696
},

src/unified_diff.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,13 @@ mod tests {
456456
}
457457
// This test diff is intentionally reversed.
458458
// We want it to turn the alef into bet.
459+
let patched = &format!("{target}/alef");
459460
let diff = diff(
460461
&alef,
461462
&bet,
462463
&Params {
463-
from: "a/alef".into(),
464-
to: (&format!("{target}/alef")).into(),
464+
from: patched.into(),
465+
to: patched.into(),
465466
context_count: 2,
466467
..Default::default()
467468
},
@@ -572,12 +573,13 @@ mod tests {
572573
}
573574
// This test diff is intentionally reversed.
574575
// We want it to turn the alef into bet.
576+
let patched = &format!("{target}/alefn");
575577
let diff = diff(
576578
&alef,
577579
&bet,
578580
&Params {
579-
from: "a/alefn".into(),
580-
to: (&format!("{target}/alefn")).into(),
581+
from: patched.into(),
582+
to: patched.into(),
581583
context_count: 2,
582584
..Default::default()
583585
},
@@ -668,12 +670,13 @@ mod tests {
668670
}
669671
// This test diff is intentionally reversed.
670672
// We want it to turn the alef into bet.
673+
let patched = &format!("{target}/alef_");
671674
let diff = diff(
672675
&alef,
673676
&bet,
674677
&Params {
675-
from: "a/alef_".into(),
676-
to: (&format!("{target}/alef_")).into(),
678+
from: patched.into(),
679+
to: patched.into(),
677680
context_count: 2,
678681
..Default::default()
679682
},
@@ -749,12 +752,13 @@ mod tests {
749752
}
750753
// This test diff is intentionally reversed.
751754
// We want it to turn the alef into bet.
755+
let patched = &format!("{target}/alefx");
752756
let diff = diff(
753757
&alef,
754758
&bet,
755759
&Params {
756-
from: "a/alefx".into(),
757-
to: (&format!("{target}/alefx")).into(),
760+
from: patched.into(),
761+
to: patched.into(),
758762
context_count: 2,
759763
..Default::default()
760764
},
@@ -835,12 +839,13 @@ mod tests {
835839
}
836840
// This test diff is intentionally reversed.
837841
// We want it to turn the alef into bet.
842+
let patched = &format!("{target}/alefr");
838843
let diff = diff(
839844
&alef,
840845
&bet,
841846
&Params {
842-
from: "a/alefr".into(),
843-
to: (&format!("{target}/alefr")).into(),
847+
from: patched.into(),
848+
to: patched.into(),
844849
context_count: 2,
845850
..Default::default()
846851
},

0 commit comments

Comments
 (0)