From 9cef9e01e5da669f39d7f8f1ba1b1e61562693e9 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Sat, 21 Jan 2023 00:03:16 -0500 Subject: [PATCH] Move tests to lib --- src/cli/main.rs | 24 ---------------- src/lib/lib.rs | 38 +++++++++++++++++++++++++ {.lune => src}/tests/process/args.luau | 0 {.lune => src}/tests/process/env.luau | 0 {.lune => src}/tests/process/spawn.luau | 0 5 files changed, 38 insertions(+), 24 deletions(-) rename {.lune => src}/tests/process/args.luau (100%) rename {.lune => src}/tests/process/env.luau (100%) rename {.lune => src}/tests/process/spawn.luau (100%) diff --git a/src/cli/main.rs b/src/cli/main.rs index 02f6640..7eb5c43 100644 --- a/src/cli/main.rs +++ b/src/cli/main.rs @@ -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", - } -} diff --git a/src/lib/lib.rs b/src/lib/lib.rs index 3153ca9..25448ea 100644 --- a/src/lib/lib.rs +++ b/src/lib/lib.rs @@ -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", + } +} diff --git a/.lune/tests/process/args.luau b/src/tests/process/args.luau similarity index 100% rename from .lune/tests/process/args.luau rename to src/tests/process/args.luau diff --git a/.lune/tests/process/env.luau b/src/tests/process/env.luau similarity index 100% rename from .lune/tests/process/env.luau rename to src/tests/process/env.luau diff --git a/.lune/tests/process/spawn.luau b/src/tests/process/spawn.luau similarity index 100% rename from .lune/tests/process/spawn.luau rename to src/tests/process/spawn.luau