summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-04-12 07:55:38 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-04-12 09:18:43 +0200
commitfc08312ebf8cf01a53b4826acce0f1c3aedcdc53 (patch)
tree5b1c3a1276037b482102bfe2c36bcb31c459acac /tests
parent58fcb1d7f55424de904fd6ae53954b46d82aae8c (diff)
downloadfengari-fc08312ebf8cf01a53b4826acce0f1c3aedcdc53.tar.gz
fengari-fc08312ebf8cf01a53b4826acce0f1c3aedcdc53.tar.bz2
fengari-fc08312ebf8cf01a53b4826acce0f1c3aedcdc53.zip
debug.traceback
Diffstat (limited to 'tests')
-rw-r--r--tests/ldblib.js117
1 files changed, 117 insertions, 0 deletions
diff --git a/tests/ldblib.js b/tests/ldblib.js
index 475c031..c95ab9e 100644
--- a/tests/ldblib.js
+++ b/tests/ldblib.js
@@ -89,3 +89,120 @@ test('debug.upvalueid', function (t) {
);
});
+
+
+test('debug.traceback (with a global)', function (t) {
+ let luaCode = `
+ local trace
+
+ rec = function(n)
+ n = n or 0
+ if n < 10 then
+ rec(n + 1)
+ else
+ trace = debug.traceback()
+ end
+ end
+
+ rec()
+
+ return trace
+ `, L;
+
+ t.plan(3);
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ luaCode = lua.to_luastring(luaCode);
+ lauxlib.luaL_loadbuffer(L, luaCode, luaCode.length, lua.to_luastring("traceback-test"));
+
+ }, "Lua program loaded without error");
+
+ t.doesNotThrow(function () {
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "Lua program ran without error");
+
+ t.strictEqual(
+ lapi.lua_tojsstring(L, -1),
+`stack traceback:
+\t...[string "traceback-test"]9: in function 'rec'
+\t...[string "traceback-test"]7: in function 'rec'
+\t...[string "traceback-test"]7: in function 'rec'
+\t...[string "traceback-test"]7: in function 'rec'
+\t...[string "traceback-test"]7: in function 'rec'
+\t...[string "traceback-test"]7: in function 'rec'
+\t...[string "traceback-test"]7: in function 'rec'
+\t...[string "traceback-test"]7: in function 'rec'
+\t...[string "traceback-test"]7: in function 'rec'
+\t...[string "traceback-test"]7: in function 'rec'
+\t...[string "traceback-test"]7: in function 'rec'
+\t...[string "traceback-test"]15: in main chunk`,
+ "Correct element(s) on the stack"
+ );
+
+});
+
+
+test('debug.traceback (with a upvalue)', function (t) {
+ let luaCode = `
+ local trace
+ local rec
+
+ rec = function(n)
+ n = n or 0
+ if n < 10 then
+ rec(n + 1)
+ else
+ trace = debug.traceback()
+ end
+ end
+
+ rec()
+
+ return trace
+ `, L;
+
+ t.plan(3);
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ luaCode = lua.to_luastring(luaCode);
+ lauxlib.luaL_loadbuffer(L, luaCode, luaCode.length, lua.to_luastring("traceback-test"));
+
+ }, "Lua program loaded without error");
+
+ t.doesNotThrow(function () {
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "Lua program ran without error");
+
+ t.strictEqual(
+ lapi.lua_tojsstring(L, -1),
+`stack traceback:
+\t...[string "traceback-test"]10: in upvalue 'rec'
+\t...[string "traceback-test"]8: in upvalue 'rec'
+\t...[string "traceback-test"]8: in upvalue 'rec'
+\t...[string "traceback-test"]8: in upvalue 'rec'
+\t...[string "traceback-test"]8: in upvalue 'rec'
+\t...[string "traceback-test"]8: in upvalue 'rec'
+\t...[string "traceback-test"]8: in upvalue 'rec'
+\t...[string "traceback-test"]8: in upvalue 'rec'
+\t...[string "traceback-test"]8: in upvalue 'rec'
+\t...[string "traceback-test"]8: in upvalue 'rec'
+\t...[string "traceback-test"]8: in local 'rec'
+\t...[string "traceback-test"]16: in main chunk`,
+ "Correct element(s) on the stack"
+ );
+
+});