Add a test ensuring that userdata is dropped

This commit is contained in:
Jonas Schievink 2017-07-23 12:50:42 +02:00
parent 2bd7a2ee8c
commit 1c53ba3d4c
1 changed files with 27 additions and 0 deletions

View File

@ -844,3 +844,30 @@ fn test_expired_userdata() {
hatch:access()
"#, None).unwrap();
}
#[test]
fn detroys_userdata() {
use std::sync::atomic::{Ordering, AtomicBool, ATOMIC_BOOL_INIT};
static DROPPED: AtomicBool = ATOMIC_BOOL_INIT;
struct Userdata;
impl LuaUserDataType for Userdata {}
impl Drop for Userdata {
fn drop(&mut self) {
DROPPED.store(true, Ordering::SeqCst);
}
}
let lua = Lua::new();
{
let globals = lua.globals();
globals.set("userdata", Userdata).unwrap();
}
assert_eq!(DROPPED.load(Ordering::SeqCst), false);
drop(lua); // should destroy all objects
assert_eq!(DROPPED.load(Ordering::SeqCst), true);
}