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
|
#!/bin/bash
|
||||||
|
|
||||||
release_mode=""
|
release_mode=""
|
||||||
|
|
||||||
filter=""
|
filter=""
|
||||||
test_names=""
|
test_names=""
|
||||||
|
keep_output=""
|
||||||
|
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
if [ "$arg" == "--release" ]; then
|
if [ "$arg" == "--release" ]; then
|
||||||
@ -11,10 +13,12 @@ for arg in "$@"; do
|
|||||||
filter="--filter=Fast";
|
filter="--filter=Fast";
|
||||||
elif [ "$arg" == "--slow" ]; then
|
elif [ "$arg" == "--slow" ]; then
|
||||||
filter="--filter=Slow";
|
filter="--filter=Slow";
|
||||||
|
elif [ "$arg" == "--keep_output" ]; then
|
||||||
|
filter="--keep_output";
|
||||||
else
|
else
|
||||||
test_names="--test_names=$arg";
|
test_names="--test_names=$arg";
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
cd tests;
|
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;
|
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() {
|
fn main() {
|
||||||
let flags = Flags::from_args();
|
let mut t = runner::TestRunner::new(runner::Flags::from_args());
|
||||||
let mut t = runner::TestRunner::new(flags.filter, flags.test_names);
|
|
||||||
|
|
||||||
map_conversion::run(t.suite("map_conversion"));
|
map_conversion::run(t.suite("map_conversion"));
|
||||||
parking::run(t.suite("parking"));
|
parking::run(t.suite("parking"));
|
||||||
|
@ -3,6 +3,8 @@ use runner::TestRunner;
|
|||||||
use sim;
|
use sim;
|
||||||
|
|
||||||
pub fn run(t: &mut TestRunner) {
|
pub fn run(t: &mut TestRunner) {
|
||||||
|
// TODO Lots of boilerplate between these two. Can we do better?
|
||||||
|
|
||||||
t.run_slow(
|
t.run_slow(
|
||||||
"park_on_goal_st",
|
"park_on_goal_st",
|
||||||
Box::new(|h| {
|
Box::new(|h| {
|
||||||
@ -11,7 +13,6 @@ pub fn run(t: &mut TestRunner) {
|
|||||||
None,
|
None,
|
||||||
&mut Timer::new("setup test"),
|
&mut Timer::new("setup test"),
|
||||||
);
|
);
|
||||||
|
|
||||||
let north_bldg = map.bldg("north");
|
let north_bldg = map.bldg("north");
|
||||||
let south_bldg = map.bldg("south");
|
let south_bldg = map.bldg("south");
|
||||||
let north_parking = map.parking_lane("north", 18);
|
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| {}));
|
sim.run_until_done(&map, &control_map, Box::new(|_sim| {}));
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
t.run_slow(
|
||||||
#[test]
|
"wander_around_for_parking",
|
||||||
fn wander_around_for_parking() {
|
Box::new(|h| {
|
||||||
let (map, control_map, mut sim) = setup("wander_around_for_parking", make_test_map());
|
let (map, control_map, mut sim) = sim::load(
|
||||||
let (south_parking, north_parking) = (LaneID(1), LaneID(4));
|
sim::SimFlags::synthetic_test("parking_test", "wander_around_for_parking"),
|
||||||
let (north_bldg, south_bldg) = (BuildingID(0), BuildingID(1));
|
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);
|
let car = sim.seed_specific_parked_cars(south_parking, south_bldg, vec![2])[0];
|
||||||
assert_eq!(map.get_l(north_parking).number_parking_spots(), 8);
|
// Fill up all of the north spots, forcing parking to happen on the south lane behind
|
||||||
// There's a free spot behind the car, so they have to loop around to their original lane to
|
// the original spot
|
||||||
// find it.
|
sim.seed_specific_parked_cars(north_parking, north_bldg, (0..18).collect());
|
||||||
let car = sim.seed_specific_parked_cars(south_parking, south_bldg, (1..8).collect())[2];
|
// TODO I just want to say (south_bldg, north_bldg), not mode...
|
||||||
sim.seed_specific_parked_cars(north_parking, north_bldg, (0..8).collect());
|
sim.seed_trip_using_parked_car(south_bldg, north_bldg, car, &map);
|
||||||
sim.make_ped_using_car(&map, car, north_bldg);
|
h.setup_done(&sim);
|
||||||
|
|
||||||
sim.run_until_expectations_met(
|
sim.run_until_expectations_met(
|
||||||
&map,
|
&map,
|
||||||
&control_map,
|
&control_map,
|
||||||
vec![sim::Event::CarReachedParkingSpot(
|
vec![sim::Event::CarReachedParkingSpot(
|
||||||
car,
|
car,
|
||||||
sim::ParkingSpot::new(south_parking, 0),
|
sim::ParkingSpot::new(south_parking, 0),
|
||||||
)],
|
)],
|
||||||
sim::Tick::from_minutes(2),
|
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 sim::Sim;
|
||||||
use std;
|
use std;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use structopt::StructOpt;
|
||||||
use yansi::Paint;
|
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 {
|
pub struct TestRunner {
|
||||||
current_suite: Option<String>,
|
current_suite: Option<String>,
|
||||||
results: Vec<TestResult>,
|
results: Vec<TestResult>,
|
||||||
filter: Filter,
|
flags: Flags,
|
||||||
test_name_filter: Option<String>,
|
|
||||||
output_dir: String,
|
output_dir: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,7 +41,7 @@ struct TestResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TestResult {
|
impl TestResult {
|
||||||
fn print(&self) {
|
fn print(&self, flags: &Flags) {
|
||||||
if self.pass {
|
if self.pass {
|
||||||
println!(
|
println!(
|
||||||
"- {} ({}): {}",
|
"- {} ({}): {}",
|
||||||
@ -40,6 +56,8 @@ impl TestResult {
|
|||||||
self.duration,
|
self.duration,
|
||||||
Paint::red("FAIL")
|
Paint::red("FAIL")
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
if !self.pass || flags.keep_output {
|
||||||
println!(" {}", Paint::cyan(&self.output_path));
|
println!(" {}", Paint::cyan(&self.output_path));
|
||||||
if let Some(ref path) = self.debug_with_savestate {
|
if let Some(ref path) = self.debug_with_savestate {
|
||||||
println!(" {}", Paint::yellow(path));
|
println!(" {}", Paint::yellow(path));
|
||||||
@ -49,12 +67,11 @@ impl TestResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TestRunner {
|
impl TestRunner {
|
||||||
pub fn new(filter: Filter, test_name_filter: Option<String>) -> TestRunner {
|
pub fn new(flags: Flags) -> TestRunner {
|
||||||
TestRunner {
|
TestRunner {
|
||||||
current_suite: None,
|
current_suite: None,
|
||||||
results: Vec::new(),
|
results: Vec::new(),
|
||||||
filter,
|
flags,
|
||||||
test_name_filter,
|
|
||||||
output_dir: format!(
|
output_dir: format!(
|
||||||
"/tmp/abst_tests_{}",
|
"/tmp/abst_tests_{}",
|
||||||
std::time::SystemTime::now()
|
std::time::SystemTime::now()
|
||||||
@ -87,10 +104,12 @@ impl TestRunner {
|
|||||||
specific_test_name
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if let Some(ref filter) = self.test_name_filter {
|
if let Some(ref filter) = self.flags.test_names {
|
||||||
if !test_name.contains(filter) {
|
if !test_name.contains(filter) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -128,7 +147,7 @@ impl TestRunner {
|
|||||||
})).is_ok()
|
})).is_ok()
|
||||||
};
|
};
|
||||||
|
|
||||||
if pass {
|
if pass && !self.flags.keep_output {
|
||||||
std::fs::remove_file(&output_path).expect(&format!(
|
std::fs::remove_file(&output_path).expect(&format!(
|
||||||
"Couldn't delete successful test log {}",
|
"Couldn't delete successful test log {}",
|
||||||
output_path
|
output_path
|
||||||
@ -142,7 +161,7 @@ impl TestRunner {
|
|||||||
debug_with_savestate: helper.debug_with_savestate,
|
debug_with_savestate: helper.debug_with_savestate,
|
||||||
};
|
};
|
||||||
print!("\r");
|
print!("\r");
|
||||||
result.print();
|
result.print(&self.flags);
|
||||||
self.results.push(result);
|
self.results.push(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user