From d891e1034d86fcfd22254891d1ec41887fb90aa4 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 23 Jan 2024 11:42:12 +0100 Subject: [PATCH] run clippy pedantic $ cargo +nightly clippy --allow-dirty --fix -- -W clippy::pedantic --- src/context_diff.rs | 77 +++++++++++++---------------- src/ed_diff.rs | 38 ++++++-------- src/main.rs | 6 +-- src/normal_diff.rs | 66 +++++++++++-------------- src/params.rs | 13 ++--- src/unified_diff.rs | 117 ++++++++++++++++++-------------------------- 6 files changed, 133 insertions(+), 184 deletions(-) diff --git a/src/context_diff.rs b/src/context_diff.rs index dbc54db..b650985 100644 --- a/src/context_diff.rs +++ b/src/context_diff.rs @@ -253,6 +253,7 @@ fn make_diff(expected: &[u8], actual: &[u8], context_size: usize) -> Vec Vec { - 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); } } diff --git a/src/ed_diff.rs b/src/ed_diff.rs index 5bafef4..3e674d7 100644 --- a/src/ed_diff.rs +++ b/src/ed_diff.rs @@ -152,7 +152,7 @@ mod tests { use super::*; pub fn diff_w(expected: &[u8], actual: &[u8], filename: &str) -> Result, 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); } } diff --git a/src/main.rs b/src/main.rs index ad0555e..eaa7d55 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 diff --git a/src/normal_diff.rs b/src/normal_diff.rs index 0955dce..c3297a1 100644 --- a/src/normal_diff.rs +++ b/src/normal_diff.rs @@ -109,6 +109,7 @@ fn make_diff(expected: &[u8], actual: &[u8]) -> Vec { results } +#[must_use] pub fn diff(expected: &[u8], actual: &[u8]) -> Vec { 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); } } diff --git a/src/params.rs b/src/params.rs index 9c1517a..b118be7 100644 --- a/src/params.rs +++ b/src/params.rs @@ -30,11 +30,9 @@ pub struct Params { pub fn parse_params>(opts: I) -> Result { let mut opts = opts.into_iter(); // parse CLI - let exe = match opts.next() { - Some(from) => from, - None => { - return Err("Usage: ".to_string()); - } + + let Some(exe) = opts.next() else { + return Err("Usage: ".to_string()); }; let mut from = None; let mut to = None; @@ -101,9 +99,8 @@ pub fn parse_params>(opts: I) -> Result return Err(format!("Unknown option: {}", String::from_utf8_lossy(&[b]))), } @@ -111,7 +108,7 @@ pub fn parse_params>(opts: I) -> Result ", exe.to_string_lossy())); } diff --git a/src/unified_diff.rs b/src/unified_diff.rs index 05074e5..18d93bc 100644 --- a/src/unified_diff.rs +++ b/src/unified_diff.rs @@ -79,7 +79,7 @@ fn make_diff(expected: &[u8], actual: &[u8], context_size: usize) -> Vec 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 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 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 Vec { - 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); } }