filter tests by name

This commit is contained in:
Dustin Carlino 2018-11-24 09:51:45 -08:00
parent cec29beda5
commit 03712f65d5
3 changed files with 19 additions and 3 deletions

View File

@ -2,6 +2,7 @@
release_mode=""
filter=""
test_names=""
for arg in "$@"; do
if [ "$arg" == "--release" ]; then
@ -10,8 +11,10 @@ for arg in "$@"; do
filter="--filter=Fast";
elif [ "$arg" == "--slow" ]; then
filter="--filter=Slow";
else
test_names="--test_names=$arg";
fi
done
cd tests;
RUST_BACKTRACE=1 cargo run $release_mode -- $filter
RUST_BACKTRACE=1 cargo run $release_mode -- $filter $test_names

View File

@ -21,10 +21,15 @@ struct Flags {
/// Which tests to run?
#[structopt(long = "filter", default_value = "All")]
filter: runner::Filter,
/// If specified, only run tests with names containing this substring.
#[structopt(long = "test_names")]
test_names: Option<String>,
}
fn main() {
let mut t = runner::TestRunner::new(Flags::from_args().filter);
let flags = Flags::from_args();
let mut t = runner::TestRunner::new(flags.filter, flags.test_names);
map_conversion::run(t.suite("map_conversion"));
physics::run(t.suite("physics"));

View File

@ -12,6 +12,7 @@ pub struct TestRunner {
current_suite: Option<String>,
results: Vec<TestResult>,
filter: Filter,
test_name_filter: Option<String>,
}
struct TestResult {
@ -22,11 +23,12 @@ struct TestResult {
}
impl TestRunner {
pub fn new(filter: Filter) -> TestRunner {
pub fn new(filter: Filter, test_name_filter: Option<String>) -> TestRunner {
TestRunner {
current_suite: None,
results: Vec::new(),
filter,
test_name_filter,
}
}
@ -56,6 +58,12 @@ impl TestRunner {
println!("Skipping {}", test_name);
return;
}
if let Some(ref filter) = self.test_name_filter {
if !test_name.contains(filter) {
println!("Skipping {}", test_name);
return;
}
}
print!("Running {}...", test_name);
std::io::stdout().flush().unwrap();