mirror of
https://github.com/lune-org/lune.git
synced 2025-05-04 10:43:57 +01:00
add test to check that modules are cached correctly
This commit is contained in:
parent
94ba331ed0
commit
8cc4a396f5
4 changed files with 33 additions and 0 deletions
|
@ -95,6 +95,7 @@ create_tests! {
|
||||||
require_nested: "require/tests/nested",
|
require_nested: "require/tests/nested",
|
||||||
require_parents: "require/tests/parents",
|
require_parents: "require/tests/parents",
|
||||||
require_siblings: "require/tests/siblings",
|
require_siblings: "require/tests/siblings",
|
||||||
|
require_state: "require/tests/state",
|
||||||
|
|
||||||
global_g_table: "globals/_G",
|
global_g_table: "globals/_G",
|
||||||
global_version: "globals/_VERSION",
|
global_version: "globals/_VERSION",
|
||||||
|
|
16
tests/require/tests/state.luau
Normal file
16
tests/require/tests/state.luau
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
-- the idea of this test is that state_module stores some state in one of its local variable
|
||||||
|
-- we also set a global in the module to ensure the change we would have expected happens
|
||||||
|
local state_module = require("./state_module")
|
||||||
|
|
||||||
|
-- we confirm that without anything happening, the initial value is what we ecpect
|
||||||
|
assert(state_module.state == 10)
|
||||||
|
assert(_state_test_global == 10)
|
||||||
|
|
||||||
|
-- this second file also requires state_module and calls a function that changes both the local state and the global to 11
|
||||||
|
require("./state_second")
|
||||||
|
|
||||||
|
-- with correct module caching, we should see the change done in state_secone reflected here
|
||||||
|
assert(state_module.state == 11)
|
||||||
|
-- if this also fails then there is either a problem with globals, or state_second is not doing what we expect it to
|
||||||
|
assert(_state_test_global == 11)
|
||||||
|
|
11
tests/require/tests/state_module.luau
Normal file
11
tests/require/tests/state_module.luau
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
M.state = 10
|
||||||
|
_state_test_global = 10
|
||||||
|
|
||||||
|
function M.set_state(n: number)
|
||||||
|
M.state = n
|
||||||
|
_state_test_global = n
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
5
tests/require/tests/state_second.luau
Normal file
5
tests/require/tests/state_second.luau
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
local state_module = require("./state_module")
|
||||||
|
|
||||||
|
state_module.set_state(11)
|
||||||
|
|
||||||
|
return {}
|
Loading…
Add table
Reference in a new issue