From 7d58c3b7314e4a63591fa375546cfc76a042e644 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Mon, 20 Feb 2017 14:57:49 +0100 Subject: ldebug, lua_error, error --- tests/lbaselib.js | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'tests') 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 -- cgit v1.2.3-70-g09d2