diff options
author | daurnimator <quae@daurnimator.com> | 2018-05-30 17:48:40 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2018-05-30 17:48:58 +1000 |
commit | 3a2c1dc98b0ba4ca7e4600cd86f11472311954fc (patch) | |
tree | 846aad638a8b23d2a11502642657ca61acf68579 /vendor/compat53/tests | |
parent | 77d38ec3be5030397f895fd19959a87a065fac14 (diff) | |
parent | 18b7d200cbaadf7aee592f739e2e0cb4be4ce298 (diff) | |
download | luaossl-3a2c1dc98b0ba4ca7e4600cd86f11472311954fc.tar.gz luaossl-3a2c1dc98b0ba4ca7e4600cd86f11472311954fc.tar.bz2 luaossl-3a2c1dc98b0ba4ca7e4600cd86f11472311954fc.zip |
Merge commit '18b7d200cbaadf7aee592f739e2e0cb4be4ce298'
Update to compat-5.3 v0.6
Diffstat (limited to 'vendor/compat53/tests')
-rwxr-xr-x | vendor/compat53/tests/test.lua | 165 | ||||
-rw-r--r-- | vendor/compat53/tests/testmod.c | 39 |
2 files changed, 131 insertions, 73 deletions
diff --git a/vendor/compat53/tests/test.lua b/vendor/compat53/tests/test.lua index 582f55e..2f6c7f6 100755 --- a/vendor/compat53/tests/test.lua +++ b/vendor/compat53/tests/test.lua @@ -40,7 +40,7 @@ local mode = "global" if arg[1] == "module" then mode = "module" end - +local self = arg[0] package.path = "../?.lua;../?/init.lua" package.cpath = "./?-"..V..".so;./?-"..V..".dll;./?.so;./?.dll" @@ -603,11 +603,11 @@ end ___'' do writefile("data.txt", "123 18.8 hello world\ni'm here\n") - for a,b in io.lines("test.lua", 2, "*l") do + for a,b in io.lines(self, 2, "*l") do print("io.lines()", a, b) break end - for l in io.lines("test.lua") do + for l in io.lines(self) do print("io.lines()", l) break end @@ -624,7 +624,7 @@ do for l in io.lines("no_such_file.txt") do print(l) end end)) if mode ~= "module" then - local f = assert(io.open("test.lua", "r")) + local f = assert(io.open(self, "r")) for a,b in f:lines(2, "*l") do print("file:lines()", a, b) break @@ -657,133 +657,158 @@ ___'' print("testing C API ...") local mod = require("testmod") ___'' -print(mod.isinteger(1)) -print(mod.isinteger(0)) -print(mod.isinteger(1234567)) -print(mod.isinteger(12.3)) -print(mod.isinteger(math.huge)) -print(mod.isinteger(math.sqrt(-1))) +print("isinteger", mod.isinteger(1)) +print("isinteger", mod.isinteger(0)) +print("isinteger", mod.isinteger(1234567)) +print("isinteger", mod.isinteger(12.3)) +print("isinteger", mod.isinteger(math.huge)) +print("isinteger", mod.isinteger(math.sqrt(-1))) ___'' -print(mod.rotate(1, 1, 2, 3, 4, 5, 6)) -print(mod.rotate(-1, 1, 2, 3, 4, 5, 6)) -print(mod.rotate(4, 1, 2, 3, 4, 5, 6)) -print(mod.rotate(-4, 1, 2, 3, 4, 5, 6)) +print("rotate", mod.rotate(1, 1, 2, 3, 4, 5, 6)) +print("rotate", mod.rotate(-1, 1, 2, 3, 4, 5, 6)) +print("rotate", mod.rotate(4, 1, 2, 3, 4, 5, 6)) +print("rotate", mod.rotate(-4, 1, 2, 3, 4, 5, 6)) ___'' -print(mod.strtonum("+123")) -print(mod.strtonum(" 123 ")) -print(mod.strtonum("-1.23")) -print(mod.strtonum(" 123 abc")) -print(mod.strtonum("jkl")) +print("strtonum", mod.strtonum("+123")) +print("strtonum", mod.strtonum(" 123 ")) +print("strtonum", mod.strtonum("-1.23")) +print("strtonum", mod.strtonum(" 123 abc")) +print("strtonum", mod.strtonum("jkl")) ___'' local a, b, c = mod.requiref() -print( type(a), type(b), type(c), - a.boolean, b.boolean, c.boolean, - type(requiref1), type(requiref2), type(requiref3)) +print("requiref", type(a), type(b), type(c), + a.boolean, b.boolean, c.boolean, + type(requiref1), type(requiref2), type(requiref3)) ___'' local proxy, backend = {}, {} setmetatable(proxy, { __index = backend, __newindex = backend }) -print(rawget(proxy, 1), rawget(backend, 1)) -print(mod.getseti(proxy, 1)) -print(rawget(proxy, 1), rawget(backend, 1)) -print(mod.getseti(proxy, 1)) -print(rawget(proxy, 1), rawget(backend, 1)) +print("geti/seti", rawget(proxy, 1), rawget(backend, 1)) +print("geti/seti", mod.getseti(proxy, 1)) +print("geti/seti", rawget(proxy, 1), rawget(backend, 1)) +print("geti/seti", mod.getseti(proxy, 1)) +print("geti/seti", rawget(proxy, 1), rawget(backend, 1)) -- tests for Lua 5.1 ___'' -print(mod.tonumber(12)) -print(mod.tonumber("12")) -print(mod.tonumber("0")) -print(mod.tonumber(false)) -print(mod.tonumber("error")) +print("tonumber", mod.tonumber(12)) +print("tonumber", mod.tonumber("12")) +print("tonumber", mod.tonumber("0")) +print("tonumber", mod.tonumber(false)) +print("tonumber", mod.tonumber("error")) ___'' -print(mod.tointeger(12)) -print(mod.tointeger("12")) -print(mod.tointeger("0")) -print( "aaa" ) -print(mod.tointeger(math.pi)) -print( "bbb" ) -print(mod.tointeger(false)) -print(mod.tointeger("error")) +print("tointeger", mod.tointeger(12)) +print("tointeger", mod.tointeger("12")) +print("tointeger", mod.tointeger("0")) +print("tointeger", mod.tointeger(math.pi)) +print("tointeger", mod.tointeger(false)) +print("tointeger", mod.tointeger("error")) ___'' -print(mod.len("123")) -print(mod.len({ 1, 2, 3})) -print(pcall(mod.len, true)) +print("len", mod.len("123")) +print("len", mod.len({ 1, 2, 3})) +print("len", pcall(mod.len, true)) local ud, meta = mod.newproxy() meta.__len = function() return 5 end -print(mod.len(ud)) +print("len", mod.len(ud)) meta.__len = function() return true end -print(pcall(mod.len, ud)) +print("len", pcall(mod.len, ud)) ___'' -print(mod.copy(true, "string", {}, 1)) +print("copy", mod.copy(true, "string", {}, 1)) ___'' -print(mod.rawxetp()) -print(mod.rawxetp("I'm back")) +print("rawgetp/rawsetp", mod.rawxetp()) +print("rawgetp/rawsetp", mod.rawxetp("I'm back")) ___'' -print(F(mod.globals()), mod.globals() == _G) +print("globals", F(mod.globals()), mod.globals() == _G) ___'' local t = {} -print(F(mod.subtable(t))) +print("getsubtable", F(mod.subtable(t))) local x, msg = mod.subtable(t) -print(F(x, msg, x == t.xxx)) +print("getsubtable", F(x, msg, x == t.xxx)) ___'' -print(F(mod.udata())) -print(mod.udata("nosuchtype")) +print("udata", F(mod.udata())) +print("udata", mod.udata("nosuchtype")) ___'' -print(F(mod.uservalue())) +print("uservalue", F(mod.uservalue())) ___'' -print(mod.getupvalues()) +print("upvalues", mod.getupvalues()) ___'' -print(mod.absindex("hi", true)) +print("absindex", mod.absindex("hi", true)) ___'' -print(mod.arith(2, 1)) -print(mod.arith(3, 5)) +print("arith", mod.arith(2, 1)) +print("arith", mod.arith(3, 5)) ___'' -print(mod.compare(1, 1)) -print(mod.compare(2, 1)) -print(mod.compare(1, 2)) +print("compare", mod.compare(1, 1)) +print("compare", mod.compare(2, 1)) +print("compare", mod.compare(1, 2)) ___'' -print(mod.tolstring("string")) +print("tolstring", mod.tolstring("string")) local t = setmetatable({}, { __tostring = function(v) return "mytable" end }) -print(mod.tolstring(t)) +print("tolstring", mod.tolstring(t)) local t = setmetatable({}, { __tostring = function(v) return nil end }) -print(pcall(mod.tolstring, t)) +print("tolstring", pcall(mod.tolstring, t)) local ud, meta = mod.newproxy() meta.__name = "XXX" -print(mod.tolstring(ud):gsub(":.*$", ": yyy")) +print("tolstring", mod.tolstring(ud):gsub(":.*$", ": yyy")) + +___'' +print("pushstring", mod.pushstring()) ___'' -print(mod.pushstring()) +print("Buffer", mod.buffer()) ___'' -print(mod.buffer()) +print("execresult", mod.exec("exit 0")) +print("execresult", mod.exec("exit 1")) +print("execresult", mod.exec("exit 25")) ___'' -print(mod.exec("exit 0")) -print(mod.exec("exit 1")) -print(mod.exec("exit 25")) +do + local bin = string.dump(function() end) + local modes = { "t", "b", "bt" } + local codes = { + "", "return true", bin, "invalidsource", "\27invalidbinary" + } + for _,m in ipairs(modes) do + for i,c in ipairs(codes) do + print("loadbufferx", m, i, F(mod.loadstring(c, m))) + end + end + + ___'' + local bom = "\239\187\191" + local shebang = "#!/usr/bin/env lua\n" + codes[#codes+1] = bom .. shebang .. "return true" + codes[#codes+1] = bom .. shebang .. bin + codes[#codes+1] = bom .. shebang .. "invalidsource" + codes[#codes+1] = bom .. shebang .. "\027invalidbinary" + for _,m in ipairs(modes) do + for i,c in ipairs(codes) do + print("loadfilex", m, i, F(mod.loadfile(c, m))) + end + end +end ___'' diff --git a/vendor/compat53/tests/testmod.c b/vendor/compat53/tests/testmod.c index 868136b..a0d2e2a 100644 --- a/vendor/compat53/tests/testmod.c +++ b/vendor/compat53/tests/testmod.c @@ -1,7 +1,5 @@ #include <stdio.h> #include <stdlib.h> -#include <lua.h> -#include <lauxlib.h> #include "compat-5.3.h" @@ -12,7 +10,7 @@ static int test_isinteger (lua_State *L) { static int test_rotate (lua_State *L) { - int r = luaL_checkint(L, 1); + int r = (int)luaL_checkinteger(L, 1); int n = lua_gettop(L)-1; luaL_argcheck(L, (r < 0 ? -r : r) <= n, 1, "not enough arguments"); lua_rotate(L, 2, r); @@ -274,6 +272,33 @@ static int test_exec (lua_State *L) { return luaL_execresult(L, system(cmd)); } +static int test_loadstring (lua_State *L) { + size_t len = 0; + char const* s = luaL_checklstring(L, 1, &len); + char const* mode = luaL_optstring(L, 2, "bt"); + lua_pushinteger(L, luaL_loadbufferx(L, s, len, s, mode)); + return 2; +} + +static int test_loadfile (lua_State *L) { + char filename[L_tmpnam+1] = { 0 }; + size_t len = 0; + char const* s = luaL_checklstring(L, 1, &len); + char const* mode = luaL_optstring(L, 2, "bt"); + if (tmpnam(filename)) { + FILE* f = fopen(filename, "wb"); + if (f) { + fwrite(s, 1, len, f); + fclose(f); + lua_pushinteger(L, luaL_loadfilex(L, filename, mode)); + remove(filename); + return 2; + } else + remove(filename); + } + return 0; +} + static const luaL_Reg funcs[] = { { "isinteger", test_isinteger }, @@ -297,6 +322,8 @@ static const luaL_Reg funcs[] = { { "pushstring", test_pushstring }, { "buffer", test_buffer }, { "exec", test_exec }, + { "loadstring", test_loadstring }, + { "loadfile", test_loadfile }, { NULL, NULL } }; @@ -307,6 +334,9 @@ static const luaL_Reg more_funcs[] = { }; +#ifdef __cplusplus +extern "C" { +#endif int luaopen_testmod (lua_State *L) { int i = 1; luaL_newlib(L, funcs); @@ -315,4 +345,7 @@ int luaopen_testmod (lua_State *L) { luaL_setfuncs(L, more_funcs, NUP); return 1; } +#ifdef __cplusplus +} +#endif |