The 'src' and 'tests' top-level directories now contain tools sources and integration tests for any of the library crates.
48 lines
1.5 KiB
Rust
48 lines
1.5 KiB
Rust
use CommandResult;
|
|
use utils::read_to_string;
|
|
use filecheck::{CheckerBuilder, Checker, NO_VARIABLES};
|
|
use std::io::{self, Read};
|
|
|
|
pub fn run(files: Vec<String>, verbose: bool) -> CommandResult {
|
|
if files.is_empty() {
|
|
return Err("No check files".to_string());
|
|
}
|
|
let checker = try!(read_checkfile(&files[0]));
|
|
if checker.is_empty() {
|
|
return Err(format!("{}: no filecheck directives found", files[0]));
|
|
}
|
|
|
|
// Print out the directives under --verbose.
|
|
if verbose {
|
|
println!("{}", checker);
|
|
}
|
|
|
|
let mut buffer = String::new();
|
|
try!(io::stdin().read_to_string(&mut buffer).map_err(|e| format!("stdin: {}", e)));
|
|
|
|
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 {
|
|
let (_, explain) = try!(checker.explain(&buffer, NO_VARIABLES).map_err(|e| e.to_string()));
|
|
print!("{}", explain);
|
|
Err("Check failed".to_string())
|
|
}
|
|
}
|
|
|
|
fn read_checkfile(filename: &str) -> Result<Checker, String> {
|
|
let buffer = try!(read_to_string(&filename).map_err(|e| format!("{}: {}", filename, e)));
|
|
let mut builder = CheckerBuilder::new();
|
|
try!(builder.text(&buffer).map_err(|e| format!("{}: {}", filename, e)));
|
|
Ok(builder.finish())
|
|
}
|