fix regression in luaL_typerror and Change NTest so it can run tests on the host emulating node.task.post (#3357)

* Change NTest so it can run tests on the host emulating node.task.post
* Add executing first host test
* Regression: fix luaL_typerror
This commit is contained in:
Gregor Hartmann 2021-01-09 22:25:22 +01:00 committed by GitHub
parent 53fc7170bd
commit 4023df7e60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 43 deletions

View File

@ -179,6 +179,13 @@ jobs:
../../luac.cross -e ../NTest/NTest_NTest.lua | tee log ../../luac.cross -e ../NTest/NTest_NTest.lua | tee log
grep "failed. 0" log grep "failed. 0" log
shell: bash shell: bash
- name: NTest hosttests
run: |
cd tests
cp NTest/NTest.lua .
../luac.cross -e NTest_lua.lua | tee log
(if grep " ==> " log ; then exit 1 ; fi)
shell: bash
NTest_win: NTest_win:
@ -207,6 +214,13 @@ jobs:
../../luac.cross.exe -e ../NTest/NTest_NTest.lua | tee log ../../luac.cross.exe -e ../NTest/NTest_NTest.lua | tee log
grep "failed. 0" log grep "failed. 0" log
shell: bash shell: bash
- name: NTest hosttests
run: |
cd tests
cp NTest/NTest.lua .
../luac.cross.exe -e NTest_lua.lua | tee log
(if grep " ==> " log ; then exit 1 ; fi)
shell: bash
luacheck: luacheck:

View File

@ -214,7 +214,7 @@ LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) {
LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) { LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) {
const char *msg = lua_pushfstring(L, "%s expected, got %s", const char *msg = lua_pushfstring(L, "%s expected, got %s",
tname, lua_typename(L, narg)); tname, luaL_typename(L, narg));
return luaL_argerror(L, narg, msg); return luaL_argerror(L, narg, msg);
} }

View File

@ -19,6 +19,39 @@ local function TERMINAL_HANDLER(e, test, msg, errormsg)
end end
end end
-- implement pseudo task handling for on host testing
local drain_post_queue = function() end
if not node then -- assume we run on host, not on MCU
local post_queue = {{},{},{}}
drain_post_queue = function()
while #post_queue[1] + #post_queue[2] + #post_queue[3] > 0 do
for i = 3, 1, -1 do
if #post_queue[i] > 0 then
local f = table.remove(post_queue[i], 1)
if f then
f()
end
break
end
end
end
end
-- luacheck: push ignore 121 122 (setting read-only global variable)
node = {}
node.task = {LOW_PRIORITY = 1, MEDIUM_PRIORITY = 2, HIGH_PRIORITY = 3}
node.task.post = function (p, f)
table.insert(post_queue[p], f)
end
node.setonerror = function(fn) node.Host_Error_Func = fn end -- luacheck: ignore 142
-- luacheck: pop
end
--[[ --[[
if equal returns true if equal returns true
if different returns {msg = "<reason>"} if different returns {msg = "<reason>"}
@ -233,6 +266,7 @@ local function NTest(testrunname, failoldinterface)
table.insert(pendingtests, testfn) table.insert(pendingtests, testfn)
if #pendingtests == 1 then if #pendingtests == 1 then
runpending() runpending()
drain_post_queue()
end end
end end

View File

@ -406,43 +406,13 @@ end -- load_tests()
local cbWrap = function(cb) return cb end local cbWrap = function(cb) return cb end
-- implement pseudo task handling for on host testing if not node.LFS then -- assume we run on host, not on MCU. node is already defined by NTest if running on host
local drain_post_queue = function() end
if not node then
local post_queue = {{},{},{}}
drain_post_queue = function()
while #post_queue[1] + #post_queue[2] + #post_queue[3] > 0 do
for i = 3, 1, -1 do
if #post_queue[i] > 0 then
local f = table.remove(post_queue[i], 1)
if f then
f()
end
break
end
end
end
end
-- luacheck: push ignore 121 122 (setting read-only global variable)
node = {}
node.task = {LOW_PRIORITY = 1, MEDIUM_PRIORITY = 2, HIGH_PRIORITY = 3}
node.task.post = function (p, f)
table.insert(post_queue[p], f)
end
local errorfunc
node.setonerror = function(fn) errorfunc = fn end
-- luacheck: pop
cbWrap = function(cb) cbWrap = function(cb)
return function(...) return function(...)
local ok, p1,p2,p3,p4 = pcall(cb, ...) local ok, p1,p2,p3,p4 = pcall(cb, ...)
if not ok then if not ok then
if errorfunc then if node.Host_Error_Func then -- luacheck: ignore 143
errorfunc(p1) node.Host_Error_Func(p1) -- luacheck: ignore 143
else else
print(p1, "::::::::::::: reboot :::::::::::::") print(p1, "::::::::::::: reboot :::::::::::::")
end end
@ -535,6 +505,12 @@ local function drain_async_queue()
end end
metatest = function(name, f, expectedPassed, expectedFailed, expectedExcept, asyncMode) metatest = function(name, f, expectedPassed, expectedFailed, expectedExcept, asyncMode)
table.insert(expected, {
name = name,
pass = expectedPassed,
fail = expectedFailed,
except = expectedExcept or {}
})
local ff = f local ff = f
if asyncMode then if asyncMode then
ff = function(...) ff = function(...)
@ -549,15 +525,7 @@ metatest = function(name, f, expectedPassed, expectedFailed, expectedExcept, asy
else else
N.test(name, ff) N.test(name, ff)
end end
table.insert(expected, {
name = name,
pass = expectedPassed,
fail = expectedFailed,
except = expectedExcept or {}
})
end end
load_tests() load_tests()
drain_post_queue()

6
tests/NTest_lua.lua Normal file
View File

@ -0,0 +1,6 @@
local N = require "NTest" ("Lua detail tests")
N.test('typeerror', function()
fail(function() math.abs("") end, "number expected, got string", "string")
fail(function() math.abs() end, "number expected, got no value", "no value")
end)