Skip to content

Commit cbae4fe

Browse files
committed
More async tests
1 parent c68e3c4 commit cbae4fe

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/async.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ async fn test_async_function_wrap() -> Result<()> {
4848
let res: String = lua.load(r#"f("hello")"#).eval_async().await?;
4949
assert_eq!(res, "hello");
5050

51+
// Return error
52+
let ferr = Function::wrap_async(|| async move { Err::<(), _>(Error::runtime("some async error")) });
53+
lua.globals().set("ferr", ferr)?;
54+
lua.load(
55+
r#"
56+
local ok, err = pcall(ferr)
57+
assert(not ok and tostring(err):find("some async error"))
58+
"#,
59+
)
60+
.exec_async()
61+
.await
62+
.unwrap();
63+
5164
Ok(())
5265
}
5366

@@ -376,6 +389,13 @@ async fn test_async_table_object_like() -> Result<()> {
376389
table.set_metatable(Some(metatable));
377390
assert_eq!(table.call_async::<i64>(()).await.unwrap(), 15);
378391

392+
match table.call_async_method::<()>("non_existent", ()).await {
393+
Err(Error::RuntimeError(err)) => {
394+
assert!(err.contains("attempt to call a nil value (function 'non_existent')"))
395+
}
396+
r => panic!("expected RuntimeError, got {r:?}"),
397+
}
398+
379399
Ok(())
380400
}
381401

0 commit comments

Comments
 (0)