summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlex Orlenko <zxteam@protonmail.com>2022-02-19 14:15:15 +0000
committerAlex Orlenko <zxteam@protonmail.com>2022-03-20 20:30:20 +0000
commitc322e028e2201fbb12a77caceb1dc97b1822ae54 (patch)
tree7d625c01e641a96516ea1042f2b4c6e8399e3285 /tests
parent6dc127f4eb500398ffd81edcb24d45353b0ff4cf (diff)
downloadmlua-c322e028e2201fbb12a77caceb1dc97b1822ae54.zip
Initial Luau support
Diffstat (limited to 'tests')
-rw-r--r--tests/async.rs4
-rw-r--r--tests/function.rs1
-rw-r--r--tests/hooks.rs2
-rw-r--r--tests/memory.rs7
-rw-r--r--tests/tests.rs24
-rw-r--r--tests/thread.rs3
-rw-r--r--tests/userdata.rs13
7 files changed, 33 insertions, 21 deletions
diff --git a/tests/async.rs b/tests/async.rs
index dead884..2bfde03 100644
--- a/tests/async.rs
+++ b/tests/async.rs
@@ -299,7 +299,7 @@ async fn test_async_userdata() -> Result<()> {
Ok(format!("elapsed:{}ms", n))
});
- #[cfg(not(feature = "lua51"))]
+ #[cfg(not(any(feature = "lua51", feature = "luau")))]
methods.add_async_meta_method(mlua::MetaMethod::Call, |_, data, ()| async move {
let n = data.0.load(Ordering::Relaxed);
Delay::new(Duration::from_millis(n)).await;
@@ -363,7 +363,7 @@ async fn test_async_userdata() -> Result<()> {
.exec_async()
.await?;
- #[cfg(not(feature = "lua51"))]
+ #[cfg(not(any(feature = "lua51", feature = "luau")))]
lua.load(
r#"
userdata:set_value(15)
diff --git a/tests/function.rs b/tests/function.rs
index a7bdd9f..f245c37 100644
--- a/tests/function.rs
+++ b/tests/function.rs
@@ -93,6 +93,7 @@ fn test_c_function() -> Result<()> {
Ok(())
}
+#[cfg(not(feature = "luau"))]
#[test]
fn test_dump() -> Result<()> {
let lua = unsafe { Lua::unsafe_new() };
diff --git a/tests/hooks.rs b/tests/hooks.rs
index 3e8e876..8c44b5d 100644
--- a/tests/hooks.rs
+++ b/tests/hooks.rs
@@ -1,3 +1,5 @@
+#![cfg(not(feature = "luau"))]
+
use std::cell::RefCell;
use std::ops::Deref;
use std::str;
diff --git a/tests/memory.rs b/tests/memory.rs
index 45332f4..36d094e 100644
--- a/tests/memory.rs
+++ b/tests/memory.rs
@@ -41,7 +41,12 @@ fn test_gc_control() -> Result<()> {
#[cfg(feature = "lua54")]
assert_eq!(lua.gc_gen(0, 0), mlua::GCMode::Incremental);
- #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
+ #[cfg(any(
+ feature = "lua54",
+ feature = "lua53",
+ feature = "lua52",
+ feature = "luau"
+ ))]
{
assert!(lua.gc_is_running());
lua.gc_stop();
diff --git a/tests/tests.rs b/tests/tests.rs
index 6c6b132..2d99911 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -11,6 +11,7 @@ use mlua::{
UserData, Value, Variadic,
};
+#[cfg(not(feature = "luau"))]
#[test]
fn test_safety() -> Result<()> {
let lua = Lua::new();
@@ -120,6 +121,7 @@ fn test_exec() -> Result<()> {
"#,
)
.eval()?;
+ println!("checkpoint");
assert!(module.contains_key("func")?);
assert_eq!(
module.get::<_, Function>("func")?.call::<_, String>(())?,
@@ -150,6 +152,7 @@ fn test_eval() -> Result<()> {
Ok(())
}
+#[cfg(not(feature = "luau"))]
#[test]
fn test_load_mode() -> Result<()> {
let lua = unsafe { Lua::unsafe_new() };
@@ -250,15 +253,7 @@ fn test_error() -> Result<()> {
}
}
- impl error::Error for TestError {
- fn description(&self) -> &str {
- "test error"
- }
-
- fn cause(&self) -> Option<&dyn error::Error> {
- None
- }
- }
+ impl error::Error for TestError {}
let lua = Lua::new();
@@ -295,8 +290,8 @@ fn test_error() -> Result<()> {
end, 3)
local function handler(err)
- if string.match(_VERSION, ' 5%.1$') or string.match(_VERSION, ' 5%.2$') then
- -- Special case for Lua 5.1/5.2
+ if string.match(_VERSION, ' 5%.1$') or string.match(_VERSION, ' 5%.2$') or _VERSION == "Luau" then
+ -- Special case for Lua 5.1/5.2 and Luau
local caps = string.match(err, ': (%d+)$')
if caps then
err = caps
@@ -1096,7 +1091,11 @@ fn test_context_thread() -> Result<()> {
))]
f.call::<_, ()>(lua.current_thread())?;
- #[cfg(any(feature = "lua51", all(feature = "luajit", not(feature = "luajit52"))))]
+ #[cfg(any(
+ feature = "lua51",
+ all(feature = "luajit", not(feature = "luajit52")),
+ feature = "luau"
+ ))]
f.call::<_, ()>(Nil)?;
Ok(())
@@ -1170,6 +1169,7 @@ fn test_load_from_function() -> Result<()> {
Ok(())
}
+#[cfg(not(feature = "luau"))]
#[test]
fn test_inspect_stack() -> Result<()> {
let lua = Lua::new();
diff --git a/tests/thread.rs b/tests/thread.rs
index ab687ad..5873680 100644
--- a/tests/thread.rs
+++ b/tests/thread.rs
@@ -155,7 +155,8 @@ fn test_coroutine_from_closure() -> Result<()> {
feature = "lua54",
feature = "lua53",
feature = "lua52",
- feature = "luajit"
+ feature = "luajit",
+ feature = "luau"
))]
let thrd: Thread = lua.load("coroutine.create(main)").eval()?;
#[cfg(feature = "lua51")]
diff --git a/tests/userdata.rs b/tests/userdata.rs
index cba2638..c78b1db 100644
--- a/tests/userdata.rs
+++ b/tests/userdata.rs
@@ -350,7 +350,7 @@ fn test_userdata_take() -> Result<()> {
}
#[test]
-fn test_destroy_userdata() -> Result<()> {
+fn test_userdata_destroy() -> Result<()> {
struct MyUserdata(Arc<()>);
impl UserData for MyUserdata {}
@@ -358,12 +358,15 @@ fn test_destroy_userdata() -> Result<()> {
let rc = Arc::new(());
let lua = Lua::new();
- lua.globals().set("userdata", MyUserdata(rc.clone()))?;
+ let ud = lua.create_userdata(MyUserdata(rc.clone()))?;
+ ud.set_user_value(MyUserdata(rc.clone()))?;
+ lua.globals().set("userdata", ud)?;
- assert_eq!(Arc::strong_count(&rc), 2);
+ assert_eq!(Arc::strong_count(&rc), 3);
- // should destroy all objects
- let _ = lua.globals().raw_remove("userdata")?;
+ // Should destroy all objects
+ lua.globals().raw_remove("userdata")?;
+ lua.gc_collect()?;
lua.gc_collect()?;
assert_eq!(Arc::strong_count(&rc), 1);