summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-20 14:57:49 +0100
committerBenoit Giannangeli <giann008@gmail.com>2017-02-20 21:37:27 +0100
commit7d58c3b7314e4a63591fa375546cfc76a042e644 (patch)
treec51d390ee3830f924b2fb1e289b9461c8310d625 /tests
parent5860ec2bde3b220eff01b3bd1462e60905ef2fe9 (diff)
downloadfengari-7d58c3b7314e4a63591fa375546cfc76a042e644.tar.gz
fengari-7d58c3b7314e4a63591fa375546cfc76a042e644.tar.bz2
fengari-7d58c3b7314e4a63591fa375546cfc76a042e644.zip
ldebug, lua_error, error
Diffstat (limited to 'tests')
-rw-r--r--tests/lbaselib.js53
1 files changed, 52 insertions, 1 deletions
diff --git a/tests/lbaselib.js b/tests/lbaselib.js
index 87009ca..b55afde 100644
--- a/tests/lbaselib.js
+++ b/tests/lbaselib.js
@@ -34,7 +34,7 @@ test('print', function (t) {
lapi.lua_load(L, bc, "test-print");
- lapi.lua_call(L, 0, 1);
+ lapi.lua_call(L, 0, -1);
}, "JS Lua program ran without error");
});
@@ -239,4 +239,55 @@ test('type', function (t) {
"nil",
"Correct element(s) on the stack"
);
+});
+
+
+test('error', function (t) {
+ let luaCode = `
+ error("you fucked up")
+ `, L;
+
+ t.plan(1);
+
+ t.throws(function () {
+
+ let bc = toByteCode(luaCode).dataView;
+
+ L = lauxlib.luaL_newstate();
+
+ linit.luaL_openlibs(L);
+
+ lapi.lua_load(L, bc, "test-error");
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "JS Lua program ran without error");
+});
+
+
+test('error, protected', function (t) {
+ let luaCode = `
+ error("you fucked up")
+ `, 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-error");
+
+ lapi.lua_pcall(L, 0, -1, 0);
+
+ }, "JS Lua program ran without error");
+
+ t.ok(
+ lapi.lua_tostring(L, -1).endsWith("you fucked up"),
+ "Error is on the stack"
+ )
}); \ No newline at end of file