extern crate clap;
use clap::{value_t, App, Arg};
use std::io::{self, Write};
use std::path::Path;
use std::time::Instant;
fn main() {
let now = Instant::now();
let matches = App::new("nix-test-runner")
.version("0.0.1")
.author("Christoph H. <schtoeffel@gmail.com>")
.about("Run nix expression tests.")
.arg(
Arg::with_name("TEST")
.required(true)
.index(1)
.help("A nix expression containing testcases."),
)
.arg(
Arg::with_name("reporter")
.required(false)
.short("r")
.long("reporter")
.default_value("human")
.possible_values(&nix_test_runner::Reporter::variants())
.case_insensitive(true),
)
.get_matches();
let test_file = matches.value_of("TEST").unwrap();
let reporter =
value_t!(matches, "reporter", nix_test_runner::Reporter).unwrap_or_else(|e| e.exit());
let test_file_path = Path::new(test_file);
assert!(
test_file_path.exists(),
"You need to provide an existing file."
);
let result = nix_test_runner::run(test_file).format(now.elapsed(), reporter);
io::stdout().write_all(result.as_bytes()).unwrap();
}