aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-04-12 10:06:25 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-04-12 10:54:41 +0200
commiteeb3d8ac1de70703ce7db4788b7fb43fcda80aa8 (patch)
treea3d8b2dffceeb2cd7b0bc0dc95feaaa2386939c4 /tests
parentfc08312ebf8cf01a53b4826acce0f1c3aedcdc53 (diff)
downloadfengari-eeb3d8ac1de70703ce7db4788b7fb43fcda80aa8.tar.gz
fengari-eeb3d8ac1de70703ce7db4788b7fb43fcda80aa8.tar.bz2
fengari-eeb3d8ac1de70703ce7db4788b7fb43fcda80aa8.zip
debug.getinfo
Diffstat (limited to 'tests')
-rw-r--r--tests/ldblib.js84
1 files changed, 84 insertions, 0 deletions
diff --git a/tests/ldblib.js b/tests/ldblib.js
index c95ab9e..a770c76 100644
--- a/tests/ldblib.js
+++ b/tests/ldblib.js
@@ -206,3 +206,87 @@ test('debug.traceback (with a upvalue)', function (t) {
);
});
+
+test('debug.getinfo', function (t) {
+ let luaCode = `
+ local alocal = function(p1, p2) end
+ global = function() return alocal end
+
+ local d1 = debug.getinfo(alocal)
+ local d2 = debug.getinfo(global)
+
+ print(d1.short_src, d1.nups, d1.what, d1.nparams,
+ d2.short_src, d2.nups, d2.what, d2.nparams)
+
+ return d1.short_src, d1.nups, d1.what, d1.nparams,
+ d2.short_src, d2.nups, d2.what, d2.nparams
+ `, L;
+
+ t.plan(10);
+
+ 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("getinfo-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, -8),
+ `[string "getinfo-test"]`,
+ "Correct element(s) on the stack"
+ );
+
+ t.strictEqual(
+ lapi.lua_tointeger(L, -7),
+ 0,
+ "Correct element(s) on the stack"
+ );
+
+ t.strictEqual(
+ lapi.lua_tojsstring(L, -6),
+ `Lua`,
+ "Correct element(s) on the stack"
+ );
+
+ t.strictEqual(
+ lapi.lua_tointeger(L, -5),
+ 2,
+ "Correct element(s) on the stack"
+ );
+
+ t.strictEqual(
+ lapi.lua_tojsstring(L, -4),
+ `[string "getinfo-test"]`,
+ "Correct element(s) on the stack"
+ );
+
+ t.strictEqual(
+ lapi.lua_tointeger(L, -3),
+ 1,
+ "Correct element(s) on the stack"
+ );
+
+ t.strictEqual(
+ lapi.lua_tojsstring(L, -2),
+ `Lua`,
+ "Correct element(s) on the stack"
+ );
+
+ t.strictEqual(
+ lapi.lua_tointeger(L, -1),
+ 0,
+ "Correct element(s) on the stack"
+ );
+
+});