From 255231d9edf467a6dbcf30f1ce943e750232012e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 2 Apr 2016 23:41:25 +0300 Subject: [PATCH] don't read config twice during tests --- tests/system.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/tests/system.rs b/tests/system.rs index eac45b83ca0..7081d73f778 100644 --- a/tests/system.rs +++ b/tests/system.rs @@ -74,12 +74,8 @@ fn checkstyle_test() { // Helper function for comparing the results of rustfmt // to a known output file generated by one of the write modes. fn assert_output(source: &str, expected_filename: &str, write_mode: Option) { - let file_map = run_rustfmt(source.to_string(), write_mode); - - let mut config = read_config(&source); - if let Some(write_mode) = write_mode { - config.write_mode = write_mode; - } + let config = read_config(&source, write_mode); + let file_map = run_rustfmt(source.to_string(), &config); // Populate output by writing to a vec. let mut out = vec![]; @@ -180,7 +176,7 @@ fn print_mismatches(result: HashMap>) { assert!(t.reset().unwrap()); } -fn read_config(filename: &str) -> Config { +fn read_config(filename: &str, write_mode: Option) -> Config { let sig_comments = read_significant_comments(&filename); let mut config = get_config(sig_comments.get("config").map(|x| &(*x)[..])); @@ -192,15 +188,16 @@ fn read_config(filename: &str) -> Config { // Don't generate warnings for to-do items. config.report_todo = ReportTactic::Never; + + if let Some(mode) = write_mode { + config.write_mode = mode + } + config } // Simulate run() -fn run_rustfmt(filename: String, write_mode: Option) -> FileMap { - let mut config = read_config(&filename); - if let Some(write_mode) = write_mode { - config.write_mode = write_mode; - } +fn run_rustfmt(filename: String, config: &Config) -> FileMap { format(Path::new(&filename), &config) } @@ -208,8 +205,8 @@ pub fn idempotent_check(filename: String, write_mode: Option) -> Result>> { let sig_comments = read_significant_comments(&filename); - let config = read_config(&filename); - let mut file_map = run_rustfmt(filename, write_mode); + let config = read_config(&filename, write_mode); + let mut file_map = run_rustfmt(filename, &config); let format_report = fmt_lines(&mut file_map, &config); let mut write_result = HashMap::new();