模块:Deep2 CrashTest

来自希服维基

可在模块:Deep2 CrashTest/doc创建此模块的帮助文档

local p = {}
function p.test()
    -- Try some operations that might crash or leak
    local results = {}

    -- Try to create infinite recursion (will be caught by Lua)
    local function recurse(n)
        if n > 0 then return recurse(n - 1) end
        return "OK"
    end
    local ok, err = pcall(recurse, 5000)
    results[1] = "recurse_" .. tostring(ok) .. ":" .. tostring(err)

    -- Try to allocate too much memory
    local ok2, err2 = pcall(function()
        local t = {}
        for i = 1, 100000 do t[i] = string.rep("x", 100) end
    end)
    results[2] = "memory_" .. tostring(ok2) .. ":" .. tostring(err2)

    -- Try string.rep with negative (might cause issues)
    local ok3, err3 = pcall(string.rep, "x", -1)
    results[3] = "strrep_neg=" .. tostring(ok3) .. ":" .. tostring(err3)

    return table.concat(results, " | ")
end
return p