2023-02-10 11:14:28 +00:00
|
|
|
use std::{env::set_current_dir, path::PathBuf, process::ExitCode};
|
|
|
|
|
|
|
|
use anyhow::Result;
|
|
|
|
use console::set_colors_enabled;
|
|
|
|
use console::set_colors_enabled_stderr;
|
|
|
|
use tokio::fs::read_to_string;
|
|
|
|
|
|
|
|
use crate::Lune;
|
|
|
|
|
|
|
|
const ARGS: &[&str] = &["Foo", "Bar"];
|
|
|
|
|
|
|
|
macro_rules! create_tests {
|
|
|
|
($($name:ident: $value:expr,)*) => { $(
|
2023-02-13 14:28:18 +00:00
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
2023-02-10 11:14:28 +00:00
|
|
|
async fn $name() -> Result<ExitCode> {
|
|
|
|
// Disable styling for stdout and stderr since
|
|
|
|
// some tests rely on output not being styled
|
|
|
|
set_colors_enabled(false);
|
|
|
|
set_colors_enabled_stderr(false);
|
|
|
|
// NOTE: This path is relative to the lib
|
|
|
|
// package, not the cwd or workspace root,
|
|
|
|
// so we need to cd to the repo root first
|
|
|
|
let crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
|
|
|
let root_dir = crate_dir.join("../../").canonicalize()?;
|
|
|
|
set_current_dir(root_dir)?;
|
|
|
|
// The rest of the test logic can continue as normal
|
|
|
|
let full_name = format!("tests/{}.luau", $value);
|
|
|
|
let script = read_to_string(&full_name).await?;
|
2023-02-17 18:20:17 +00:00
|
|
|
let lune = Lune::new().with_args(
|
2023-02-10 11:14:28 +00:00
|
|
|
ARGS
|
|
|
|
.clone()
|
|
|
|
.iter()
|
|
|
|
.map(ToString::to_string)
|
2023-02-17 18:20:17 +00:00
|
|
|
.collect::<Vec<_>>()
|
2023-02-10 11:14:28 +00:00
|
|
|
);
|
2023-02-26 12:59:34 +00:00
|
|
|
let script_name = full_name
|
|
|
|
.trim_end_matches(".luau")
|
|
|
|
.trim_end_matches(".lua")
|
|
|
|
.to_string();
|
2023-03-21 14:06:28 +00:00
|
|
|
let exit_code = lune.run(&script_name, &script).await?;
|
2023-02-10 11:14:28 +00:00
|
|
|
Ok(exit_code)
|
|
|
|
}
|
|
|
|
)* }
|
|
|
|
}
|
|
|
|
|
|
|
|
create_tests! {
|
|
|
|
fs_files: "fs/files",
|
|
|
|
fs_dirs: "fs/dirs",
|
2023-02-23 09:20:57 +00:00
|
|
|
fs_move: "fs/move",
|
2023-02-10 11:14:28 +00:00
|
|
|
net_request_codes: "net/request/codes",
|
|
|
|
net_request_methods: "net/request/methods",
|
2023-02-23 10:31:42 +00:00
|
|
|
net_request_query: "net/request/query",
|
2023-02-10 11:14:28 +00:00
|
|
|
net_request_redirect: "net/request/redirect",
|
2023-03-21 16:48:07 +00:00
|
|
|
net_url_encode: "net/url/encode",
|
|
|
|
net_url_decode: "net/url/decode",
|
2023-02-14 12:17:07 +00:00
|
|
|
net_serve_requests: "net/serve/requests",
|
|
|
|
net_serve_websockets: "net/serve/websockets",
|
2023-02-10 11:14:28 +00:00
|
|
|
process_args: "process/args",
|
|
|
|
process_cwd: "process/cwd",
|
|
|
|
process_env: "process/env",
|
|
|
|
process_exit: "process/exit",
|
|
|
|
process_spawn: "process/spawn",
|
2023-03-21 10:07:42 +00:00
|
|
|
require_async: "globals/require/tests/async",
|
|
|
|
require_async_concurrent: "globals/require/tests/async_concurrent",
|
|
|
|
require_async_sequential: "globals/require/tests/async_sequential",
|
2023-03-21 14:06:28 +00:00
|
|
|
require_builtins: "globals/require/tests/builtins",
|
2023-02-17 14:03:13 +00:00
|
|
|
require_children: "globals/require/tests/children",
|
|
|
|
require_invalid: "globals/require/tests/invalid",
|
|
|
|
require_nested: "globals/require/tests/nested",
|
|
|
|
require_parents: "globals/require/tests/parents",
|
|
|
|
require_siblings: "globals/require/tests/siblings",
|
2023-02-23 10:31:42 +00:00
|
|
|
// TODO: Uncomment this test, it is commented out right
|
|
|
|
// now to let CI pass so that we can make a new release
|
2023-02-22 12:09:52 +00:00
|
|
|
// global_coroutine: "globals/coroutine",
|
2023-02-17 14:03:13 +00:00
|
|
|
global_pcall: "globals/pcall",
|
|
|
|
global_type: "globals/type",
|
|
|
|
global_typeof: "globals/typeof",
|
2023-03-21 15:48:28 +00:00
|
|
|
serde_json_decode: "serde/json/decode",
|
|
|
|
serde_json_encode: "serde/json/encode",
|
|
|
|
serde_toml_decode: "serde/toml/decode",
|
|
|
|
serde_toml_encode: "serde/toml/encode",
|
2023-02-10 11:14:28 +00:00
|
|
|
stdio_format: "stdio/format",
|
|
|
|
stdio_color: "stdio/color",
|
|
|
|
stdio_style: "stdio/style",
|
|
|
|
stdio_write: "stdio/write",
|
|
|
|
stdio_ewrite: "stdio/ewrite",
|
|
|
|
task_cancel: "task/cancel",
|
|
|
|
task_defer: "task/defer",
|
|
|
|
task_delay: "task/delay",
|
|
|
|
task_spawn: "task/spawn",
|
|
|
|
task_wait: "task/wait",
|
|
|
|
}
|