diff --git a/tests/src/main.rs b/tests/src/main.rs index 0bb7835664..9673b7499c 100644 --- a/tests/src/main.rs +++ b/tests/src/main.rs @@ -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(); } diff --git a/tests/src/map_conversion.rs b/tests/src/map_conversion.rs index 1b6965be75..3b91a95972 100644 --- a/tests/src/map_conversion.rs +++ b/tests/src/map_conversion.rs @@ -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"); + } + }), + ); } diff --git a/tests/src/runner.rs b/tests/src/runner.rs index 78d18619ea..b4db891881 100644 --- a/tests/src/runner.rs +++ b/tests/src/runner.rs @@ -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, results: Vec, } @@ -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) { + 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) { + 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)); } }