From 613dacb2dc37ec0dbbe62e63c1dade43e8bab59c Mon Sep 17 00:00:00 2001 From: benluiwj Date: Sun, 10 Nov 2024 13:29:43 +0800 Subject: [PATCH] refactor check_diff --- check_diff/src/lib.rs | 60 +++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/check_diff/src/lib.rs b/check_diff/src/lib.rs index d05ff874205..43bf541edfd 100644 --- a/check_diff/src/lib.rs +++ b/check_diff/src/lib.rs @@ -56,8 +56,8 @@ impl From for GitError { // will be used in future PRs, just added to make the compiler happy #[allow(dead_code)] pub struct CheckDiffRunners { - feature_runner: RustfmtRunner, - src_runner: RustfmtRunner, + pub feature_runner: RustfmtRunner, + pub src_runner: RustfmtRunner, } pub struct RustfmtRunner { @@ -80,6 +80,33 @@ impl RustfmtRunner { let binary_version = std::str::from_utf8(&command.stdout)?.trim(); return Ok(binary_version.to_string()); } + + // Run rusfmt with the --check flag to see if a diff is produced. + // + // Parameters: + // binary_path: Path to a rustfmt binary + // output_path: Output file path for the diff + // config: Any additional configuration options to pass to rustfmt + // + fn create_diff(&self, output_path: &Path, config: Option>) { + let config_arg: String = match config { + Some(configs) => { + let mut result = String::new(); + result.push(','); + for arg in configs.iter() { + result.push_str(arg.as_str()); + result.push(','); + } + result.pop(); + result + } + None => String::new(), + }; + let config = format!( + "error_on_line_overflow=false,error_on_unformatted=false{}", + config_arg.as_str() + ); + } } /// Clone a git repository @@ -227,35 +254,6 @@ pub fn build_rustfmt_from_src(binary_path: PathBuf) -> Result>) { - let config_arg: String = match config { - Some(configs) => { - let mut result = String::new(); - result.push(','); - for arg in configs.iter() { - result.push_str(arg.as_str()); - result.push(','); - } - result.pop(); - result - } - None => String::new(), - }; - let config = format!( - "error_on_line_overflow=false,error_on_unformatted=false{}", - config_arg.as_str() - ); -} - // Compiles and produces two rustfmt binaries. // One for the current master, and another for the feature branch // Parameters: