Move tests to lib

This commit is contained in:
Filip Tibell 2023-01-21 00:03:16 -05:00
parent 94393419c2
commit 9cef9e01e5
No known key found for this signature in database
5 changed files with 38 additions and 24 deletions

View file

@ -16,27 +16,3 @@ async fn main() -> Result<()> {
cli.run().await?;
Ok(())
}
#[cfg(test)]
mod tests {
macro_rules! tests {
($($name:ident: $value:expr,)*) => {
$(
#[tokio::test]
async fn $name() {
let args = vec!["Foo".to_owned(), "Bar".to_owned()];
let cli = crate::Cli::from_path_with_args($value, args);
if let Err(e) = cli.run().await {
panic!("{}", e.to_string())
}
}
)*
}
}
tests! {
process_args: "tests/process/args",
process_env: "tests/process/env",
process_spawn: "tests/process/spawn",
}
}

View file

@ -58,3 +58,41 @@ impl Lune {
}
}
}
#[cfg(test)]
mod tests {
macro_rules! run_tests {
($($name:ident: $value:expr,)*) => {
$(
#[tokio::test]
async fn $name() {
let args = vec![
"Foo".to_owned(),
"Bar".to_owned()
];
let path = std::env::current_dir()
.unwrap()
.join(format!("src/tests/{}.luau", $value));
let lune = crate::Lune::new()
.unwrap()
.with_args(args)
.unwrap()
.with_default_globals()
.unwrap();
let script = tokio::fs::read_to_string(&path)
.await
.unwrap();
if let Err(e) = lune.run_with_name(&script, $value).await {
panic!("{}", e.to_string())
}
}
)*
}
}
run_tests! {
process_args: "process/args",
process_env: "process/env",
process_spawn: "process/spawn",
}
}