use std::collections::HashSet;
use std::path::PathBuf;
use std::time::Duration;
#[derive(Default)]
pub struct ScriptCtx {
pub argv: Vec<String>,
pub current_file: Option<PathBuf>,
pub required: HashSet<PathBuf>,
http_agent: Option<ureq::Agent>,
pub tests: Vec<TestCase>,
}
pub struct TestCase {
pub name: String,
pub body: Vec<tatara_lisp::Spanned>,
}
impl ScriptCtx {
pub fn with_argv<I, S>(argv: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
Self {
argv: argv.into_iter().map(Into::into).collect(),
current_file: None,
required: HashSet::new(),
http_agent: None,
tests: Vec::new(),
}
}
pub fn http(&mut self) -> &ureq::Agent {
self.http_agent.get_or_insert_with(|| {
ureq::Agent::config_builder()
.timeout_global(Some(Duration::from_secs(30)))
.build()
.new_agent()
})
}
}