aboutsummaryrefslogtreecommitdiff
path: root/tests/lbaselib.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-21 15:24:37 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-21 15:24:37 +0100
commit653f4a07af6506e0b8ef71e8957976b9559f67e4 (patch)
tree7bf59628c6e68bb33fa278d24f9e07f0104995ad /tests/lbaselib.js
parent82ef443de9a3ba53b4a5b9abd161ddc164776a59 (diff)
downloadfengari-653f4a07af6506e0b8ef71e8957976b9559f67e4.tar.gz
fengari-653f4a07af6506e0b8ef71e8957976b9559f67e4.tar.bz2
fengari-653f4a07af6506e0b8ef71e8957976b9559f67e4.zip
pcall, xpcall
Diffstat (limited to 'tests/lbaselib.js')
-rw-r--r--tests/lbaselib.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/lbaselib.js b/tests/lbaselib.js
index b55afde..cca3ebe 100644
--- a/tests/lbaselib.js
+++ b/tests/lbaselib.js
@@ -290,4 +290,74 @@ test('error, protected', function (t) {
lapi.lua_tostring(L, -1).endsWith("you fucked up"),
"Error is on the stack"
)
+});
+
+
+test('pcall', function (t) {
+ let luaCode = `
+ local willFail = function ()
+ error("you fucked up")
+ end
+
+ return pcall(willFail)
+ `, L;
+
+ t.plan(2);
+
+ t.doesNotThrow(function () {
+
+ let bc = toByteCode(luaCode).dataView;
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ lapi.lua_load(L, bc, "test-pcall");
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "JS Lua program ran without error");
+
+ t.ok(
+ lapi.lua_tostring(L, -1).endsWith("you fucked up"),
+ "Error is on the stack"
+ )
+});
+
+
+test('xpcall', function (t) {
+ let luaCode = `
+ local willFail = function ()
+ error("you fucked up")
+ end
+
+ local msgh = function (err)
+ return "Something's wrong: " .. err
+ end
+
+ return xpcall(willFail, msgh)
+ `, L;
+
+ t.plan(1);
+
+ t.doesNotThrow(function () {
+
+ let bc = toByteCode(luaCode).dataView;
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ lapi.lua_load(L, bc, "test-pcall");
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "JS Lua program ran without error");
+
+ console.log(lapi.lua_tostring(L, -1));
+
+ // t.ok(
+ // lapi.lua_tostring(L, -1).endsWith("you fucked up"),
+ // "Error is on the stack"
+ // )
}); \ No newline at end of file