Merge pull request #2288 from davidalber/fix-2078

Reporting test parse errors as test failures
This commit is contained in:
Nick Cameron 2017-12-22 15:44:19 +13:00 committed by GitHub
commit baa0dad582
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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,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<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 +367,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 +394,7 @@ fn handle_result(
if failures.is_empty() {
Ok(())
} else {
Err(failures)
Err(IdempotentCheckError::Mismatch(failures))
}
}