Skip to content

Commit 46a26e8

Browse files
authored
Merge pull request #58 from oSoMoN/ed-diff-tests-fix-path
Move test assertions in the cfg block where they belong (fixes #3)
2 parents 00a5c0b + 14799ee commit 46a26e8

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

src/ed_diff.rs

+27-27
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,8 @@ mod tests {
188188
for &d in &[0, 1, 2] {
189189
for &e in &[0, 1, 2] {
190190
for &f in &[0, 1, 2] {
191-
use std::fs::{self, File};
191+
use std::fs::File;
192192
use std::io::Write;
193-
use std::process::Command;
194193
let mut alef = Vec::new();
195194
let mut bet = Vec::new();
196195
alef.write_all(if a == 0 { b"a\n" } else { b"b\n" })
@@ -226,7 +225,7 @@ mod tests {
226225
// This test diff is intentionally reversed.
227226
// We want it to turn the alef into bet.
228227
let diff = diff_w(&alef, &bet, &format!("{target}/alef")).unwrap();
229-
File::create("target/ab.ed")
228+
File::create(&format!("{target}/ab.ed"))
230229
.unwrap()
231230
.write_all(&diff)
232231
.unwrap();
@@ -238,17 +237,18 @@ mod tests {
238237
let _ = fb;
239238
#[cfg(not(windows))] // there's no ed on windows
240239
{
240+
use std::process::Command;
241241
let output = Command::new("ed")
242242
.arg(&format!("{target}/alef"))
243-
.stdin(File::open("target/ab.ed").unwrap())
243+
.stdin(File::open(&format!("{target}/ab.ed")).unwrap())
244244
.output()
245245
.unwrap();
246246
assert!(output.status.success(), "{output:?}");
247+
//println!("{}", String::from_utf8_lossy(&output.stdout));
248+
//println!("{}", String::from_utf8_lossy(&output.stderr));
249+
let alef = std::fs::read(&format!("{target}/alef")).unwrap();
250+
assert_eq!(alef, bet);
247251
}
248-
//println!("{}", String::from_utf8_lossy(&output.stdout));
249-
//println!("{}", String::from_utf8_lossy(&output.stderr));
250-
let alef = fs::read(&format!("{target}/alef")).unwrap();
251-
assert_eq!(alef, bet);
252252
}
253253
}
254254
}
@@ -268,9 +268,8 @@ mod tests {
268268
for &d in &[0, 1, 2] {
269269
for &e in &[0, 1, 2] {
270270
for &f in &[0, 1, 2] {
271-
use std::fs::{self, File};
271+
use std::fs::File;
272272
use std::io::Write;
273-
use std::process::Command;
274273
let mut alef = Vec::new();
275274
let mut bet = Vec::new();
276275
alef.write_all(if a == 0 { b"\n" } else { b"b\n" }).unwrap();
@@ -299,30 +298,31 @@ mod tests {
299298
}
300299
// This test diff is intentionally reversed.
301300
// We want it to turn the alef into bet.
302-
let diff = diff_w(&alef, &bet, "target/alef_").unwrap();
303-
File::create("target/ab_.ed")
301+
let diff = diff_w(&alef, &bet, &format!("{target}/alef_")).unwrap();
302+
File::create(&format!("{target}/ab_.ed"))
304303
.unwrap()
305304
.write_all(&diff)
306305
.unwrap();
307-
let mut fa = File::create("target/alef_").unwrap();
306+
let mut fa = File::create(&format!("{target}/alef_")).unwrap();
308307
fa.write_all(&alef[..]).unwrap();
309308
let mut fb = File::create(&format!("{target}/bet_")).unwrap();
310309
fb.write_all(&bet[..]).unwrap();
311310
let _ = fa;
312311
let _ = fb;
313312
#[cfg(not(windows))] // there's no ed on windows
314313
{
314+
use std::process::Command;
315315
let output = Command::new("ed")
316-
.arg("target/alef_")
317-
.stdin(File::open("target/ab_.ed").unwrap())
316+
.arg(&format!("{target}/alef_"))
317+
.stdin(File::open(&format!("{target}/ab_.ed")).unwrap())
318318
.output()
319319
.unwrap();
320320
assert!(output.status.success(), "{output:?}");
321+
//println!("{}", String::from_utf8_lossy(&output.stdout));
322+
//println!("{}", String::from_utf8_lossy(&output.stderr));
323+
let alef = std::fs::read(&format!("{target}/alef_")).unwrap();
324+
assert_eq!(alef, bet);
321325
}
322-
//println!("{}", String::from_utf8_lossy(&output.stdout));
323-
//println!("{}", String::from_utf8_lossy(&output.stderr));
324-
let alef = fs::read("target/alef_").unwrap();
325-
assert_eq!(alef, bet);
326326
}
327327
}
328328
}
@@ -342,9 +342,8 @@ mod tests {
342342
for &d in &[0, 1, 2] {
343343
for &e in &[0, 1, 2] {
344344
for &f in &[0, 1, 2] {
345-
use std::fs::{self, File};
345+
use std::fs::File;
346346
use std::io::Write;
347-
use std::process::Command;
348347
let mut alef = Vec::new();
349348
let mut bet = Vec::new();
350349
alef.write_all(if a == 0 { b"a\n" } else { b"f\n" })
@@ -380,7 +379,7 @@ mod tests {
380379
// This test diff is intentionally reversed.
381380
// We want it to turn the alef into bet.
382381
let diff = diff_w(&alef, &bet, &format!("{target}/alefr")).unwrap();
383-
File::create("target/abr.ed")
382+
File::create(&format!("{target}/abr.ed"))
384383
.unwrap()
385384
.write_all(&diff)
386385
.unwrap();
@@ -392,17 +391,18 @@ mod tests {
392391
let _ = fb;
393392
#[cfg(not(windows))] // there's no ed on windows
394393
{
394+
use std::process::Command;
395395
let output = Command::new("ed")
396396
.arg(&format!("{target}/alefr"))
397-
.stdin(File::open("target/abr.ed").unwrap())
397+
.stdin(File::open(&format!("{target}/abr.ed")).unwrap())
398398
.output()
399399
.unwrap();
400400
assert!(output.status.success(), "{output:?}");
401+
//println!("{}", String::from_utf8_lossy(&output.stdout));
402+
//println!("{}", String::from_utf8_lossy(&output.stderr));
403+
let alef = std::fs::read(&format!("{target}/alefr")).unwrap();
404+
assert_eq!(alef, bet);
401405
}
402-
//println!("{}", String::from_utf8_lossy(&output.stdout));
403-
//println!("{}", String::from_utf8_lossy(&output.stderr));
404-
let alef = fs::read(&format!("{target}/alefr")).unwrap();
405-
assert_eq!(alef, bet);
406406
}
407407
}
408408
}

0 commit comments

Comments
 (0)