diff options
author | daurnimator <quae@daurnimator.com> | 2018-04-14 14:53:11 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2018-04-14 16:52:26 +1000 |
commit | 65d022bf3d7330a3d8dc69c08e07a81f25b8ba4b (patch) | |
tree | 1a47ef2f9c393d6e024f161ac50b1880d0639cc1 | |
parent | ce9fd9bdca0caa6a33ce37a01f41593ca42ba95b (diff) | |
download | fengari-65d022bf3d7330a3d8dc69c08e07a81f25b8ba4b.tar.gz fengari-65d022bf3d7330a3d8dc69c08e07a81f25b8ba4b.tar.bz2 fengari-65d022bf3d7330a3d8dc69c08e07a81f25b8ba4b.zip |
test/test-suite: Move ported PUC-Rio test suite to jest
-rw-r--r-- | package.json | 6 | ||||
-rw-r--r-- | test/test-suite/api.test.js (renamed from test/test-suite/api.js) | 1544 | ||||
-rw-r--r-- | test/test-suite/attrib.test.js (renamed from test/test-suite/attrib.js) | 191 | ||||
-rw-r--r-- | test/test-suite/bitwise.test.js (renamed from test/test-suite/bitwise.js) | 246 | ||||
-rw-r--r-- | test/test-suite/calls.test.js (renamed from test/test-suite/calls.js) | 486 | ||||
-rw-r--r-- | test/test-suite/closure.test.js (renamed from test/test-suite/closure.js) | 246 | ||||
-rw-r--r-- | test/test-suite/code.test.js (renamed from test/test-suite/code.js) | 457 | ||||
-rw-r--r-- | test/test-suite/constructs.test.js (renamed from test/test-suite/constructs.js) | 186 | ||||
-rw-r--r-- | test/test-suite/coroutine.test.js (renamed from test/test-suite/coroutine.js) | 1118 | ||||
-rw-r--r-- | test/test-suite/db.test.js (renamed from test/test-suite/db.js) | 822 | ||||
-rw-r--r-- | test/test-suite/errors.test.js (renamed from test/test-suite/errors.js) | 1056 | ||||
-rw-r--r-- | test/test-suite/events.test.js (renamed from test/test-suite/events.js) | 425 | ||||
-rw-r--r-- | test/test-suite/goto.test.js (renamed from test/test-suite/goto.js) | 186 | ||||
-rw-r--r-- | test/test-suite/literals.test.js (renamed from test/test-suite/literals.js) | 460 | ||||
-rw-r--r-- | test/test-suite/locals.test.js (renamed from test/test-suite/locals.js) | 156 | ||||
-rw-r--r-- | test/test-suite/math.test.js (renamed from test/test-suite/math.js) | 1056 | ||||
-rw-r--r-- | test/test-suite/nextvar.test.js (renamed from test/test-suite/nextvar.js) | 756 | ||||
-rw-r--r-- | test/test-suite/pm.test.js (renamed from test/test-suite/pm.js) | 546 | ||||
-rw-r--r-- | test/test-suite/sort.test.js (renamed from test/test-suite/sort.js) | 366 | ||||
-rw-r--r-- | test/test-suite/strings.test.js (renamed from test/test-suite/strings.js) | 546 | ||||
-rw-r--r-- | test/test-suite/tpack.test.js (renamed from test/test-suite/tpack.js) | 486 | ||||
-rw-r--r-- | test/test-suite/utf8.test.js (renamed from test/test-suite/utf8.js) | 222 | ||||
-rw-r--r-- | test/test-suite/vararg.test.js (renamed from test/test-suite/vararg.js) | 126 |
23 files changed, 3563 insertions, 8126 deletions
diff --git a/package.json b/package.json index 54883c4..7424f82 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "scripts": { "lint": "eslint src/ test/", "prepublishOnly": "git diff-index --quiet --cached HEAD -- && npm run lint && npm run test", - "test": "jest && (tape test/test-suite/*.js | faucet)" + "test": "jest" }, "repository": { "type": "git", @@ -31,9 +31,7 @@ "homepage": "https://github.com/fengari-lua/fengari#readme", "devDependencies": { "eslint": "^4.19.1", - "faucet": "^0.0.1", - "jest": "^22.4.3", - "tape": "^4.9.0" + "jest": "^22.4.3" }, "dependencies": { "readline-sync": "^1.4.9", diff --git a/test/test-suite/api.js b/test/test-suite/api.test.js index 0061c88..152ddcf 100644 --- a/test/test-suite/api.js +++ b/test/test-suite/api.test.js @@ -1,13 +1,11 @@ "use strict"; -const test = require('tape'); - -const lua = require('../../src/lua.js'); +const lua = require('../../src/lua.js'); const lauxlib = require('../../src/lauxlib.js'); -const lualib = require('../../src/lualib.js'); +const lualib = require('../../src/lualib.js'); const {to_luastring} = require("../../src/fengaricore.js"); -const ltests = require('./ltests.js'); +const ltests = require('./ltests.js'); // TODO: a lot of gc related tests are skipped // TODO: io.read is used in several tests, uncomment them when it's implemented @@ -28,65 +26,44 @@ const prefix = ` end `; -test("[test-suite] api: registry", function (t) { +test("[test-suite] api: registry", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` a = T.testC("pushvalue R; return 1") assert(a == debug.getregistry()) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: absindex", function (t) { +test("[test-suite] api: absindex", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(T.testC("settop 10; absindex -1; return 1") == 10) assert(T.testC("settop 5; absindex -5; return 1") == 1) assert(T.testC("settop 10; absindex 1; return 1") == 1) assert(T.testC("settop 10; absindex R; return 1") < -10) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing alignment", function (t) { +test("[test-suite] api: testing alignment", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` -- Useless tests in fengari since we do the same thing in d2s than in string.pack a = T.d2s(12458954321123.0) @@ -99,31 +76,19 @@ test("[test-suite] api: testing alignment", function (t) { f = T.makeCfunc("pushnum 1; pushnum 2; pushnum 3; return 2") a,b,c = f() assert(a == 2 and b == 3 and not c) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: test that all trues are equal", function (t) { +test("[test-suite] api: test that all trues are equal", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` a,b,c = T.testC("pushbool 1; pushbool 2; pushbool 0; return 3") assert(a == b and a == true and c == false) @@ -164,31 +129,19 @@ test("[test-suite] api: test that all trues are equal", function (t) { t = pack(T.testC("copy -3 -1; return *", 2, 3, 4, 5)) tcheck(t, {n=4,2,3,4,3}) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing 'rotate'", function (t) { +test("[test-suite] api: testing 'rotate'", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do -- testing 'rotate' local t = {10, 20, 30, 40, 50, 60} @@ -212,31 +165,19 @@ test("[test-suite] api: testing 'rotate'", function (t) { t = pack(T.testC("rotate 5 -1; return *", 10, 20, 30, 40)) tcheck(t, {10, 20, 30, 40}) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing non-function message handlers", function (t) { +test("[test-suite] api: testing non-function message handlers", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local f = T.makeCfunc[[ @@ -265,60 +206,36 @@ test("[test-suite] api: testing non-function message handlers", function (t) { t = pack(T.testC("concat 5; return *", "alo", 2, 3, "joao", 12)) tcheck(t, {n=1,"alo23joao12"}) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing MULTRET", function (t) { +test("[test-suite] api: testing MULTRET", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` t = pack(T.testC("call 2,-1; return *", function (a,b) return 1,2,3,4,a,b end, "alo", "joao")) tcheck(t, {n=6,1,2,3,4,"alo", "joao"}) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: test returning more results than fit in the caller stack", function (t) { +test("[test-suite] api: test returning more results than fit in the caller stack", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do -- test returning more results than fit in the caller stack local a = {} @@ -327,31 +244,19 @@ test("[test-suite] api: test returning more results than fit in the caller stack table.unpack, a) assert(b == "10") end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing globals", function (t) { +test("[test-suite] api: testing globals", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` _G.a = 14; _G.b = "a31" local a = {T.testC[[ @@ -362,31 +267,19 @@ test("[test-suite] api: testing globals", function (t) { return * ]]} assert(a[2] == 14 and a[3] == "a31" and a[4] == nil and _G.a == "a31") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing arith", function (t) { +test("[test-suite] api: testing arith", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(T.testC("pushnum 10; pushnum 20; arith /; return 1") == 0.5) assert(T.testC("pushnum 10; pushnum 20; arith -; return 1") == -10) @@ -420,59 +313,35 @@ test("[test-suite] api: testing arith", function (t) { assert(T.testC("arith %; return 1", a, c)[1] == 4%-3) assert(T.testC("arith _; arith +; arith %; return 1", b, a, c)[1] == 8 % (4 + (-3)*2)) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: errors in arithmetic", function (t) { +test("[test-suite] api: errors in arithmetic", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checkerr("divide by zero", T.testC, "arith \\\\", 10, 0) checkerr("%%0", T.testC, "arith %", 10, 0) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing lessthan and lessequal", function (t) { +test("[test-suite] api: testing lessthan and lessequal", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(T.testC("compare LT 2 5, return 1", 3, 2, 2, 4, 2, 2)) assert(T.testC("compare LE 2 5, return 1", 3, 2, 2, 4, 2, 2)) @@ -481,31 +350,19 @@ test("[test-suite] api: testing lessthan and lessequal", function (t) { assert(T.testC("compare LT 5 2, return 1", 4, 2, 2, 3, 2, 2)) assert(not T.testC("compare LT 2 -3, return 1", "4", "2", "2", "3", "2", "2")) assert(not T.testC("compare LT -3 2, return 1", "3", "2", "2", "4", "2", "2")) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: non-valid indices produce false", function (t) { +test("[test-suite] api: non-valid indices produce false", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(not T.testC("compare LT 1 4, return 1")) assert(not T.testC("compare LE 9 1, return 1")) @@ -524,31 +381,19 @@ test("[test-suite] api: non-valid indices produce false", function (t) { assert(a == 20 and b == false) a,b = T.testC("compare LE 5 -6, return 2", a1, 2, 2, a1, 2, 20) assert(a == 20 and b == true) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing length", function (t) { +test("[test-suite] api: testing length", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local t = setmetatable({x = 20}, {__len = function (t) return t.x end}) a,b,c = T.testC([[ @@ -575,31 +420,19 @@ test("[test-suite] api: testing length", function (t) { return 2 ]], t) assert(a == print and c == 1) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing __concat", function (t) { +test("[test-suite] api: testing __concat", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` a = setmetatable({x="u"}, {__concat = function (a,b) return a.x..'.'..b.x end}) x,y = T.testC([[ @@ -617,31 +450,19 @@ test("[test-suite] api: testing __concat", function (t) { -- concat with 1 element assert(T.testC("concat 1; return 1", "xuxu") == "xuxu") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing lua_is", function (t) { +test("[test-suite] api: testing lua_is", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` function B(x) return x and 1 or 0 end @@ -672,31 +493,19 @@ test("[test-suite] api: testing lua_is", function (t) { assert(count(nil) == 1) assert(count(io.stdin) == 1) assert(count(nil, 15) == 100) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing lua_to...", function (t) { +test("[test-suite] api: testing lua_to...", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` function to (s, x, n) n = n or 2 @@ -733,30 +542,18 @@ test("[test-suite] api: testing lua_to...", function (t) { assert(to("func2num", hfunc) ~= 0) -- "heavy" C function (with upvalue) a = to("tocfunction", math.deg) assert(a(3) == math.deg(3) and a == math.deg) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing panic function", function (t) { +test("[test-suite] api: testing panic function", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do -- trivial error @@ -792,31 +589,19 @@ test("[test-suite] api: testing panic function", function (t) { end end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing deep JS stack", { skip: true }, function (t) { +test.skip("[test-suite] api: testing deep JS stack", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do checkerr("XXXX", T.testC, "checkstack 1000023 XXXX") -- too deep @@ -848,31 +633,19 @@ test("[test-suite] api: testing deep JS stack", { skip: true }, function (t) { for i = 1,lim do assert(t[i] == i*10); t[i] = nil end assert(next(t) == nil) prog, g, t = nil - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing errors", function (t) { +test("[test-suite] api: testing errors", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` a = T.testC([[ loadstring 2; pcall 0 1 0; @@ -891,31 +664,19 @@ test("[test-suite] api: testing errors", function (t) { check3(":1:", T.testC("loadstring 2; return *", "x=")) check3("%.", T.testC("loadfile 2; return *", ".")) check3("xxxx", T.testC("loadfile 2; return *", "xxxx")) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: test errors in non protected threads", { skip: true }, function (t) { +test("[test-suite] api: test errors in non protected threads", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` function checkerrnopro (code, msg) local th = coroutine.create(function () end) -- create new thread @@ -929,31 +690,19 @@ test("[test-suite] api: test errors in non protected threads", { skip: true }, f function f () f() end checkerrnopro("getglobal 'f'; call 0 0;", "stack overflow") end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing table access", function (t) { +test("[test-suite] api: testing table access", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do -- getp/setp local a = {} @@ -992,31 +741,19 @@ test("[test-suite] api: testing table access", function (t) { T.testC("settable 2", b, 19) assert(a[b] == 19) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing getfield/setfield with long keys", function (t) { +test("[test-suite] api: testing getfield/setfield with long keys", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do -- testing getfield/setfield with long keys local t = {_012345678901234567890123456789012345678901234567890123456789 = 32} @@ -1032,31 +769,19 @@ test("[test-suite] api: testing getfield/setfield with long keys", function (t) assert(_012345678901234567890123456789012345678901234567890123456789 == 33) _012345678901234567890123456789012345678901234567890123456789 = nil end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing next", function (t) { +test("[test-suite] api: testing next", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` a = {} t = pack(T.testC("next; return *", a, nil)) @@ -1066,31 +791,19 @@ test("[test-suite] api: testing next", function (t) { tcheck(t, {n=3,a,'a',3}) t = pack(T.testC("next; pop 1; next; return *", a, nil)) tcheck(t, {n=1,a}) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing upvalues", function (t) { +test("[test-suite] api: testing upvalues", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local A = T.testC[[ pushnum 10; pushnum 20; pushcclosure 2; return 1]] @@ -1106,31 +819,19 @@ test("[test-suite] api: testing upvalues", function (t) { assert(b.x == 1 and c.x == 2) -- T.checkmemory() end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing absent upvalues from JS-function pointers", function (t) { +test("[test-suite] api: testing absent upvalues from JS-function pointers", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(T.testC[[isnull U1; return 1]] == true) assert(T.testC[[isnull U100; return 1]] == true) @@ -1142,31 +843,19 @@ test("[test-suite] api: testing absent upvalues from JS-function pointers", func T.upvalue(f, 3) == nil) T.upvalue(f, 2, "xuxu") assert(T.upvalue(f, 2) == "xuxu") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: large closures", function (t) { +test("[test-suite] api: large closures", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local A = "checkstack 300 msg;" .. @@ -1179,31 +868,19 @@ test("[test-suite] api: large closures", function (t) { assert(A("isnull U256; return 1")) assert(not A("isnil U256; return 1")) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing get/setuservalue", function (t) { +test("[test-suite] api: testing get/setuservalue", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` -- bug in 5.1.2 checkerr("got number", debug.setuservalue, 3, {}) @@ -1226,62 +903,38 @@ test("[test-suite] api: testing get/setuservalue", function (t) { debug.setuservalue(b, 134) -- collectgarbage() -- number should not be a problem for collector assert(debug.getuservalue(b) == 134) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing get/setuservalue", { skip: true }, function (t) { +test.skip("[test-suite] api: testing get/setuservalue", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` T.gcstate("atomic") assert(T.gccolor(b) == "black") debug.setuservalue(b, {x = 100}) T.gcstate("pause") -- complete collection assert(debug.getuservalue(b).x == 100) -- uvalue should be there - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: long chain of userdata", { skip: true }, function (t) { +test.skip("[test-suite] api: long chain of userdata", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` for i = 1, 1000 do local bb = T.newuserdata(0) @@ -1294,31 +947,19 @@ test("[test-suite] api: long chain of userdata", { skip: true }, function (t) { end assert(debug.getuservalue(b).x == 100) b = nil - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: reuse of references", { skip: true }, function (t) { +test.skip("[test-suite] api: reuse of references", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local i = T.ref{} T.unref(i) @@ -1366,31 +1007,19 @@ test("[test-suite] api: reuse of references", { skip: true }, function (t) { -- collectgarbage() assert(type(T.getref(a)) == 'table') - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: collect in cl the `val' of all collected userdata", { skip: true }, function (t) { +test.skip("[test-suite] api: collect in cl the `val' of all collected userdata", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` tt = {} cl = {n=0} @@ -1494,31 +1123,19 @@ test("[test-suite] api: collect in cl the `val' of all collected userdata", { sk for n in pairs(a) do a[n] = nil end collectgarbage() assert(#cl == 1 and cl[1] == x) -- old 'x' must be collected - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: test whether udate collection frees memory in the right time", { skip: true }, function (t) { +test.skip("[test-suite] api: test whether udate collection frees memory in the right time", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do collectgarbage(); @@ -1550,31 +1167,19 @@ test("[test-suite] api: test whether udate collection frees memory in the right assert(collectgarbage("count") <= x+1) collectgarbage("restart") end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing lua_equal", function (t) { +test("[test-suite] api: testing lua_equal", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(T.testC("compare EQ 2 4; return 1", print, 1, print, 20)) assert(T.testC("compare EQ 3 2; return 1", 'alo', "alo")) @@ -1582,31 +1187,19 @@ test("[test-suite] api: testing lua_equal", function (t) { assert(not T.testC("compare EQ 2 3; return 1", {}, {})) assert(not T.testC("compare EQ 2 3; return 1")) assert(not T.testC("compare EQ 2 3; return 1", 3)) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing lua_equal with fallbacks", function (t) { +test("[test-suite] api: testing lua_equal with fallbacks", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local map = {} @@ -1624,31 +1217,19 @@ test("[test-suite] api: testing lua_equal with fallbacks", function (t) { t.__eq = nil assert(f(10) ~= f(10)) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing changing hooks during hooks", function (t) { +test("[test-suite] api: testing changing hooks during hooks", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` _G.t = {} T.sethook([[ @@ -1670,31 +1251,19 @@ test("[test-suite] api: testing changing hooks during hooks", function (t) { assert(t[3] == "line" and t[4] == line + 1) assert(t[5] == "line" and t[6] == line + 2) assert(t[7] == nil) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing errors during GC", { skip: true }, function (t) { +test.skip("[test-suite] api: testing errors during GC", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do -- testing errors during GC local a = {} @@ -1722,31 +1291,19 @@ test("[test-suite] api: testing errors during GC", { skip: true }, function (t) assert(A == 10) -- number of normal collections end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: test for userdata vals", function (t) { +test("[test-suite] api: test for userdata vals", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local a = {}; local lim = 30 @@ -1757,31 +1314,19 @@ test("[test-suite] api: test for userdata vals", function (t) { for i=0,lim do a[T.pushuserdata(i)] = i end assert(type(tostring(a[1])) == "string") end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing multiple states", function (t) { +test("[test-suite] api: testing multiple states", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` T.closestate(T.newstate()); L1 = T.newstate() @@ -1828,58 +1373,31 @@ test("[test-suite] api: testing multiple states", function (t) { assert(T.doremote(L1, "return a.x") == "1") T.closestate(L1) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing memory limits", { skip: true }, function (t) { +test.skip("[test-suite] api: testing memory limits", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checkerr("block too big", T.newuserdata, math.maxinteger) collectgarbage() T.totalmem(T.totalmem()+5000) -- set low memory limit (+5k) checkerr("not enough memory", load"local a={}; for i=1,100000 do a[i]=i end") T.totalmem(0) -- restore high limit - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); @@ -1910,61 +1428,40 @@ const memprefix = ` `; -test("[test-suite] api: testing memory errors when creating a new state", { skip: true }, function (t) { +test.skip("[test-suite] api: testing memory errors when creating a new state", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` b = testamem("state creation", T.newstate) T.closestate(b); -- close new state - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + memprefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + memprefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: get main thread from registry (at index LUA_RIDX_MAINTHREAD == 1)", function (t) { +test("[test-suite] api: get main thread from registry (at index LUA_RIDX_MAINTHREAD == 1)", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` mt = T.testC("rawgeti R 1; return 1") assert(type(mt) == "thread" and coroutine.running() == mt) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + memprefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + memprefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: test thread creation after stressing GC", { skip: true }, function (t) { +test.skip("[test-suite] api: test thread creation after stressing GC", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` function expand (n,s) if n==0 then return "" end @@ -1980,60 +1477,36 @@ test("[test-suite] api: test thread creation after stressing GC", { skip: true } testamem("thread creation", function () return T.doonnewstack("x=1") == 0 -- try to create thread end) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + memprefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + memprefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing memory x compiler", { skip: true }, function (t) { +test.skip("[test-suite] api: testing memory x compiler", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` testamem("loadstring", function () return load("x=1") -- try to do load a string end) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + memprefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + memprefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing memory x dofile", { skip: true }, function (t) { +test.skip("[test-suite] api: testing memory x dofile", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local testprog = [[ local function foo () return end @@ -2055,31 +1528,19 @@ test("[test-suite] api: testing memory x dofile", { skip: true }, function (t) { end) assert(os.remove(t)) assert(_G.a == "aaax") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + memprefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + memprefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: other generic tests", { skip: true }, function (t) { +test.skip("[test-suite] api: other generic tests", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` testamem("string creation", function () local a, b = string.gsub("alo alo", "(a)", function (x) return x..'b' end) @@ -2138,31 +1599,19 @@ test("[test-suite] api: other generic tests", { skip: true }, function (t) { return (#table.concat(a, ",") == 20*lim + lim - 1) end) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + memprefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + memprefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing some auxlib functions", function (t) { +test("[test-suite] api: testing some auxlib functions", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function gsub (a, b, c) a, b = T.testC("gsub 2 3 4; gettop; return 2", a, b, c) @@ -2175,31 +1624,19 @@ test("[test-suite] api: testing some auxlib functions", function (t) { assert(gsub("", "alo", "//") == "") assert(gsub("...", ".", "/.") == "/././.") assert(gsub("...", "...", "") == "") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] api: testing luaL_newmetatable", function (t) { +test("[test-suite] api: testing luaL_newmetatable", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local mt_xuxu, res, top = T.testC("newmetatable xuxu; gettop; return 3") assert(type(mt_xuxu) == "table" and res and top == 3) @@ -2247,25 +1684,10 @@ test("[test-suite] api: testing luaL_newmetatable", function (t) { assert(r.xuxu == mt_xuxu and r.xuxu1 == d) r.xuxu = nil; r.xuxu1 = nil end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); diff --git a/test/test-suite/attrib.js b/test/test-suite/attrib.test.js index 5053a31..596c82c 100644 --- a/test/test-suite/attrib.js +++ b/test/test-suite/attrib.test.js @@ -1,13 +1,14 @@ "use strict"; -const test = require('tape'); - -const lua = require('../../src/lua.js'); +const lua = require('../../src/lua.js'); const lauxlib = require('../../src/lauxlib.js'); -const lualib = require('../../src/lualib.js'); +const lualib = require('../../src/lualib.js'); const {to_luastring} = require("../../src/fengaricore.js"); -test("[test-suite] attrib: testing require", function (t) { +test("[test-suite] attrib: testing require", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(require"string" == string) assert(require"math" == math) @@ -52,34 +53,25 @@ test("[test-suite] attrib: testing require", function (t) { assert(not s and string.find(err, "package.path")) package.path = oldpath end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); + // TODO: when io.write etc. -test("[test-suite] attrib: system specific tests for 'require'", { skip: true }, function (t) { +test.skip("[test-suite] attrib: system specific tests for 'require'", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); }); -test("[test-suite] attrib: testing assignments, logical operators, and constructors", function (t) { +test("[test-suite] attrib: testing assignments, logical operators, and constructors", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local res, res2 = 27 @@ -168,30 +160,18 @@ test("[test-suite] attrib: testing assignments, logical operators, and construct assert(a[1]==10 and a[-3]==a.a and a[f]==print and a.x=='a' and not a.y) a[1], f(a)[2], b, c = {['alo']=assert}, 10, a[1], a[f], 6, 10, 23, f(a), 2 a[1].alo(a[2]==10 and b==10 and c==print) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] attrib: test of large float/integer indices ", function (t) { +test("[test-suite] attrib: test of large float/integer indices ", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` a = {} a[true] = 20 @@ -244,30 +224,18 @@ test("[test-suite] attrib: test of large float/integer indices ", function (t) { assert(a[maxintF] == 20 and a[maxintF - 1.0] == 11 and a[-maxintF] == 22 and a[-maxintF + 1.0] == 13) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] attrib: test conflicts in multiple assignment", function (t) { +test("[test-suite] attrib: test conflicts in multiple assignment", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local a,i,j,b @@ -276,30 +244,18 @@ test("[test-suite] attrib: test conflicts in multiple assignment", function (t) assert(i == 2 and b[1] == 1 and a == 1 and j == b and b[2] == 2 and b[3] == 1) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] attrib: repeat test with upvalues", function (t) { +test("[test-suite] attrib: repeat test with upvalues", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local a,i,j,b @@ -314,30 +270,18 @@ test("[test-suite] attrib: repeat test with upvalues", function (t) { (function (a) t[a], a = 10, 20 end)(1); assert(t[1] == 10) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] attrib: bug in 5.2 beta", function (t) { +test("[test-suite] attrib: bug in 5.2 beta", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function foo () local a @@ -350,24 +294,9 @@ test("[test-suite] attrib: bug in 5.2 beta", function (t) { local a, b = foo()() assert(a == 3 and b == 14) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); diff --git a/test/test-suite/bitwise.js b/test/test-suite/bitwise.test.js index 17e3c84..bf8de5c 100644 --- a/test/test-suite/bitwise.js +++ b/test/test-suite/bitwise.test.js @@ -1,10 +1,8 @@ "use strict"; -const test = require('tape'); - -const lua = require('../../src/lua.js'); +const lua = require('../../src/lua.js'); const lauxlib = require('../../src/lauxlib.js'); -const lualib = require('../../src/lualib.js'); +const lualib = require('../../src/lualib.js'); const {to_luastring} = require("../../src/fengaricore.js"); const prefix = ` @@ -116,7 +114,10 @@ const prefix = ` local bit32 = require'bit32' `; -test("[test-suite] bitwise: testing bitwise operations", function (t) { +test("[test-suite] bitwise: testing bitwise operations", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local numbits = string.packsize('j') * 8 @@ -175,30 +176,18 @@ test("[test-suite] bitwise: testing bitwise operations", function (t) { -- embedded zeros assert(not pcall(function () return "0xffffffffffffffff\\0" | 0 end)) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] bitwise: testing bitwise library", function (t) { +test("[test-suite] bitwise: testing bitwise library", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(bit32.band() == bit32.bnot(0)) assert(bit32.btest() == true) @@ -207,30 +196,18 @@ test("[test-suite] bitwise: testing bitwise library", function (t) { assert(bit32.band() == bit32.band(0xffffffff)) assert(bit32.band(1,2) == 0) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] bitwise: out-of-range numbers", function (t) { +test("[test-suite] bitwise: out-of-range numbers", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(bit32.band(-1) == 0xffffffff) assert(bit32.band((1 << 33) - 1) == 0xffffffff) @@ -284,30 +261,18 @@ test("[test-suite] bitwise: out-of-range numbers", function (t) { assert(0x12345678 >> 8 == 0x00123456) assert(0x12345678 >> 32 == 0) assert(0x12345678 >> -32 == 0x1234567800000000) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] bitwise: some special cases", function (t) { +test("[test-suite] bitwise: some special cases", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local c = {0, 1, 2, 3, 10, 0x80000000, 0xaaaaaaaa, 0x55555555, 0xffffffff, 0x7fffffff} @@ -339,30 +304,18 @@ test("[test-suite] bitwise: some special cases", function (t) { assert(bit32.lshift(bit32.lshift(b, -4), 4) == bit32.band(b, bit32.bnot(0xf))) assert(bit32.rshift(bit32.rshift(b, 4), -4) == bit32.band(b, bit32.bnot(0xf))) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] bitwise: for this test, use at most 24 bits (mantissa of a single float)", function (t) { +test("[test-suite] bitwise: for this test, use at most 24 bits (mantissa of a single float)", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` c = {0, 1, 2, 3, 10, 0x800000, 0xaaaaaa, 0x555555, 0xffffff, 0x7fffff} for _, b in pairs(c) do @@ -378,30 +331,18 @@ test("[test-suite] bitwise: for this test, use at most 24 bits (mantissa of a si assert(not pcall(bit32.lshift, 45)) assert(not pcall(bit32.lshift, 45, print)) assert(not pcall(bit32.rshift, 45, print)) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] bitwise: testing extract/replace", function (t) { +test("[test-suite] bitwise: testing extract/replace", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(bit32.extract(0x12345678, 0, 4) == 8) assert(bit32.extract(0x12345678, 4, 4) == 7) @@ -421,57 +362,33 @@ test("[test-suite] bitwise: testing extract/replace", function (t) { assert(bit32.replace(0, -1, 4) == 2^4) assert(bit32.replace(-1, 0, 31) == (1 << 31) - 1) assert(bit32.replace(-1, 0, 1, 2) == (1 << 32) - 7) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] bitwise: testing conversion of floats", function (t) { +test("[test-suite] bitwise: testing conversion of floats", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(bit32.bor(3.0) == 3) assert(bit32.bor(-4.0) == 0xfffffffc) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] bitwise: large floats and large-enough integers?", function (t) { +test("[test-suite] bitwise: large floats and large-enough integers?", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` if 2.0^50 < 2.0^50 + 1.0 and 2.0^50 < (-1 >> 1) then assert(bit32.bor(2.0^32 - 5.0) == 0xfffffffb) @@ -479,24 +396,9 @@ test("[test-suite] bitwise: large floats and large-enough integers?", function ( assert(bit32.bor(2.0^48 - 5.0) == 0xfffffffb) assert(bit32.bor(-2.0^48 - 6.0) == 0xfffffffa) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); diff --git a/test/test-suite/calls.js b/test/test-suite/calls.test.js index 2044e5c..1604337 100644 --- a/test/test-suite/calls.js +++ b/test/test-suite/calls.test.js @@ -1,13 +1,14 @@ "use strict"; -const test = require('tape'); - -const lua = require('../../src/lua.js'); +const lua = require('../../src/lua.js'); const lauxlib = require('../../src/lauxlib.js'); -const lualib = require('../../src/lualib.js'); +const lualib = require('../../src/lualib.js'); const {to_luastring} = require("../../src/fengaricore.js"); -test("[test-suite] calls: test 'type'", function (t) { +test("[test-suite] calls: test 'type'", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(type(1<2) == 'boolean') assert(type(true) == 'boolean' and type(false) == 'boolean') @@ -21,30 +22,18 @@ test("[test-suite] calls: test 'type'", function (t) { function f (x) return a:x (x) end assert(type(f) == 'function') assert(not pcall(type)) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] calls: test error in 'print'", function (t) { +test("[test-suite] calls: test error in 'print'", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do -- test error in 'print' too... local tostring = _ENV.tostring @@ -59,30 +48,18 @@ test("[test-suite] calls: test error in 'print'", function (t) { _ENV.tostring = tostring end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] calls: testing local-function recursion", function (t) { +test("[test-suite] calls: testing local-function recursion", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` fact = false do @@ -95,30 +72,18 @@ test("[test-suite] calls: testing local-function recursion", function (t) { assert(fact(5) == 120) end assert(fact == false) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] calls: testing declarations", function (t) { +test("[test-suite] calls: testing declarations", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` a = {i = 10} self = 20 @@ -202,30 +167,18 @@ test("[test-suite] calls: testing declarations", function (t) { a = nil (function (x) a=x end)(23) assert(a == 23 and (function (x) return x*2 end)(20) == 40) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] calls: testing closures", function (t) { +test("[test-suite] calls: testing closures", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` -- fixed-point operator Z = function (le) @@ -260,30 +213,18 @@ test("[test-suite] calls: testing closures", function (t) { assert(f(9, 16) == 10+11+12+13+10+9+16+10) Z, F, f = nil - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] calls: testing multiple returns", function (t) { +test("[test-suite] calls: testing multiple returns", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` function unlpack (t, i) i = i or 1 @@ -318,59 +259,35 @@ test("[test-suite] calls: testing multiple returns", function (t) { a = ret2{ unlpack{1,2,3}, unlpack{3,2,1}, unlpack{"a", "b"}} assert(a[1] == 1 and a[2] == 3 and a[3] == "a" and a[4] == "b") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] calls: testing calls with 'incorrect' arguments", function (t) { +test("[test-suite] calls: testing calls with 'incorrect' arguments", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` rawget({}, "x", 1) rawset({}, "x", 1, 2) assert(math.sin(1,2) == math.sin(1)) table.sort({10,9,8,4,19,23,0,0}, function (a,b) return a<b end, "extra arg") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] calls: test for generic load", function (t) { +test("[test-suite] calls: test for generic load", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local x = "-- a comment\\0\\0\\0\\n x = 10 + \\n23; \\ local a = function () x = 'hi' end; \\ @@ -419,56 +336,32 @@ test("[test-suite] calls: test for generic load", function (t) { cannotload("unexpected symbol", load(read1("*a = 123"))) cannotload("unexpected symbol", load("*a = 123")) cannotload("hhi", load(function () error("hhi") end)) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] calls: any value is valid for _ENV", function (t) { +test("[test-suite] calls: any value is valid for _ENV", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(load("return _ENV", nil, nil, 123)() == 123) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] calls: load when _ENV is not first upvalue", function (t) { +test("[test-suite] calls: load when _ENV is not first upvalue", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local x; XX = 123 local function h () @@ -482,30 +375,18 @@ test("[test-suite] calls: load when _ENV is not first upvalue", function (t) { assert(x() == 123) assert(assert(load("return XX + ...", nil, nil, {XX = 13}))(4) == 17) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] calls: test generic load with nested functions", function (t) { +test("[test-suite] calls: test generic load with nested functions", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` function read1 (x) local i = 0 @@ -527,30 +408,18 @@ test("[test-suite] calls: test generic load with nested functions", function (t) a = assert(load(read1(x))) assert(a()(2)(3)(10) == 15) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] calls: test for dump/undump with upvalues", function (t) { +test("[test-suite] calls: test for dump/undump with upvalues", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local a, b = 20, 30 x = load(string.dump(function (x) @@ -567,30 +436,18 @@ test("[test-suite] calls: test for dump/undump with upvalues", function (t) { assert(x() == 23) x("set") assert(x() == 24) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] calls: test for dump/undump with many upvalues", function (t) { +test("[test-suite] calls: test for dump/undump with many upvalues", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local nup = 200 -- maximum number of local variables @@ -614,30 +471,18 @@ test("[test-suite] calls: test for dump/undump with many upvalues", function (t) end assert(f() == 10 * nup) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] calls: test for long method names", function (t) { +test("[test-suite] calls: test for long method names", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local t = {x = 1} @@ -646,58 +491,34 @@ test("[test-suite] calls: test for long method names", function (t) { end assert(t:_012345678901234567890123456789012345678901234567890123456789() == 1) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] calls: test for bug in parameter adjustment", function (t) { +test("[test-suite] calls: test for bug in parameter adjustment", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert((function () return nil end)(4) == nil) assert((function () local a; return a end)(4) == nil) assert((function (a) return a end)() == nil) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] calls: testing binary chunks", function (t) { +test("[test-suite] calls: testing binary chunks", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local header = string.pack("c4BBc6BBBBBj", @@ -733,24 +554,9 @@ test("[test-suite] calls: testing binary chunks", function (t) { end assert(assert(load(c))() == 10) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); diff --git a/test/test-suite/closure.js b/test/test-suite/closure.test.js index 79a2226..d44d908 100644 --- a/test/test-suite/closure.js +++ b/test/test-suite/closure.test.js @@ -1,13 +1,14 @@ "use strict"; -const test = require('tape'); - -const lua = require('../../src/lua.js'); +const lua = require('../../src/lua.js'); const lauxlib = require('../../src/lauxlib.js'); -const lualib = require('../../src/lualib.js'); +const lualib = require('../../src/lualib.js'); const {to_luastring} = require("../../src/fengaricore.js"); -test("[test-suite] closure: testing equality", function (t) { +test("[test-suite] closure: testing equality", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` a = {} for i = 1, 5 do a[i] = function (x) return x + a + _ENV end end @@ -20,30 +21,18 @@ test("[test-suite] closure: testing equality", function (t) { return function (x) return math.sin(_ENV[x]) end end assert(f() == f()) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] closure: testing closures with 'for' control variable", function (t) { +test("[test-suite] closure: testing closures with 'for' control variable", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` a = {} for i=1,10 do @@ -73,30 +62,18 @@ test("[test-suite] closure: testing closures with 'for' control variable", funct a[2].set('a', 'b') r,s = a[2].get() assert(r == "a" and s == "b") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] closure: testing closures with 'for' control variable x break", function (t) { +test("[test-suite] closure: testing closures with 'for' control variable x break", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local t = {"a", "b"} @@ -113,30 +90,18 @@ test("[test-suite] closure: testing closures with 'for' control variable x break end assert(({f()})[1] == 1) assert(({f()})[2] == "a") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] closure: testing closure x break x return x errors", function (t) { +test("[test-suite] closure: testing closure x break x return x errors", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local b function f(x) @@ -169,30 +134,18 @@ test("[test-suite] closure: testing closure x break x return x errors", function pcall(f, 4); assert(b('get') == 'xuxu') b('set', 10); assert(b('get') == 14) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] closure: testing multi-level closure", function (t) { +test("[test-suite] closure: testing multi-level closure", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local w function f(x) @@ -204,30 +157,18 @@ test("[test-suite] closure: testing multi-level closure", function (t) { y = f(10) w = 1.345 assert(y(20)(30) == 60+w) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] closure: testing closures x repeat-until", function (t) { +test("[test-suite] closure: testing closures x repeat-until", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local a = {} local i = 1 @@ -236,30 +177,18 @@ test("[test-suite] closure: testing closures x repeat-until", function (t) { a[i] = function () i = x+1; return x end until i > 10 or a[i]() ~= x assert(i == 11 and a[1]() == 1 and a[3]() == 3 and i == 4) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] closure: testing closures created in 'then' and 'else' parts of 'if's", function (t) { +test("[test-suite] closure: testing closures created in 'then' and 'else' parts of 'if's", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` a = {} for i = 1, 10 do @@ -289,30 +218,18 @@ test("[test-suite] closure: testing closures created in 'then' and 'else' parts for i = 1, 10 do assert(a[i](i * 10) == i % 3 and a[i]() == i * 10) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] closure: test for correctly closing upvalues in tail calls of vararg functions", function (t) { +test("[test-suite] closure: test for correctly closing upvalues in tail calls of vararg functions", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function t () local function c(a,b) assert(a=="test" and b=="OK") end @@ -321,24 +238,9 @@ test("[test-suite] closure: test for correctly closing upvalues in tail calls of return v(function() return x end) end t() - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); diff --git a/test/test-suite/code.js b/test/test-suite/code.test.js index 57c97cb..d37030c 100644 --- a/test/test-suite/code.js +++ b/test/test-suite/code.test.js @@ -1,15 +1,16 @@ "use strict"; -const test = require('tape'); - -const lua = require('../../src/lua.js'); +const lua = require('../../src/lua.js'); const lauxlib = require('../../src/lauxlib.js'); -const lualib = require('../../src/lualib.js'); +const lualib = require('../../src/lualib.js'); const {to_luastring} = require("../../src/fengaricore.js"); -const ltests = require('./ltests.js'); +const ltests = require('./ltests.js'); + +test("[test-suite] code: testing reuse in constant table", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); -test("[test-suite] code: testing reuse in constant table", function (t) { let luaCode = ` local function checkKlist (func, list) local k = T.listk(func) @@ -30,27 +31,12 @@ test("[test-suite] code: testing reuse in constant table", function (t) { end checkKlist(foo, {3, 0, 0.0, 3.78/4, -3.78/4, -3.79/4, 3.0}) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); @@ -77,36 +63,28 @@ const prefix = ` end `; -test("[test-suite] code: some basic instructions", function (t) { + +test("[test-suite] code: some basic instructions", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` check(function () (function () end){f()} end, 'CLOSURE', 'NEWTABLE', 'GETTABUP', 'CALL', 'SETLIST', 'CALL', 'RETURN') - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] code: sequence of LOADNILs", function (t) { +test("[test-suite] code: sequence of LOADNILs", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` check(function () local a,b,c @@ -125,58 +103,34 @@ test("[test-suite] code: sequence of LOADNILs", function (t) { d=nil;c=nil;b=nil;a=nil assert(a == nil and b == nil and c == nil and d == nil) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] code: single return", function (t) { +test("[test-suite] code: single return", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` check (function (a,b,c) return a end, 'RETURN') - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] code: infinite loops", function (t) { +test("[test-suite] code: infinite loops", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` check(function () while true do local a = -1 end end, 'LOADK', 'JMP', 'RETURN') @@ -186,89 +140,53 @@ test("[test-suite] code: infinite loops", function (t) { check(function () repeat local x = 1 until true end, 'LOADK', 'RETURN') - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] code: concat optimization", function (t) { +test("[test-suite] code: concat optimization", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` check(function (a,b,c,d) return a..b..c..d end, 'MOVE', 'MOVE', 'MOVE', 'MOVE', 'CONCAT', 'RETURN') - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] code: not", function (t) { +test("[test-suite] code: not", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` check(function () return not not nil end, 'LOADBOOL', 'RETURN') check(function () return not not false end, 'LOADBOOL', 'RETURN') check(function () return not not true end, 'LOADBOOL', 'RETURN') check(function () return not not 1 end, 'LOADBOOL', 'RETURN') - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] code: direct access to locals", function (t) { +test("[test-suite] code: direct access to locals", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` check(function () local a,b,c,d @@ -279,31 +197,19 @@ test("[test-suite] code: direct access to locals", function (t) { 'MUL', 'DIV', 'ADD', 'GETTABLE', 'SUB', 'GETTABLE', 'POW', 'UNM', 'SETTABLE', 'SETTABLE', 'RETURN') - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] code: direct access to constants", function (t) { +test("[test-suite] code: direct access to constants", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` check(function () local a,b @@ -326,31 +232,19 @@ test("[test-suite] code: direct access to constants", function (t) { a[true] = false end, 'LOADNIL', 'SETTABLE', 'RETURN') - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] code: constant folding", function (t) { +test("[test-suite] code: constant folding", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function checkK (func, val) check(func, 'LOADK', 'RETURN') @@ -372,61 +266,37 @@ test("[test-suite] code: constant folding", function (t) { checkK(function () return ~(~0xFF0 | 0xFF0) end, 0) checkK(function () return ~~-100024.0 end, -100024) checkK(function () return ((100 << 6) << -4) >> 2 end, 100) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] code: no folding", function (t) { +test("[test-suite] code: no folding", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` check(function () return -0.0 end, 'LOADK', 'UNM', 'RETURN') check(function () return 3/0 end, 'DIV', 'RETURN') check(function () return 0%0 end, 'MOD', 'RETURN') check(function () return -4//0 end, 'IDIV', 'RETURN') - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] code: bug in constant folding for 5.1", function (t) { +test("[test-suite] code: bug in constant folding for 5.1", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` check(function () return -nil end, 'LOADNIL', 'UNM', 'RETURN') @@ -444,31 +314,19 @@ test("[test-suite] code: bug in constant folding for 5.1", function (t) { 'MOVE', 'MOVE', 'MOVE', -- no code for a = a 'RETURN') - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] code: x == nil , x ~= nil", function (t) { +test("[test-suite] code: x == nil , x ~= nil", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checkequal(function () if (a==nil) then a=1 end; if a~=nil then a=1 end end, function () if (a==9) then a=1 end; if a~=9 then a=1 end end) @@ -481,31 +339,19 @@ test("[test-suite] code: x == nil , x ~= nil", function (t) { checkequal(function (l) local a; return 0 <= a and a <= l end, function (l) local a; return not (not(a >= 0) or not(a <= l)) end) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] code: if-goto optimizations", function (t) { +test("[test-suite] code: if-goto optimizations", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` check(function (a, b, c, d, e) if a == b then goto l1 @@ -528,25 +374,10 @@ test("[test-suite] code: if-goto optimizations", function (t) { function (a) while a < 10 do a = a + 1 end end, function (a) while true do if not(a < 10) then break end; a = a + 1; end end ) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); diff --git a/test/test-suite/constructs.js b/test/test-suite/constructs.test.js index 93bbf1a..de0648d 100644 --- a/test/test-suite/constructs.js +++ b/test/test-suite/constructs.test.js @@ -1,10 +1,8 @@ "use strict"; -const test = require('tape'); - -const lua = require('../../src/lua.js'); +const lua = require('../../src/lua.js'); const lauxlib = require('../../src/lauxlib.js'); -const lualib = require('../../src/lualib.js'); +const lualib = require('../../src/lualib.js'); const {to_luastring} = require("../../src/fengaricore.js"); const checkload = ` @@ -13,61 +11,40 @@ const checkload = ` end `; -test('[test-suite] constructs: testing semicolons', function (t) { +test('[test-suite] constructs: testing semicolons', () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do ;;; end ; do ; a = 3; assert(a == 3) end; ; - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkload + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkload + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test('[test-suite] constructs: invalid operations should not raise errors when not executed', function (t) { +test('[test-suite] constructs: invalid operations should not raise errors when not executed', () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` if false then a = 3 // 0; a = 0 % 0 end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkload + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkload + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test('[test-suite] constructs: testing priorities', function (t) { +test('[test-suite] constructs: testing priorities', () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(2^3^2 == 2^(3^2)); assert(2^3*4 == (2^3)*4); @@ -109,30 +86,18 @@ test('[test-suite] constructs: testing priorities', function (t) { assert((x>y) and x or y == 2); assert(1234567890 == tonumber('1234567890') and 1234567890+1 == 1234567891) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkload + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkload + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test('[test-suite] constructs: silly loops', function (t) { +test('[test-suite] constructs: silly loops', () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` repeat until 1; repeat until true; while false do end; while nil do end; @@ -295,29 +260,17 @@ test('[test-suite] constructs: silly loops', function (t) { a,b = F(1)~=nil; assert(a == true and b == nil); a,b = F(nil)==nil; assert(a == true and b == nil) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkload + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkload + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test.skip('[test-suite] constructs: huge loops, upvalue', function (t) { +test.skip('[test-suite] constructs: huge loops, upvalue', () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` -- sometimes will be 0, sometimes will not... _ENV.GLOB1 = math.floor(os.time()) % 2 @@ -382,30 +335,18 @@ test.skip('[test-suite] constructs: huge loops, upvalue', function (t) { if i % 60000 == 0 then print('+') end end end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkload + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkload + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] constructs: testing some syntax errors (chosen through 'gcov')", function (t) { +test("[test-suite] constructs: testing some syntax errors (chosen through 'gcov')", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` _soft = true @@ -418,24 +359,9 @@ test("[test-suite] constructs: testing some syntax errors (chosen through 'gcov' s = "while true do " .. s .. "end" checkload(s, "too long") end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkload + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkload + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); diff --git a/test/test-suite/coroutine.js b/test/test-suite/coroutine.test.js index 969c65e..de92317 100644 --- a/test/test-suite/coroutine.js +++ b/test/test-suite/coroutine.test.js @@ -1,13 +1,11 @@ "use strict"; -const test = require('tape'); - -const lua = require('../../src/lua.js'); +const lua = require('../../src/lua.js'); const lauxlib = require('../../src/lauxlib.js'); -const lualib = require('../../src/lualib.js'); +const lualib = require('../../src/lualib.js'); const {to_luastring} = require("../../src/fengaricore.js"); -const ltests = require('./ltests.js'); +const ltests = require('./ltests.js'); const prefix = ` mt = { @@ -57,64 +55,43 @@ const prefix = ` end `; -test("[test-suite] coroutine: is main thread", function (t) { +test("[test-suite] coroutine: is main thread", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local main, ismain = coroutine.running() assert(type(main) == "thread" and ismain) assert(not coroutine.resume(main)) assert(not coroutine.isyieldable()) assert(not pcall(coroutine.yield)) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: trivial errors", function (t) { +test("[test-suite] coroutine: trivial errors", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(not pcall(coroutine.resume, 0)) assert(not pcall(coroutine.status, 0)) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: tests for multiple yield/resume arguments", function (t) { +test("[test-suite] coroutine: tests for multiple yield/resume arguments", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function eqtab (t1, t2) assert(#t1 == #t2) @@ -158,30 +135,18 @@ test("[test-suite] coroutine: tests for multiple yield/resume arguments", functi assert(coroutine.status(f) == "dead") s, a = coroutine.resume(f, "xuxu") assert(not s and string.find(a, "dead") and coroutine.status(f) == "dead") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: yields in tail calls", function (t) { +test("[test-suite] coroutine: yields in tail calls", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function foo (i) return coroutine.yield(i) end f = coroutine.wrap(function () @@ -192,30 +157,18 @@ test("[test-suite] coroutine: yields in tail calls", function (t) { end) for i=1,10 do _G.x = i; assert(f(i) == i) end _G.x = 'xuxu'; assert(f('xuxu') == 'a') - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: recursive", function (t) { +test("[test-suite] coroutine: recursive", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` function pf (n, i) coroutine.yield(n) @@ -228,30 +181,18 @@ test("[test-suite] coroutine: recursive", function (t) { assert(f(1, 1) == s) s = s*i end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: sieve", function (t) { +test("[test-suite] coroutine: sieve", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` function gen (n) return coroutine.wrap(function () @@ -281,30 +222,18 @@ test("[test-suite] coroutine: sieve", function (t) { assert(#a == 25 and a[#a] == 97) x, a = nil - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: yielding across JS boundaries", function (t) { +test("[test-suite] coroutine: yielding across JS boundaries", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local f = function (s, i) return coroutine.yield(i) end @@ -333,30 +262,18 @@ test("[test-suite] coroutine: yielding across JS boundaries", function (t) { assert(co() == 10) r, msg = co(100) assert(not r and msg == 240) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: unyieldable JS call", function (t) { +test("[test-suite] coroutine: unyieldable JS call", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local function f (c) @@ -371,30 +288,18 @@ test("[test-suite] coroutine: unyieldable JS call", function (t) { end) assert(co() == "aa") end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: errors in coroutines", function (t) { +test("[test-suite] coroutine: errors in coroutines", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` function foo () assert(debug.getinfo(1).currentline == debug.getinfo(foo).linedefined + 1) @@ -416,30 +321,18 @@ test("[test-suite] coroutine: errors in coroutines", function (t) { assert(not a and b == foo and coroutine.status(x) == "dead") a,b = coroutine.resume(x) assert(not a and string.find(b, "dead") and coroutine.status(x) == "dead") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: co-routines x for loop", function (t) { +test("[test-suite] coroutine: co-routines x for loop", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` function all (a, n, k) if k == 0 then coroutine.yield(a) @@ -456,30 +349,18 @@ test("[test-suite] coroutine: co-routines x for loop", function (t) { a = a+1 end assert(a == 5^4) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: old bug: attempt to resume itself", function (t) { +test("[test-suite] coroutine: old bug: attempt to resume itself", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` function co_func (current_co) assert(coroutine.running() == current_co) @@ -499,30 +380,18 @@ test("[test-suite] coroutine: old bug: attempt to resume itself", function (t) { assert(a == true and b == 10) assert(coroutine.resume(co, co) == false) assert(coroutine.resume(co, co) == false) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: old bug: other old bug when attempting to resume itself", function (t) { +test("[test-suite] coroutine: old bug: other old bug when attempting to resume itself", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local A = coroutine.running() @@ -534,30 +403,18 @@ test("[test-suite] coroutine: old bug: other old bug when attempting to resume i st, res = A() assert(not st and string.find(res, "non%-suspended")) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: attempt to resume 'normal' coroutine", function (t) { +test("[test-suite] coroutine: attempt to resume 'normal' coroutine", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local co1, co2 co1 = coroutine.create(function () return co2() end) @@ -570,58 +427,34 @@ test("[test-suite] coroutine: attempt to resume 'normal' coroutine", function (t a,b = coroutine.resume(co1) assert(a and b == 3) assert(coroutine.status(co1) == 'dead') - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: infinite recursion of coroutines", function (t) { +test("[test-suite] coroutine: infinite recursion of coroutines", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` a = function(a) coroutine.wrap(a)(a) end assert(not pcall(a, a)) a = nil - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: access to locals of erroneous coroutines", function (t) { +test("[test-suite] coroutine: access to locals of erroneous coroutines", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local x = coroutine.create (function () local a = 10 @@ -634,29 +467,17 @@ test("[test-suite] coroutine: access to locals of erroneous coroutines", functio assert(not coroutine.resume(x, 1, 1, 1, 1, 1, 1, 1)) assert(_G.f() == 11) assert(_G.f() == 12) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: leaving a pending coroutine open", function (t) { +test("[test-suite] coroutine: leaving a pending coroutine open", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` _X = coroutine.wrap(function () local a = 10 @@ -665,30 +486,18 @@ test("[test-suite] coroutine: leaving a pending coroutine open", function (t) { end) _X() - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: stack overflow", function (t) { +test("[test-suite] coroutine: stack overflow", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` -- bug (stack overflow) local j = 2^9 @@ -705,30 +514,18 @@ test("[test-suite] coroutine: stack overflow", function (t) { assert(not r) end co = nil - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: testing yields inside metamethods", function (t) { +test("[test-suite] coroutine: testing yields inside metamethods", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local a = new(10) local b = new(12) @@ -765,30 +562,18 @@ test("[test-suite] coroutine: testing yields inside metamethods", function (t) { a.BB = print return a.BB end, {"nidx", "idx"}) == print) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: tests for comparsion operators", function (t) { +test("[test-suite] coroutine: tests for comparsion operators", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local mt1 = { @@ -829,30 +614,18 @@ test("[test-suite] coroutine: tests for comparsion operators", function (t) { run(test) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: getuptable & setuptable", function (t) { +test("[test-suite] coroutine: getuptable & setuptable", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local _ENV = _ENV f = function () AAA = BBB + 1; return AAA end @@ -861,30 +634,18 @@ test("[test-suite] coroutine: getuptable & setuptable", function (t) { debug.setupvalue(f, 1, g) assert(run(f, {"idx", "nidx", "idx"}) == 11) assert(g.k.AAA == 11) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: testing yields inside 'for' iterators", function (t) { +test("[test-suite] coroutine: testing yields inside 'for' iterators", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local f = function (s, i) if i%2 == 0 then coroutine.yield(nil, "for") end @@ -896,26 +657,11 @@ test("[test-suite] coroutine: testing yields inside 'for' iterators", function ( for i in f, 4, 0 do s = s + i end return s end, {"for", "for", "for"}) == 10) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); @@ -930,7 +676,10 @@ const jsprefix = ` end `; -test("[test-suite] coroutine: testing yields inside hooks", function (t) { +test("[test-suite] coroutine: testing yields inside hooks", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local A, B = 0, 0 @@ -950,31 +699,19 @@ test("[test-suite] coroutine: testing yields inside hooks", function (t) { end assert(B // A == 7) -- fact(7) // fact(6) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(jsprefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(jsprefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: testing yields inside line hook", function (t) { +test("[test-suite] coroutine: testing yields inside line hook", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local line = debug.getinfo(1, "l").currentline + 2 -- get line number local function foo () @@ -993,31 +730,19 @@ test("[test-suite] coroutine: testing yields inside line hook", function (t) { _G.X = nil; co(); assert(_G.X == line + 2 and _G.XX == nil) _G.X = nil; co(); assert(_G.X == line + 3 and _G.XX == 20) assert(co() == 10) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(jsprefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(jsprefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: testing yields in count hook", function (t) { +test("[test-suite] coroutine: testing yields in count hook", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local line = debug.getinfo(1, "l").currentline + 2 -- get line number local function foo () @@ -1034,31 +759,19 @@ test("[test-suite] coroutine: testing yields in count hook", function (t) { local c = 0 repeat c = c + 1; local a = co() until a == 10 assert(_G.XX == 20 and c >= 5) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(jsprefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(jsprefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: testing yields inside line hook", function (t) { +test("[test-suite] coroutine: testing yields inside line hook", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local line = debug.getinfo(1, "l").currentline + 2 -- get line number local function foo () @@ -1084,31 +797,19 @@ test("[test-suite] coroutine: testing yields inside line hook", function (t) { repeat c = c + 1; local a = co() until a == 10 assert(_G.XX == 20 and c >= 5) _G.X = nil; _G.XX = nil - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(jsprefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(jsprefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: testing debug library on a coroutine suspended inside a hook", function (t) { +test("[test-suite] coroutine: testing debug library on a coroutine suspended inside a hook", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do -- testing debug library on a coroutine suspended inside a hook @@ -1136,31 +837,19 @@ test("[test-suite] coroutine: testing debug library on a coroutine suspended ins assert(v[1] == true and v[2] == 2 and v[3] == 20 and v[4] == nil) assert(not coroutine.resume(c)) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: testing debug library on last function in a suspended coroutine", function (t) { +test("[test-suite] coroutine: testing debug library on last function in a suspended coroutine", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do -- testing debug library on last function in a suspended coroutine @@ -1172,31 +861,19 @@ test("[test-suite] coroutine: testing debug library on last function in a suspen a, b = debug.getlocal(c, 0, 2) assert(b == 10) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: reusing a thread", function (t) { +test("[test-suite] coroutine: reusing a thread", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(T.testC([[ newthread # create thread @@ -1218,31 +895,19 @@ test("[test-suite] coroutine: reusing a thread", function (t) { ]], function (...) return ... end) == 'b b b') assert(X == 'a a a' and Y == 'OK') - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: resuming running coroutine", function (t) { +test("[test-suite] coroutine: resuming running coroutine", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` C = coroutine.create(function () return T.testC([[ @@ -1267,30 +932,18 @@ test("[test-suite] coroutine: resuming running coroutine", function (t) { return 4]]) assert(a == coroutine.running() and string.find(b, "non%-suspended") and c == "ERRRUN" and d == 4) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: using a main thread as a coroutine", function (t) { +test("[test-suite] coroutine: using a main thread as a coroutine", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local state = T.newstate() T.loadlib(state) @@ -1322,31 +975,19 @@ test("[test-suite] coroutine: using a main thread as a coroutine", function (t) assert(T.doremote(state, "return B") == 'BB') T.closestate(state) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: tests for coroutine API", function (t) { +test("[test-suite] coroutine: tests for coroutine API", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function apico (...) local x = {...} @@ -1386,31 +1027,19 @@ test("[test-suite] coroutine: tests for coroutine API", function (t) { a[7] == "YIELD" and a[8] == 3 and a[9] == "YIELD" and a[10] == 4) assert(not pcall(co)) -- coroutine is dead now - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: tests for coroutine API", function (t) { +test("[test-suite] coroutine: tests for coroutine API", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` f = T.makeCfunc("pushnum 3; pushnum 5; yield 1;") co = coroutine.wrap(function () @@ -1419,31 +1048,19 @@ test("[test-suite] coroutine: tests for coroutine API", function (t) { assert(co(23,16) == 5) assert(co(23,16) == 5) assert(co(23,16) == 10) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: testing coroutines with C bodies", function (t) { +test("[test-suite] coroutine: testing coroutines with C bodies", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function eqtab (t1, t2) assert(#t1 == #t2) @@ -1476,31 +1093,19 @@ test("[test-suite] coroutine: testing coroutines with C bodies", function (t) { return 4; ]], f) assert(a == 'YIELD' and b == 'a' and c == 102 and d == 'OK') - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: testing chain of suspendable C calls", function (t) { +test("[test-suite] coroutine: testing chain of suspendable C calls", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local count = 3 -- number of levels @@ -1531,31 +1136,19 @@ test("[test-suite] coroutine: testing chain of suspendable C calls", function (t a = {co()} -- three '34's (one from each pending C call) assert(#a == 3 and a[1] == a[2] and a[2] == a[3] and a[3] == 34) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: testing yields with continuations", function (t) { +test("[test-suite] coroutine: testing yields with continuations", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` co = coroutine.wrap(function (...) return T.testC([[ # initial function @@ -1608,31 +1201,19 @@ test("[test-suite] coroutine: testing yields with continuations", function (t) { assert(x == "YIELD" and y == 4) assert(not pcall(co)) -- coroutine should be dead - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] coroutine: bug in nCcalls", function (t) { +test("[test-suite] coroutine: bug in nCcalls", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local co = coroutine.wrap(function () local a = {pcall(pcall,pcall,pcall,pcall,pcall,pcall,pcall,error,"hi")} @@ -1641,25 +1222,10 @@ test("[test-suite] coroutine: bug in nCcalls", function (t) { local a = {co()} assert(a[10] == "hi") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); diff --git a/test/test-suite/db.js b/test/test-suite/db.test.js index 9209ab9..38330db 100644 --- a/test/test-suite/db.js +++ b/test/test-suite/db.test.js @@ -1,10 +1,8 @@ "use strict"; -const test = require('tape'); - -const lua = require('../../src/lua.js'); +const lua = require('../../src/lua.js'); const lauxlib = require('../../src/lauxlib.js'); -const lualib = require('../../src/lualib.js'); +const lualib = require('../../src/lualib.js'); const {to_luastring} = require("../../src/fengaricore.js"); const prefix = ` @@ -24,7 +22,10 @@ const prefix = ` end `; -test("[test-suite] db: getinfo, ...line...", function (t) { +test("[test-suite] db: getinfo, ...line...", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(not pcall(debug.getinfo, print, "X")) -- invalid option assert(not debug.getinfo(1000)) -- out of range level @@ -41,30 +42,18 @@ test("[test-suite] db: getinfo, ...line...", function (t) { b.activelines[b.lastlinedefined]) assert(not b.activelines[b.linedefined] and not b.activelines[b.lastlinedefined + 1]) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: test file and string names truncation", function (t) { +test("[test-suite] db: test file and string names truncation", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` a = "function f () end" local function dostring (s, x) return load(s, x)() end @@ -89,29 +78,17 @@ test("[test-suite] db: test file and string names truncation", function (t) { dostring(a, "=") assert(debug.getinfo(f).short_src == "") a = nil; f = nil; - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: local", function (t) { +test("[test-suite] db: local", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` repeat local g = {x = function () @@ -148,30 +125,18 @@ test("[test-suite] db: local", function (t) { function g(x) if not x then return 3 end return (x('a', 'x')) end assert(g(f) == 'a') until 1 - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: line hook", function (t) { +test("[test-suite] db: line hook", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` test([[if math.sin(1) @@ -226,57 +191,33 @@ test("[test-suite] db: line hook", function (t) { ]], {1,2,1,2,1,3}) test([[for i=1,4 do a=1 end]], {1,1,1,1,1}) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: invalid levels in [gs]etlocal", function (t) { +test("[test-suite] db: invalid levels in [gs]etlocal", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(not pcall(debug.getlocal, 20, 1)) assert(not pcall(debug.setlocal, -1, 1, 10)) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: parameter names", function (t) { +test("[test-suite] db: parameter names", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function foo (a,b,...) local d, e end local co = coroutine.create(foo) @@ -289,30 +230,18 @@ test("[test-suite] db: parameter names", function (t) { assert(not debug.getlocal(co, foo, 3)) assert(not debug.getlocal(print, 1)) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: vararg", function (t) { +test("[test-suite] db: vararg", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function foo (a, ...) local t = table.pack(...) @@ -338,57 +267,33 @@ test("[test-suite] db: vararg", function (t) { for i = 1, (_soft and 100 or 1000) do a[i] = i end foo(table.unpack(a)) a = nil - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: access to vararg in non-vararg function", function (t) { +test("[test-suite] db: access to vararg in non-vararg function", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function foo () return debug.getlocal(1, -1) end assert(not foo(10)) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: test hook presence in debug info", function (t) { +test("[test-suite] db: test hook presence in debug info", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do -- test hook presence in debug info assert(not debug.gethook()) @@ -473,30 +378,18 @@ test("[test-suite] db: test hook presence in debug info", function (t) { g() assert(a[f] and a[g] and a[assert] and a[debug.getlocal] and not a[print]) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: tests for manipulating non-registered locals (C and Lua temporaries)", function (t) { +test("[test-suite] db: tests for manipulating non-registered locals (C and Lua temporaries)", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local n, v = debug.getlocal(0, 1) assert(v == 0 and n == "(*temporary)") @@ -519,30 +412,18 @@ test("[test-suite] db: tests for manipulating non-registered locals (C and Lua t debug.sethook(nil); assert(debug.gethook() == nil) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: testing access to function arguments", function (t) { +test("[test-suite] db: testing access to function arguments", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function collectlocals (level) local tab = {} @@ -580,30 +461,18 @@ test("[test-suite] db: testing access to function arguments", function (t) { assert(X.self == a and X.a == 1 and X.b == 2 and X.c == nil) assert(XX == 12) assert(debug.gethook() == nil) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: testing access to local variables in return hook (bug in 5.2)", function (t) { +test("[test-suite] db: testing access to local variables in return hook (bug in 5.2)", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function collectlocals (level) local tab = {} @@ -639,30 +508,18 @@ test("[test-suite] db: testing access to local variables in return hook (bug in debug.sethook(aux, "r"); foo(100, 200); debug.sethook() assert(foo == nil) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: testing upvalue access", function (t) { +test("[test-suite] db: testing upvalue access", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function getupvalues (f) local t = {} @@ -691,30 +548,18 @@ test("[test-suite] db: testing upvalue access", function (t) { assert(({debug.getupvalue(foo2, 3)})[2] == "xuxu") -- upvalues of C functions are allways "called" "" (the empty string) assert(debug.getupvalue(string.gmatch("x", "x"), 1) == "") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: testing count hooks", function (t) { +test("[test-suite] db: testing count hooks", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local a=0 debug.sethook(function (e) a=a+1 end, "", 1) @@ -733,30 +578,18 @@ test("[test-suite] db: testing count hooks", function (t) { end debug.sethook() - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: tests for tail calls", function (t) { +test("[test-suite] db: tests for tail calls", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function f (x) if x then @@ -812,30 +645,18 @@ test("[test-suite] db: tests for tail calls", function (t) { end foo(lim) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: testing local function information", function (t) { +test("[test-suite] db: testing local function information", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` co = load[[ local A = function () @@ -854,30 +675,18 @@ test("[test-suite] db: testing local function information", function (t) { co() -- run local function definition debug.sethook() -- turn off hook assert(a == 2) -- ensure all two lines where hooked - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: testing traceback", function (t) { +test("[test-suite] db: testing traceback", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(debug.traceback(print) == print) assert(debug.traceback(print, 4) == print) @@ -891,30 +700,18 @@ test("[test-suite] db: testing traceback", function (t) { local st, msg = (function () return pcall end)()(debug.traceback) assert(st == true and string.find(msg, "pcall")) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: testing nparams, nups e isvararg", function (t) { +test("[test-suite] db: testing nparams, nups e isvararg", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local t = debug.getinfo(print, "u") assert(t.isvararg == true and t.nparams == 0 and t.nups == 0) @@ -928,30 +725,18 @@ test("[test-suite] db: testing nparams, nups e isvararg", function (t) { t = debug.getinfo(1) -- main assert(t.isvararg == true and t.nparams == 0 and t.nups == 1 and debug.getupvalue(t.func, 1) == "_ENV") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: testing debugging of coroutines", function (t) { +test("[test-suite] db: testing debugging of coroutines", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function checktraceback (co, p, level) local tb = debug.traceback(co, nil, level) @@ -1018,32 +803,19 @@ test("[test-suite] db: testing debugging of coroutines", function (t) { assert(debug.gethook(co) == foo) assert(not debug.gethook()) checktraceback(co, {}) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - let b = to_luastring(luaCode); - if (lauxlib.luaL_loadbuffer(L, b, b.length, to_luastring("@db.lua")) !== lua.LUA_OK) - throw Error(lua.lua_tojsstring(L, -1)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + let b = to_luastring(luaCode); + if (lauxlib.luaL_loadbuffer(L, b, b.length, to_luastring("@db.lua")) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: check get/setlocal in coroutines", function (t) { +test("[test-suite] db: check get/setlocal in coroutines", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` co = coroutine.create(function (x) local a, b = coroutine.yield(x) @@ -1059,30 +831,18 @@ test("[test-suite] db: check get/setlocal in coroutines", function (t) { assert(not debug.setlocal(co, 1, 5, 40)) a, b = coroutine.resume(co, 100) assert(a and b == 30) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: check traceback of suspended (or dead with error) coroutines", function (t) { +test("[test-suite] db: check traceback of suspended (or dead with error) coroutines", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function checktraceback (co, p, level) local tb = debug.traceback(co, nil, level) @@ -1106,30 +866,18 @@ test("[test-suite] db: check traceback of suspended (or dead with error) corouti end t[1] = "'error'" checktraceback(co, t) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: check test acessing line numbers of a coroutine from a resume inside a C function", function (t) { +test("[test-suite] db: check test acessing line numbers of a coroutine from a resume inside a C function", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function g(x) coroutine.yield(x) @@ -1149,30 +897,18 @@ test("[test-suite] db: check test acessing line numbers of a coroutine from a re assert(type(debug.getregistry()) == "table") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: test tagmethod information", function (t) { +test("[test-suite] db: test tagmethod information", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local a = {} local function f (t) @@ -1201,30 +937,18 @@ test("[test-suite] db: test tagmethod information", function (t) { assert (a>=b and a.op == "__le") assert (a>b and a.op == "__lt") assert(~a == "__bnot") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: testing for-iterator name", function (t) { +test("[test-suite] db: testing for-iterator name", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local function f() @@ -1233,30 +957,18 @@ test("[test-suite] db: testing for-iterator name", function (t) { for i in f do end end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: testing traceback sizes", function (t) { +test("[test-suite] db: testing traceback sizes", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function countlines (s) return select(2, string.gsub(s, "\\n", "")) @@ -1292,32 +1004,19 @@ test("[test-suite] db: testing traceback sizes", function (t) { coroutine.wrap(checkdeep)(d, l) end end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - let b = to_luastring(luaCode); - if (lauxlib.luaL_loadbuffer(L, b, b.length, to_luastring("@db.lua")) !== lua.LUA_OK) - throw Error(lua.lua_tojsstring(L, -1)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + let b = to_luastring(luaCode); + if (lauxlib.luaL_loadbuffer(L, b, b.length, to_luastring("@db.lua")) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: testing debug functions on chunk without debug info", function (t) { +test("[test-suite] db: testing debug functions on chunk without debug info", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` prog = [[-- program to be loaded without debug information local debug = require'debug' @@ -1361,30 +1060,18 @@ test("[test-suite] db: testing debug functions on chunk without debug info", fun local f = assert(load(string.dump(load(prog), true))) assert(f() == 13) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] db: tests for 'source' in binary dumps", function (t) { +test("[test-suite] db: tests for 'source' in binary dumps", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local prog = [[ @@ -1417,24 +1104,9 @@ test("[test-suite] db: tests for 'source' in binary dumps", function (t) { debug.getinfo(g).source == '=?' and debug.getinfo(h).source == '=?') end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); diff --git a/test/test-suite/errors.js b/test/test-suite/errors.test.js index 0b05e9d..83c7a90 100644 --- a/test/test-suite/errors.js +++ b/test/test-suite/errors.test.js @@ -1,10 +1,8 @@ "use strict"; -const test = require('tape'); - -const lua = require('../../src/lua.js'); +const lua = require('../../src/lua.js'); const lauxlib = require('../../src/lauxlib.js'); -const lualib = require('../../src/lualib.js'); +const lualib = require('../../src/lualib.js'); const {to_luastring} = require("../../src/fengaricore.js"); const prefix = ` @@ -44,59 +42,38 @@ const prefix = ` end `; -test("[test-suite] errors: test error message with no extra info", function (t) { +test("[test-suite] errors: test error message with no extra info", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(doit("error('hi', 0)") == 'hi') - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: test error message with no info", function (t) { +test("[test-suite] errors: test error message with no info", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(doit("error()") == nil) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: test common errors/errors that crashed in the past", function (t) { +test("[test-suite] errors: test common errors/errors that crashed in the past", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(doit("table.unpack({}, 1, n=2^30)")) assert(doit("a=math.sin()")) @@ -114,30 +91,18 @@ test("[test-suite] errors: test common errors/errors that crashed in the past", local a = {4 ]], "'}' expected (to close '{' at line 1)", "<eof>", 3) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: tests for better error messages", function (t) { +test("[test-suite] errors: tests for better error messages", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checkmessage("a = {} + 1", "arithmetic") checkmessage("a = {} | 1", "bitwise operation") @@ -160,30 +125,18 @@ test("[test-suite] errors: tests for better error messages", function (t) { checkmessage("local aaa={bbb={}}; aaa.bbb:ddd(9)", "method 'ddd'") checkmessage("local a,b,c; (function () a = b+1 end)()", "upvalue 'b'") assert(not doit"local aaa={bbb={ddd=next}}; aaa.bbb:ddd(nil)") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: upvalues being indexed do not go to the stack", function (t) { +test("[test-suite] errors: upvalues being indexed do not go to the stack", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checkmessage("local a,b,cc; (function () a = cc[1] end)()", "upvalue 'cc'") checkmessage("local a,b,cc; (function () a.x = 1 end)()", "upvalue 'a'") @@ -194,30 +147,18 @@ test("[test-suite] errors: upvalues being indexed do not go to the stack", funct checkmessage("aaa={}; x=3/aaa", "global 'aaa'") checkmessage("aaa='2'; b=nil;x=aaa*b", "global 'b'") checkmessage("aaa={}; x=-aaa", "global 'aaa'") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: short circuit", function (t) { +test("[test-suite] errors: short circuit", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checkmessage("a=1; local a,bbbb=2,3; a = math.sin(1) and bbbb(3)", "local 'bbbb'") @@ -231,30 +172,18 @@ test("[test-suite] errors: short circuit", function (t) { checkmessage("print(print < print)", "two function values") checkmessage("print('10' < 10)", "string with number") checkmessage("print(10 < '23')", "number with string") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: float->integer conversions", function (t) { +test("[test-suite] errors: float->integer conversions", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checkmessage("local a = 2.0^100; x = a << 2", "local a") checkmessage("local a = 1 >> 2.0^100", "has no integer representation") @@ -273,30 +202,18 @@ test("[test-suite] errors: float->integer conversions", function (t) { checkmessage("return 34 >> {}", "table value") checkmessage("a = 24 // 0", "divide by zero") checkmessage("a = 1 % 0", "'n%0'") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: passing light userdata instead of full userdata", function (t) { +test("[test-suite] errors: passing light userdata instead of full userdata", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` _G.D = debug checkmessage([[ @@ -305,30 +222,18 @@ test("[test-suite] errors: passing light userdata instead of full userdata", fun D.setuservalue(x, {}) ]], "light userdata") _G.D = nil - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: named objects (field '__name')", function (t) { +test("[test-suite] errors: named objects (field '__name')", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do checkmessage("math.sin(io.input())", "(number expected, got FILE*)") @@ -342,57 +247,33 @@ test("[test-suite] errors: named objects (field '__name')", function (t) { checkmessage("return XX < io.stdin", "My Type with FILE*") _G.XX = nil end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: global functions", function (t) { +test("[test-suite] errors: global functions", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checkmessage("(io.write or print){}", "io.write") checkmessage("(collectgarbage or print){}", "collectgarbage") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: errors in functions without debug info", function (t) { +test("[test-suite] errors: errors in functions without debug info", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local f = function (a) return a + 1 end @@ -407,30 +288,18 @@ test("[test-suite] errors: errors in functions without debug info", function (t) -- symbolic execution should not get lost checkerr("^%?:%-1:.*table value", f) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: tests for field accesses after RK limit", function (t) { +test("[test-suite] errors: tests for field accesses after RK limit", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local t = {} for i = 1, 1000 do @@ -442,30 +311,18 @@ test("[test-suite] errors: tests for field accesses after RK limit", function (t checkmessage("local _ENV=_ENV;"..s.."; a = bbb + 1", "global 'bbb'") checkmessage(s.."; local t = {}; a = t.bbb + 1", "field 'bbb'") checkmessage(s.."; local t = {}; t:bbb()", "method 'bbb'") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: global", function (t) { +test("[test-suite] errors: global", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checkmessage([[aaa=9 repeat until 3==3 @@ -477,59 +334,35 @@ test("[test-suite] errors: global", function (t) { 3+1>3+1, {d = x and aaa[x or y]}} ]], "global 'aaa'") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: field", function (t) { +test("[test-suite] errors: field", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checkmessage([[ local x,y = {},1 if math.sin(1) == 0 then return 3 end -- return x.a()]], "field 'a'") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: global insert", function (t) { +test("[test-suite] errors: global insert", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checkmessage([[ prefix = nil @@ -539,86 +372,50 @@ test("[test-suite] errors: global insert", function (t) { if nil then break end insert(prefix, a) end]], "global 'insert'") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: sin", function (t) { +test("[test-suite] errors: sin", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checkmessage([[ -- tail call return math.sin("a") ]], "'sin'") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: concatenate", function (t) { +test("[test-suite] errors: concatenate", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checkmessage([[x = print .. "a"]], "concatenate") checkmessage([[x = "a" .. false]], "concatenate") checkmessage([[x = {} .. 2]], "concatenate") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: unknown global", function (t) { +test("[test-suite] errors: unknown global", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checkmessage([[ local Var @@ -627,30 +424,18 @@ test("[test-suite] errors: unknown global", function (t) { end main() ]], "global 'NoSuchName'") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: __index", function (t) { +test("[test-suite] errors: __index", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` a = {}; setmetatable(a, {__index = string}) checkmessage("a:sub()", "bad self") @@ -659,30 +444,18 @@ test("[test-suite] errors: __index", function (t) { checkmessage("table.sort({1,2,3}, table.sort)", "'table.sort'") checkmessage("string.gsub('s', 's', setmetatable)", "'setmetatable'") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: tests for errors in coroutines", function (t) { +test("[test-suite] errors: tests for errors in coroutines", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function f (n) local c = coroutine.create(f) @@ -695,30 +468,18 @@ test("[test-suite] errors: tests for errors in coroutines", function (t) { f = coroutine.wrap(function () table.sort({1,2,3}, coroutine.yield) end) checkerr("yield across", f) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: testing size of 'source' info", function (t) { +test("[test-suite] errors: testing size of 'source' info", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` idsize = 60 - 1 local function checksize (source) @@ -734,30 +495,18 @@ test("[test-suite] errors: testing size of 'source' info", function (t) { checksize("=" .. string.rep("x", i)) -- exact sources end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: testing line error", function (t) { +test("[test-suite] errors: testing line error", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function lineerror (s, l) local err,msg = pcall(load(s)) @@ -811,30 +560,18 @@ test("[test-suite] errors: testing line error", function (t) { X=0;lineerror((p), nil) X=1;lineerror((p), 2) X=2;lineerror((p), 1) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: several tests that exhaust the Lua stack", function (t) { +test("[test-suite] errors: several tests that exhaust the Lua stack", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` C = 0 local l = debug.getinfo(1, "l").currentline; function y () C=C+1; y() end @@ -846,30 +583,18 @@ test("[test-suite] errors: several tests that exhaust the Lua stack", function ( assert(checkstackmessage(doit('y()'))) assert(checkstackmessage(doit('y()'))) assert(checkstackmessage(doit('y()'))) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: error lines in stack overflow", function (t) { +test("[test-suite] errors: error lines in stack overflow", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` C = 0 local l = debug.getinfo(1, "l").currentline; function y () C=C+1; y() end @@ -889,30 +614,18 @@ test("[test-suite] errors: error lines in stack overflow", function (t) { i = i+1 end assert(i > 15) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: error in error handling", function (t) { +test("[test-suite] errors: error in error handling", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local res, msg = xpcall(error, error) assert(not res and type(msg) == 'string') @@ -926,30 +639,18 @@ test("[test-suite] errors: error in error handling", function (t) { end end f(3) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: too many results", function (t) { +test("[test-suite] errors: too many results", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function loop (x,y,z) return 1 + loop(x, y, z) end @@ -965,30 +666,18 @@ test("[test-suite] errors: too many results", function (t) { for i = 999900, 1000000, 1 do table.unpack({}, 1, i) end end checkerr("too many results", f) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: non string messages", function (t) { +test("[test-suite] errors: non string messages", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do -- non string messages @@ -1023,59 +712,35 @@ test("[test-suite] errors: non string messages", function (t) { res, msg = pcall(assert) assert(not res and string.find(msg, "value expected")) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadbuffer(L, to_luastring(prefix + luaCode), null, to_luastring("@errors.lua")); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadbuffer(L, to_luastring(prefix + luaCode), null, to_luastring("@errors.lua")) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: xpcall with arguments", function (t) { +test("[test-suite] errors: xpcall with arguments", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` a, b, c = xpcall(string.find, error, "alo", "al") assert(a and b == 1 and c == 2) a, b, c = xpcall(string.find, function (x) return {} end, true, "al") assert(not a and type(b) == "table" and c == nil) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: testing tokens in error messages", function (t) { +test("[test-suite] errors: testing tokens in error messages", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checksyntax("syntax error", "", "error", 1) checksyntax("1.000", "", "1.000", 1) @@ -1083,85 +748,49 @@ test("[test-suite] errors: testing tokens in error messages", function (t) { checksyntax("'aa'", "", "'aa'", 1) checksyntax("while << do end", "", "<<", 1) checksyntax("for >> do end", "", ">>", 1) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: test invalid non-printable char in a chunk", function (t) { +test("[test-suite] errors: test invalid non-printable char in a chunk", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checksyntax("a\\1a = 1", "", "<\\\\1>", 1) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: test 255 as first char in a chunk", function (t) { +test("[test-suite] errors: test 255 as first char in a chunk", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checksyntax("\\255a = 1", "", "<\\\\255>", 1) doit('I = load("a=9+"); a=3') assert(a==3 and I == nil) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: lots of errors", function (t) { +test("[test-suite] errors: lots of errors", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` lim = 1000 if _soft then lim = 100 end @@ -1169,30 +798,18 @@ test("[test-suite] errors: lots of errors", function (t) { doit('a = ') doit('a = 4+nil') end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: testing syntax limits", function (t) { +test("[test-suite] errors: testing syntax limits", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local maxClevel = 200 -- LUAI_MAXCCALLS (in llimits.h) @@ -1216,30 +833,18 @@ test("[test-suite] errors: testing syntax limits", function (t) { testrep("local a; a=", "a^", "a", "") checkmessage("a = f(x" .. string.rep(",x", 260) .. ")", "too many registers") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: upvalues limit", function (t) { +test("[test-suite] errors: upvalues limit", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local lim = 127 local s = "local function fooA ()\\n local " @@ -1262,30 +867,18 @@ test("[test-suite] errors: upvalues limit", function (t) { local a,b = load(s) assert(c > 255 and string.find(b, "too many upvalues") and string.find(b, "line 5")) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] errors: local variables limit", function (t) { +test("[test-suite] errors: local variables limit", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` s = "\\nfunction foo ()\\n local " for j = 1,300 do @@ -1294,24 +887,9 @@ test("[test-suite] errors: local variables limit", function (t) { s = s.."b\\n" local a,b = load(s) assert(string.find(b, "line 2") and string.find(b, "too many local variables")) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); diff --git a/test/test-suite/events.js b/test/test-suite/events.test.js index 143bdf5..67faad6 100644 --- a/test/test-suite/events.js +++ b/test/test-suite/events.test.js @@ -1,15 +1,16 @@ "use strict"; -const test = require('tape'); - -const lua = require('../../src/lua.js'); +const lua = require('../../src/lua.js'); const lauxlib = require('../../src/lauxlib.js'); -const lualib = require('../../src/lualib.js'); +const lualib = require('../../src/lualib.js'); const {to_luastring} = require("../../src/fengaricore.js"); -const ltests = require('./ltests.js'); +const ltests = require('./ltests.js'); + +test("[test-suite] events: testing metatable", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); -test("[test-suite] events: testing metatable", function (t) { let luaCode = ` X = 20; B = 30 @@ -181,30 +182,18 @@ test("[test-suite] events: testing metatable", function (t) { assert(cap[0] == "shl" and cap[1] == a and cap[2] == 3) assert(1.5 >> a == 1.5) assert(cap[0] == "shr" and cap[1] == 1.5 and cap[2] == a) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] events: test for rawlen", function (t) { +test("[test-suite] events: test for rawlen", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` t = setmetatable({1,2,3}, {__len = function () return 10 end}) assert(#t == 10 and rawlen(t) == 3) @@ -215,30 +204,18 @@ test("[test-suite] events: test for rawlen", function (t) { -- rawlen for long strings assert(rawlen(string.rep('a', 1000)) == 1000) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] events: test comparison", function (t) { +test("[test-suite] events: test comparison", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` t = {} t.__lt = function (a,b,c) @@ -276,30 +253,18 @@ test("[test-suite] events: test comparison", function (t) { end test() -- retest comparisons, now using both 'lt' and 'le' - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] events: test 'partial order'", function (t) { +test("[test-suite] events: test 'partial order'", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` t = {} @@ -359,30 +324,18 @@ test("[test-suite] events: test 'partial order'", function (t) { -- '__eq' is not used for table accesses t[Set{1,3,5}] = 1 assert(t[Set{1,3,5}] == nil) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] events: __eq between userdata", function (t) { +test("[test-suite] events: __eq between userdata", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` T = require('T') @@ -402,32 +355,19 @@ test("[test-suite] events: __eq between userdata", function (t) { assert(u1 == u3 and u3 == u1 and u1 ~= u2) assert(u2 == u1 and u2 == u3 and u3 == u2) assert(u2 ~= {}) -- different types cannot be equal - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] events: concat", function (t) { +test("[test-suite] events: concat", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` t = {} @@ -454,32 +394,19 @@ test("[test-suite] events: concat", function (t) { assert(getmetatable(x) == t and x.val == 'cd') x = 0 .."a".."b"..c..d.."e".."f".."g" assert(x.val == "0abcdefg") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] events: concat metamethod x numbers (bug in 5.1.1)", function (t) { +test("[test-suite] events: concat metamethod x numbers (bug in 5.1.1)", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` c = {} local x @@ -489,32 +416,19 @@ test("[test-suite] events: concat metamethod x numbers (bug in 5.1.1)", function end}) assert(c..5 == c and 5 .. c == c) assert(4 .. c .. 5 == c and 4 .. 5 .. 6 .. 7 .. c == c) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] events: test comparison compatibilities", function (t) { +test("[test-suite] events: test comparison compatibilities", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local t1, t2, c, d t1 = {}; c = {}; setmetatable(c, t1) @@ -528,32 +442,19 @@ test("[test-suite] events: test comparison compatibilities", function (t) { t2.__lt = t1.__lt setmetatable(d, t2) assert(c == d and c < d and not(d <= c)) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] events: test for several levels of callstest for several levels of calls", function (t) { +test("[test-suite] events: test for several levels of callstest for several levels of calls", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local i local tt = { @@ -572,32 +473,19 @@ test("[test-suite] events: test for several levels of callstest for several leve i = 0 x = c(3,4,5) assert(i == 3 and x[1] == 3 and x[3] == 5) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] events: __index on _ENV", function (t) { +test("[test-suite] events: __index on _ENV", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local _g = _G _ENV = setmetatable({}, {__index=function (_,k) return _g[k] end}) @@ -605,32 +493,19 @@ test("[test-suite] events: __index on _ENV", function (t) { a = {} rawset(a, "x", 1, 2, 3) assert(a.x == 1 and rawget(a, "x", 3) == 1) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] events: testing metatables for basic types", function (t) { +test("[test-suite] events: testing metatables for basic types", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` mt = {__index = function (a,b) return a+b end, __len = function (x) return math.floor(x) end} @@ -660,62 +535,36 @@ test("[test-suite] events: testing metatables for basic types", function (t) { assert(getmetatable(nil) == nil) debug.setmetatable(nil, {}) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] events: loops in delegation", function (t) { +test("[test-suite] events: loops in delegation", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` a = {}; setmetatable(a, a); a.__index = a; a.__newindex = a assert(not pcall(function (a,b) return a[b] end, a, 10)) assert(not pcall(function (a,b,c) a[b] = c end, a, 10, true)) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] events: bug in 5.1", function (t) { +test("[test-suite] events: bug in 5.1", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` T, K, V = nil grandparent = {} @@ -728,26 +577,10 @@ test("[test-suite] events: bug in 5.1", function (t) { child = setmetatable({}, parent) child.foo = 10 --> CRASH (on some machines) assert(T == parent and K == "foo" and V == 10) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - ltests.luaopen_tests(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + ltests.luaopen_tests(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); diff --git a/test/test-suite/goto.js b/test/test-suite/goto.test.js index dc52c73..17e0397 100644 --- a/test/test-suite/goto.js +++ b/test/test-suite/goto.test.js @@ -1,13 +1,14 @@ "use strict"; -const test = require('tape'); - -const lua = require('../../src/lua.js'); +const lua = require('../../src/lua.js'); const lauxlib = require('../../src/lauxlib.js'); -const lualib = require('../../src/lualib.js'); +const lualib = require('../../src/lualib.js'); const {to_luastring} = require("../../src/fengaricore.js"); -test("[test-suite] goto: error messages", function (t) { +test("[test-suite] goto: error messages", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function errmsg (code, m) local st, msg = load(code) @@ -44,30 +45,18 @@ test("[test-suite] goto: error messages", function (t) { ::cont:: until xuxu < x ]], "local 'xuxu'") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] goto", function (t) { +test("[test-suite] goto", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` -- simple gotos local x @@ -123,30 +112,18 @@ test("[test-suite] goto", function (t) { local x ::l1:: ; ::l2:: ;; else end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] goto: to repeat a label in a different function is OK", function (t) { +test("[test-suite] goto: to repeat a label in a different function is OK", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function foo () local a = {} @@ -163,30 +140,18 @@ test("[test-suite] goto: to repeat a label in a different function is OK", funct end ::l6:: foo() - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] goto: bug in 5.2 -> 5.3.2", function (t) { +test("[test-suite] goto: bug in 5.2 -> 5.3.2", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do -- bug in 5.2 -> 5.3.2 local x @@ -202,30 +167,18 @@ test("[test-suite] goto: bug in 5.2 -> 5.3.2", function (t) { end assert(x == 2 and y == true) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] goto: testing closing of upvalues", function (t) { +test("[test-suite] goto: testing closing of upvalues", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function foo () local t = {} @@ -287,30 +240,18 @@ test("[test-suite] goto: testing closing of upvalues", function (t) { == (i == j)) end end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] goto: testing if x goto optimizations", function (t) { +test("[test-suite] goto: testing if x goto optimizations", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function testG (a) if a == 1 then @@ -341,24 +282,9 @@ test("[test-suite] goto: testing if x goto optimizations", function (t) { assert(testG(3) == "3") assert(testG(4) == 5) assert(testG(5) == 10) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); diff --git a/test/test-suite/literals.js b/test/test-suite/literals.test.js index 6e3205e..3e9307b 100644 --- a/test/test-suite/literals.js +++ b/test/test-suite/literals.test.js @@ -1,74 +1,51 @@ "use strict"; -const test = require('tape'); - -const lua = require('../../src/lua.js'); +const lua = require('../../src/lua.js'); const lauxlib = require('../../src/lauxlib.js'); -const lualib = require('../../src/lualib.js'); +const lualib = require('../../src/lualib.js'); const {to_luastring} = require("../../src/fengaricore.js"); const dostring = ` local function dostring (x) return assert(load(x), "")() end `; -test("[test-suite] literals: dostring", function (t) { +test("[test-suite] literals: dostring", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` dostring("x \\v\\f = \\t\\r 'a\\0a' \\v\\f\\f") assert(x == 'a\\0a' and string.len(x) == 3) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); // TODO: bell character '\a' in JS is parsed as 'a' -test("[test-suite] literals: escape sequences", function (t) { +test("[test-suite] literals: escape sequences", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert('\\n\\"\\'\\\\' == [[ "'\\]]) assert(string.find("\\b\\f\\n\\r\\t\\v", "^%c%c%c%c%c%c$")) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] literals: assume ASCII just for tests", function (t) { +test("[test-suite] literals: assume ASCII just for tests", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert("\\09912" == 'c12') assert("\\99ab" == 'cab') @@ -77,30 +54,18 @@ test("[test-suite] literals: assume ASCII just for tests", function (t) { assert('\\0\\0\\0alo' == '\\0' .. '\\0\\0' .. 'alo') assert(010 .. 020 .. -030 == "1020-30") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] literals: hexadecimal escapes", function (t) { +test("[test-suite] literals: hexadecimal escapes", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert("\\x00\\x05\\x10\\x1f\\x3C\\xfF\\xe8" == "\\0\\5\\16\\31\\60\\255\\232") @@ -124,30 +89,18 @@ assert("abc\\z def\\z ghi\\z " == 'abcdefghi') - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] literals: UTF-8 sequences", function (t) { +test("[test-suite] literals: UTF-8 sequences", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert("\\u{0}\\u{00000000}\\x00\\0" == string.char(0, 0, 0, 0)) @@ -162,30 +115,18 @@ test("[test-suite] literals: UTF-8 sequences", function (t) { -- limits for 4-byte sequences assert("\\u{10000}\\u{10FFFF}" == "\\xF0\\x90\\x80\\x80\\z\\xF4\\x8F\\xBF\\xBF") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] literals: Error in escape sequences", function (t) { +test("[test-suite] literals: Error in escape sequences", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function lexerror (s, err) local st, msg = load('return ' .. s, '') @@ -228,30 +169,18 @@ test("[test-suite] literals: Error in escape sequences", function (t) { lexerror("'alo \\\\z \\n\\n", "<eof>") lexerror("'alo \\\\z", "<eof>") lexerror([['alo \\98]], "<eof>") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] literals: valid characters in variable names", function (t) { +test("[test-suite] literals: valid characters in variable names", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` for i = 0, 255 do local s = string.char(i) @@ -259,30 +188,18 @@ test("[test-suite] literals: valid characters in variable names", function (t) { assert(not string.find(s, "[a-zA-Z_0-9]") == not load("a" .. s .. "1 = 1", "")) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] literals: long variable names", function (t) { +test("[test-suite] literals: long variable names", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` var1 = string.rep('a', 15000) .. '1' var2 = string.rep('a', 15000) .. '2' @@ -294,56 +211,32 @@ test("[test-suite] literals: long variable names", function (t) { local f = dostring(prog) assert(_G[var1] == 5 and _G[var2] == 6 and f() == -1) var1, var2, f = nil - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] literals: escapes", function (t) { +test("[test-suite] literals: escapes", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = `assert("\\n\\t" == [[\n\n\t]]) assert([[\n\n $debug]] == "\\n $debug") -assert([[ [ ]] ~= [[ ] ]])`, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - +assert([[ [ ]] ~= [[ ] ]])`; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] literals: long strings", function (t) { +test("[test-suite] literals: long strings", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = `b = "001234567890123456789012345678901234567891234567890123456789012345678901234567890012345678901234567890123456789012345678912345678901234567890123456789012345678900123456789012345678901234567890123456789123456789012345678901234567890123456789001234567890123456789012345678901234567891234567890123456789012345678901234567890012345678901234567890123456789012345678912345678901234567890123456789012345678900123456789012345678901234567890123456789123456789012345678901234567890123456789001234567890123456789012345678901234567891234567890123456789012345678901234567890012345678901234567890123456789012345678912345678901234567890123456789012345678900123456789012345678901234567890123456789123456789012345678901234567890123456789001234567890123456789012345678901234567891234567890123456789012345678901234567890012345678901234567890123456789012345678912345678901234567890123456789012345678900123456789012345678901234567890123456789123456789012345678901234567890123456789" assert(string.len(b) == 960) prog = [=[ @@ -395,30 +288,18 @@ assert(x) prog = nil a = nil -b = nil`, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - +b = nil`; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] literals: testing line ends", function (t) { +test("[test-suite] literals: testing line ends", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = `prog = [[ a = 1 -- a comment b = 2 @@ -437,30 +318,18 @@ for _, n in pairs{"\\n", "\\r", "\\n\\r", "\\r\\n"} do local prog, nn = string.gsub(prog, "\\n", n) assert(dostring(prog) == nn) assert(_G.x == "hi\\n" and _G.y == "\\nhello\\r\\n\\n") -end`, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - +end`; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] literals: testing comments and strings with long brackets", function (t) { +test("[test-suite] literals: testing comments and strings with long brackets", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = `a = [==[]=]==] assert(a == "]=") @@ -479,31 +348,18 @@ x y z [==[ blu foo ]== ] ]=]==] -error error]=]===]`, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - - +error error]=]===]`; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] literals: generate all strings of four of these chars", function (t) { +test("[test-suite] literals: generate all strings of four of these chars", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = `local x = {"=", "[", "]", "\\n"} local len = 4 local function gen (c, n) @@ -517,84 +373,42 @@ end for s in coroutine.wrap(function () gen("", len) end) do assert(s == load("return [====[\\n"..s.."]====]", "")()) -end`, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - - +end`; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] literals: testing %q x line ends", function (t) { +test("[test-suite] literals: testing %q x line ends", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local s = "a string with \\r and \\n and \\r\\n and \\n\\r" local c = string.format("return %q", s) assert(assert(load(c))() == s) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] literals: testing errors", function (t) { +test("[test-suite] literals: testing errors", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(not load"a = 'non-ending string") assert(not load"a = 'non-ending string\\n'") assert(not load"a = '\\\\345'") assert(not load"a = [=x]") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(dostring + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); diff --git a/test/test-suite/locals.js b/test/test-suite/locals.test.js index d1dc3e4..2701519 100644 --- a/test/test-suite/locals.js +++ b/test/test-suite/locals.test.js @@ -1,13 +1,14 @@ "use strict"; -const test = require('tape'); - -const lua = require('../../src/lua.js'); +const lua = require('../../src/lua.js'); const lauxlib = require('../../src/lauxlib.js'); -const lualib = require('../../src/lualib.js'); +const lualib = require('../../src/lualib.js'); const {to_luastring} = require("../../src/fengaricore.js"); -test('[test-suite] locals: bug in 5.1', function (t) { +test('[test-suite] locals: bug in 5.1', () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function f(x) x = nil; return x end assert(f(10) == nil) @@ -17,30 +18,18 @@ test('[test-suite] locals: bug in 5.1', function (t) { local function f(x) x = nil; local y; return x, y end assert(f(10) == nil and select(2, f(20)) == nil) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test('[test-suite] locals: local scope', function (t) { +test('[test-suite] locals: local scope', () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local i = 10 @@ -89,26 +78,11 @@ test('[test-suite] locals: local scope', function (t) { f(2) assert(type(f) == 'function') - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); @@ -121,7 +95,10 @@ const getenv = ` `; -test('[test-suite] locals: test for global table of loaded chunks', function (t) { +test('[test-suite] locals: test for global table of loaded chunks', () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(getenv(load"a=3") == _G) local c = {}; local f = load("a = 3", nil, nil, c) @@ -129,30 +106,18 @@ test('[test-suite] locals: test for global table of loaded chunks', function (t) assert(c.a == nil) f() assert(c.a == 3) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(getenv + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(getenv + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test('[test-suite] locals: old test for limits for special instructions (now just a generic test)', function (t) { +test('[test-suite] locals: old test for limits for special instructions (now just a generic test)', () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local i = 2 @@ -172,30 +137,18 @@ test('[test-suite] locals: old test for limits for special instructions (now jus p = 2 * p; i = i + 1 until p <= 0 end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test('[test-suite] locals: testing lexical environments', function (t) { +test('[test-suite] locals: testing lexical environments', () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(_ENV == _G) @@ -226,24 +179,9 @@ test('[test-suite] locals: testing lexical environments', function (t) { end assert(x==20) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(getenv + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(getenv + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); diff --git a/test/test-suite/math.js b/test/test-suite/math.test.js index 1e54772..c649225 100644 --- a/test/test-suite/math.js +++ b/test/test-suite/math.test.js @@ -1,10 +1,8 @@ "use strict"; -const test = require('tape'); - -const lua = require('../../src/lua.js'); +const lua = require('../../src/lua.js'); const lauxlib = require('../../src/lauxlib.js'); -const lualib = require('../../src/lualib.js'); +const lualib = require('../../src/lualib.js'); const {to_luastring} = require("../../src/fengaricore.js"); const prefix = ` @@ -54,34 +52,25 @@ const prefix = ` end `; -test("[test-suite] math: int bits", function (t) { +test("[test-suite] math: int bits", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(minint == 1 << (intbits - 1)) assert(maxint == minint - 1) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: number of bits in the mantissa of a floating-point number", function (t) { +test("[test-suite] math: number of bits in the mantissa of a floating-point number", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(isNaN(0/0)) assert(not isNaN(1/0)) @@ -97,30 +86,18 @@ test("[test-suite] math: number of bits in the mantissa of a floating-point numb assert(math.type(0) == "integer" and math.type(0.0) == "float" and math.type("10") == nil) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: basic float notation", function (t) { +test("[test-suite] math: basic float notation", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(0e12 == 0 and .0 == 0 and 0. == 0 and .2e2 == 20 and 2.E-1 == 0.2) @@ -161,87 +138,51 @@ test("[test-suite] math: basic float notation", function (t) { a,b = math.modf(minint) assert(eqT(a, minint) and eqT(b, 0.0)) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: math.huge", function (t) { +test("[test-suite] math: math.huge", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(math.huge > 10e30) assert(-math.huge < -10e30) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: integer arithmetic", function (t) { +test("[test-suite] math: integer arithmetic", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(minint < minint + 1) assert(maxint - 1 < maxint) assert(0 - minint == minint) assert(minint * minint == 0) assert(maxint * maxint * maxint == maxint) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: testing floor division and conversions", function (t) { +test("[test-suite] math: testing floor division and conversions", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` for _, i in pairs{-16, -15, -3, -2, -1, 0, 1, 2, 3, 15} do for _, j in pairs{-16, -15, -3, -2, -1, 1, 2, 3, 15} do @@ -273,30 +214,18 @@ test("[test-suite] math: testing floor division and conversions", function (t) { assert(minint // -1 == -minint) assert(minint // -2 == 2^(intbits - 2)) assert(maxint // -1 == -maxint) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: negative exponents", function (t) { +test("[test-suite] math: negative exponents", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do assert(2^-3 == 1 / 2^3) @@ -310,30 +239,18 @@ test("[test-suite] math: negative exponents", function (t) { end end end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: comparison between floats and integers (border cases)", function (t) { +test("[test-suite] math: comparison between floats and integers (border cases)", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` if floatbits < intbits then assert(2.0^floatbits == (1 << floatbits)) @@ -350,30 +267,18 @@ test("[test-suite] math: comparison between floats and integers (border cases)", assert(maxint + 0.0 == 2.0^(intbits - 1) - 1.0) assert(minint + 0.0 == minint) assert(minint + 0.0 == -2.0^(intbits - 1)) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: order between floats and integers", function (t) { +test("[test-suite] math: order between floats and integers", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(minint == 1 << (intbits - 1)) assert(maxint == minint - 1) @@ -459,30 +364,18 @@ test("[test-suite] math: order between floats and integers", function (t) { assert(not (minint <= NaN)) assert(not (minint < NaN)) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: avoiding errors at compile time", function (t) { +test("[test-suite] math: avoiding errors at compile time", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checkcompt("divide by zero", "return 2 // 0") checkcompt(msgf2i, "return 2.3 >> 0") @@ -490,29 +383,17 @@ test("[test-suite] math: avoiding errors at compile time", function (t) { checkcompt("field 'huge'", "return math.huge << 1") checkcompt(msgf2i, ("return 1 | 2.0^%d"):format(intbits - 1)) checkcompt(msgf2i, "return 2.3 ~ '0.0'") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: testing overflow errors when converting from float to integer (runtime)", function (t) { +test("[test-suite] math: testing overflow errors when converting from float to integer (runtime)", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function f2i (x) return x | x end checkerror(msgf2i, f2i, math.huge) -- +inf @@ -543,59 +424,35 @@ test("[test-suite] math: testing overflow errors when converting from float to i -- 'minint' should be representable as a float no matter the precision assert(f2i(minint + 0.0) == minint) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: testing numeric strings", function (t) { +test("[test-suite] math: testing numeric strings", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert("2" + 1 == 3) assert("2 " + 1 == 3) assert(" -2 " + 1 == -1) assert(" -0xa " + 1 == -9) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: Literal integer Overflows (new behavior in 5.3.3)", function (t) { +test("[test-suite] math: Literal integer Overflows (new behavior in 5.3.3)", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do -- no overflows @@ -630,59 +487,35 @@ test("[test-suite] math: Literal integer Overflows (new behavior in 5.3.3)", fun assert(eqT(10000000000000000000000.0, 10000000000000000000000)) assert(eqT(-10000000000000000000000.0, -10000000000000000000000)) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: 'tonumber' with numbers", function (t) { +test("[test-suite] math: 'tonumber' with numbers", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(tonumber(3.4) == 3.4) assert(eqT(tonumber(3), 3)) assert(eqT(tonumber(maxint), maxint) and eqT(tonumber(minint), minint)) assert(tonumber(1/0) == 1/0) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: 'tonumber' with strings", function (t) { +test("[test-suite] math: 'tonumber' with strings", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(tonumber("0") == 0) assert(tonumber("") == nil) @@ -721,30 +554,18 @@ test("[test-suite] math: 'tonumber' with strings", function (t) { local i10 = i2 * i2 * i2 * i2 * i2 -- i^10 assert(tonumber('\\t10000000000\\t', i) == i10) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: tests with very long numerals", function (t) { +test("[test-suite] math: tests with very long numerals", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(tonumber("0x"..string.rep("f", 13)..".0") == 2.0^(4*13) - 1) assert(tonumber("0x"..string.rep("f", 150)..".0") == 2.0^(4*150) - 1) @@ -759,30 +580,18 @@ test("[test-suite] math: tests with very long numerals", function (t) { assert(tonumber('0xe03' .. string.rep('0', 1000) .. 'p-4000') == 3587.0) assert(tonumber('0x.' .. string.rep('0', 1000) .. '74p4004') == 0x7.4) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: testing 'tonumber' for invalid formats", function (t) { +test("[test-suite] math: testing 'tonumber' for invalid formats", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function f (...) if select('#', ...) == 1 then @@ -815,30 +624,18 @@ test("[test-suite] math: testing 'tonumber' for invalid formats", function (t) { assert(f(tonumber('e1')) == nil) assert(f(tonumber('e 1')) == nil) assert(f(tonumber(' 3.4.5 ')) == nil) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: testing 'tonumber' for invalid hexadecimal formats", function (t) { +test("[test-suite] math: testing 'tonumber' for invalid hexadecimal formats", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(tonumber('0x') == nil) assert(tonumber('x') == nil) @@ -852,30 +649,18 @@ test("[test-suite] math: testing 'tonumber' for invalid hexadecimal formats", fu assert(tonumber('-0xaaP ') == nil) -- no exponent assert(tonumber('0x0.51p') == nil) assert(tonumber('0x5p+-2') == nil) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: testing hexadecimal numerals", function (t) { +test("[test-suite] math: testing hexadecimal numerals", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(0x10 == 16 and 0xfff == 2^12 - 1 and 0XFB == 251) assert(0x0p12 == 0 and 0x.0p-3 == 0) @@ -886,30 +671,18 @@ test("[test-suite] math: testing hexadecimal numerals", function (t) { -- possible confusion with decimal exponent assert(0E+1 == 0 and 0xE+1 == 15 and 0xe-1 == 13) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: floating hexas", function (t) { +test("[test-suite] math: floating hexas", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(tonumber(' 0x2.5 ') == 0x25/16) assert(tonumber(' -0x2.5 ') == -0x25/16) @@ -934,30 +707,18 @@ test("[test-suite] math: floating hexas", function (t) { assert(0.123456 > 0.123455) assert(tonumber('+1.23E18') == 1.23*10.0^18) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: testing order operators", function (t) { +test("[test-suite] math: testing order operators", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(not(1<1) and (1<2) and not(2<1)) assert(not('a'<'a') and ('a'<'b') and not('b'<'a')) @@ -968,30 +729,18 @@ test("[test-suite] math: testing order operators", function (t) { assert((1>=1) and not(1>=2) and (2>=1)) assert(('a'>='a') and not('a'>='b') and ('b'>='a')) assert(1.3 < 1.4 and 1.3 <= 1.4 and not (1.3 < 1.3) and 1.3 <= 1.3) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: testing mod operator", function (t) { +test("[test-suite] math: testing mod operator", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(eqT(-4 % 3, 2)) assert(eqT(4 % -3, -2)) @@ -1009,30 +758,18 @@ test("[test-suite] math: testing mod operator", function (t) { assert(minint % -1 == 0) assert(minint % -2 == 0) assert(maxint % -2 == -1) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: non-portable tests because Windows C library cannot compute fmod(1, huge) correctly", function (t) { +test("[test-suite] math: non-portable tests because Windows C library cannot compute fmod(1, huge) correctly", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function anan (x) assert(isNaN(x)) end -- assert Not a Number anan(0.0 % 0) @@ -1046,30 +783,18 @@ test("[test-suite] math: non-portable tests because Windows C library cannot com assert(1e30 % -math.huge == -math.huge) assert(-1 % math.huge == math.huge) assert(-1 % -math.huge == -1) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: testing unsigned comparisons", function (t) { +test("[test-suite] math: testing unsigned comparisons", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(math.ult(3, 4)) assert(not math.ult(4, 4)) @@ -1102,58 +827,34 @@ test("[test-suite] math: testing unsigned comparisons", function (t) { assert(tonumber(' 1.3e-2 ') == 1.3e-2) assert(tonumber(' -1.00000000000001 ') == -1.00000000000001) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: testing constant limits", function (t) { +test("[test-suite] math: testing constant limits", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(8388609 + -8388609 == 0) assert(8388608 + -8388608 == 0) assert(8388607 + -8388607 == 0) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: testing floor & ceil", function (t) { +test("[test-suite] math: testing floor & ceil", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do assert(eqT(math.floor(3.4), 3)) @@ -1197,30 +898,18 @@ test("[test-suite] math: testing floor & ceil", function (t) { assert(math.tointeger({}) == nil) assert(math.tointeger(0/0) == nil) -- NaN end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: testing fmod for integers", function (t) { +test("[test-suite] math: testing fmod for integers", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` for i = -6, 6 do for j = -6, 6 do @@ -1241,30 +930,18 @@ test("[test-suite] math: testing fmod for integers", function (t) { assert(eqT(math.fmod(maxint - 1, maxint), maxint - 1)) checkerror("zero", math.fmod, 3, 0) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: testing max/min", function (t) { +test("[test-suite] math: testing max/min", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do checkerror("value expected", math.max) @@ -1281,58 +958,34 @@ test("[test-suite] math: testing max/min", function (t) { assert(eqT(math.min(maxint, maxint - 1), maxint - 1)) assert(eqT(math.min(maxint - 2, maxint, maxint - 1), maxint - 2)) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: testing implicit convertions", function (t) { +test("[test-suite] math: testing implicit convertions", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local a,b = '10', '20' assert(a*b == 200 and a+b == 30 and a-b == -10 and a/b == 0.5 and -b == -20) assert(a == '10' and b == '20') - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: testing -0 and NaN", function (t) { +test("[test-suite] math: testing -0 and NaN", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do print("testing -0 and NaN") @@ -1368,30 +1021,18 @@ test("[test-suite] math: testing -0 and NaN", function (t) { assert(a1 == a2 and a2 == a4 and a1 ~= a3) assert(a3 == a5) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: test random for floats", function (t) { +test("[test-suite] math: test random for floats", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` math.randomseed(0) @@ -1411,30 +1052,18 @@ test("[test-suite] math: test random for floats", function (t) { assert(false) ::ok:: end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: test random for small intervals", function (t) { +test("[test-suite] math: test random for small intervals", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local function aux (p, lim) -- test random for small intervals @@ -1467,30 +1096,18 @@ test("[test-suite] math: test random for small intervals", function (t) { aux({minint, minint + 9}) aux({maxint - 3, maxint}) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: test random for large intervals", function (t) { +test("[test-suite] math: test random for large intervals", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local function aux(p1, p2) -- test random for large intervals @@ -1525,80 +1142,41 @@ test("[test-suite] math: test random for large intervals", function (t) { end assert(not pcall(math.random, 1, 2, 3)) -- too many arguments - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: test random for empty interval", function (t) { +test("[test-suite] math: test random for empty interval", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(not pcall(math.random, minint + 1, minint)) assert(not pcall(math.random, maxint, maxint - 1)) assert(not pcall(math.random, maxint, minint)) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] math: interval too large", function (t) { +test("[test-suite] math: interval too large", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(not pcall(math.random, minint, 0)) assert(not pcall(math.random, -1, maxint)) assert(not pcall(math.random, minint // 2, maxint // 2 + 1)) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); diff --git a/test/test-suite/nextvar.js b/test/test-suite/nextvar.test.js index 3e05490..1c4f331 100644 --- a/test/test-suite/nextvar.js +++ b/test/test-suite/nextvar.test.js @@ -1,10 +1,8 @@ "use strict"; -const test = require('tape'); - -const lua = require('../../src/lua.js'); +const lua = require('../../src/lua.js'); const lauxlib = require('../../src/lauxlib.js'); -const lualib = require('../../src/lualib.js'); +const lualib = require('../../src/lualib.js'); const {to_luastring} = require("../../src/fengaricore.js"); const prefix = ` @@ -14,7 +12,10 @@ const prefix = ` end `; -test("[test-suite] nextvar: testing size operator", function (t) { +test("[test-suite] nextvar: testing size operator", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local a = {} @@ -26,30 +27,18 @@ test("[test-suite] nextvar: testing size operator", function (t) { a[i] = true assert(#a == i) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: testing ipairs", function (t) { +test("[test-suite] nextvar: testing ipairs", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local x = 0 for k,v in ipairs{10,20,30;x=12} do @@ -58,30 +47,18 @@ test("[test-suite] nextvar: testing ipairs", function (t) { end for _ in ipairs{x=12, y=24} do assert(nil) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: test for 'false' x ipair", function (t) { +test("[test-suite] nextvar: test for 'false' x ipair", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` x = false local i = 0 @@ -91,56 +68,32 @@ test("[test-suite] nextvar: test for 'false' x ipair", function (t) { assert(x == v) end assert(i == 4) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: iterator function is always the same", function (t) { +test("[test-suite] nextvar: iterator function is always the same", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(type(ipairs{}) == 'function' and ipairs{} == ipairs{}) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: JS tests", { skip: true }, function (t) { +test.skip("[test-suite] nextvar: JS tests", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` -- testing table sizes @@ -271,90 +224,54 @@ test("[test-suite] nextvar: JS tests", { skip: true }, function (t) { end local a = {} for i=1,lim do a[i] = true; foo(i, table.unpack(a)) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: test size operation on empty tables", function (t) { +test("[test-suite] nextvar: test size operation on empty tables", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(#{} == 0) assert(#{nil} == 0) assert(#{nil, nil} == 0) assert(#{nil, nil, nil} == 0) assert(#{nil, nil, nil, nil} == 0) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: test size operation on empty tables", function (t) { +test("[test-suite] nextvar: test size operation on empty tables", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(#{} == 0) assert(#{nil} == 0) assert(#{nil, nil} == 0) assert(#{nil, nil, nil} == 0) assert(#{nil, nil, nil, nil} == 0) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: next uses always the same iteration function", function (t) { +test("[test-suite] nextvar: next uses always the same iteration function", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local nofind = {} @@ -392,83 +309,47 @@ test("[test-suite] nextvar: next uses always the same iteration function", funct assert(nofind==find("return")) _G["xxx"] = 1 assert(xxx==find("xxx")) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: invalid key to 'next'", function (t) { +test("[test-suite] nextvar: invalid key to 'next'", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checkerror("invalid key", next, {10,20}, 3) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: both 'pairs' and 'ipairs' need an argument", function (t) { +test("[test-suite] nextvar: both 'pairs' and 'ipairs' need an argument", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checkerror("bad argument", pairs) checkerror("bad argument", ipairs) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: fmod table", function (t) { +test("[test-suite] nextvar: fmod table", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` a = {} for i=0,10000 do @@ -484,30 +365,18 @@ test("[test-suite] nextvar: fmod table", function (t) { end assert(n.n == 9000) a = nil - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: check next", function (t) { +test("[test-suite] nextvar: check next", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function checknext (a) local b = {} @@ -521,30 +390,18 @@ test("[test-suite] nextvar: check next", function (t) { checknext{1,2,3,x=1,y=2,z=3} checknext{1,2,3,4,x=1,y=2,z=3} checknext{1,2,3,4,5,x=1,y=2,z=3} - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: # operator", function (t) { +test("[test-suite] nextvar: # operator", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(#{} == 0) assert(#{[-1] = 2} == 0) @@ -554,30 +411,18 @@ test("[test-suite] nextvar: # operator", function (t) { for j=1,i do a[j]=j end assert(#a == i) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: maxn", function (t) { +test("[test-suite] nextvar: maxn", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` -- 'maxn' is now deprecated, but it is easily defined in Lua function table.maxn (t) @@ -595,58 +440,34 @@ test("[test-suite] nextvar: maxn", function (t) { assert(table.maxn{[10] = true, [100*math.pi] = print} == 100*math.pi) table.maxn = nil - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: int overflow", function (t) { +test("[test-suite] nextvar: int overflow", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` a = {} for i=0,50 do a[2^i] = true end assert(a[#a]) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: erasing values", function (t) { +test("[test-suite] nextvar: erasing values", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local t = {[{1}] = 1, [{2}] = 2, [string.rep("x ", 4)] = 3, [100.3] = 4, [4] = 5} @@ -720,30 +541,18 @@ test("[test-suite] nextvar: erasing values", function (t) { assert(a[#a] == 30) assert(table.remove(a, 2) == 20) assert(a[#a] == 30 and #a == 2) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: testing table library with metamethods", function (t) { +test("[test-suite] nextvar: testing table library with metamethods", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local function test (proxy, t) @@ -790,30 +599,18 @@ test("[test-suite] nextvar: testing table library with metamethods", function (t assert(table.concat(t, ";") == "2;3;4;5;6") end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: JS tests", { skip: true }, function (t) { +test.skip("[test-suite] nextvar: JS tests", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local tab = {10, 20, 30} local mt = {} @@ -843,30 +640,18 @@ test("[test-suite] nextvar: JS tests", { skip: true }, function (t) { debug.setmetatable(u2, {__newindex = function (_, k, v) tab2[k] = v end}) table.move(u, 1, 4, 1, u2) assert(#tab2 == 4 and tab2[1] == tab[1] and tab2[4] == tab[4]) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: next", function (t) { +test("[test-suite] nextvar: next", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` a = {} for i=1,1000 do @@ -882,30 +667,18 @@ test("[test-suite] nextvar: next", function (t) { for i=0,1,-1 do error'not here' end a = nil; for i=1,1 do assert(not a); a=1 end; assert(a) a = nil; for i=1,1,-1 do assert(not a); a=1 end; assert(a) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: testing floats in numeric for", function (t) { +test("[test-suite] nextvar: testing floats in numeric for", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local a @@ -925,56 +698,32 @@ test("[test-suite] nextvar: testing floats in numeric for", function (t) { a = 0; for i=99999, 1e5, -1.0 do a=a+1 end; assert(a==0) a = 0; for i=1.0, 0.99999, -1 do a=a+1 end; assert(a==1) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: conversion", function (t) { +test("[test-suite] nextvar: conversion", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` a = 0; for i="10","1","-2" do a=a+1 end; assert(a==5) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: checking types", function (t) { +test("[test-suite] nextvar: checking types", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local c @@ -1029,30 +778,18 @@ test("[test-suite] nextvar: checking types", function (t) { for i = math.maxinteger, 10e100, -1 do assert(false) end end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: testing generic 'for'", function (t) { +test("[test-suite] nextvar: testing generic 'for'", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function f (n, p) local t = {}; for i=1,p do t[i] = i*10 end @@ -1070,30 +807,18 @@ test("[test-suite] nextvar: testing generic 'for'", function (t) { assert(a == 10 and b == 20 and c == 30 and d == nil) end assert(x == 5) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: testing __pairs and __ipairs metamethod", function (t) { +test("[test-suite] nextvar: testing __pairs and __ipairs metamethod", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` a = {} do @@ -1122,30 +847,18 @@ test("[test-suite] nextvar: testing __pairs and __ipairs metamethod", function ( a.n = 5 a[3] = 30 - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] nextvar: testing ipairs with metamethods", function (t) { +test("[test-suite] nextvar: testing ipairs with metamethods", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` a = {n=10} setmetatable(a, { __index = function (t,k) @@ -1157,24 +870,9 @@ test("[test-suite] nextvar: testing ipairs with metamethods", function (t) { assert(k == i and v == i * 10) end assert(i == a.n) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); diff --git a/test/test-suite/pm.js b/test/test-suite/pm.test.js index d78b385..c2d0de5 100644 --- a/test/test-suite/pm.js +++ b/test/test-suite/pm.test.js @@ -1,13 +1,14 @@ "use strict"; -const test = require('tape'); - -const lua = require('../../src/lua.js'); +const lua = require('../../src/lua.js'); const lauxlib = require('../../src/lauxlib.js'); -const lualib = require('../../src/lualib.js'); +const lualib = require('../../src/lualib.js'); const {to_luastring} = require("../../src/fengaricore.js"); -test("[test-suite] pm: pattern matching", function (t) { +test("[test-suite] pm: pattern matching", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` function f(s, p) local i,e = string.find(s, p) @@ -85,30 +86,18 @@ test("[test-suite] pm: pattern matching", function (t) { -- assert(f(']]]áb', '[^]]') == 'á') assert(f("0alo alo", "%x*") == "0a") assert(f("alo alo", "%C+") == "alo alo") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] pm: tonumber", function (t) { +test("[test-suite] pm: tonumber", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` function f1(s, p) p = string.gsub(p, "%%([0-9])", function (s) @@ -124,30 +113,18 @@ test("[test-suite] pm: tonumber", function (t) { -- assert(f1('axz123= 4= 4 34', '(.+)=(.*)=%2 %1') == '3= 4= 4 3') -- assert(f1('=======', '^(=*)=%1$') == '=======') assert(string.match('==========', '^([=]*)=%1$') == nil) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] pm: range", function (t) { +test("[test-suite] pm: range", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function range (i, j) if i <= j then @@ -176,78 +153,42 @@ test("[test-suite] pm: range", function (t) { assert(strset('[%^%[%-a%]%-b]') == '-[]^ab') assert(strset('%Z') == strset('[\\1-\\255]')) assert(strset('.') == strset('[\\1-\\255%z]')) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -// Can't be represented by JS string, testing from actual lua file -test("[test-suite] pm: classes", function (t) { - let L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadfile(L, to_luastring("test/test-suite/pm-classes.lua")); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - -}); // Can't be represented by JS string, testing from actual lua file -test("[test-suite] pm: gsub", function (t) { - let L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadfile(L, to_luastring("test/test-suite/pm-gsub.lua")); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); +test("[test-suite] pm: classes", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadfile(L, to_luastring("test/test-suite/pm-classes.lua")) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); +}); - }, "Lua program ran without error"); +// Can't be represented by JS string, testing from actual lua file +test("[test-suite] pm: gsub", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadfile(L, to_luastring("test/test-suite/pm-gsub.lua")) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] pm: empty matches", function (t) { +test("[test-suite] pm: empty matches", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do -- new (5.3.3) semantics for empty matches assert(string.gsub("a b cd", " *", "-") == "-a-b-c-d-") @@ -261,30 +202,18 @@ test("[test-suite] pm: empty matches", function (t) { end assert(res == "-a-b-c-d-") end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] pm: gsub", function (t) { +test("[test-suite] pm: gsub", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(string.gsub("um (dois) tres (quatro)", "(%(%w+%))", string.upper) == "um (DOIS) tres (QUATRO)") @@ -315,30 +244,18 @@ test("[test-suite] pm: gsub", function (t) { t[a] = b-a; end) assert(s == r and t[1] == 1 and t[3] == 3 and t[7] == 4 and t[13] == 4) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] pm: gsub isbalanced", function (t) { +test("[test-suite] pm: gsub isbalanced", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` function isbalanced (s) return string.find(string.gsub(s, "%b()", ""), "[()]") == nil @@ -347,30 +264,18 @@ test("[test-suite] pm: gsub isbalanced", function (t) { assert(isbalanced("(9 ((8))(\\0) 7) \\0\\0 a b ()(c)() a")) assert(not isbalanced("(9 ((8) 7) a b (\\0 c) a")) assert(string.gsub("alo 'oi' alo", "%b''", '"') == 'alo " alo') - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] pm: capture", function (t) { +test("[test-suite] pm: capture", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function checkerror (msg, f, ...) local s, err = pcall(f, ...) @@ -396,30 +301,18 @@ test("[test-suite] pm: capture", function (t) { checkerror("invalid capture index %%0", string.gsub, "alo", "(%0)", "a") checkerror("invalid capture index %%1", string.gsub, "alo", "(%1)", "a") checkerror("invalid use of '%%'", string.gsub, "alo", ".", "%x") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] pm: bug since 2.5 (C-stack overflow) (TODO: _soft)", function (t) { +test("[test-suite] pm: bug since 2.5 (C-stack overflow) (TODO: _soft)", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` _soft = true if not _soft then -- TODO @@ -433,30 +326,18 @@ test("[test-suite] pm: bug since 2.5 (C-stack overflow) (TODO: _soft)", function r, m = f(200000) assert(not r and string.find(m, "too complex")) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] pm: big strings (TODO: _soft)", function (t) { +test("[test-suite] pm: big strings (TODO: _soft)", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` _soft = true -- TODO if not _soft then @@ -470,30 +351,18 @@ test("[test-suite] pm: big strings (TODO: _soft)", function (t) { a = string.rep('a', 10000) .. string.rep('b', 10000) assert(not pcall(string.gsub, a, 'b')) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] pm: recursive nest of gsubs", function (t) { +test("[test-suite] pm: recursive nest of gsubs", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` function rev (s) return string.gsub(s, "(.)(.+)", function (c,s1) return rev(s1)..c end) @@ -501,30 +370,18 @@ test("[test-suite] pm: recursive nest of gsubs", function (t) { local x = "abcdef" assert(rev(rev(x)) == x) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] pm: gsub with tables", function (t) { +test("[test-suite] pm: gsub with tables", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(string.gsub("alo alo", ".", {}) == "alo alo") assert(string.gsub("alo alo", "(.)", {a="AA", l=""}) == "AAo AAo") @@ -535,30 +392,18 @@ test("[test-suite] pm: gsub with tables", function (t) { t = {}; setmetatable(t, {__index = function (t,s) return string.upper(s) end}) assert(string.gsub("a alo b hi", "%w%w+", t) == "a ALO b HI") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] pm: gmatch", function (t) { +test("[test-suite] pm: gmatch", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local a = 0 for i in string.gmatch('abcde', '()') do assert(i == a+1); a=i end @@ -583,30 +428,18 @@ test("[test-suite] pm: gmatch", function (t) { a = 0 for k,v in pairs(t) do assert(k+1 == v+0); a=a+1 end assert(a == 3) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] pm: tests for '%f' ('frontiers')", function (t) { +test("[test-suite] pm: tests for '%f' ('frontiers')", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(string.gsub("aaa aa a aaa a", "%f[%w]a", "x") == "xaa xa x xaa x") assert(string.gsub("[[]] [][] [[[[", "%f[[].", "x") == "x[]] x]x] x[[[") @@ -633,30 +466,18 @@ test("[test-suite] pm: tests for '%f' ('frontiers')", function (t) { assert(table.remove(a, 1) == k) end assert(#a == 0) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] pm: malformed patterns", function (t) { +test("[test-suite] pm: malformed patterns", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function malform (p, m) m = m or "malformed" @@ -675,30 +496,18 @@ test("[test-suite] pm: malformed patterns", function (t) { malform("%ba") malform("%") malform("%f", "missing") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] pm: \\0 in patterns", function (t) { +test("[test-suite] pm: \\0 in patterns", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(string.match("ab\\0\\1\\2c", "[\\0-\\2]+") == "\\0\\1\\2") assert(string.match("ab\\0\\1\\2c", "[\\0-\\0]+") == "\\0") @@ -707,51 +516,24 @@ test("[test-suite] pm: \\0 in patterns", function (t) { assert(string.match("abc\\0efg\\0\\1e\\1g", "%b\\0\\1") == "\\0efg\\0\\1e\\1") assert(string.match("abc\\0\\0\\0", "%\\0+") == "\\0\\0\\0") assert(string.match("abc\\0\\0\\0", "%\\0%\\0?") == "\\0\\0") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] pm: magic char after \\0", function (t) { +test("[test-suite] pm: magic char after \\0", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(string.find("abc\\0\\0","\\0.") == 4) assert(string.find("abcx\\0\\0abc\\0abc","x\\0\\0abc\\0a.") == 4) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); diff --git a/test/test-suite/sort.js b/test/test-suite/sort.test.js index c52f30c..154db03 100644 --- a/test/test-suite/sort.js +++ b/test/test-suite/sort.test.js @@ -1,10 +1,8 @@ "use strict"; -const test = require('tape'); - -const lua = require('../../src/lua.js'); +const lua = require('../../src/lua.js'); const lauxlib = require('../../src/lauxlib.js'); -const lualib = require('../../src/lualib.js'); +const lualib = require('../../src/lualib.js'); const {to_luastring} = require("../../src/fengaricore.js"); const prefix = ` @@ -32,7 +30,10 @@ const prefix = ` if _soft then limit = 5000 end `; -test("[test-suite] sort: testing unpack", function (t) { +test("[test-suite] sort: testing unpack", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checkerror("wrong number of arguments", table.insert, {}, 2, 3, 4) @@ -58,30 +59,18 @@ test("[test-suite] sort: testing unpack", function (t) { assert(a==1 and x==nil) a,x = unpack({1,2}, 1, 1) assert(a==1 and x==nil) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] sort: testing unpack", function (t) { +test("[test-suite] sort: testing unpack", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local maxi = (1 << 31) - 1 -- maximum value for an int (usually) @@ -110,60 +99,36 @@ test("[test-suite] sort: testing unpack", function (t) { a, b = unpack(t, minI, minI); assert(a == 12.3 and b == nil) a, b = unpack(t, minI + 1, minI); assert(a == nil and b == nil) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] sort: testing unpack", function (t) { +test("[test-suite] sort: testing unpack", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do -- length is not an integer local t = setmetatable({}, {__len = function () return 'abc' end}) assert(#t == 'abc') checkerror("object length is not an integer", table.insert, t, 1) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] sort: testing pack", function (t) { +test("[test-suite] sort: testing pack", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` a = table.pack() assert(a[1] == nil and a.n == 0) @@ -173,30 +138,18 @@ test("[test-suite] sort: testing pack", function (t) { a = table.pack(nil, nil, nil, nil) assert(a[1] == nil and a.n == 4) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] sort: testing move", function (t) { +test("[test-suite] sort: testing move", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do @@ -268,30 +221,18 @@ test("[test-suite] sort: testing move", function (t) { local stat, msg = pcall(table.move, b, 10, 13, 3, b) assert(not stat and msg == b) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] sort: testing long move", function (t) { +test("[test-suite] sort: testing long move", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do -- for very long moves, just check initial accesses and interrupt @@ -319,60 +260,36 @@ test("[test-suite] sort: testing long move", function (t) { checkerror("wrap around", table.move, {}, 1, maxI, 2) checkerror("wrap around", table.move, {}, 1, 2, maxI) checkerror("wrap around", table.move, {}, minI, -2, 2) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] sort: testing sort, strange lengths", function (t) { +test("[test-suite] sort: testing sort, strange lengths", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local a = setmetatable({}, {__len = function () return -1 end}) assert(#a == -1) table.sort(a, error) -- should not compare anything a = setmetatable({}, {__len = function () return maxI end}) checkerror("too big", table.sort, a) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] sort: test checks for invalid order functions", function (t) { +test("[test-suite] sort: test checks for invalid order functions", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function check (t) local function f(a, b) assert(a and b); return true end @@ -382,30 +299,18 @@ test("[test-suite] sort: test checks for invalid order functions", function (t) check{1,2,3,4} check{1,2,3,4,5} check{1,2,3,4,5,6} - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] sort: sort alpha", function (t) { +test("[test-suite] sort: sort alpha", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` function check (a, f) f = f or function (x,y) return x<y end; @@ -419,30 +324,18 @@ test("[test-suite] sort: sort alpha", function (t) { table.sort(a) check(a) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] sort: sort perm", function (t) { +test("[test-suite] sort: sort perm", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` function check (a, f) f = f or function (x,y) return x<y end; @@ -476,30 +369,18 @@ test("[test-suite] sort: sort perm", function (t) { perm{1,2,3,3,5} perm{1,2,3,4,5,6} perm{2,2,3,3,5,6} - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] sort: Invert-sorting", function (t) { +test("[test-suite] sort: Invert-sorting", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` function check (a, f) f = f or function (x,y) return x<y end; @@ -526,30 +407,18 @@ test("[test-suite] sort: Invert-sorting", function (t) { timesort(a, limit, function(x,y) return nil end, "equal") for i,v in pairs(a) do assert(v == false) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] sort: sorting", function (t) { +test("[test-suite] sort: sorting", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` function check (a, f) f = f or function (x,y) return x<y end; @@ -575,24 +444,9 @@ test("[test-suite] sort: sorting", function (t) { table.sort(a) check(a, tt.__lt) check(a) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); diff --git a/test/test-suite/strings.js b/test/test-suite/strings.test.js index cbffe5c..7003b89 100644 --- a/test/test-suite/strings.js +++ b/test/test-suite/strings.test.js @@ -1,10 +1,8 @@ "use strict"; -const test = require('tape'); - -const lua = require('../../src/lua.js'); +const lua = require('../../src/lua.js'); const lauxlib = require('../../src/lauxlib.js'); -const lualib = require('../../src/lualib.js'); +const lualib = require('../../src/lualib.js'); const {to_luastring} = require("../../src/fengaricore.js"); const checkerror = ` @@ -16,7 +14,10 @@ const checkerror = ` end `; -test('[test-suite] strings: string comparisons', function (t) { +test('[test-suite] strings: string comparisons', () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert('alo' < 'alo1') assert('' < 'a') @@ -35,30 +36,18 @@ test('[test-suite] strings: string comparisons', function (t) { assert('\\0\\0\\0' <= '\\0\\0\\0') assert('\\0\\0\\0' >= '\\0\\0\\0') assert(not ('\\0\\0b' < '\\0\\0a\\0')) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test('[test-suite] strings: string.sub', function (t) { +test('[test-suite] strings: string.sub', () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert('alo' < 'alo1') assert('' < 'a') @@ -77,30 +66,18 @@ test('[test-suite] strings: string.sub', function (t) { assert('\\0\\0\\0' <= '\\0\\0\\0') assert('\\0\\0\\0' >= '\\0\\0\\0') assert(not ('\\0\\0b' < '\\0\\0a\\0')) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test('[test-suite] strings: string.find', function (t) { +test('[test-suite] strings: string.find', () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(string.find("123456789", "345") == 3) a,b = string.find("123456789", "345") @@ -115,30 +92,18 @@ test('[test-suite] strings: string.find', function (t) { assert(not string.find("", "", 2)) assert(string.find('', 'aaa', 1) == nil) assert(('alo(.)alo'):find('(.)', 1, 1) == 4) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test('[test-suite] strings: string.len and #', function (t) { +test('[test-suite] strings: string.len and #', () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(string.len("") == 0) assert(string.len("\\0\\0\\0") == 3) @@ -147,30 +112,18 @@ test('[test-suite] strings: string.len and #', function (t) { assert(#"" == 0) assert(#"\\0\\0\\0" == 3) assert(#"1234567890" == 10) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test('[test-suite] strings: string.byte/string.char', function (t) { +test('[test-suite] strings: string.byte/string.char', () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(string.byte("a") == 97) assert(string.byte("\\xe4") > 127) @@ -204,30 +157,18 @@ test('[test-suite] strings: string.byte/string.char', function (t) { checkerror("too large", string.rep, 'aa', (1 << 30)) checkerror("too large", string.rep, 'a', (1 << 30), ',') end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test('[test-suite] strings: repetitions with separator', function (t) { +test('[test-suite] strings: repetitions with separator', () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(string.rep('teste', 0, 'xuxu') == '') assert(string.rep('teste', 1, 'xuxu') == 'teste') @@ -241,30 +182,18 @@ test('[test-suite] strings: repetitions with separator', function (t) { assert(string.reverse"\\0001234" == "4321\\0") for i=0,30 do assert(string.len(string.rep('a', i)) == i) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test('[test-suite] strings: tostring', function (t) { +test('[test-suite] strings: tostring', () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(type(tostring(nil)) == 'string') assert(type(tostring(12)) == 'string') @@ -293,30 +222,18 @@ test('[test-suite] strings: tostring', function (t) { assert('' .. 12 == '12' and 12.0 .. '' == '12') assert(tostring(-1203 + 0.0) == "-1203") end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test('[test-suite] strings: string.format', function (t) { +test('[test-suite] strings: string.format', () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` x = '"ílo"\\n\\\\' assert(string.format('%q%s', x, x) == '"\\\\"ílo\\\\"\\\\\\n\\\\\\\\""ílo"\\n\\\\') @@ -340,30 +257,18 @@ test('[test-suite] strings: string.format', function (t) { "-"..string.rep("%", 20)..".20s") assert(string.format('"-%20s.20s"', string.rep("%", 2000)) == string.format("%q", "-"..string.rep("%", 2000)..".20s")) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test('[test-suite] strings: %q', function (t) { +test('[test-suite] strings: %q', () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local function checkQ (v) @@ -381,57 +286,33 @@ test('[test-suite] strings: %q', function (t) { checkQ(false) checkerror("no literal", string.format, "%q", {}) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test('[test-suite] strings: embedded zeros error', function (t) { +test('[test-suite] strings: embedded zeros error', () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(string.format("\\0%s\\0", "\\0\\0\\1") == "\\0\\0\\0\\1\\0") checkerror("contains zeros", string.format, "%10s", "\\0") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test('[test-suite] strings: format x tostring', function (t) { +test('[test-suite] strings: format x tostring', () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(string.format("%s %s", nil, true) == "nil true") assert(string.format("%s %.4s", false, true) == "false true") @@ -451,30 +332,18 @@ test('[test-suite] strings: format x tostring', function (t) { -- assert(string.format("%08X", 0xFFFFFFFF) == "FFFFFFFF") assert(string.format("%+08d", 31501) == "+0031501") assert(string.format("%+08d", -30927) == "-0030927") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test('[test-suite] strings: longest number that can be formatted', function (t) { +test('[test-suite] strings: longest number that can be formatted', () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local i = 1 @@ -488,30 +357,18 @@ test('[test-suite] strings: longest number that can be formatted', function (t) -- assert(string.len(s) >= i + 101) assert(tonumber(s) == -(10^i)) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test('[test-suite] strings: large numbers for format', function (t) { +test('[test-suite] strings: large numbers for format', () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do -- assume at least 32 bits local max, min = 0x7fffffff, -0x80000000 -- "large" for 32 bits @@ -537,30 +394,18 @@ test('[test-suite] strings: large numbers for format', function (t) { assert(tostring(1234567890123) == '1234567890123') end end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] strings: 'format %a %A'", function (t) { +test("[test-suite] strings: 'format %a %A'", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local function matchhexa (n) @@ -594,30 +439,18 @@ test("[test-suite] strings: 'format %a %A'", function (t) { assert(string.find(string.format("%.4A", -12), "^%-0X%x%.%x000P%+?%d$")) end end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] strings: errors in format", function (t) { +test("[test-suite] strings: errors in format", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` local function check (fmt, msg) checkerror(msg, string.format, fmt, 10) @@ -634,30 +467,18 @@ test("[test-suite] strings: errors in format", function (t) { assert(load("return 1\\n--comment without ending EOL")() == 1) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] strings: table.concat", function (t) { +test("[test-suite] strings: table.concat", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checkerror("table expected", table.concat, 3) assert(table.concat{} == "") @@ -685,31 +506,19 @@ test("[test-suite] strings: table.concat", function (t) { assert(table.concat(a, ",", 2) == "b,c") assert(table.concat(a, ",", 3) == "c") assert(table.concat(a, ",", 4) == "") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); // TODO: os.setlocale NYI -test.skip("[test-suite] strings: locale", function (t) { +test.skip("[test-suite] strings: locale", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` if not _port then @@ -741,30 +550,18 @@ test.skip("[test-suite] strings: locale", function (t) { assert(os.setlocale(nil, "numeric") == 'C') end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] strings: bug in Lua 5.3.2: 'gmatch' iterator does not work across coroutines", function (t) { +test("[test-suite] strings: bug in Lua 5.3.2: 'gmatch' iterator does not work across coroutines", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local f = string.gmatch("1 2 3 4 5", "%d+") @@ -772,24 +569,9 @@ test("[test-suite] strings: bug in Lua 5.3.2: 'gmatch' iterator does not work ac co = coroutine.wrap(f) assert(co() == "2") end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(checkerror + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); diff --git a/test/test-suite/tpack.js b/test/test-suite/tpack.test.js index 745c151..132956e 100644 --- a/test/test-suite/tpack.js +++ b/test/test-suite/tpack.test.js @@ -1,10 +1,8 @@ "use strict"; -const test = require('tape'); - -const lua = require('../../src/lua.js'); +const lua = require('../../src/lua.js'); const lauxlib = require('../../src/lauxlib.js'); -const lualib = require('../../src/lualib.js'); +const lualib = require('../../src/lualib.js'); const {to_luastring} = require("../../src/fengaricore.js"); const prefix = ` @@ -32,7 +30,10 @@ const prefix = ` local align = packsize("!xXi16") `; -test("[test-suite] tpack: maximum size for integers", function (t) { +test("[test-suite] tpack: maximum size for integers", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(1 <= sizeshort and sizeshort <= sizeint and sizeint <= sizelong and sizefloat <= sizedouble) @@ -45,30 +46,18 @@ test("[test-suite] tpack: maximum size for integers", function (t) { sizeLI, sizenumber)) print("\\t" .. (little and "little" or "big") .. " endian") print("\\talignment: " .. align) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] tpack: minimum behavior for integer formats", function (t) { +test("[test-suite] tpack: minimum behavior for integer formats", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(unpack("B", pack("B", 0xff)) == 0xff) assert(unpack("b", pack("b", 0x7f)) == 0x7f) @@ -81,30 +70,18 @@ test("[test-suite] tpack: minimum behavior for integer formats", function (t) { assert(unpack("L", pack("L", 0xffffffff)) == 0xffffffff) assert(unpack("l", pack("l", 0x7fffffff)) == 0x7fffffff) assert(unpack("l", pack("l", -0x80000000)) == -0x80000000) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] tpack: minimum behavior for integer formats", function (t) { +test("[test-suite] tpack: minimum behavior for integer formats", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` for i = 1, NB do -- small numbers with signal extension ("\\xFF...") @@ -120,30 +97,18 @@ test("[test-suite] tpack: minimum behavior for integer formats", function (t) { assert(pack(">I" .. i, 0xAA) == s:reverse()) assert(unpack(">I" .. i, s:reverse()) == 0xAA) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] tpack: minimum behavior for integer formats", function (t) { +test("[test-suite] tpack: minimum behavior for integer formats", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local lnum = 0x13121110090807060504030201 @@ -165,30 +130,18 @@ test("[test-suite] tpack: minimum behavior for integer formats", function (t) { checkerror("does not fit", unpack, ">i" .. i, "\\1" .. ("\\x00"):rep(i - 1)) end end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] tpack: minimum behavior for integer formats", function (t) { +test("[test-suite] tpack: minimum behavior for integer formats", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` for i = 1, sizeLI do local lstr = "\\1\\2\\3\\4\\5\\6\\7\\8\\9\\10\\11\\12\\13" @@ -199,30 +152,18 @@ test("[test-suite] tpack: minimum behavior for integer formats", function (t) { assert(pack(">i" .. i, n) == s:reverse()) assert(unpack(">i" .. i, s:reverse()) == n) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] tpack: sign extension", function (t) { +test("[test-suite] tpack: sign extension", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local u = 0xf0 @@ -232,30 +173,18 @@ test("[test-suite] tpack: sign extension", function (t) { u = u * 256 + 0xff end end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] tpack: mixed endianness", function (t) { +test("[test-suite] tpack: mixed endianness", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do assert(pack(">i2 <i2", 10, 20) == "\\0\\10\\20\\0") @@ -263,30 +192,18 @@ test("[test-suite] tpack: mixed endianness", function (t) { assert(a == 10 and b == 20) assert(pack("=i4", 2001) == pack("i4", 2001)) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] tpack: testing invalid formats", function (t) { +test("[test-suite] tpack: testing invalid formats", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checkerror("out of limits", pack, "i0", 0) checkerror("out of limits", pack, "i" .. NB + 1, 0) @@ -298,30 +215,18 @@ test("[test-suite] tpack: testing invalid formats", function (t) { checkerror("missing size", pack, "c", "") checkerror("variable%-length format", packsize, "s") checkerror("variable%-length format", packsize, "z") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] tpack: overflow in option size (error will be in digit after limit)", function (t) { +test("[test-suite] tpack: overflow in option size (error will be in digit after limit)", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` checkerror("invalid format", packsize, "c1" .. string.rep("0", 40)) @@ -333,30 +238,18 @@ test("[test-suite] tpack: overflow in option size (error will be in digit after s = string.rep("c268435456", 2^3 - 1) .. "c268435455" assert(packsize(s) == 0x7fffffff) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] tpack: overflow in packing", function (t) { +test("[test-suite] tpack: overflow in packing", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` for i = 1, sizeLI - 1 do local umax = (1 << (i * 8)) - 1 @@ -374,30 +267,18 @@ test("[test-suite] tpack: overflow in packing", function (t) { assert(unpack("<i" .. i, pack("<i" .. i, min)) == min) assert(unpack(">I" .. i, pack(">I" .. i, umax)) == umax) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] tpack: Lua integer size", function (t) { +test("[test-suite] tpack: Lua integer size", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` assert(unpack(">j", pack(">j", math.maxinteger)) == math.maxinteger) assert(unpack("<j", pack("<j", math.mininteger)) == math.mininteger) @@ -408,30 +289,18 @@ test("[test-suite] tpack: Lua integer size", function (t) { else assert(pack("f", 24) == pack(">f", 24)) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] tpack: testing pack/unpack of floating-point numbers", function (t) { +test("[test-suite] tpack: testing pack/unpack of floating-point numbers", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` for _, n in ipairs{0, -1.1, 1.9, 1/0, -1/0, 1e20, -1e20, 0.1, 2000.7} do assert(unpack("n", pack("n", n)) == n) @@ -448,30 +317,18 @@ test("[test-suite] tpack: testing pack/unpack of floating-point numbers", functi assert(unpack("<d", pack("<d", n)) == n) assert(unpack(">d", pack(">d", n)) == n) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] tpack: testing pack/unpack of strings", function (t) { +test("[test-suite] tpack: testing pack/unpack of strings", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local s = string.rep("abc", 1000) @@ -514,30 +371,18 @@ test("[test-suite] tpack: testing pack/unpack of strings", function (t) { assert(a == "abcdefghi" and b == "xyz" and c == 14) checkerror("longer than", pack, "c3", "1234") end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] tpack: testing multiple types and sequence", function (t) { +test("[test-suite] tpack: testing multiple types and sequence", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local x = pack("<b h b f d f n i", 1, 2, 3, 4, 5, 6, 7, 8) @@ -546,30 +391,18 @@ test("[test-suite] tpack: testing multiple types and sequence", function (t) { assert(a == 1 and b == 2 and c == 3 and d == 4 and e == 5 and f == 6 and g == 7 and h == 8) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] tpack: testing alignment", function (t) { +test("[test-suite] tpack: testing alignment", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do assert(pack(" < i1 i2 ", 2, 3) == "\\2\\3\\0") -- no alignment by default @@ -612,30 +445,18 @@ test("[test-suite] tpack: testing alignment", function (t) { checkerror("invalid next option", unpack, "X i", "") checkerror("invalid next option", pack, "Xc1") end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] tpack: testing initial position", function (t) { +test("[test-suite] tpack: testing initial position", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` do local x = pack("i4i4i4i4", 1, 2, 3, 4) @@ -667,24 +488,9 @@ test("[test-suite] tpack: testing initial position", function (t) { checkerror("out of string", unpack, "c0", x, -(#x + 1)) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(prefix + luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); diff --git a/test/test-suite/utf8.js b/test/test-suite/utf8.test.js index 173dffd..7e809da 100644 --- a/test/test-suite/utf8.js +++ b/test/test-suite/utf8.test.js @@ -1,10 +1,8 @@ "use strict"; -const test = require('tape'); - -const lua = require('../../src/lua.js'); +const lua = require('../../src/lua.js'); const lauxlib = require('../../src/lauxlib.js'); -const lualib = require('../../src/lualib.js'); +const lualib = require('../../src/lualib.js'); const {to_luastring} = require("../../src/fengaricore.js"); const prefix = ` @@ -96,28 +94,25 @@ const prefix = ` end `; -test("[test-suite] utf8: offset", function (t) { +test("[test-suite] utf8: offset", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = prefix + ` assert(utf8.offset("alo", 5) == nil) assert(utf8.offset("alo", -4) == nil) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - L = lauxlib.luaL_newstate(); - lualib.luaL_openlibs(L); - if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) - throw new SyntaxError(lua.lua_tojsstring(L, -1)); - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - lua.lua_call(L, 0, -1); - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] utf8: error indication in utf8.len", function (t) { +test("[test-suite] utf8: error indication in utf8.len", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = prefix + ` do local function check (s, p) @@ -129,24 +124,18 @@ test("[test-suite] utf8: error indication in utf8.len", function (t) { check("\\xF4\\x9F\\xBF", 1) check("\\xF4\\x9F\\xBF\\xBF", 1) end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - L = lauxlib.luaL_newstate(); - lualib.luaL_openlibs(L); - if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) - throw new SyntaxError(lua.lua_tojsstring(L, -1)); - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - lua.lua_call(L, 0, -1); - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] utf8: error in initial position for offset", function (t) { +test("[test-suite] utf8: error in initial position for offset", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = prefix + ` checkerror("position out of range", utf8.offset, "abc", 1, 5) checkerror("position out of range", utf8.offset, "abc", 1, -4) @@ -155,24 +144,18 @@ test("[test-suite] utf8: error in initial position for offset", function (t) { checkerror("continuation byte", utf8.offset, "𦧺", 1, 2) checkerror("continuation byte", utf8.offset, "𦧺", 1, 2) checkerror("continuation byte", utf8.offset, "\\x80", 1) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - L = lauxlib.luaL_newstate(); - lualib.luaL_openlibs(L); - if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) - throw new SyntaxError(lua.lua_tojsstring(L, -1)); - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - lua.lua_call(L, 0, -1); - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] utf8: codepoints", function (t) { +test("[test-suite] utf8: codepoints", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = prefix + ` local s = "hello World" local t = {string.byte(s, 1, -1)} @@ -199,110 +182,80 @@ test("[test-suite] utf8: codepoints", function (t) { assert(utf8.codepoint(utf8.char(0x10FFFF)) == 0x10FFFF) checkerror("value out of range", utf8.char, 0x10FFFF + 1) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - L = lauxlib.luaL_newstate(); - lualib.luaL_openlibs(L); - if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) - throw new SyntaxError(lua.lua_tojsstring(L, -1)); - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - lua.lua_call(L, 0, -1); - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] utf8: UTF-8 representation for 0x11ffff (value out of valid range)", function (t) { +test("[test-suite] utf8: UTF-8 representation for 0x11ffff (value out of valid range)", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = prefix + ` invalid("\\xF4\\x9F\\xBF\\xBF") - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - L = lauxlib.luaL_newstate(); - lualib.luaL_openlibs(L); - if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) - throw new SyntaxError(lua.lua_tojsstring(L, -1)); - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - lua.lua_call(L, 0, -1); - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] utf8: overlong sequences", function (t) { +test("[test-suite] utf8: overlong sequences", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = prefix + ` invalid("\\xC0\\x80") -- zero invalid("\\xC1\\xBF") -- 0x7F (should be coded in 1 byte) invalid("\\xE0\\x9F\\xBF") -- 0x7FF (should be coded in 2 bytes) invalid("\\xF0\\x8F\\xBF\\xBF") -- 0xFFFF (should be coded in 3 bytes) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - L = lauxlib.luaL_newstate(); - lualib.luaL_openlibs(L); - if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) - throw new SyntaxError(lua.lua_tojsstring(L, -1)); - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - lua.lua_call(L, 0, -1); - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] utf8: invalid bytes", function (t) { +test("[test-suite] utf8: invalid bytes", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = prefix + ` invalid("\\x80") -- continuation byte invalid("\\xBF") -- continuation byte invalid("\\xFE") -- invalid byte invalid("\\xFF") -- invalid byte - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - L = lauxlib.luaL_newstate(); - lualib.luaL_openlibs(L); - if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) - throw new SyntaxError(lua.lua_tojsstring(L, -1)); - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - lua.lua_call(L, 0, -1); - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] utf8: empty strings", function (t) { +test("[test-suite] utf8: empty strings", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = prefix + ` check("", {}) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - L = lauxlib.luaL_newstate(); - lualib.luaL_openlibs(L); - if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) - throw new SyntaxError(lua.lua_tojsstring(L, -1)); - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - lua.lua_call(L, 0, -1); - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] utf8: minimum and maximum values for each sequence size", function (t) { +test("[test-suite] utf8: minimum and maximum values for each sequence size", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = prefix + ` s = "\\0 \\x7F\\z \\xC2\\x80 \\xDF\\xBF\\z @@ -332,18 +285,9 @@ test("[test-suite] utf8: minimum and maximum values for each sequence size", fun assert(utf8.offset(x, 0, p + j - 1) == p) end end - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - L = lauxlib.luaL_newstate(); - lualib.luaL_openlibs(L); - if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) - throw new SyntaxError(lua.lua_tojsstring(L, -1)); - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - lua.lua_call(L, 0, -1); - }, "Lua program ran without error"); + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); diff --git a/test/test-suite/vararg.js b/test/test-suite/vararg.test.js index 1cc5ace..78439f1 100644 --- a/test/test-suite/vararg.js +++ b/test/test-suite/vararg.test.js @@ -1,13 +1,14 @@ "use strict"; -const test = require('tape'); - -const lua = require('../../src/lua.js'); +const lua = require('../../src/lua.js'); const lauxlib = require('../../src/lauxlib.js'); -const lualib = require('../../src/lualib.js'); +const lualib = require('../../src/lualib.js'); const {to_luastring} = require("../../src/fengaricore.js"); -test("[test-suite] vararg: testing vararg", function (t) { +test("[test-suite] vararg: testing vararg", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` function f(a, ...) local arg = {n = select('#', ...), ...} @@ -72,30 +73,18 @@ test("[test-suite] vararg: testing vararg", function (t) { i = 1 while i <= lim do a[i] = i; i=i+1 end assert(call(math.max, a) == lim) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] vararg: new-style varargs", function (t) { +test("[test-suite] vararg: new-style varargs", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` function oneless (a, ...) return ... end @@ -117,30 +106,18 @@ test("[test-suite] vararg: new-style varargs", function (t) { a,b,c,d,e = f(4) assert(a==nil and b==nil and c==nil and d==nil and e==nil) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] vararg: varargs for main chunks", function (t) { +test("[test-suite] vararg: varargs for main chunks", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` f = load[[ return {...} ]] x = f(2,3) @@ -167,30 +144,18 @@ test("[test-suite] vararg: varargs for main chunks", function (t) { assert(a[1] == 5 and a[2] == 7 and a[3] == nil) pcall(select, 10000) pcall(select, -10000) - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); -test("[test-suite] vararg: bug in 5.2.2", function (t) { +test("[test-suite] vararg: bug in 5.2.2", () => { + let L = lauxlib.luaL_newstate(); + if (!L) throw Error("failed to create lua state"); + let luaCode = ` function f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, @@ -203,24 +168,9 @@ test("[test-suite] vararg: bug in 5.2.2", function (t) { -- assertion fail here f() - `, L; - - t.plan(2); - - t.doesNotThrow(function () { - - L = lauxlib.luaL_newstate(); - - lualib.luaL_openlibs(L); - - lauxlib.luaL_loadstring(L, to_luastring(luaCode)); - - }, "Lua program loaded without error"); - - t.doesNotThrow(function () { - - lua.lua_call(L, 0, -1); - - }, "Lua program ran without error"); - + `; + lualib.luaL_openlibs(L); + if (lauxlib.luaL_loadstring(L, to_luastring(luaCode)) === lua.LUA_ERRSYNTAX) + throw new SyntaxError(lua.lua_tojsstring(L, -1)); + lua.lua_call(L, 0, 0); }); |