Improve code coverage
This commit is contained in:
parent
3b94b4e86f
commit
bf286751fa
|
@ -180,6 +180,7 @@ pub enum Error {
|
|||
/// A specialized `Result` type used by `mlua`'s API.
|
||||
pub type Result<T> = StdResult<T, Error>;
|
||||
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
|
|
|
@ -93,7 +93,7 @@ struct MemoryInfo {
|
|||
/// More information can be found in the Lua 5.x [documentation].
|
||||
///
|
||||
/// [documentation]: https://www.lua.org/manual/5.4/manual.html#2.5
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum GCMode {
|
||||
Incremental,
|
||||
/// Requires `feature = "lua54"`
|
||||
|
@ -525,6 +525,7 @@ impl Lua {
|
|||
// Executes module entrypoint function, which returns only one Value.
|
||||
// The returned value then pushed to the Lua stack.
|
||||
#[doc(hidden)]
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
pub fn entrypoint1<'lua, 'callback, R, F>(&'lua self, func: F) -> Result<c_int>
|
||||
where
|
||||
'lua: 'callback,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::borrow::Cow;
|
||||
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
|
||||
use std::ffi::CString;
|
||||
use std::ffi::{CStr, CString};
|
||||
|
||||
use maplit::{btreemap, btreeset, hashmap, hashset};
|
||||
use mlua::{Lua, Result};
|
||||
|
@ -72,7 +72,12 @@ fn test_conv_cstring() -> Result<()> {
|
|||
let s = CString::new(b"hello".to_vec()).unwrap();
|
||||
lua.globals().set("s", s.clone())?;
|
||||
let s2: CString = lua.globals().get("s")?;
|
||||
assert!(s == s2);
|
||||
assert_eq!(s, s2);
|
||||
|
||||
let cs = CStr::from_bytes_with_nul(b"hello\0").unwrap();
|
||||
lua.globals().set("cs", cs)?;
|
||||
let cs2: CString = lua.globals().get("cs")?;
|
||||
assert_eq!(cs, cs2.as_c_str());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use mlua::{Lua, Result, UserData};
|
||||
use mlua::{GCMode, Lua, Result, UserData};
|
||||
|
||||
#[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
|
||||
use mlua::Error;
|
||||
|
@ -38,6 +38,9 @@ fn test_gc_control() -> Result<()> {
|
|||
let lua = Lua::new();
|
||||
let globals = lua.globals();
|
||||
|
||||
#[cfg(feature = "lua54")]
|
||||
assert_eq!(lua.gc_gen(0, 0), GCMode::Incremental);
|
||||
|
||||
#[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
|
||||
{
|
||||
assert!(lua.gc_is_running());
|
||||
|
@ -59,6 +62,9 @@ fn test_gc_control() -> Result<()> {
|
|||
lua.gc_collect()?;
|
||||
assert_eq!(Arc::strong_count(&rc), 1);
|
||||
|
||||
#[cfg(feature = "lua54")]
|
||||
assert_eq!(lua.gc_inc(0, 0, 0), GCMode::Generational);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -93,8 +93,8 @@ fn test_thread() -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "lua54", all(feature = "luajit", feature = "vendored")))]
|
||||
#[test]
|
||||
#[cfg(any(feature = "lua54", all(feature = "luajit", feature = "vendored")))]
|
||||
fn test_thread_reset() -> Result<()> {
|
||||
use mlua::{AnyUserData, UserData};
|
||||
use std::sync::Arc;
|
||||
|
|
|
@ -362,6 +362,12 @@ fn test_fields() -> Result<()> {
|
|||
index.set("f", 321)?;
|
||||
Ok(index)
|
||||
});
|
||||
fields.add_meta_field_with(MetaMethod::NewIndex, |lua| {
|
||||
lua.create_function(|lua, (_, field, val): (AnyUserData, String, Value)| {
|
||||
lua.globals().set(field, val)?;
|
||||
Ok(())
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -379,6 +385,9 @@ fn test_fields() -> Result<()> {
|
|||
assert(ud.uval == "hello")
|
||||
|
||||
assert(ud.f == 321)
|
||||
|
||||
ud.unknown = 789
|
||||
assert(unknown == 789)
|
||||
"#,
|
||||
)
|
||||
.exec()?;
|
||||
|
|
Loading…
Reference in New Issue