mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 04:50:36 +00:00
Move tests to lib
This commit is contained in:
parent
94393419c2
commit
9cef9e01e5
5 changed files with 38 additions and 24 deletions
|
@ -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",
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue