diff options
author | daurnimator <quae@daurnimator.com> | 2018-05-30 17:48:40 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2018-05-30 17:48:40 +1000 |
commit | 18b7d200cbaadf7aee592f739e2e0cb4be4ce298 (patch) | |
tree | b231730217df8f635734467d2f186a625d3d0900 /tests | |
parent | 7333333568b13db56136e2354c55556adc7714ed (diff) | |
download | luaossl-18b7d200cbaadf7aee592f739e2e0cb4be4ce298.tar.gz luaossl-18b7d200cbaadf7aee592f739e2e0cb4be4ce298.tar.bz2 luaossl-18b7d200cbaadf7aee592f739e2e0cb4be4ce298.zip |
Squashed 'vendor/compat53/' changes from 6f3deea..bc91f40
bc91f40 Merge pull request #38 from ThePhD/warnings/vcxx
3615e44 fix VC warnings for integer down-conversions to char
db8446d Merge pull request #37 from keplerproject/strerror
447deca Add braces and suppress warning.
b782901 Do less stuff when sz is 0 in compat53_strerror().
9895acb Transparently handle GNU/XSI strerror_r.
9cb6834 Add Travis-CI integration
ee2d198 Fix links in the README.md.
c381aa3 Merge branch 'ThePhD-feature/luaL_loadfilebufferx'
09b201c Add tests for `luaL_load{buffer,file}x`.
3b52d81 Add Lua 5.3 version of `lua_load`.
8425f99 Merge branch 'feature/luaL_loadfilebufferx' of https://github.com/ThePhD/lua-compat-5.3 into ThePhD-feature/luaL_loadfilebufferx
9435c6c Merge branch 'daurnimator-luaL_Stream'
bf96f3d Include lualib.h, remove #define LUA_FILEHANDLE.
f76fb00 Merge branch 'luaL_Stream' of https://github.com/daurnimator/lua-compat-5.3 into daurnimator-luaL_Stream
7fc7aba Merge branch 'ThePhD-fix/lua_Number_casts'
ee862eb Merge branch 'fix/lua_Number_casts' of https://github.com/ThePhD/lua-compat-5.3 into ThePhD-fix/lua_Number_casts
f3b1160 Merge branch 'ThePhD-feature/LUA_ERRGCMM'
73a7b6b fix usage of tabs
0c9d432 fix `lua_Integer` casts that error on Visual C++ and other pedantic conversion-warning compilers for 64-bit builds
7320d58 define LUA_ERRGCMM code for return values
6065d10 update readme
8ee5245 implement luaL_loadbufferx and luaL_loadfilex
0821294 Merge pull request #26 from daurnimator/lua_resume
c0a59dd Add (partial) luaL_Stream definition
c0db566 Add LUA_FILEHANDLE define
690239b Add lua_resume
1037026 Merge pull request #24 from daurnimator/implicit-fallthrough
a3f456a Use FALLTHROUGH annotation to fix -Wimplicit-fallthrough warning
git-subtree-dir: vendor/compat53
git-subtree-split: bc91f40919196e6af6371c26f851f8f94da0b15c
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/test.lua | 165 | ||||
-rw-r--r-- | tests/testmod.c | 39 |
2 files changed, 131 insertions, 73 deletions
diff --git a/tests/test.lua b/tests/test.lua index 582f55e..2f6c7f6 100755 --- a/tests/test.lua +++ b/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/tests/testmod.c b/tests/testmod.c index 868136b..a0d2e2a 100644 --- a/tests/testmod.c +++ b/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 |