diff options
author | Benoit Giannangeli <giann008@gmail.com> | 2017-05-29 19:05:07 +0200 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-05-31 22:26:56 +1000 |
commit | 2e9c10dd6f9b9fd83b7424eb10684570b663348b (patch) | |
tree | b6ef9277a25fa088ceef84bfe2ccbfc117d0bff0 /tests/test-suite | |
parent | da7551f134377574bbda7dfe5b73e3989fddeb77 (diff) | |
download | fengari-2e9c10dd6f9b9fd83b7424eb10684570b663348b.tar.gz fengari-2e9c10dd6f9b9fd83b7424eb10684570b663348b.tar.bz2 fengari-2e9c10dd6f9b9fd83b7424eb10684570b663348b.zip |
src/ldebug.js: Test for null result of findlocal in lua_setlocal
Diffstat (limited to 'tests/test-suite')
-rw-r--r-- | tests/test-suite/inprogress/db.js | 248 |
1 files changed, 248 insertions, 0 deletions
diff --git a/tests/test-suite/inprogress/db.js b/tests/test-suite/inprogress/db.js index 5ff307c..af1d042 100644 --- a/tests/test-suite/inprogress/db.js +++ b/tests/test-suite/inprogress/db.js @@ -96,3 +96,251 @@ test("[test-suite] db: getinfo, ...line...", function (t) { }, "Lua program ran without error"); }); + + +test("[test-suite] db: test file ad string names truncation", function (t) { + let luaCode = ` + a = "function f () end" + local function dostring (s, x) return load(s, x)() end + dostring(a) + assert(debug.getinfo(f).short_src == string.format('[string "%s"]', a)) + dostring(a..string.format("; %s\\n=1", string.rep('p', 400))) + assert(string.find(debug.getinfo(f).short_src, '^%[string [^\\n]*%.%.%."%]$')) + dostring(a..string.format("; %s=1", string.rep('p', 400))) + assert(string.find(debug.getinfo(f).short_src, '^%[string [^\\n]*%.%.%."%]$')) + dostring("\\n"..a) + assert(debug.getinfo(f).short_src == '[string "..."]') + dostring(a, "") + assert(debug.getinfo(f).short_src == '[string ""]') + dostring(a, "@xuxu") + assert(debug.getinfo(f).short_src == "xuxu") + dostring(a, "@"..string.rep('p', 1000)..'t') + assert(string.find(debug.getinfo(f).short_src, "^%.%.%.p*t$")) + dostring(a, "=xuxu") + assert(debug.getinfo(f).short_src == "xuxu") + dostring(a, string.format("=%s", string.rep('x', 500))) + assert(string.find(debug.getinfo(f).short_src, "^x*$")) + dostring(a, "=") + assert(debug.getinfo(f).short_src == "") + a = nil; f = nil; + `, L; + + t.plan(2); + + t.doesNotThrow(function () { + + L = lauxlib.luaL_newstate(); + + lualib.luaL_openlibs(L); + + lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode)); + + }, "Lua program loaded without error"); + + t.doesNotThrow(function () { + + lua.lua_call(L, 0, -1); + + }, "Lua program ran without error"); + +}); + +test("[test-suite] db: local", function (t) { + let luaCode = ` + repeat + local g = {x = function () + local a = debug.getinfo(2) + assert(a.name == 'f' and a.namewhat == 'local') + a = debug.getinfo(1) + assert(a.name == 'x' and a.namewhat == 'field') + return 'xixi' + end} + local f = function () return 1+1 and (not 1 or g.x()) end + assert(f() == 'xixi') + g = debug.getinfo(f) + assert(g.what == "Lua" and g.func == f and g.namewhat == "" and not g.name) + + function f (x, name) -- local! + name = name or 'f' + local a = debug.getinfo(1) + assert(a.name == name and a.namewhat == 'local') + return x + end + + -- breaks in different conditions + if 3>4 then break end; f() + if 3<4 then a=1 else break end; f() + while 1 do local x=10; break end; f() + local b = 1 + if 3>4 then return math.sin(1) end; f() + a = 3<4; f() + a = 3<4 or 1; f() + repeat local x=20; if 4>3 then f() else break end; f() until 1 + g = {} + f(g).x = f(2) and f(10)+f(9) + assert(g.x == f(19)) + function g(x) if not x then return 3 end return (x('a', 'x')) end + assert(g(f) == 'a') + until 1 + `, L; + + t.plan(2); + + t.doesNotThrow(function () { + + L = lauxlib.luaL_newstate(); + + lualib.luaL_openlibs(L); + + lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode)); + + }, "Lua program loaded without error"); + + t.doesNotThrow(function () { + + lua.lua_call(L, 0, -1); + + }, "Lua program ran without error"); + +}); + + +test("[test-suite] db: line hook", function (t) { + let luaCode = ` + test([[if + math.sin(1) + then + a=1 + else + a=2 + end + ]], {2,3,4,7}) + + test([[-- + if nil then + a=1 + else + a=2 + end + ]], {2,5,6}) + + test([[a=1 + repeat + a=a+1 + until a==3 + ]], {1,3,4,3,4}) + + test([[ do + return + end + ]], {2}) + + test([[local a + a=1 + while a<=3 do + a=a+1 + end + ]], {1,2,3,4,3,4,3,4,3,5}) + + test([[while math.sin(1) do + if math.sin(1) + then break + end + end + a=1]], {1,2,3,6}) + + test([[for i=1,3 do + a=i + end + ]], {1,2,1,2,1,2,1,3}) + + test([[for i,v in pairs{'a','b'} do + a=tostring(i) .. v + end + ]], {1,2,1,2,1,3}) + + test([[for i=1,4 do a=1 end]], {1,1,1,1,1}) + `, L; + + t.plan(2); + + t.doesNotThrow(function () { + + L = lauxlib.luaL_newstate(); + + lualib.luaL_openlibs(L); + + lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode)); + + }, "Lua program loaded without error"); + + t.doesNotThrow(function () { + + lua.lua_call(L, 0, -1); + + }, "Lua program ran without error"); + +}); + + +test("[test-suite] db: invalid levels in [gs]etlocal", function (t) { + let luaCode = ` + assert(not pcall(debug.getlocal, 20, 1)) + assert(not pcall(debug.setlocal, -1, 1, 10)) + `, L; + + t.plan(2); + + t.doesNotThrow(function () { + + L = lauxlib.luaL_newstate(); + + lualib.luaL_openlibs(L); + + lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode)); + + }, "Lua program loaded without error"); + + t.doesNotThrow(function () { + + lua.lua_call(L, 0, -1); + + }, "Lua program ran without error"); + +}); + + +test("[test-suite] db: parameter names", function (t) { + let luaCode = ` + local function foo (a,b,...) local d, e end + local co = coroutine.create(foo) + + assert(debug.getlocal(foo, 1) == 'a') + assert(debug.getlocal(foo, 2) == 'b') + assert(not debug.getlocal(foo, 3)) + assert(debug.getlocal(co, foo, 1) == 'a') + assert(debug.getlocal(co, foo, 2) == 'b') + assert(not debug.getlocal(co, foo, 3)) + + assert(not debug.getlocal(print, 1)) + `, L; + + t.plan(2); + + t.doesNotThrow(function () { + + L = lauxlib.luaL_newstate(); + + lualib.luaL_openlibs(L); + + lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode)); + + }, "Lua program loaded without error"); + + t.doesNotThrow(function () { + + lua.lua_call(L, 0, -1); + + }, "Lua program ran without error"); + +}); |