diff --git a/tests/system.rs b/tests/system.rs index 212e23f4f10..c1d838169ae 100644 --- a/tests/system.rs +++ b/tests/system.rs @@ -75,7 +75,7 @@ fn checkstyle_test() { // to a known output file generated by one of the write modes. fn assert_output(source: &Path, expected_filename: &Path) { let config = read_config(source); - let (file_map, _report) = format_file(source, &config); + let (_error_summary, file_map, _report) = format_file(source, &config); // Populate output by writing to a vec. let mut out = vec![]; @@ -214,8 +214,10 @@ where fails += 1; } Ok(report) => reports.push(report), - Err(msg) => { - print_mismatches(msg); + Err(err) => { + if let IdempotentCheckError::Mismatch(msg) = err { + print_mismatches(msg); + } fails += 1; } } @@ -263,20 +265,24 @@ fn read_config(filename: &Path) -> Config { config } -fn format_file>(filepath: P, config: &Config) -> (FileMap, FormatReport) { +fn format_file>(filepath: P, config: &Config) -> (Summary, FileMap, FormatReport) { let filepath = filepath.into(); let input = Input::File(filepath); - let (_error_summary, file_map, report) = - format_input::(input, config, None).unwrap(); - (file_map, report) + format_input::(input, config, None).unwrap() } -pub fn idempotent_check( - filename: PathBuf, -) -> Result>> { +pub enum IdempotentCheckError { + Mismatch(HashMap>), + Parse, +} + +pub fn idempotent_check(filename: PathBuf) -> Result { let sig_comments = read_significant_comments(&filename); let config = read_config(&filename); - let (file_map, format_report) = format_file(filename, &config); + let (error_summary, file_map, format_report) = format_file(filename, &config); + if error_summary.has_parsing_errors() { + return Err(IdempotentCheckError::Parse); + } let mut write_result = HashMap::new(); for &(ref filename, ref text) in &file_map { @@ -361,7 +367,7 @@ fn read_significant_comments(file_name: &Path) -> HashMap { fn handle_result( result: HashMap, target: Option<&str>, -) -> Result<(), HashMap>> { +) -> Result<(), IdempotentCheckError> { let mut failures = HashMap::new(); for (file_name, fmt_text) in result { @@ -388,7 +394,7 @@ fn handle_result( if failures.is_empty() { Ok(()) } else { - Err(failures) + Err(IdempotentCheckError::Mismatch(failures)) } }