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:
Jakob Stoklund Olesen
2016-09-16 17:00:55 -07:00
parent b26f7be6c9
commit 4bc41bbcff
3 changed files with 20 additions and 17 deletions

View File

@@ -4,7 +4,10 @@
//! available test commands.
use std::path::Path;
use cton_reader::TestCommand;
use CommandResult;
use cat;
use print_cfg;
use filetest::runner::TestRunner;
pub mod subtest;
@@ -34,3 +37,17 @@ pub fn run(files: Vec<String>) -> CommandResult {
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)),
}
}