Promote the src/tools crate to the top-level workspace.

The 'src' and 'tests' top-level directories now contain tools sources
and integration tests for any of the library crates.
This commit is contained in:
Jakob Stoklund Olesen
2016-10-17 14:57:42 -07:00
parent 0764df28b5
commit a8a79df620
18 changed files with 25 additions and 23 deletions

47
src/rsfilecheck.rs Normal file
View File

@@ -0,0 +1,47 @@
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())
}