Skip to content

Commit ba7cb0a

Browse files
Do not create dummy files
Since we now returning SystemTime::now() for invalid file input, there is no need to crate dummy files
1 parent 33783d0 commit ba7cb0a

File tree

2 files changed

+28
-57
lines changed

2 files changed

+28
-57
lines changed

src/context_diff.rs

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -427,15 +427,13 @@ mod tests {
427427
if f != 2 {
428428
bet.write_all(b"l\n").unwrap();
429429
}
430-
let _ = File::create(&format!("{target}/aalef")).unwrap();
431-
let mut fa = File::create(&format!("{target}/alef")).unwrap();
432430
// This test diff is intentionally reversed.
433431
// We want it to turn the alef into bet.
434432
let diff = diff(
435433
&alef,
436434
&bet,
437435
&Params {
438-
from: (&format!("{target}/aalef")).into(),
436+
from: "a/alef".into(),
439437
to: (&format!("{target}/alef")).into(),
440438
context_count: 2,
441439
..Default::default()
@@ -445,6 +443,7 @@ mod tests {
445443
.unwrap()
446444
.write_all(&diff)
447445
.unwrap();
446+
let mut fa = File::create(&format!("{target}/alef")).unwrap();
448447
fa.write_all(&alef[..]).unwrap();
449448
let mut fb = File::create(&format!("{target}/bet")).unwrap();
450449
fb.write_all(&bet[..]).unwrap();
@@ -509,15 +508,13 @@ mod tests {
509508
if f != 2 {
510509
bet.write_all(b"l\n").unwrap();
511510
}
512-
let _ = File::create(&format!("{target}/aalef_")).unwrap();
513-
let mut fa = File::create(&format!("{target}/alef_")).unwrap();
514511
// This test diff is intentionally reversed.
515512
// We want it to turn the alef into bet.
516513
let diff = diff(
517514
&alef,
518515
&bet,
519516
&Params {
520-
from: (&format!("{target}/aalef_")).into(),
517+
from: "a/alef_".into(),
521518
to: (&format!("{target}/alef_")).into(),
522519
context_count: 2,
523520
..Default::default()
@@ -527,6 +524,7 @@ mod tests {
527524
.unwrap()
528525
.write_all(&diff)
529526
.unwrap();
527+
let mut fa = File::create(&format!("{target}/alef_")).unwrap();
530528
fa.write_all(&alef[..]).unwrap();
531529
let mut fb = File::create(&format!("{target}/bet_")).unwrap();
532530
fb.write_all(&bet[..]).unwrap();
@@ -594,15 +592,13 @@ mod tests {
594592
if alef.is_empty() && bet.is_empty() {
595593
continue;
596594
};
597-
let _ = File::create(&format!("{target}/aalefx")).unwrap();
598-
let mut fa = File::create(&format!("{target}/alefx")).unwrap();
599595
// This test diff is intentionally reversed.
600596
// We want it to turn the alef into bet.
601597
let diff = diff(
602598
&alef,
603599
&bet,
604600
&Params {
605-
from: (&format!("{target}/aalefx")).into(),
601+
from: "a/alefx".into(),
606602
to: (&format!("{target}/alefx")).into(),
607603
context_count: 2,
608604
..Default::default()
@@ -612,6 +608,7 @@ mod tests {
612608
.unwrap()
613609
.write_all(&diff)
614610
.unwrap();
611+
let mut fa = File::create(&format!("{target}/alefx")).unwrap();
615612
fa.write_all(&alef[..]).unwrap();
616613
let mut fb = File::create(&format!("{target}/betx")).unwrap();
617614
fb.write_all(&bet[..]).unwrap();
@@ -682,15 +679,13 @@ mod tests {
682679
if f != 2 {
683680
bet.write_all(b"f\n").unwrap();
684681
}
685-
let _ = File::create(&format!("{target}/aalefr")).unwrap();
686-
let mut fa = File::create(&format!("{target}/alefr")).unwrap();
687682
// This test diff is intentionally reversed.
688683
// We want it to turn the alef into bet.
689684
let diff = diff(
690685
&alef,
691686
&bet,
692687
&Params {
693-
from: (&format!("{target}/aalefr")).into(),
688+
from: "a/alefr".into(),
694689
to: (&format!("{target}/alefr")).into(),
695690
context_count: 2,
696691
..Default::default()
@@ -700,6 +695,7 @@ mod tests {
700695
.unwrap()
701696
.write_all(&diff)
702697
.unwrap();
698+
let mut fa = File::create(&format!("{target}/alefr")).unwrap();
703699
fa.write_all(&alef[..]).unwrap();
704700
let mut fb = File::create(&format!("{target}/betr")).unwrap();
705701
fb.write_all(&bet[..]).unwrap();
@@ -727,15 +723,10 @@ mod tests {
727723
#[test]
728724
fn test_stop_early() {
729725
use crate::assert_diff_eq;
730-
use std::fs::File;
731726

732-
let target = "target/context-diff";
733-
let _ = std::fs::create_dir(target);
734-
let from_filename = &format!("{target}/foo");
735-
let _ = File::create(from_filename).unwrap();
727+
let from_filename = "foo";
736728
let from = ["a", "b", "c", ""].join("\n");
737-
let to_filename = &format!("{target}/bar");
738-
let _ = File::create(to_filename).unwrap();
729+
let to_filename = "bar";
739730
let to = ["a", "d", "c", ""].join("\n");
740731

741732
let diff_full = diff(
@@ -749,8 +740,8 @@ mod tests {
749740
);
750741

751742
let expected_full = [
752-
"*** target/context-diff/foo\tTIMESTAMP",
753-
"--- target/context-diff/bar\tTIMESTAMP",
743+
"*** foo\tTIMESTAMP",
744+
"--- bar\tTIMESTAMP",
754745
"***************",
755746
"*** 1,3 ****",
756747
" a",
@@ -776,12 +767,7 @@ mod tests {
776767
},
777768
);
778769

779-
let expected_brief = [
780-
"*** target/context-diff/foo\tTIMESTAMP",
781-
"--- target/context-diff/bar\tTIMESTAMP",
782-
"",
783-
]
784-
.join("\n");
770+
let expected_brief = ["*** foo\tTIMESTAMP", "--- bar\tTIMESTAMP", ""].join("\n");
785771
assert_diff_eq!(diff_brief, expected_brief);
786772

787773
let nodiff_full = diff(

src/unified_diff.rs

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -454,15 +454,13 @@ mod tests {
454454
if f != 2 {
455455
bet.write_all(b"l\n").unwrap();
456456
}
457-
let _ = File::create(&format!("{target}/aalef")).unwrap();
458-
let mut fa = File::create(&format!("{target}/alef")).unwrap();
459457
// This test diff is intentionally reversed.
460458
// We want it to turn the alef into bet.
461459
let diff = diff(
462460
&alef,
463461
&bet,
464462
&Params {
465-
from: (&format!("{target}/aalef")).into(),
463+
from: "a/alef".into(),
466464
to: (&format!("{target}/alef")).into(),
467465
context_count: 2,
468466
..Default::default()
@@ -472,6 +470,7 @@ mod tests {
472470
.unwrap()
473471
.write_all(&diff)
474472
.unwrap();
473+
let mut fa = File::create(&format!("{target}/alef")).unwrap();
475474
fa.write_all(&alef[..]).unwrap();
476475
let mut fb = File::create(&format!("{target}/bet")).unwrap();
477476
fb.write_all(&bet[..]).unwrap();
@@ -571,15 +570,13 @@ mod tests {
571570
}
572571
_ => unreachable!(),
573572
}
574-
let _ = File::create(&format!("{target}/aalefn")).unwrap();
575-
let mut fa = File::create(&format!("{target}/alefn")).unwrap();
576573
// This test diff is intentionally reversed.
577574
// We want it to turn the alef into bet.
578575
let diff = diff(
579576
&alef,
580577
&bet,
581578
&Params {
582-
from: (&format!("{target}/aalefn")).into(),
579+
from: "a/alefn".into(),
583580
to: (&format!("{target}/alefn")).into(),
584581
context_count: 2,
585582
..Default::default()
@@ -589,6 +586,7 @@ mod tests {
589586
.unwrap()
590587
.write_all(&diff)
591588
.unwrap();
589+
let mut fa = File::create(&format!("{target}/alefn")).unwrap();
592590
fa.write_all(&alef[..]).unwrap();
593591
let mut fb = File::create(&format!("{target}/betn")).unwrap();
594592
fb.write_all(&bet[..]).unwrap();
@@ -668,15 +666,13 @@ mod tests {
668666
3 => {}
669667
_ => unreachable!(),
670668
}
671-
let _ = File::create(&format!("{target}/aalef_")).unwrap();
672-
let mut fa = File::create(&format!("{target}/alef_")).unwrap();
673669
// This test diff is intentionally reversed.
674670
// We want it to turn the alef into bet.
675671
let diff = diff(
676672
&alef,
677673
&bet,
678674
&Params {
679-
from: (&format!("{target}/aalef_")).into(),
675+
from: "a/alef_".into(),
680676
to: (&format!("{target}/alef_")).into(),
681677
context_count: 2,
682678
..Default::default()
@@ -686,6 +682,7 @@ mod tests {
686682
.unwrap()
687683
.write_all(&diff)
688684
.unwrap();
685+
let mut fa = File::create(&format!("{target}/alef_")).unwrap();
689686
fa.write_all(&alef[..]).unwrap();
690687
let mut fb = File::create(&format!("{target}/bet_")).unwrap();
691688
fb.write_all(&bet[..]).unwrap();
@@ -750,15 +747,13 @@ mod tests {
750747
if f != 2 {
751748
bet.write_all(b"l\n").unwrap();
752749
}
753-
let _ = File::create(&format!("{target}/aalefx")).unwrap();
754-
let mut fa = File::create(&format!("{target}/alefx")).unwrap();
755750
// This test diff is intentionally reversed.
756751
// We want it to turn the alef into bet.
757752
let diff = diff(
758753
&alef,
759754
&bet,
760755
&Params {
761-
from: (&format!("{target}/aalefx")).into(),
756+
from: "a/alefx".into(),
762757
to: (&format!("{target}/alefx")).into(),
763758
context_count: 2,
764759
..Default::default()
@@ -768,6 +763,7 @@ mod tests {
768763
.unwrap()
769764
.write_all(&diff)
770765
.unwrap();
766+
let mut fa = File::create(&format!("{target}/alefx")).unwrap();
771767
fa.write_all(&alef[..]).unwrap();
772768
let mut fb = File::create(&format!("{target}/betx")).unwrap();
773769
fb.write_all(&bet[..]).unwrap();
@@ -837,15 +833,13 @@ mod tests {
837833
if f != 2 {
838834
bet.write_all(b"f\n").unwrap();
839835
}
840-
let _ = File::create(&format!("{target}/aalefr")).unwrap();
841-
let mut fa = File::create(&format!("{target}/alefr")).unwrap();
842836
// This test diff is intentionally reversed.
843837
// We want it to turn the alef into bet.
844838
let diff = diff(
845839
&alef,
846840
&bet,
847841
&Params {
848-
from: (&format!("{target}/aalefr")).into(),
842+
from: "a/alefr".into(),
849843
to: (&format!("{target}/alefr")).into(),
850844
context_count: 2,
851845
..Default::default()
@@ -855,6 +849,7 @@ mod tests {
855849
.unwrap()
856850
.write_all(&diff)
857851
.unwrap();
852+
let mut fa = File::create(&format!("{target}/alefr")).unwrap();
858853
fa.write_all(&alef[..]).unwrap();
859854
let mut fb = File::create(&format!("{target}/betr")).unwrap();
860855
fb.write_all(&bet[..]).unwrap();
@@ -881,15 +876,10 @@ mod tests {
881876
#[test]
882877
fn test_stop_early() {
883878
use crate::assert_diff_eq;
884-
use std::fs::File;
885879

886-
let target = "target/context-diff";
887-
let _ = std::fs::create_dir(target);
888-
let from_filename = &format!("{target}/foo");
889-
let _ = File::create(from_filename).unwrap();
880+
let from_filename = "foo";
890881
let from = ["a", "b", "c", ""].join("\n");
891-
let to_filename = &format!("{target}/bar");
892-
let _ = File::create(to_filename).unwrap();
882+
let to_filename = "bar";
893883
let to = ["a", "d", "c", ""].join("\n");
894884

895885
let diff_full = diff(
@@ -903,8 +893,8 @@ mod tests {
903893
);
904894

905895
let expected_full = [
906-
"--- target/context-diff/foo\tTIMESTAMP",
907-
"+++ target/context-diff/bar\tTIMESTAMP",
896+
"--- foo\tTIMESTAMP",
897+
"+++ bar\tTIMESTAMP",
908898
"@@ -1,3 +1,3 @@",
909899
" a",
910900
"-b",
@@ -926,12 +916,7 @@ mod tests {
926916
},
927917
);
928918

929-
let expected_brief = [
930-
"--- target/context-diff/foo\tTIMESTAMP",
931-
"+++ target/context-diff/bar\tTIMESTAMP",
932-
"",
933-
]
934-
.join("\n");
919+
let expected_brief = ["--- foo\tTIMESTAMP", "+++ bar\tTIMESTAMP", ""].join("\n");
935920
assert_diff_eq!(diff_brief, expected_brief);
936921

937922
let nodiff_full = diff(

0 commit comments

Comments
 (0)