diff options
author | kyren <kerriganw@gmail.com> | 2018-03-12 16:00:11 -0400 |
---|---|---|
committer | kyren <kerriganw@gmail.com> | 2018-03-12 16:00:11 -0400 |
commit | f79d771f1a9e49cc5e7e7cf2553abb0d37339e36 (patch) | |
tree | a51441efe97a46bd99ba426d4621be1462aec5be /src/tests/thread.rs | |
parent | ee23f199f0670c2c159bd653baaddd4015c602f0 (diff) | |
download | mlua-f79d771f1a9e49cc5e7e7cf2553abb0d37339e36.zip |
Documentation improvements, split scope into its own module, improved tests
Also makes `Lua` and associated types !UnwindSafe and !RefUnwindSafe, which they
should be because they are intensely internally mutable. Lua IS still panic
safe, but that doesn't mean it should be marked as UnwindSafe (as I understand
it).
Diffstat (limited to 'src/tests/thread.rs')
-rw-r--r-- | src/tests/thread.rs | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/tests/thread.rs b/src/tests/thread.rs index ccfb397..56b671d 100644 --- a/src/tests/thread.rs +++ b/src/tests/thread.rs @@ -1,6 +1,6 @@ use std::panic::catch_unwind; -use {Error, Function, Lua, Thread, ThreadStatus}; +use {Error, Function, Lua, Result, Thread, ThreadStatus}; #[test] fn test_thread() { @@ -97,18 +97,17 @@ fn coroutine_from_closure() { #[test] fn coroutine_panic() { - // check that coroutines propagate panics correctly - let lua = Lua::new(); - let thrd_main = lua.create_function(|lua, ()| { - // whoops, 'main' has a wrong type - let _coro: u32 = lua.globals().get("main").unwrap(); - Ok(()) - }).unwrap(); - lua.globals().set("main", thrd_main.clone()).unwrap(); - let thrd: Thread = lua.create_thread(thrd_main).unwrap(); - - match catch_unwind(|| thrd.resume::<_, ()>(())) { + match catch_unwind(|| -> Result<()> { + // check that coroutines propagate panics correctly + let lua = Lua::new(); + let thrd_main = lua.create_function(|lua, ()| -> Result<()> { + panic!("test_panic"); + })?; + lua.globals().set("main", thrd_main.clone())?; + let thrd: Thread = lua.create_thread(thrd_main)?; + thrd.resume(()) + }) { Ok(r) => panic!("coroutine panic not propagated, instead returned {:?}", r), - Err(_) => {} + Err(p) => assert!(*p.downcast::<&str>().unwrap() == "test_panic"), } } |