Add an explainer mode to filecheck.

The -c flag to 'cton-util filecheck' will now print out a description of how
the directives are matching the input.

This explanation is also printed when a match fails.
This commit is contained in:
Jakob Stoklund Olesen
2016-09-09 17:08:29 -07:00
parent 1ce5bc3509
commit 38952eea00
5 changed files with 255 additions and 15 deletions

View File

@@ -20,10 +20,21 @@ pub fn run(files: Vec<String>, verbose: bool) -> CommandResult {
let mut buffer = String::new();
try!(io::stdin().read_to_string(&mut buffer).map_err(|e| format!("stdin: {}", e)));
if try!(checker.check(&buffer, NO_VARIABLES).map_err(|e| e.to_string())) {
if verbose {
let (success, explain) = try!(checker.explain(&buffer, NO_VARIABLES)
.map_err(|e| e.to_string()));
print!("{}", explain);
if success {
println!("OK");
Ok(())
} else {
Err("Check failed".to_string())
}
} else if try!(checker.check(&buffer, NO_VARIABLES).map_err(|e| e.to_string())) {
Ok(())
} else {
// TODO: We need to do better than this.
let (_, explain) = try!(checker.explain(&buffer, NO_VARIABLES).map_err(|e| e.to_string()));
print!("{}", explain);
Err("Check failed".to_string())
}
}