--[[-- Test environment for module/features.lua Extends the shared stubs with a fresh copy of the features module and a stub of exp_util storage which lets tests act out on_init and on_load. Run as a chunk by test/lua/runner.js, receiving the shared folder. The suite returned here becomes `...` in each test file. ]] local shared_root = ... --- @type string local source = assert(debug.getinfo(1, "S")).source:gsub("\\", "/") local plugin_root = assert(source:match("^@(.*)/test/module/env%.lua$")) local Framework = assert(loadfile(shared_root .. "/framework.lua"))() --- @type Framework --- @class ExpScenario.TestEnv : Stubs --- @field Feature ExpScenario.Features A fresh copy of the features module --- @field storage table The table registered with storage, as on_init would store it --- @field on_load fun(tbl: table) Act out on_load with the given storage table --- @field load_config fun(name: string): ExpScenario.Feature Load module/config/.lua --- @field load_module fun(name: string): any Load module/.lua, such as "control/player_settings" --- @field logged string[] Messages passed to log --- @field events table[] Raised events, name and tick filled in return Framework.suite(function(env) --- @cast env ExpScenario.TestEnv local callback --- @type fun(tbl: table) env.logged = {} log = function(message) env.logged[#env.logged + 1] = message end table_size = function(tbl) local size = 0 for _ in pairs(tbl) do size = size + 1 end return size end env.extend_requires{ ["modules/exp_util/storage"] = { register = function(tbl, fn) env.storage = tbl callback = fn end, }, } env.Feature = assert(loadfile(plugin_root .. "/module/features.lua"))() env.extend_requires{ ["modules/exp_scenario/features"] = env.Feature } function env.on_load(tbl) env.storage = tbl callback(tbl) end function env.load_config(name) return assert(loadfile(plugin_root .. "/module/config/" .. name .. ".lua"))() end function env.load_module(name) return assert(loadfile(plugin_root .. "/module/" .. name .. ".lua"))() end return env end)