From 54067a7466645ba3b41261b80566b6de343dad43 Mon Sep 17 00:00:00 2001 From: David Alber Date: Sun, 17 Dec 2017 16:50:09 -0800 Subject: [PATCH 1/2] Reporting test parse errors as test failures Fixes 2078. --- tests/system.rs | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/tests/system.rs b/tests/system.rs index 212e23f4f10..b16821a97f1 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,11 @@ where fails += 1; } Ok(report) => reports.push(report), - Err(msg) => { - print_mismatches(msg); + Err(err) => { + match err { + IdempotentCheckError::Mismatch(msg) => print_mismatches(msg), + IdempotentCheckError::Parse => (), + } fails += 1; } } @@ -263,20 +266,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 +368,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 +395,7 @@ fn handle_result( if failures.is_empty() { Ok(()) } else { - Err(failures) + Err(IdempotentCheckError::Mismatch(failures)) } } From fa0a63989e4e4f014f1c1fcfecee74fd83417fd5 Mon Sep 17 00:00:00 2001 From: David Alber Date: Mon, 18 Dec 2017 01:02:48 -0800 Subject: [PATCH 2/2] Using `if let` to be more concise --- tests/system.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/system.rs b/tests/system.rs index b16821a97f1..c1d838169ae 100644 --- a/tests/system.rs +++ b/tests/system.rs @@ -215,9 +215,8 @@ where } Ok(report) => reports.push(report), Err(err) => { - match err { - IdempotentCheckError::Mismatch(msg) => print_mismatches(msg), - IdempotentCheckError::Parse => (), + if let IdempotentCheckError::Mismatch(msg) = err { + print_mismatches(msg); } fails += 1; }