diff --git a/packages/lib-roblox/src/datatypes/types/mod.rs b/packages/lib-roblox/src/datatypes/types/mod.rs index d9c1371..db3d455 100644 --- a/packages/lib-roblox/src/datatypes/types/mod.rs +++ b/packages/lib-roblox/src/datatypes/types/mod.rs @@ -25,3 +25,59 @@ pub use vector2::Vector2; pub use vector2int16::Vector2int16; pub use vector3::Vector3; pub use vector3int16::Vector3int16; + +#[cfg(test)] +mod tests { + use std::{env::set_current_dir, fs::read_to_string, path::PathBuf}; + + use anyhow::{Context, Result}; + use mlua::prelude::*; + + use crate::make_all_datatypes; + + macro_rules! create_tests { + ($($test_name:ident: $file_path:expr,)*) => { $( + #[test] + fn $test_name() -> Result<()> { + // 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)?; + // Create all datatypes as globals + let lua = Lua::new(); + let env = lua.globals(); + for (name, tab) in make_all_datatypes(&lua)? { + env.set(name, tab)?; + } + // The rest of the test logic can continue as normal + let full_name = format!("tests/roblox/{}.luau", $file_path); + let script = read_to_string(full_name) + .with_context(|| format!( + "Failed to read test file '{}'", + $file_path + ))?; + lua.load(&script) + .set_name($file_path)? + .set_environment(env)? + .exec()?; + Ok(()) + } + )* } + } + + create_tests! { + brick_color: "datatypes/BrickColor", + color3: "datatypes/Color3", + color_sequence: "datatypes/ColorSequence", + color_sequence_keypoint: "datatypes/ColorSequenceKeypoint", + r#enum: "datatypes/Enum", + udim: "datatypes/UDim", + udim2: "datatypes/UDim2", + vector2: "datatypes/Vector2", + vector2int16: "datatypes/Vector2int16", + vector3: "datatypes/Vector3", + vector3int16: "datatypes/Vector3int16", + } +} diff --git a/packages/lib-roblox/src/lib.rs b/packages/lib-roblox/src/lib.rs index a687558..34d863f 100644 --- a/packages/lib-roblox/src/lib.rs +++ b/packages/lib-roblox/src/lib.rs @@ -4,9 +4,6 @@ pub mod datatypes; pub mod document; pub mod instance; -#[cfg(test)] -mod tests; - fn make_dt(lua: &Lua, f: F) -> LuaResult where F: Fn(&Lua, &LuaTable) -> LuaResult<()>, diff --git a/packages/lib-roblox/src/tests.rs b/packages/lib-roblox/src/tests.rs deleted file mode 100644 index 725e2c3..0000000 --- a/packages/lib-roblox/src/tests.rs +++ /dev/null @@ -1,52 +0,0 @@ -use std::{env::set_current_dir, fs::read_to_string, path::PathBuf}; - -use anyhow::{Context, Result}; -use mlua::prelude::*; - -use super::make_all_datatypes; - -macro_rules! create_tests { - ($($test_name:ident: $file_path:expr,)*) => { $( - #[test] - fn $test_name() -> Result<()> { - // 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)?; - // Create all datatypes as globals - let lua = Lua::new(); - let env = lua.globals(); - for (name, tab) in make_all_datatypes(&lua)? { - env.set(name, tab)?; - } - // The rest of the test logic can continue as normal - let full_name = format!("tests/roblox/{}.luau", $file_path); - let script = read_to_string(full_name) - .with_context(|| format!( - "Failed to read test file '{}'", - $file_path - ))?; - lua.load(&script) - .set_name($file_path)? - .set_environment(env)? - .exec()?; - Ok(()) - } - )* } -} - -create_tests! { - datatypes_brick_color: "datatypes/BrickColor", - datatypes_color3: "datatypes/Color3", - datatypes_color_sequence: "datatypes/ColorSequence", - datatypes_color_sequence_keypoint: "datatypes/ColorSequenceKeypoint", - datatypes_enum: "datatypes/Enum", - datatypes_udim: "datatypes/UDim", - datatypes_udim2: "datatypes/UDim2", - datatypes_vector2: "datatypes/Vector2", - datatypes_vector2int16: "datatypes/Vector2int16", - datatypes_vector3: "datatypes/Vector3", - datatypes_vector3int16: "datatypes/Vector3int16", -}