mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 23:43:25 +03:00
revive the other parking test. add option to always show savestate
This commit is contained in:
parent
56c885e7ab
commit
88ad929644
@ -1,8 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
release_mode=""
|
||||
|
||||
filter=""
|
||||
test_names=""
|
||||
keep_output=""
|
||||
|
||||
for arg in "$@"; do
|
||||
if [ "$arg" == "--release" ]; then
|
||||
@ -11,10 +13,12 @@ for arg in "$@"; do
|
||||
filter="--filter=Fast";
|
||||
elif [ "$arg" == "--slow" ]; then
|
||||
filter="--filter=Slow";
|
||||
elif [ "$arg" == "--keep_output" ]; then
|
||||
filter="--keep_output";
|
||||
else
|
||||
test_names="--test_names=$arg";
|
||||
fi
|
||||
done
|
||||
|
||||
cd tests;
|
||||
RUST_BACKTRACE=1 cargo run $release_mode -- $filter $test_names
|
||||
RUST_BACKTRACE=1 cargo run $release_mode -- $filter $keep_output $test_names
|
||||
|
@ -18,21 +18,8 @@ mod transit;
|
||||
|
||||
use structopt::StructOpt;
|
||||
|
||||
#[derive(StructOpt)]
|
||||
#[structopt(name = "tests")]
|
||||
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 flags = Flags::from_args();
|
||||
let mut t = runner::TestRunner::new(flags.filter, flags.test_names);
|
||||
let mut t = runner::TestRunner::new(runner::Flags::from_args());
|
||||
|
||||
map_conversion::run(t.suite("map_conversion"));
|
||||
parking::run(t.suite("parking"));
|
||||
|
@ -3,6 +3,8 @@ use runner::TestRunner;
|
||||
use sim;
|
||||
|
||||
pub fn run(t: &mut TestRunner) {
|
||||
// TODO Lots of boilerplate between these two. Can we do better?
|
||||
|
||||
t.run_slow(
|
||||
"park_on_goal_st",
|
||||
Box::new(|h| {
|
||||
@ -11,7 +13,6 @@ pub fn run(t: &mut TestRunner) {
|
||||
None,
|
||||
&mut Timer::new("setup test"),
|
||||
);
|
||||
|
||||
let north_bldg = map.bldg("north");
|
||||
let south_bldg = map.bldg("south");
|
||||
let north_parking = map.parking_lane("north", 18);
|
||||
@ -37,32 +38,38 @@ pub fn run(t: &mut TestRunner) {
|
||||
sim.run_until_done(&map, &control_map, Box::new(|_sim| {}));
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
#[test]
|
||||
fn wander_around_for_parking() {
|
||||
let (map, control_map, mut sim) = setup("wander_around_for_parking", make_test_map());
|
||||
let (south_parking, north_parking) = (LaneID(1), LaneID(4));
|
||||
let (north_bldg, south_bldg) = (BuildingID(0), BuildingID(1));
|
||||
t.run_slow(
|
||||
"wander_around_for_parking",
|
||||
Box::new(|h| {
|
||||
let (map, control_map, mut sim) = sim::load(
|
||||
sim::SimFlags::synthetic_test("parking_test", "wander_around_for_parking"),
|
||||
None,
|
||||
&mut Timer::new("setup test"),
|
||||
);
|
||||
let north_bldg = map.bldg("north");
|
||||
let south_bldg = map.bldg("south");
|
||||
let north_parking = map.parking_lane("north", 18);
|
||||
let south_parking = map.parking_lane("south", 18);
|
||||
|
||||
assert_eq!(map.get_l(south_parking).number_parking_spots(), 8);
|
||||
assert_eq!(map.get_l(north_parking).number_parking_spots(), 8);
|
||||
// There's a free spot behind the car, so they have to loop around to their original lane to
|
||||
// find it.
|
||||
let car = sim.seed_specific_parked_cars(south_parking, south_bldg, (1..8).collect())[2];
|
||||
sim.seed_specific_parked_cars(north_parking, north_bldg, (0..8).collect());
|
||||
sim.make_ped_using_car(&map, car, north_bldg);
|
||||
let car = sim.seed_specific_parked_cars(south_parking, south_bldg, vec![2])[0];
|
||||
// Fill up all of the north spots, forcing parking to happen on the south lane behind
|
||||
// the original spot
|
||||
sim.seed_specific_parked_cars(north_parking, north_bldg, (0..18).collect());
|
||||
// TODO I just want to say (south_bldg, north_bldg), not mode...
|
||||
sim.seed_trip_using_parked_car(south_bldg, north_bldg, car, &map);
|
||||
h.setup_done(&sim);
|
||||
|
||||
sim.run_until_expectations_met(
|
||||
&map,
|
||||
&control_map,
|
||||
vec![sim::Event::CarReachedParkingSpot(
|
||||
car,
|
||||
sim::ParkingSpot::new(south_parking, 0),
|
||||
)],
|
||||
sim::Tick::from_minutes(2),
|
||||
sim.run_until_expectations_met(
|
||||
&map,
|
||||
&control_map,
|
||||
vec![sim::Event::CarReachedParkingSpot(
|
||||
car,
|
||||
sim::ParkingSpot::new(south_parking, 0),
|
||||
)],
|
||||
sim::Tick::from_minutes(2),
|
||||
);
|
||||
sim.run_until_done(&map, &control_map, Box::new(|_sim| {}));
|
||||
}),
|
||||
);
|
||||
sim.run_until_done(&map, &control_map, Box::new(|_sim| {}));
|
||||
}
|
||||
*/
|
||||
|
@ -6,13 +6,29 @@ use gag::Redirect;
|
||||
use sim::Sim;
|
||||
use std;
|
||||
use std::io::Write;
|
||||
use structopt::StructOpt;
|
||||
use yansi::Paint;
|
||||
|
||||
#[derive(StructOpt)]
|
||||
#[structopt(name = "tests")]
|
||||
pub struct Flags {
|
||||
/// Which tests to run?
|
||||
#[structopt(long = "filter", default_value = "All")]
|
||||
filter: Filter,
|
||||
|
||||
/// If specified, only run tests with names containing this substring.
|
||||
#[structopt(long = "test_names")]
|
||||
test_names: Option<String>,
|
||||
|
||||
/// Keep the log and savestate even for passing tests.
|
||||
#[structopt(long = "keep_output")]
|
||||
keep_output: bool,
|
||||
}
|
||||
|
||||
pub struct TestRunner {
|
||||
current_suite: Option<String>,
|
||||
results: Vec<TestResult>,
|
||||
filter: Filter,
|
||||
test_name_filter: Option<String>,
|
||||
flags: Flags,
|
||||
output_dir: String,
|
||||
}
|
||||
|
||||
@ -25,7 +41,7 @@ struct TestResult {
|
||||
}
|
||||
|
||||
impl TestResult {
|
||||
fn print(&self) {
|
||||
fn print(&self, flags: &Flags) {
|
||||
if self.pass {
|
||||
println!(
|
||||
"- {} ({}): {}",
|
||||
@ -40,6 +56,8 @@ impl TestResult {
|
||||
self.duration,
|
||||
Paint::red("FAIL")
|
||||
);
|
||||
}
|
||||
if !self.pass || flags.keep_output {
|
||||
println!(" {}", Paint::cyan(&self.output_path));
|
||||
if let Some(ref path) = self.debug_with_savestate {
|
||||
println!(" {}", Paint::yellow(path));
|
||||
@ -49,12 +67,11 @@ impl TestResult {
|
||||
}
|
||||
|
||||
impl TestRunner {
|
||||
pub fn new(filter: Filter, test_name_filter: Option<String>) -> TestRunner {
|
||||
pub fn new(flags: Flags) -> TestRunner {
|
||||
TestRunner {
|
||||
current_suite: None,
|
||||
results: Vec::new(),
|
||||
filter,
|
||||
test_name_filter,
|
||||
flags,
|
||||
output_dir: format!(
|
||||
"/tmp/abst_tests_{}",
|
||||
std::time::SystemTime::now()
|
||||
@ -87,10 +104,12 @@ impl TestRunner {
|
||||
specific_test_name
|
||||
);
|
||||
|
||||
if (fast && self.filter == Filter::Slow) || (!fast && self.filter == Filter::Fast) {
|
||||
if (fast && self.flags.filter == Filter::Slow)
|
||||
|| (!fast && self.flags.filter == Filter::Fast)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if let Some(ref filter) = self.test_name_filter {
|
||||
if let Some(ref filter) = self.flags.test_names {
|
||||
if !test_name.contains(filter) {
|
||||
return;
|
||||
}
|
||||
@ -128,7 +147,7 @@ impl TestRunner {
|
||||
})).is_ok()
|
||||
};
|
||||
|
||||
if pass {
|
||||
if pass && !self.flags.keep_output {
|
||||
std::fs::remove_file(&output_path).expect(&format!(
|
||||
"Couldn't delete successful test log {}",
|
||||
output_path
|
||||
@ -142,7 +161,7 @@ impl TestRunner {
|
||||
debug_with_savestate: helper.debug_with_savestate,
|
||||
};
|
||||
print!("\r");
|
||||
result.print();
|
||||
result.print(&self.flags);
|
||||
self.results.push(result);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user