Move subtest::new() into the parent module.
This saves on importing of all the sub-modules that implement new test commands, and it provides a nice overview of what 'cton-util test' can do.
This commit is contained in:
@@ -4,7 +4,10 @@
|
|||||||
//! available test commands.
|
//! available test commands.
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use cton_reader::TestCommand;
|
||||||
use CommandResult;
|
use CommandResult;
|
||||||
|
use cat;
|
||||||
|
use print_cfg;
|
||||||
use filetest::runner::TestRunner;
|
use filetest::runner::TestRunner;
|
||||||
|
|
||||||
pub mod subtest;
|
pub mod subtest;
|
||||||
@@ -34,3 +37,17 @@ pub fn run(files: Vec<String>) -> CommandResult {
|
|||||||
|
|
||||||
runner.run()
|
runner.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a new subcommand trait object to match `parsed.command`.
|
||||||
|
///
|
||||||
|
/// This function knows how to create all of the possible `test <foo>` commands that can appear in
|
||||||
|
/// a .cton test file.
|
||||||
|
fn new_subtest(parsed: &TestCommand) -> subtest::Result<Box<subtest::SubTest>> {
|
||||||
|
match parsed.command {
|
||||||
|
"cat" => cat::subtest(parsed),
|
||||||
|
"print-cfg" => print_cfg::subtest(parsed),
|
||||||
|
"domtree" => domtree::subtest(parsed),
|
||||||
|
"verifier" => verifier::subtest(parsed),
|
||||||
|
_ => Err(format!("unknown test command '{}'", parsed.command)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use utils::read_to_string;
|
|||||||
use cton_reader::parse_test;
|
use cton_reader::parse_test;
|
||||||
use cretonne::ir::Function;
|
use cretonne::ir::Function;
|
||||||
use cretonne::verify_function;
|
use cretonne::verify_function;
|
||||||
|
use filetest::new_subtest;
|
||||||
use filetest::subtest::{self, SubTest, Context};
|
use filetest::subtest::{self, SubTest, Context};
|
||||||
|
|
||||||
type TestResult = Result<time::Duration, String>;
|
type TestResult = Result<time::Duration, String>;
|
||||||
@@ -218,7 +219,7 @@ impl Job {
|
|||||||
}
|
}
|
||||||
// Parse the test commands.
|
// Parse the test commands.
|
||||||
let mut tests =
|
let mut tests =
|
||||||
try!(testfile.commands.iter().map(subtest::new).collect::<subtest::Result<Vec<_>>>());
|
try!(testfile.commands.iter().map(new_subtest).collect::<subtest::Result<Vec<_>>>());
|
||||||
|
|
||||||
// Sort the tests so the mutators are at the end, and those that
|
// Sort the tests so the mutators are at the end, and those that
|
||||||
// don't need the verifier are at the front
|
// don't need the verifier are at the front
|
||||||
|
|||||||
@@ -3,26 +3,11 @@
|
|||||||
use std::result;
|
use std::result;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use cretonne::ir::Function;
|
use cretonne::ir::Function;
|
||||||
use cton_reader::{TestCommand, Details};
|
use cton_reader::Details;
|
||||||
use filecheck::{self, CheckerBuilder, Checker, Value as FCValue};
|
use filecheck::{self, CheckerBuilder, Checker, Value as FCValue};
|
||||||
|
|
||||||
pub type Result<T> = result::Result<T, String>;
|
pub type Result<T> = result::Result<T, String>;
|
||||||
|
|
||||||
/// Create a new subcommand trait object to match `parsed.command`.
|
|
||||||
pub fn new(parsed: &TestCommand) -> Result<Box<SubTest>> {
|
|
||||||
use cat;
|
|
||||||
use print_cfg;
|
|
||||||
use filetest::domtree;
|
|
||||||
use filetest::verifier;
|
|
||||||
match parsed.command {
|
|
||||||
"cat" => cat::subtest(parsed),
|
|
||||||
"print-cfg" => print_cfg::subtest(parsed),
|
|
||||||
"domtree" => domtree::subtest(parsed),
|
|
||||||
"verifier" => verifier::subtest(parsed),
|
|
||||||
_ => Err(format!("unknown test command '{}'", parsed.command)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Context for running a a test on a single function.
|
/// Context for running a a test on a single function.
|
||||||
pub struct Context<'a> {
|
pub struct Context<'a> {
|
||||||
/// Additional details about the function from the parser.
|
/// Additional details about the function from the parser.
|
||||||
|
|||||||
Reference in New Issue
Block a user