From cbae4fe59c0cb0ef56d99fe7b524bd2b3ba95bca Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Fri, 18 Oct 2024 22:50:15 +0100 Subject: [PATCH] More async tests --- tests/async.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/async.rs b/tests/async.rs index f939a68..4ce1bdd 100644 --- a/tests/async.rs +++ b/tests/async.rs @@ -48,6 +48,19 @@ async fn test_async_function_wrap() -> Result<()> { let res: String = lua.load(r#"f("hello")"#).eval_async().await?; assert_eq!(res, "hello"); + // Return error + let ferr = Function::wrap_async(|| async move { Err::<(), _>(Error::runtime("some async error")) }); + lua.globals().set("ferr", ferr)?; + lua.load( + r#" + local ok, err = pcall(ferr) + assert(not ok and tostring(err):find("some async error")) + "#, + ) + .exec_async() + .await + .unwrap(); + Ok(()) } @@ -376,6 +389,13 @@ async fn test_async_table_object_like() -> Result<()> { table.set_metatable(Some(metatable)); assert_eq!(table.call_async::(()).await.unwrap(), 15); + match table.call_async_method::<()>("non_existent", ()).await { + Err(Error::RuntimeError(err)) => { + assert!(err.contains("attempt to call a nil value (function 'non_existent')")) + } + r => panic!("expected RuntimeError, got {r:?}"), + } + Ok(()) }