Skip to content

Commit 5878315

Browse files
committed
Fix the sense of the cfg(feature = "lua-no-oslib") test.
Add tests.
1 parent ffe8a41 commit 5878315

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/lua.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ unsafe fn load_from_std_lib(state: *mut ffi::lua_State, lua_mod: StdLib) {
782782
if lua_mod.contains(StdLib::IO) {
783783
requiref(state, cstr!("io"), Some(ffi::luaopen_io), 1);
784784
}
785-
#[cfg(feature = "lua-no-oslib")]
785+
#[cfg(not(feature = "lua-no-oslib"))]
786786
if lua_mod.contains(StdLib::OS) {
787787
requiref(state, cstr!("os"), Some(ffi::luaopen_os), 1);
788788
}

tests/tests.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,3 +1437,38 @@ fn context_thread_lua51() {
14371437
thrd.resume::<_, ()>(thrd_cloned).unwrap();
14381438
});
14391439
}
1440+
1441+
// Test the lua-no-oslib feature
1442+
#[cfg(feature = "lua-no-oslib")]
1443+
#[test]
1444+
fn test_no_oslib() {
1445+
Lua::new().context(|lua_ctx| {
1446+
let f = lua_ctx
1447+
.load(
1448+
r#"
1449+
assert(os == nil)
1450+
"#,
1451+
)
1452+
.into_function()
1453+
.unwrap();
1454+
f.call::<_, ()>(()).unwrap();
1455+
});
1456+
}
1457+
1458+
// Test the lua-no-oslib feature
1459+
#[cfg(not(feature = "lua-no-oslib"))]
1460+
#[test]
1461+
fn test_with_oslib() {
1462+
Lua::new().context(|lua_ctx| {
1463+
let f = lua_ctx
1464+
.load(
1465+
r#"
1466+
local x = os.time()
1467+
assert(x > 0)
1468+
"#,
1469+
)
1470+
.into_function()
1471+
.unwrap();
1472+
f.call::<_, ()>(()).unwrap();
1473+
});
1474+
}

0 commit comments

Comments
 (0)