Skip to content

Commit 8dfa212

Browse files
committed
Add thread test to check recovery when pushing bad arg
1 parent 75c23e5 commit 8dfa212

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

tests/thread.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::panic::catch_unwind;
22

3-
use mlua::{Error, Function, Lua, Result, Thread, ThreadStatus};
3+
use mlua::{Error, Function, IntoLua, Lua, Result, Thread, ThreadStatus, Value};
44

55
#[test]
66
fn test_thread() -> Result<()> {
@@ -252,3 +252,24 @@ fn test_thread_resume_error() -> Result<()> {
252252

253253
Ok(())
254254
}
255+
256+
#[test]
257+
fn test_thread_resume_bad_arg() -> Result<()> {
258+
let lua = Lua::new();
259+
260+
struct BadArg;
261+
262+
impl IntoLua for BadArg {
263+
fn into_lua(self, _lua: &Lua) -> Result<Value> {
264+
Err(Error::runtime("bad arg"))
265+
}
266+
}
267+
268+
let f = lua.create_thread(lua.create_function(|_, ()| Ok("okay"))?)?;
269+
let res = f.resume::<()>((123, BadArg));
270+
assert!(matches!(res, Err(Error::RuntimeError(msg)) if msg == "bad arg"));
271+
let res = f.resume::<String>(()).unwrap();
272+
assert_eq!(res, "okay");
273+
274+
Ok(())
275+
}

0 commit comments

Comments
 (0)