use std::io;
use std::fs::File;
use clap::{ArgMatches, SubCommand, Arg, App};
use serial_unit_testing::parser;
pub fn run(matches: &ArgMatches) -> Result<(), String> {
let filename = matches.value_of("file").unwrap();
let mut file = match File::open(filename) {
Ok(file) => file,
Err(ref e) if e.kind() == io::ErrorKind::NotFound => return Err("File not found".to_string()),
Err(e) => return Err(format!("{}", e))
};
let test_suites = match parser::parse_file(&mut file) {
Ok(test_suites) => test_suites,
Err(e) => return Err(format!("Unable to parse file: {}", e))
};
match matches.occurrences_of("verbose") {
1 => {
for test_suite in test_suites {
println!("Test suite '{}' with {} tests", test_suite.name, test_suite.len());
}
},
0 => println!("OK"),
_ => {
for test_suite in test_suites {
println!("{}", test_suite.to_string());
}
}
};
Ok(())
}
pub fn command<'a>() -> App<'a, 'a> {
SubCommand::with_name("verify")
.about("Verify a script can be parsed")
.arg(Arg::with_name("file")
.help("Script to verify")
.required(true)
.takes_value(true))
.arg(Arg::with_name("verbose")
.long("verbose")
.short("v")
.help("Show verbose output")
.multiple(true))
}