Reporting test parse errors as test failures

Fixes 2078.
This commit is contained in:
David Alber 2017-12-17 16:50:09 -08:00
parent 8998c1d5b5
commit 54067a7466

View File

@ -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 @@ fn check_files<I>(files: I) -> (Vec<FormatReport>, u32, u32)
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<P: Into<PathBuf>>(filepath: P, config: &Config) -> (FileMap, FormatReport) {
fn format_file<P: Into<PathBuf>>(filepath: P, config: &Config) -> (Summary, FileMap, FormatReport) {
let filepath = filepath.into();
let input = Input::File(filepath);
let (_error_summary, file_map, report) =
format_input::<io::Stdout>(input, config, None).unwrap();
(file_map, report)
format_input::<io::Stdout>(input, config, None).unwrap()
}
pub fn idempotent_check(
filename: PathBuf,
) -> Result<FormatReport, HashMap<PathBuf, Vec<Mismatch>>> {
pub enum IdempotentCheckError {
Mismatch(HashMap<PathBuf, Vec<Mismatch>>),
Parse,
}
pub fn idempotent_check(filename: PathBuf) -> Result<FormatReport, IdempotentCheckError> {
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<String, String> {
fn handle_result(
result: HashMap<PathBuf, String>,
target: Option<&str>,
) -> Result<(), HashMap<PathBuf, Vec<Mismatch>>> {
) -> 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))
}
}