Skip to content

Commit a10ef62

Browse files
committed
Ajust the test paths
1 parent 7939749 commit a10ef62

4 files changed

Lines changed: 128 additions & 105 deletions

File tree

src/context_diff.rs

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ pub fn diff(
356356
#[test]
357357
fn test_permutations() {
358358
// test all possible six-line files.
359-
let _ = std::fs::create_dir("target");
359+
let target = "target/context-diff/";
360+
let _ = std::fs::create_dir(target);
360361
for &a in &[0, 1, 2] {
361362
for &b in &[0, 1, 2] {
362363
for &c in &[0, 1, 2] {
@@ -400,29 +401,29 @@ fn test_permutations() {
400401
}
401402
// This test diff is intentionally reversed.
402403
// We want it to turn the alef into bet.
403-
let diff = diff(&alef, "a/alef", &bet, "target/alef", 2);
404-
File::create("target/ab.diff")
404+
let diff = diff(&alef, "a/alef", &bet, &format!("{}/alef", target), 2);
405+
File::create(&format!("{}/ab.diff", target))
405406
.unwrap()
406407
.write_all(&diff)
407408
.unwrap();
408-
let mut fa = File::create("target/alef").unwrap();
409+
let mut fa = File::create(&format!("{}/alef", target)).unwrap();
409410
fa.write_all(&alef[..]).unwrap();
410-
let mut fb = File::create("target/bet").unwrap();
411+
let mut fb = File::create(&format!("{}/bet", target)).unwrap();
411412
fb.write_all(&bet[..]).unwrap();
412413
let _ = fa;
413414
let _ = fb;
414415
let output = Command::new("patch")
415416
.arg("-p0")
416417
.arg("--context")
417-
.stdin(File::open("target/ab.diff").unwrap())
418+
.stdin(File::open(&format!("{}/ab.diff", target)).unwrap())
418419
.output()
419420
.unwrap();
420421
if !output.status.success() {
421422
panic!("{:?}", output);
422423
}
423424
//println!("{}", String::from_utf8_lossy(&output.stdout));
424425
//println!("{}", String::from_utf8_lossy(&output.stderr));
425-
let alef = fs::read("target/alef").unwrap();
426+
let alef = fs::read(&format!("{}/alef", target)).unwrap();
426427
assert_eq!(alef, bet);
427428
}
428429
}
@@ -434,8 +435,9 @@ fn test_permutations() {
434435

435436
#[test]
436437
fn test_permutations_empty_lines() {
438+
let target = "target/context-diff/";
437439
// test all possible six-line files with missing newlines.
438-
let _ = std::fs::create_dir("target");
440+
let _ = std::fs::create_dir(target);
439441
for &a in &[0, 1, 2] {
440442
for &b in &[0, 1, 2] {
441443
for &c in &[0, 1, 2] {
@@ -473,29 +475,30 @@ fn test_permutations_empty_lines() {
473475
}
474476
// This test diff is intentionally reversed.
475477
// We want it to turn the alef into bet.
476-
let diff = diff(&alef, "a/alef_", &bet, "target/alef_", 2);
477-
File::create("target/ab_.diff")
478+
let diff =
479+
diff(&alef, "a/alef_", &bet, &format!("{}/alef_", target), 2);
480+
File::create(&format!("{}/ab_.diff", target))
478481
.unwrap()
479482
.write_all(&diff)
480483
.unwrap();
481-
let mut fa = File::create("target/alef_").unwrap();
484+
let mut fa = File::create(&format!("{}/alef_", target)).unwrap();
482485
fa.write_all(&alef[..]).unwrap();
483-
let mut fb = File::create("target/bet_").unwrap();
486+
let mut fb = File::create(&format!("{}/bet_", target)).unwrap();
484487
fb.write_all(&bet[..]).unwrap();
485488
let _ = fa;
486489
let _ = fb;
487490
let output = Command::new("patch")
488491
.arg("-p0")
489492
.arg("--context")
490-
.stdin(File::open("target/ab_.diff").unwrap())
493+
.stdin(File::open(&format!("{}/ab_.diff", target)).unwrap())
491494
.output()
492495
.unwrap();
493496
if !output.status.success() {
494497
panic!("{:?}", output);
495498
}
496499
//println!("{}", String::from_utf8_lossy(&output.stdout));
497500
//println!("{}", String::from_utf8_lossy(&output.stderr));
498-
let alef = fs::read("target/alef_").unwrap();
501+
let alef = fs::read(&format!("{}/alef_", target)).unwrap();
499502
assert_eq!(alef, bet);
500503
}
501504
}
@@ -507,8 +510,9 @@ fn test_permutations_empty_lines() {
507510

508511
#[test]
509512
fn test_permutations_missing_lines() {
513+
let target = "target/context-diff/";
510514
// test all possible six-line files.
511-
let _ = std::fs::create_dir("target");
515+
let _ = std::fs::create_dir(target);
512516
for &a in &[0, 1, 2] {
513517
for &b in &[0, 1, 2] {
514518
for &c in &[0, 1, 2] {
@@ -549,29 +553,30 @@ fn test_permutations_missing_lines() {
549553
};
550554
// This test diff is intentionally reversed.
551555
// We want it to turn the alef into bet.
552-
let diff = diff(&alef, "a/alefx", &bet, "target/alefx", 2);
553-
File::create("target/abx.diff")
556+
let diff =
557+
diff(&alef, "a/alefx", &bet, &format!("{}/alefx", target), 2);
558+
File::create(&format!("{}/abx.diff", target))
554559
.unwrap()
555560
.write_all(&diff)
556561
.unwrap();
557-
let mut fa = File::create("target/alefx").unwrap();
562+
let mut fa = File::create(&format!("{}/alefx", target)).unwrap();
558563
fa.write_all(&alef[..]).unwrap();
559-
let mut fb = File::create("target/betx").unwrap();
564+
let mut fb = File::create(&format!("{}/betx", target)).unwrap();
560565
fb.write_all(&bet[..]).unwrap();
561566
let _ = fa;
562567
let _ = fb;
563568
let output = Command::new("patch")
564569
.arg("-p0")
565570
.arg("--context")
566-
.stdin(File::open("target/abx.diff").unwrap())
571+
.stdin(File::open(&format!("{}/abx.diff", target)).unwrap())
567572
.output()
568573
.unwrap();
569574
if !output.status.success() {
570575
panic!("{:?}", output);
571576
}
572577
//println!("{}", String::from_utf8_lossy(&output.stdout));
573578
//println!("{}", String::from_utf8_lossy(&output.stderr));
574-
let alef = fs::read("target/alefx").unwrap();
579+
let alef = fs::read(&format!("{}/alefx", target)).unwrap();
575580
assert_eq!(alef, bet);
576581
}
577582
}
@@ -583,8 +588,9 @@ fn test_permutations_missing_lines() {
583588

584589
#[test]
585590
fn test_permutations_reverse() {
591+
let target = "target/context-diff/";
586592
// test all possible six-line files.
587-
let _ = std::fs::create_dir("target");
593+
let _ = std::fs::create_dir(target);
588594
for &a in &[0, 1, 2] {
589595
for &b in &[0, 1, 2] {
590596
for &c in &[0, 1, 2] {
@@ -628,29 +634,30 @@ fn test_permutations_reverse() {
628634
}
629635
// This test diff is intentionally reversed.
630636
// We want it to turn the alef into bet.
631-
let diff = diff(&alef, "a/alefr", &bet, "target/alefr", 2);
632-
File::create("target/abr.diff")
637+
let diff =
638+
diff(&alef, "a/alefr", &bet, &format!("{}/alefr", target), 2);
639+
File::create(&format!("{}/abr.diff", target))
633640
.unwrap()
634641
.write_all(&diff)
635642
.unwrap();
636-
let mut fa = File::create("target/alefr").unwrap();
643+
let mut fa = File::create(&format!("{}/alefr", target)).unwrap();
637644
fa.write_all(&alef[..]).unwrap();
638-
let mut fb = File::create("target/betr").unwrap();
645+
let mut fb = File::create(&format!("{}/betr", target)).unwrap();
639646
fb.write_all(&bet[..]).unwrap();
640647
let _ = fa;
641648
let _ = fb;
642649
let output = Command::new("patch")
643650
.arg("-p0")
644651
.arg("--context")
645-
.stdin(File::open("target/abr.diff").unwrap())
652+
.stdin(File::open(&format!("{}/abr.diff", target)).unwrap())
646653
.output()
647654
.unwrap();
648655
if !output.status.success() {
649656
panic!("{:?}", output);
650657
}
651658
//println!("{}", String::from_utf8_lossy(&output.stdout));
652659
//println!("{}", String::from_utf8_lossy(&output.stderr));
653-
let alef = fs::read("target/alefr").unwrap();
660+
let alef = fs::read(&format!("{}/alefr", target)).unwrap();
654661
assert_eq!(alef, bet);
655662
}
656663
}

src/ed_diff.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,9 @@ pub fn diff_w(expected: &[u8], actual: &[u8], filename: &str) -> Result<Vec<u8>,
154154

155155
#[test]
156156
fn test_permutations() {
157+
let target = "target/ed-diff/";
157158
// test all possible six-line files.
158-
let _ = std::fs::create_dir("target");
159+
let _ = std::fs::create_dir(target);
159160
for &a in &[0, 1, 2] {
160161
for &b in &[0, 1, 2] {
161162
for &c in &[0, 1, 2] {
@@ -199,19 +200,19 @@ fn test_permutations() {
199200
}
200201
// This test diff is intentionally reversed.
201202
// We want it to turn the alef into bet.
202-
let diff = diff_w(&alef, &bet, "target/alef").unwrap();
203+
let diff = diff_w(&alef, &bet, &format!("{}/alef", target)).unwrap();
203204
File::create("target/ab.ed")
204205
.unwrap()
205206
.write_all(&diff)
206207
.unwrap();
207-
let mut fa = File::create("target/alef").unwrap();
208+
let mut fa = File::create(&format!("{}/alef", target)).unwrap();
208209
fa.write_all(&alef[..]).unwrap();
209-
let mut fb = File::create("target/bet").unwrap();
210+
let mut fb = File::create(&format!("{}/bet", target)).unwrap();
210211
fb.write_all(&bet[..]).unwrap();
211212
let _ = fa;
212213
let _ = fb;
213214
let output = Command::new("ed")
214-
.arg("target/alef")
215+
.arg(&format!("{}/alef", target))
215216
.stdin(File::open("target/ab.ed").unwrap())
216217
.output()
217218
.unwrap();
@@ -220,7 +221,7 @@ fn test_permutations() {
220221
}
221222
//println!("{}", String::from_utf8_lossy(&output.stdout));
222223
//println!("{}", String::from_utf8_lossy(&output.stderr));
223-
let alef = fs::read("target/alef").unwrap();
224+
let alef = fs::read(&format!("{}/alef", target)).unwrap();
224225
assert_eq!(alef, bet);
225226
}
226227
}
@@ -232,8 +233,9 @@ fn test_permutations() {
232233

233234
#[test]
234235
fn test_permutations_empty_lines() {
236+
let target = "target/ed-diff/";
235237
// test all possible six-line files with missing newlines.
236-
let _ = std::fs::create_dir("target");
238+
let _ = std::fs::create_dir(target);
237239
for &a in &[0, 1, 2] {
238240
for &b in &[0, 1, 2] {
239241
for &c in &[0, 1, 2] {
@@ -278,7 +280,7 @@ fn test_permutations_empty_lines() {
278280
.unwrap();
279281
let mut fa = File::create("target/alef_").unwrap();
280282
fa.write_all(&alef[..]).unwrap();
281-
let mut fb = File::create("target/bet_").unwrap();
283+
let mut fb = File::create(&format!("{}/bet_", target)).unwrap();
282284
fb.write_all(&bet[..]).unwrap();
283285
let _ = fa;
284286
let _ = fb;
@@ -304,8 +306,9 @@ fn test_permutations_empty_lines() {
304306

305307
#[test]
306308
fn test_permutations_reverse() {
309+
let target = "target/ed-diff/";
307310
// test all possible six-line files.
308-
let _ = std::fs::create_dir("target");
311+
let _ = std::fs::create_dir(target);
309312
for &a in &[0, 1, 2] {
310313
for &b in &[0, 1, 2] {
311314
for &c in &[0, 1, 2] {
@@ -349,19 +352,19 @@ fn test_permutations_reverse() {
349352
}
350353
// This test diff is intentionally reversed.
351354
// We want it to turn the alef into bet.
352-
let diff = diff_w(&alef, &bet, "target/alefr").unwrap();
355+
let diff = diff_w(&alef, &bet, &format!("{}/alefr", target)).unwrap();
353356
File::create("target/abr.ed")
354357
.unwrap()
355358
.write_all(&diff)
356359
.unwrap();
357-
let mut fa = File::create("target/alefr").unwrap();
360+
let mut fa = File::create(&format!("{}/alefr", target)).unwrap();
358361
fa.write_all(&alef[..]).unwrap();
359-
let mut fb = File::create("target/betr").unwrap();
362+
let mut fb = File::create(&format!("{}/betr", target)).unwrap();
360363
fb.write_all(&bet[..]).unwrap();
361364
let _ = fa;
362365
let _ = fb;
363366
let output = Command::new("ed")
364-
.arg("target/alefr")
367+
.arg(&format!("{}/alefr", target))
365368
.stdin(File::open("target/abr.ed").unwrap())
366369
.output()
367370
.unwrap();
@@ -370,7 +373,7 @@ fn test_permutations_reverse() {
370373
}
371374
//println!("{}", String::from_utf8_lossy(&output.stdout));
372375
//println!("{}", String::from_utf8_lossy(&output.stderr));
373-
let alef = fs::read("target/alefr").unwrap();
376+
let alef = fs::read(&format!("{}/alefr", target)).unwrap();
374377
assert_eq!(alef, bet);
375378
}
376379
}

0 commit comments

Comments
 (0)