diff --git a/scripts/data/integration_tests/test_lua_api/player.lua b/scripts/data/integration_tests/test_lua_api/player.lua index 95e35e7dd9..1da817e495 100644 --- a/scripts/data/integration_tests/test_lua_api/player.lua +++ b/scripts/data/integration_tests/test_lua_api/player.lua @@ -218,6 +218,18 @@ testing.registerLocalTest('findNearestNavMeshPosition', 'Navigation mesh position ' .. testing.formatActualExpected(result, expected)) end) +testing.registerLocalTest('playerMemoryLimit', + function() + local ok, err = pcall(function() + local str = 'a' + while true do + str = str .. str + end + end) + testing.expectEqual(ok, false, 'Script reaching memory limit should fail') + testing.expectEqual(err, 'not enough memory') + end) + return { engineHandlers = { onFrame = testing.updateLocal, diff --git a/scripts/data/integration_tests/test_lua_api/test.lua b/scripts/data/integration_tests/test_lua_api/test.lua index 1bbb3b4fc2..86fb8e904c 100644 --- a/scripts/data/integration_tests/test_lua_api/test.lua +++ b/scripts/data/integration_tests/test_lua_api/test.lua @@ -206,6 +206,19 @@ local function testUTF8Strings() testing.expectEqual(utf8.offset(utf8str, 9), 11) end +local function testMemoryLimit() + local ok, err = pcall(function() + local t = {} + local n = 1 + while true do + t[n] = n + n = n + 1 + end + end) + testing.expectEqual(ok, false, 'Script reaching memory limit should fail') + testing.expectEqual(err, 'not enough memory') +end + local function initPlayer() player:teleport('', util.vector3(4096, 4096, 867.237), util.transform.identity) coroutine.yield() @@ -260,6 +273,11 @@ tests = { {'utf8Chars', testUTF8Chars}, {'utf8Strings', testUTF8Strings}, {'mwscript', testMWScript}, + {'testMemoryLimit', testMemoryLimit}, + {'playerMemoryLimit', function() + initPlayer() + testing.runLocalTest(player, 'playerMemoryLimit') + end} } return { diff --git a/scripts/integration_tests.py b/scripts/integration_tests.py index 028b55d7da..bd93a317b3 100755 --- a/scripts/integration_tests.py +++ b/scripts/integration_tests.py @@ -64,6 +64,8 @@ def runTest(name): "framerate limit = 60\n" "[Game]\n" "smooth animation transitions = true\n" + "[Lua]\n" + f"memory limit = {1024 * 1024 * 128}\n" ) stdout_lines = list() exit_ok = True