mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 01:15:12 +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"
|
gag = "0.1.10"
|
||||||
geom = { path = "../geom" }
|
geom = { path = "../geom" }
|
||||||
sim = { path = "../sim" }
|
sim = { path = "../sim" }
|
||||||
|
structopt = "0.2"
|
||||||
yansi = "0.4.0"
|
yansi = "0.4.0"
|
||||||
|
@ -4,14 +4,25 @@ extern crate dimensioned;
|
|||||||
extern crate gag;
|
extern crate gag;
|
||||||
extern crate geom;
|
extern crate geom;
|
||||||
extern crate sim;
|
extern crate sim;
|
||||||
|
extern crate structopt;
|
||||||
extern crate yansi;
|
extern crate yansi;
|
||||||
|
|
||||||
mod map_conversion;
|
mod map_conversion;
|
||||||
mod physics;
|
mod physics;
|
||||||
mod runner;
|
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() {
|
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"));
|
map_conversion::run(t.suite("map_conversion"));
|
||||||
physics::run(t.suite("physics"));
|
physics::run(t.suite("physics"));
|
||||||
|
@ -3,7 +3,7 @@ use convert_osm;
|
|||||||
use runner::TestRunner;
|
use runner::TestRunner;
|
||||||
|
|
||||||
pub fn run(t: &mut TestRunner) {
|
pub fn run(t: &mut TestRunner) {
|
||||||
t.run(
|
t.run_slow(
|
||||||
"convert_twice",
|
"convert_twice",
|
||||||
Box::new(|_| {
|
Box::new(|_| {
|
||||||
let flags = convert_osm::Flags {
|
let flags = convert_osm::Flags {
|
||||||
|
@ -6,7 +6,7 @@ use sim::{CarID, Distance, Speed, VehicleType};
|
|||||||
|
|
||||||
pub fn run(t: &mut TestRunner) {
|
pub fn run(t: &mut TestRunner) {
|
||||||
// TODO table driven test style?
|
// TODO table driven test style?
|
||||||
t.run(
|
t.run_fast(
|
||||||
"accel_to_stop_in_dist/easy",
|
"accel_to_stop_in_dist/easy",
|
||||||
Box::new(|_| {
|
Box::new(|_| {
|
||||||
let v = Vehicle {
|
let v = Vehicle {
|
||||||
@ -22,7 +22,7 @@ pub fn run(t: &mut TestRunner) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
t.run(
|
t.run_fast(
|
||||||
"accel_to_stop_in_dist/hard",
|
"accel_to_stop_in_dist/hard",
|
||||||
Box::new(|_| {
|
Box::new(|_| {
|
||||||
let v = Vehicle {
|
let v = Vehicle {
|
||||||
@ -42,7 +42,7 @@ pub fn run(t: &mut TestRunner) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
t.run(
|
t.run_fast(
|
||||||
"accel_to_stop_in_dist/bike",
|
"accel_to_stop_in_dist/bike",
|
||||||
Box::new(|_| {
|
Box::new(|_| {
|
||||||
let v = Vehicle {
|
let v = Vehicle {
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
// https://github.com/rust-lang/rust/issues/50297 would hopefully obsolete this approach.
|
// https://github.com/rust-lang/rust/issues/50297 would hopefully obsolete this approach.
|
||||||
|
|
||||||
use abstutil;
|
use abstutil;
|
||||||
|
use abstutil::Error;
|
||||||
use gag::Redirect;
|
use gag::Redirect;
|
||||||
use std;
|
use std;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use std::str::FromStr;
|
||||||
use yansi::Paint;
|
use yansi::Paint;
|
||||||
|
|
||||||
pub struct TestRunner {
|
pub struct TestRunner {
|
||||||
current_suite: Option<String>,
|
current_suite: Option<String>,
|
||||||
results: Vec<TestResult>,
|
results: Vec<TestResult>,
|
||||||
|
filter: Filter,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TestResult {
|
struct TestResult {
|
||||||
@ -19,10 +22,11 @@ struct TestResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TestRunner {
|
impl TestRunner {
|
||||||
pub fn new() -> TestRunner {
|
pub fn new(filter: Filter) -> TestRunner {
|
||||||
TestRunner {
|
TestRunner {
|
||||||
current_suite: None,
|
current_suite: None,
|
||||||
results: Vec::new(),
|
results: Vec::new(),
|
||||||
|
filter,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +35,15 @@ impl TestRunner {
|
|||||||
self
|
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!(
|
let test_name = format!(
|
||||||
"{}/{}",
|
"{}/{}",
|
||||||
self.current_suite
|
self.current_suite
|
||||||
@ -40,6 +52,11 @@ impl TestRunner {
|
|||||||
specific_test_name
|
specific_test_name
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (fast && self.filter == Filter::Slow) || (!fast && self.filter == Filter::Fast) {
|
||||||
|
println!("Skipping {}", test_name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
print!("Running {}...", test_name);
|
print!("Running {}...", test_name);
|
||||||
std::io::stdout().flush().unwrap();
|
std::io::stdout().flush().unwrap();
|
||||||
|
|
||||||
@ -110,3 +127,23 @@ impl TestRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct TestHelper {}
|
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