Files
2026-11-11 15:53:07 +03:00

70 lines
1.9 KiB
Lua

-- Мини-фреймворк тестов для запуска в Studio через MCP (node tools/run-tests.js).
-- Модули сервера клонируются в отдельную папку, чтобы каждый набор тестов получал свежее состояние.
local T = { results = {}, passed = 0, failed = 0 }
local SSS = game:GetService("ServerScriptService")
local holder = Instance.new("Folder")
holder.Name = "TestModules_" .. tostring(math.random(1, 1e9))
holder.Parent = game:GetService("ServerStorage")
T.holder = holder
-- свежая копия модулей (зависимости ищутся через script.Parent — кладём их рядом)
function T.fresh(...)
local folder = Instance.new("Folder")
folder.Parent = holder
local out = {}
for _, name in ipairs({ "Potions", "Progression", "Market", "PlayerStore" }) do
local m = SSS:FindFirstChild(name)
if m then
m:Clone().Parent = folder
end
end
for i, name in ipairs({ ... }) do
out[i] = require(folder[name])
end
return table.unpack(out)
end
function T.test(name, fn)
local ok, err = xpcall(fn, function(e)
return tostring(e) .. "\n" .. debug.traceback(nil, 2)
end)
if ok then
T.passed += 1
table.insert(T.results, "PASS " .. name)
else
T.failed += 1
table.insert(T.results, "FAIL " .. name .. " :: " .. tostring(err):sub(1, 600))
end
end
function T.eq(a, b, msg)
if a ~= b then
error(("%s: expected %s, got %s"):format(msg or "eq", tostring(b), tostring(a)), 2)
end
end
function T.ok(v, msg)
if not v then
error(msg or "expected truthy", 2)
end
end
function T.deep(t)
if type(t) ~= "table" then
return t
end
local c = {}
for k, v in pairs(t) do
c[k] = T.deep(v)
end
return c
end
function T.report(suite)
holder:Destroy()
return ("%s: %d passed, %d failed\n%s"):format(suite, T.passed, T.failed, table.concat(T.results, "\n"))
end
return T