run clippy pedantic

$ cargo +nightly clippy --allow-dirty --fix -- -W clippy::pedantic
This commit is contained in:
Sylvestre Ledru
2024-01-23 11:42:12 +01:00
parent fdc35f6b8e
commit d891e1034d
6 changed files with 133 additions and 184 deletions
+34 -43
View File
@@ -253,6 +253,7 @@ fn make_diff(expected: &[u8], actual: &[u8], context_size: usize) -> Vec<Mismatc
results
}
#[must_use]
pub fn diff(
expected: &[u8],
expected_filename: &str,
@@ -260,8 +261,7 @@ pub fn diff(
actual_filename: &str,
context_size: usize,
) -> Vec<u8> {
let mut output =
format!("*** {}\t\n--- {}\t\n", expected_filename, actual_filename).into_bytes();
let mut output = format!("*** {expected_filename}\t\n--- {actual_filename}\t\n").into_bytes();
let diff_results = make_diff(expected, actual, context_size);
if diff_results.is_empty() {
return Vec::new();
@@ -284,17 +284,16 @@ pub fn diff(
let exp_start = if end_line_number_expected == line_number_expected {
String::new()
} else {
format!("{},", line_number_expected)
format!("{line_number_expected},")
};
let act_start = if end_line_number_actual == line_number_actual {
String::new()
} else {
format!("{},", line_number_actual)
format!("{line_number_actual},")
};
writeln!(
output,
"***************\n*** {}{} ****",
exp_start, end_line_number_expected
"***************\n*** {exp_start}{end_line_number_expected} ****"
)
.expect("write to Vec is infallible");
if !result.expected_all_context {
@@ -322,7 +321,7 @@ pub fn diff(
.expect("write to Vec is infallible");
}
}
writeln!(output, "--- {}{} ----", act_start, end_line_number_actual)
writeln!(output, "--- {act_start}{end_line_number_actual} ----")
.expect("write to Vec is infallible");
if !result.actual_all_context {
for line in result.actual {
@@ -406,29 +405,27 @@ mod tests {
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff =
diff(&alef, "a/alef", &bet, &format!("{}/alef", target), 2);
File::create(&format!("{}/ab.diff", target))
diff(&alef, "a/alef", &bet, &format!("{target}/alef"), 2);
File::create(&format!("{target}/ab.diff"))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create(&format!("{}/alef", target)).unwrap();
let mut fa = File::create(&format!("{target}/alef")).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create(&format!("{}/bet", target)).unwrap();
let mut fb = File::create(&format!("{target}/bet")).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.arg("--context")
.stdin(File::open(&format!("{}/ab.diff", target)).unwrap())
.stdin(File::open(&format!("{target}/ab.diff")).unwrap())
.output()
.unwrap();
if !output.status.success() {
panic!("{:?}", output);
}
assert!(output.status.success(), "{:?}", output);
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read(&format!("{}/alef", target)).unwrap();
let alef = fs::read(&format!("{target}/alef")).unwrap();
assert_eq!(alef, bet);
}
}
@@ -481,29 +478,27 @@ mod tests {
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff =
diff(&alef, "a/alef_", &bet, &format!("{}/alef_", target), 2);
File::create(&format!("{}/ab_.diff", target))
diff(&alef, "a/alef_", &bet, &format!("{target}/alef_"), 2);
File::create(&format!("{target}/ab_.diff"))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create(&format!("{}/alef_", target)).unwrap();
let mut fa = File::create(&format!("{target}/alef_")).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create(&format!("{}/bet_", target)).unwrap();
let mut fb = File::create(&format!("{target}/bet_")).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.arg("--context")
.stdin(File::open(&format!("{}/ab_.diff", target)).unwrap())
.stdin(File::open(&format!("{target}/ab_.diff")).unwrap())
.output()
.unwrap();
if !output.status.success() {
panic!("{:?}", output);
}
assert!(output.status.success(), "{:?}", output);
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read(&format!("{}/alef_", target)).unwrap();
let alef = fs::read(&format!("{target}/alef_")).unwrap();
assert_eq!(alef, bet);
}
}
@@ -559,29 +554,27 @@ mod tests {
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff =
diff(&alef, "a/alefx", &bet, &format!("{}/alefx", target), 2);
File::create(&format!("{}/abx.diff", target))
diff(&alef, "a/alefx", &bet, &format!("{target}/alefx"), 2);
File::create(&format!("{target}/abx.diff"))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create(&format!("{}/alefx", target)).unwrap();
let mut fa = File::create(&format!("{target}/alefx")).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create(&format!("{}/betx", target)).unwrap();
let mut fb = File::create(&format!("{target}/betx")).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.arg("--context")
.stdin(File::open(&format!("{}/abx.diff", target)).unwrap())
.stdin(File::open(&format!("{target}/abx.diff")).unwrap())
.output()
.unwrap();
if !output.status.success() {
panic!("{:?}", output);
}
assert!(output.status.success(), "{:?}", output);
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read(&format!("{}/alefx", target)).unwrap();
let alef = fs::read(&format!("{target}/alefx")).unwrap();
assert_eq!(alef, bet);
}
}
@@ -640,29 +633,27 @@ mod tests {
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff =
diff(&alef, "a/alefr", &bet, &format!("{}/alefr", target), 2);
File::create(&format!("{}/abr.diff", target))
diff(&alef, "a/alefr", &bet, &format!("{target}/alefr"), 2);
File::create(&format!("{target}/abr.diff"))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create(&format!("{}/alefr", target)).unwrap();
let mut fa = File::create(&format!("{target}/alefr")).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create(&format!("{}/betr", target)).unwrap();
let mut fb = File::create(&format!("{target}/betr")).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.arg("--context")
.stdin(File::open(&format!("{}/abr.diff", target)).unwrap())
.stdin(File::open(&format!("{target}/abr.diff")).unwrap())
.output()
.unwrap();
if !output.status.success() {
panic!("{:?}", output);
}
assert!(output.status.success(), "{:?}", output);
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read(&format!("{}/alefr", target)).unwrap();
let alef = fs::read(&format!("{target}/alefr")).unwrap();
assert_eq!(alef, bet);
}
}
+15 -23
View File
@@ -152,7 +152,7 @@ mod tests {
use super::*;
pub fn diff_w(expected: &[u8], actual: &[u8], filename: &str) -> Result<Vec<u8>, DiffError> {
let mut output = diff(expected, actual)?;
writeln!(&mut output, "w {}", filename).unwrap();
writeln!(&mut output, "w {filename}").unwrap();
Ok(output)
}
@@ -204,29 +204,26 @@ mod tests {
}
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff =
diff_w(&alef, &bet, &format!("{}/alef", target)).unwrap();
let diff = diff_w(&alef, &bet, &format!("{target}/alef")).unwrap();
File::create("target/ab.ed")
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create(&format!("{}/alef", target)).unwrap();
let mut fa = File::create(&format!("{target}/alef")).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create(&format!("{}/bet", target)).unwrap();
let mut fb = File::create(&format!("{target}/bet")).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("ed")
.arg(&format!("{}/alef", target))
.arg(&format!("{target}/alef"))
.stdin(File::open("target/ab.ed").unwrap())
.output()
.unwrap();
if !output.status.success() {
panic!("{:?}", output);
}
assert!(output.status.success(), "{:?}", output);
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read(&format!("{}/alef", target)).unwrap();
let alef = fs::read(&format!("{target}/alef")).unwrap();
assert_eq!(alef, bet);
}
}
@@ -285,7 +282,7 @@ mod tests {
.unwrap();
let mut fa = File::create("target/alef_").unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create(&format!("{}/bet_", target)).unwrap();
let mut fb = File::create(&format!("{target}/bet_")).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
@@ -294,9 +291,7 @@ mod tests {
.stdin(File::open("target/ab_.ed").unwrap())
.output()
.unwrap();
if !output.status.success() {
panic!("{:?}", output);
}
assert!(output.status.success(), "{:?}", output);
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read("target/alef_").unwrap();
@@ -357,29 +352,26 @@ mod tests {
}
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff =
diff_w(&alef, &bet, &format!("{}/alefr", target)).unwrap();
let diff = diff_w(&alef, &bet, &format!("{target}/alefr")).unwrap();
File::create("target/abr.ed")
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create(&format!("{}/alefr", target)).unwrap();
let mut fa = File::create(&format!("{target}/alefr")).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create(&format!("{}/betr", target)).unwrap();
let mut fb = File::create(&format!("{target}/betr")).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("ed")
.arg(&format!("{}/alefr", target))
.arg(&format!("{target}/alefr"))
.stdin(File::open("target/abr.ed").unwrap())
.output()
.unwrap();
if !output.status.success() {
panic!("{:?}", output);
}
assert!(output.status.success(), "{:?}", output);
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read(&format!("{}/alefr", target)).unwrap();
let alef = fs::read(&format!("{target}/alefr")).unwrap();
assert_eq!(alef, bet);
}
}
+3 -3
View File
@@ -3,7 +3,7 @@
// For the full copyright and license information, please view the LICENSE-*
// files that was distributed with this source code.
use crate::params::*;
use crate::params::{parse_params, Format, Params};
use std::env;
use std::fs;
@@ -27,13 +27,13 @@ fn main() -> Result<(), String> {
let from_content = match fs::read(&from) {
Ok(from_content) => from_content,
Err(e) => {
return Err(format!("Failed to read from-file: {}", e));
return Err(format!("Failed to read from-file: {e}"));
}
};
let to_content = match fs::read(&to) {
Ok(to_content) => to_content,
Err(e) => {
return Err(format!("Failed to read from-file: {}", e));
return Err(format!("Failed to read from-file: {e}"));
}
};
// run diff
+29 -37
View File
@@ -109,6 +109,7 @@ fn make_diff(expected: &[u8], actual: &[u8]) -> Vec<Mismatch> {
results
}
#[must_use]
pub fn diff(expected: &[u8], actual: &[u8]) -> Vec<u8> {
let mut output = Vec::new();
let diff_results = make_diff(expected, actual);
@@ -221,28 +222,26 @@ mod tests {
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff = diff(&alef, &bet);
File::create(&format!("{}/ab.diff", target))
File::create(&format!("{target}/ab.diff"))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create(&format!("{}/alef", target)).unwrap();
let mut fa = File::create(&format!("{target}/alef")).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create(&format!("{}/bet", target)).unwrap();
let mut fb = File::create(&format!("{target}/bet")).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.arg(&format!("{}/alef", target))
.stdin(File::open(&format!("{}/ab.diff", target)).unwrap())
.arg(&format!("{target}/alef"))
.stdin(File::open(&format!("{target}/ab.diff")).unwrap())
.output()
.unwrap();
if !output.status.success() {
panic!("{:?}", output);
}
assert!(output.status.success(), "{:?}", output);
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read(&format!("{}/alef", target)).unwrap();
let alef = fs::read(&format!("{target}/alef")).unwrap();
assert_eq!(alef, bet);
}
}
@@ -315,30 +314,27 @@ mod tests {
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff = diff(&alef, &bet);
File::create(&format!("{}/abn.diff", target))
File::create(&format!("{target}/abn.diff"))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa =
File::create(&format!("{}/alefn", target)).unwrap();
let mut fa = File::create(&format!("{target}/alefn")).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create(&format!("{}/betn", target)).unwrap();
let mut fb = File::create(&format!("{target}/betn")).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.arg("--normal")
.arg(&format!("{}/alefn", target))
.stdin(File::open(&format!("{}/abn.diff", target)).unwrap())
.arg(&format!("{target}/alefn"))
.stdin(File::open(&format!("{target}/abn.diff")).unwrap())
.output()
.unwrap();
if !output.status.success() {
panic!("{:?}", output);
}
assert!(output.status.success(), "{:?}", output);
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read(&format!("{}/alefn", target)).unwrap();
let alef = fs::read(&format!("{target}/alefn")).unwrap();
assert_eq!(alef, bet);
}
}
@@ -392,28 +388,26 @@ mod tests {
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff = diff(&alef, &bet);
File::create(&format!("{}/ab_.diff", target))
File::create(&format!("{target}/ab_.diff"))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create(&format!("{}/alef_", target)).unwrap();
let mut fa = File::create(&format!("{target}/alef_")).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create(&format!("{}/bet_", target)).unwrap();
let mut fb = File::create(&format!("{target}/bet_")).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.arg(&format!("{}/alef_", target))
.stdin(File::open(&format!("{}/ab_.diff", target)).unwrap())
.arg(&format!("{target}/alef_"))
.stdin(File::open(&format!("{target}/ab_.diff")).unwrap())
.output()
.unwrap();
if !output.status.success() {
panic!("{:?}", output);
}
assert!(output.status.success(), "{:?}", output);
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read(&format!("{}/alef_", target)).unwrap();
let alef = fs::read(&format!("{target}/alef_")).unwrap();
assert_eq!(alef, bet);
}
}
@@ -472,28 +466,26 @@ mod tests {
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff = diff(&alef, &bet);
File::create(&format!("{}/abr.diff", target))
File::create(&format!("{target}/abr.diff"))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create(&format!("{}/alefr", target)).unwrap();
let mut fa = File::create(&format!("{target}/alefr")).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create(&format!("{}/betr", target)).unwrap();
let mut fb = File::create(&format!("{target}/betr")).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.arg(&format!("{}/alefr", target))
.stdin(File::open(&format!("{}/abr.diff", target)).unwrap())
.arg(&format!("{target}/alefr"))
.stdin(File::open(&format!("{target}/abr.diff")).unwrap())
.output()
.unwrap();
if !output.status.success() {
panic!("{:?}", output);
}
assert!(output.status.success(), "{:?}", output);
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read(&format!("{}/alefr", target)).unwrap();
let alef = fs::read(&format!("{target}/alefr")).unwrap();
assert_eq!(alef, bet);
}
}
+5 -8
View File
@@ -30,11 +30,9 @@ pub struct Params {
pub fn parse_params<I: IntoIterator<Item = OsString>>(opts: I) -> Result<Params, String> {
let mut opts = opts.into_iter();
// parse CLI
let exe = match opts.next() {
Some(from) => from,
None => {
return Err("Usage: <exe> <from> <to>".to_string());
}
let Some(exe) = opts.next() else {
return Err("Usage: <exe> <from> <to>".to_string());
};
let mut from = None;
let mut to = None;
@@ -101,9 +99,8 @@ pub fn parse_params<I: IntoIterator<Item = OsString>>(opts: I) -> Result<Params,
{
context_count = context_count_maybe;
break;
} else {
return Err("Invalid context count".to_string());
}
return Err("Invalid context count".to_string());
}
_ => return Err(format!("Unknown option: {}", String::from_utf8_lossy(&[b]))),
}
@@ -111,7 +108,7 @@ pub fn parse_params<I: IntoIterator<Item = OsString>>(opts: I) -> Result<Params,
} else if from.is_none() {
from = Some(param);
} else if to.is_none() {
to = Some(param)
to = Some(param);
} else {
return Err(format!("Usage: {} <from> <to>", exe.to_string_lossy()));
}
+47 -70
View File
@@ -79,7 +79,7 @@ fn make_diff(expected: &[u8], actual: &[u8], context_size: usize) -> Vec<Mismatc
// always come after Expected (the - lines)
mismatch.lines.push(DiffLine::Expected(str.to_vec()));
if line_number_expected > expected_lines_count {
mismatch.lines.push(DiffLine::MissingNL)
mismatch.lines.push(DiffLine::MissingNL);
}
mismatch.lines.push(DiffLine::Actual(res));
mismatch.lines.push(DiffLine::MissingNL);
@@ -89,7 +89,7 @@ fn make_diff(expected: &[u8], actual: &[u8], context_size: usize) -> Vec<Mismatc
} else {
mismatch.lines.push(DiffLine::Expected(str.to_vec()));
if line_number_expected > expected_lines_count {
mismatch.lines.push(DiffLine::MissingNL)
mismatch.lines.push(DiffLine::MissingNL);
}
}
line_number_expected += 1;
@@ -111,7 +111,7 @@ fn make_diff(expected: &[u8], actual: &[u8], context_size: usize) -> Vec<Mismatc
mismatch.lines.push(DiffLine::Actual(str.to_vec()));
if line_number_actual > actual_lines_count {
mismatch.lines.push(DiffLine::MissingNL)
mismatch.lines.push(DiffLine::MissingNL);
}
line_number_actual += 1;
lines_since_mismatch = 0;
@@ -224,6 +224,7 @@ fn make_diff(expected: &[u8], actual: &[u8], context_size: usize) -> Vec<Mismatc
results
}
#[must_use]
pub fn diff(
expected: &[u8],
expected_filename: &str,
@@ -231,8 +232,7 @@ pub fn diff(
actual_filename: &str,
context_size: usize,
) -> Vec<u8> {
let mut output =
format!("--- {}\t\n+++ {}\t\n", expected_filename, actual_filename).into_bytes();
let mut output = format!("--- {expected_filename}\t\n+++ {actual_filename}\t\n").into_bytes();
let diff_results = make_diff(expected, actual, context_size);
if diff_results.is_empty() {
return Vec::new();
@@ -334,25 +334,24 @@ pub fn diff(
// I made this comment because this stuff is not obvious from GNU's
// documentation on the format at all.
if expected_count == 0 {
line_number_expected -= 1
line_number_expected -= 1;
}
if actual_count == 0 {
line_number_actual -= 1
line_number_actual -= 1;
}
let exp_ct = if expected_count == 1 {
String::new()
} else {
format!(",{}", expected_count)
format!(",{expected_count}")
};
let act_ct = if actual_count == 1 {
String::new()
} else {
format!(",{}", actual_count)
format!(",{actual_count}")
};
writeln!(
output,
"@@ -{}{} +{}{} @@",
line_number_expected, exp_ct, line_number_actual, act_ct
"@@ -{line_number_expected}{exp_ct} +{line_number_actual}{act_ct} @@"
)
.expect("write to Vec is infallible");
for line in result.lines {
@@ -435,28 +434,26 @@ mod tests {
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff =
diff(&alef, "a/alef", &bet, &format!("{}/alef", target), 2);
File::create(&format!("{}/ab.diff", target))
diff(&alef, "a/alef", &bet, &format!("{target}/alef"), 2);
File::create(&format!("{target}/ab.diff"))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create(&format!("{}/alef", target)).unwrap();
let mut fa = File::create(&format!("{target}/alef")).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create(&format!("{}/bet", target)).unwrap();
let mut fb = File::create(&format!("{target}/bet")).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.stdin(File::open(&format!("{}/ab.diff", target)).unwrap())
.stdin(File::open(&format!("{target}/ab.diff")).unwrap())
.output()
.unwrap();
if !output.status.success() {
panic!("{:?}", output);
}
assert!(output.status.success(), "{:?}", output);
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read(&format!("{}/alef", target)).unwrap();
let alef = fs::read(&format!("{target}/alef")).unwrap();
assert_eq!(alef, bet);
}
}
@@ -528,35 +525,27 @@ mod tests {
}
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff = diff(
&alef,
"a/alefn",
&bet,
&format!("{}/alefn", target),
2,
);
File::create(&format!("{}/abn.diff", target))
let diff =
diff(&alef, "a/alefn", &bet, &format!("{target}/alefn"), 2);
File::create(&format!("{target}/abn.diff"))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa =
File::create(&format!("{}/alefn", target)).unwrap();
let mut fa = File::create(&format!("{target}/alefn")).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create(&format!("{}/betn", target)).unwrap();
let mut fb = File::create(&format!("{target}/betn")).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.stdin(File::open(&format!("{}/abn.diff", target)).unwrap())
.stdin(File::open(&format!("{target}/abn.diff")).unwrap())
.output()
.unwrap();
if !output.status.success() {
panic!("{:?}", output);
}
assert!(output.status.success(), "{:?}", output);
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read(&format!("{}/alefn", target)).unwrap();
let alef = fs::read(&format!("{target}/alefn")).unwrap();
assert_eq!(alef, bet);
}
}
@@ -624,35 +613,27 @@ mod tests {
}
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff = diff(
&alef,
"a/alef_",
&bet,
&format!("{}/alef_", target),
2,
);
File::create(&format!("{}/ab_.diff", target))
let diff =
diff(&alef, "a/alef_", &bet, &format!("{target}/alef_"), 2);
File::create(&format!("{target}/ab_.diff"))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa =
File::create(&format!("{}/alef_", target)).unwrap();
let mut fa = File::create(&format!("{target}/alef_")).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create(&format!("{}/bet_", target)).unwrap();
let mut fb = File::create(&format!("{target}/bet_")).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.stdin(File::open(&format!("{}/ab_.diff", target)).unwrap())
.stdin(File::open(&format!("{target}/ab_.diff")).unwrap())
.output()
.unwrap();
if !output.status.success() {
panic!("{:?}", output);
}
assert!(output.status.success(), "{:?}", output);
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read(&format!("{}/alef_", target)).unwrap();
let alef = fs::read(&format!("{target}/alef_")).unwrap();
assert_eq!(alef, bet);
}
}
@@ -706,28 +687,26 @@ mod tests {
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff =
diff(&alef, "a/alefx", &bet, &format!("{}/alefx", target), 2);
File::create(&format!("{}/abx.diff", target))
diff(&alef, "a/alefx", &bet, &format!("{target}/alefx"), 2);
File::create(&format!("{target}/abx.diff"))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create(&format!("{}/alefx", target)).unwrap();
let mut fa = File::create(&format!("{target}/alefx")).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create(&format!("{}/betx", target)).unwrap();
let mut fb = File::create(&format!("{target}/betx")).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.stdin(File::open(&format!("{}/abx.diff", target)).unwrap())
.stdin(File::open(&format!("{target}/abx.diff")).unwrap())
.output()
.unwrap();
if !output.status.success() {
panic!("{:?}", output);
}
assert!(output.status.success(), "{:?}", output);
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read(&format!("{}/alefx", target)).unwrap();
let alef = fs::read(&format!("{target}/alefx")).unwrap();
assert_eq!(alef, bet);
}
}
@@ -786,28 +765,26 @@ mod tests {
// This test diff is intentionally reversed.
// We want it to turn the alef into bet.
let diff =
diff(&alef, "a/alefr", &bet, &format!("{}/alefr", target), 2);
File::create(&format!("{}/abr.diff", target))
diff(&alef, "a/alefr", &bet, &format!("{target}/alefr"), 2);
File::create(&format!("{target}/abr.diff"))
.unwrap()
.write_all(&diff)
.unwrap();
let mut fa = File::create(&format!("{}/alefr", target)).unwrap();
let mut fa = File::create(&format!("{target}/alefr")).unwrap();
fa.write_all(&alef[..]).unwrap();
let mut fb = File::create(&format!("{}/betr", target)).unwrap();
let mut fb = File::create(&format!("{target}/betr")).unwrap();
fb.write_all(&bet[..]).unwrap();
let _ = fa;
let _ = fb;
let output = Command::new("patch")
.arg("-p0")
.stdin(File::open(&format!("{}/abr.diff", target)).unwrap())
.stdin(File::open(&format!("{target}/abr.diff")).unwrap())
.output()
.unwrap();
if !output.status.success() {
panic!("{:?}", output);
}
assert!(output.status.success(), "{:?}", output);
//println!("{}", String::from_utf8_lossy(&output.stdout));
//println!("{}", String::from_utf8_lossy(&output.stderr));
let alef = fs::read(&format!("{}/alefr", target)).unwrap();
let alef = fs::read(&format!("{target}/alefr")).unwrap();
assert_eq!(alef, bet);
}
}