use std::path::PathBuf;
use std::time::Duration;
use crate::cli::test::TestArgs;
use crate::loader::{LanguageConfiguration, Loader};
pub struct Tester {
configurations: Vec<LanguageConfiguration>,
test_paths: Vec<PathBuf>,
pub max_test_time: Option<Duration>,
}
impl Tester {
pub fn new(configurations: Vec<LanguageConfiguration>, test_paths: Vec<PathBuf>) -> Self {
Self {
configurations,
test_paths,
max_test_time: Some(Duration::from_secs(60)),
}
}
pub fn run(self) -> anyhow::Result<()> {
let test_paths = self
.test_paths
.into_iter()
.map(|test_path| {
std::env::current_dir()
.ok()
.and_then(|cwd| pathdiff::diff_paths(&test_path, &cwd))
.unwrap_or(test_path)
})
.collect::<Vec<_>>();
for test_path in &test_paths {
if !test_path.exists() {
panic!("Test path {} does not exist", test_path.display());
}
}
let loader = Loader::from_language_configurations(self.configurations, None)
.expect("Expected loader");
let mut args = TestArgs::new(test_paths);
args.max_test_time = self.max_test_time;
args.run(loader)
}
}