mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-27 15:03:20 +03:00
running just fast/slow tests in runner, and making the helper script
invoke the new runner
This commit is contained in:
parent
ff0e921c15
commit
878889133a
17
exec_tests.sh
Executable file
17
exec_tests.sh
Executable file
@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
release_mode=""
|
||||
filter=""
|
||||
|
||||
for arg in "$@"; do
|
||||
if [ "$arg" == "--release" ]; then
|
||||
release_mode="--release";
|
||||
elif [ "$arg" == "--fast" ]; then
|
||||
filter="--filter=Fast";
|
||||
elif [ "$arg" == "--slow" ]; then
|
||||
filter="--filter=Slow";
|
||||
fi
|
||||
done
|
||||
|
||||
cd tests;
|
||||
RUST_BACKTRACE=1 cargo run $release_mode -- $filter
|
@ -1,7 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ "$1" = "--fast" ]; then
|
||||
cargo test --no-fail-fast
|
||||
else
|
||||
cargo test --release --no-fail-fast
|
||||
fi
|
@ -10,4 +10,5 @@ dimensioned = { git = "https://github.com/paholg/dimensioned", rev = "0e1076ebfa
|
||||
gag = "0.1.10"
|
||||
geom = { path = "../geom" }
|
||||
sim = { path = "../sim" }
|
||||
structopt = "0.2"
|
||||
yansi = "0.4.0"
|
||||
|
@ -4,14 +4,25 @@ extern crate dimensioned;
|
||||
extern crate gag;
|
||||
extern crate geom;
|
||||
extern crate sim;
|
||||
extern crate structopt;
|
||||
extern crate yansi;
|
||||
|
||||
mod map_conversion;
|
||||
mod physics;
|
||||
mod runner;
|
||||
|
||||
use structopt::StructOpt;
|
||||
|
||||
#[derive(StructOpt)]
|
||||
#[structopt(name = "tests")]
|
||||
struct Flags {
|
||||
/// Which tests to run?
|
||||
#[structopt(long = "filter", default_value = "All")]
|
||||
filter: runner::Filter,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut t = runner::TestRunner::new();
|
||||
let mut t = runner::TestRunner::new(Flags::from_args().filter);
|
||||
|
||||
map_conversion::run(t.suite("map_conversion"));
|
||||
physics::run(t.suite("physics"));
|
||||
|
@ -3,7 +3,7 @@ use convert_osm;
|
||||
use runner::TestRunner;
|
||||
|
||||
pub fn run(t: &mut TestRunner) {
|
||||
t.run(
|
||||
t.run_slow(
|
||||
"convert_twice",
|
||||
Box::new(|_| {
|
||||
let flags = convert_osm::Flags {
|
||||
|
@ -6,7 +6,7 @@ use sim::{CarID, Distance, Speed, VehicleType};
|
||||
|
||||
pub fn run(t: &mut TestRunner) {
|
||||
// TODO table driven test style?
|
||||
t.run(
|
||||
t.run_fast(
|
||||
"accel_to_stop_in_dist/easy",
|
||||
Box::new(|_| {
|
||||
let v = Vehicle {
|
||||
@ -22,7 +22,7 @@ pub fn run(t: &mut TestRunner) {
|
||||
}),
|
||||
);
|
||||
|
||||
t.run(
|
||||
t.run_fast(
|
||||
"accel_to_stop_in_dist/hard",
|
||||
Box::new(|_| {
|
||||
let v = Vehicle {
|
||||
@ -42,7 +42,7 @@ pub fn run(t: &mut TestRunner) {
|
||||
}),
|
||||
);
|
||||
|
||||
t.run(
|
||||
t.run_fast(
|
||||
"accel_to_stop_in_dist/bike",
|
||||
Box::new(|_| {
|
||||
let v = Vehicle {
|
||||
|
@ -1,14 +1,17 @@
|
||||
// https://github.com/rust-lang/rust/issues/50297 would hopefully obsolete this approach.
|
||||
|
||||
use abstutil;
|
||||
use abstutil::Error;
|
||||
use gag::Redirect;
|
||||
use std;
|
||||
use std::io::Write;
|
||||
use std::str::FromStr;
|
||||
use yansi::Paint;
|
||||
|
||||
pub struct TestRunner {
|
||||
current_suite: Option<String>,
|
||||
results: Vec<TestResult>,
|
||||
filter: Filter,
|
||||
}
|
||||
|
||||
struct TestResult {
|
||||
@ -19,10 +22,11 @@ struct TestResult {
|
||||
}
|
||||
|
||||
impl TestRunner {
|
||||
pub fn new() -> TestRunner {
|
||||
pub fn new(filter: Filter) -> TestRunner {
|
||||
TestRunner {
|
||||
current_suite: None,
|
||||
results: Vec::new(),
|
||||
filter,
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,7 +35,15 @@ impl TestRunner {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn run(&mut self, specific_test_name: &str, test: Box<Fn(&mut TestHelper)>) {
|
||||
pub fn run_fast(&mut self, specific_test_name: &str, test: Box<Fn(&mut TestHelper)>) {
|
||||
self.run(specific_test_name, true, test);
|
||||
}
|
||||
|
||||
pub fn run_slow(&mut self, specific_test_name: &str, test: Box<Fn(&mut TestHelper)>) {
|
||||
self.run(specific_test_name, false, test);
|
||||
}
|
||||
|
||||
fn run(&mut self, specific_test_name: &str, fast: bool, test: Box<Fn(&mut TestHelper)>) {
|
||||
let test_name = format!(
|
||||
"{}/{}",
|
||||
self.current_suite
|
||||
@ -40,6 +52,11 @@ impl TestRunner {
|
||||
specific_test_name
|
||||
);
|
||||
|
||||
if (fast && self.filter == Filter::Slow) || (!fast && self.filter == Filter::Fast) {
|
||||
println!("Skipping {}", test_name);
|
||||
return;
|
||||
}
|
||||
|
||||
print!("Running {}...", test_name);
|
||||
std::io::stdout().flush().unwrap();
|
||||
|
||||
@ -110,3 +127,23 @@ impl TestRunner {
|
||||
}
|
||||
|
||||
pub struct TestHelper {}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub enum Filter {
|
||||
All,
|
||||
Slow,
|
||||
Fast,
|
||||
}
|
||||
|
||||
impl FromStr for Filter {
|
||||
type Err = Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"All" => Ok(Filter::All),
|
||||
"Slow" => Ok(Filter::Slow),
|
||||
"Fast" => Ok(Filter::Fast),
|
||||
_ => Err(Error::new(format!("{} isn't a valid Filter", s))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user