mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 07:25:47 +03:00
grouping tests with suite name
This commit is contained in:
parent
5de255b55b
commit
ff0e921c15
@ -13,8 +13,8 @@ mod runner;
|
||||
fn main() {
|
||||
let mut t = runner::TestRunner::new();
|
||||
|
||||
map_conversion::run(&mut t);
|
||||
physics::run(&mut t);
|
||||
map_conversion::run(t.suite("map_conversion"));
|
||||
physics::run(t.suite("physics"));
|
||||
|
||||
t.done();
|
||||
}
|
||||
|
@ -3,26 +3,29 @@ use convert_osm;
|
||||
use runner::TestRunner;
|
||||
|
||||
pub fn run(t: &mut TestRunner) {
|
||||
t.run("convert_twice", Box::new(|_| {
|
||||
let flags = convert_osm::Flags {
|
||||
osm: "../data/input/montlake.osm".to_string(),
|
||||
elevation: "../data/input/N47W122.hgt".to_string(),
|
||||
traffic_signals: "../data/input/TrafficSignals.shp".to_string(),
|
||||
parcels: "../data/seattle_parcels.abst".to_string(),
|
||||
parking_shapes: "../data/shapes/blockface".to_string(),
|
||||
gtfs: "../data/input/google_transit_2018_18_08".to_string(),
|
||||
neighborhoods: "../data/input/neighborhoods.geojson".to_string(),
|
||||
output: "".to_string(),
|
||||
};
|
||||
t.run(
|
||||
"convert_twice",
|
||||
Box::new(|_| {
|
||||
let flags = convert_osm::Flags {
|
||||
osm: "../data/input/montlake.osm".to_string(),
|
||||
elevation: "../data/input/N47W122.hgt".to_string(),
|
||||
traffic_signals: "../data/input/TrafficSignals.shp".to_string(),
|
||||
parcels: "../data/seattle_parcels.abst".to_string(),
|
||||
parking_shapes: "../data/shapes/blockface".to_string(),
|
||||
gtfs: "../data/input/google_transit_2018_18_08".to_string(),
|
||||
neighborhoods: "../data/input/neighborhoods.geojson".to_string(),
|
||||
output: "".to_string(),
|
||||
};
|
||||
|
||||
let map1 = convert_osm::convert(&flags, &mut abstutil::Timer::new("convert map"));
|
||||
let map2 = convert_osm::convert(&flags, &mut abstutil::Timer::new("convert map"));
|
||||
let map1 = convert_osm::convert(&flags, &mut abstutil::Timer::new("convert map"));
|
||||
let map2 = convert_osm::convert(&flags, &mut abstutil::Timer::new("convert map"));
|
||||
|
||||
if map1 != map2 {
|
||||
// TODO tmp files
|
||||
abstutil::write_json("map1.json", &map1).unwrap();
|
||||
abstutil::write_json("map2.json", &map2).unwrap();
|
||||
panic!("map1.json and map2.json differ");
|
||||
}
|
||||
}));
|
||||
if map1 != map2 {
|
||||
// TODO tmp files
|
||||
abstutil::write_json("map1.json", &map1).unwrap();
|
||||
abstutil::write_json("map2.json", &map2).unwrap();
|
||||
panic!("map1.json and map2.json differ");
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
@ -3,10 +3,11 @@
|
||||
use abstutil;
|
||||
use gag::Redirect;
|
||||
use std;
|
||||
use yansi::Paint;
|
||||
use std::io::Write;
|
||||
use yansi::Paint;
|
||||
|
||||
pub struct TestRunner {
|
||||
current_suite: Option<String>,
|
||||
results: Vec<TestResult>,
|
||||
}
|
||||
|
||||
@ -20,11 +21,25 @@ struct TestResult {
|
||||
impl TestRunner {
|
||||
pub fn new() -> TestRunner {
|
||||
TestRunner {
|
||||
current_suite: None,
|
||||
results: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run(&mut self, test_name: &str, test: Box<Fn(&mut TestHelper)>) {
|
||||
pub fn suite(&mut self, name: &str) -> &mut TestRunner {
|
||||
self.current_suite = Some(name.to_string());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn run(&mut self, specific_test_name: &str, test: Box<Fn(&mut TestHelper)>) {
|
||||
let test_name = format!(
|
||||
"{}/{}",
|
||||
self.current_suite
|
||||
.as_ref()
|
||||
.expect("Can't run() a test without suite()"),
|
||||
specific_test_name
|
||||
);
|
||||
|
||||
print!("Running {}...", test_name);
|
||||
std::io::stdout().flush().unwrap();
|
||||
|
||||
@ -72,10 +87,20 @@ impl TestRunner {
|
||||
for result in self.results.into_iter() {
|
||||
if result.pass {
|
||||
passed += 1;
|
||||
println!("- {} ({}): {}", result.test_name, result.duration, Paint::green("PASS"));
|
||||
println!(
|
||||
"- {} ({}): {}",
|
||||
result.test_name,
|
||||
result.duration,
|
||||
Paint::green("PASS")
|
||||
);
|
||||
} else {
|
||||
failed += 1;
|
||||
println!("- {} ({}): {}", result.test_name, result.duration, Paint::red("FAIL"));
|
||||
println!(
|
||||
"- {} ({}): {}",
|
||||
result.test_name,
|
||||
result.duration,
|
||||
Paint::red("FAIL")
|
||||
);
|
||||
println!(" {}", Paint::cyan(result.output_path));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user