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:
parent
53fc7170bd
commit
4023df7e60
|
@ -179,6 +179,13 @@ jobs:
|
|||
../../luac.cross -e ../NTest/NTest_NTest.lua | tee log
|
||||
grep "failed. 0" log
|
||||
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:
|
||||
|
@ -207,6 +214,13 @@ jobs:
|
|||
../../luac.cross.exe -e ../NTest/NTest_NTest.lua | tee log
|
||||
grep "failed. 0" log
|
||||
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:
|
||||
|
|
|
@ -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) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,39 @@ local function TERMINAL_HANDLER(e, test, msg, errormsg)
|
|||
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 different returns {msg = "<reason>"}
|
||||
|
@ -233,6 +266,7 @@ local function NTest(testrunname, failoldinterface)
|
|||
table.insert(pendingtests, testfn)
|
||||
if #pendingtests == 1 then
|
||||
runpending()
|
||||
drain_post_queue()
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -406,43 +406,13 @@ end -- load_tests()
|
|||
|
||||
local cbWrap = function(cb) return cb end
|
||||
|
||||
-- implement pseudo task handling for on host testing
|
||||
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
|
||||
|
||||
if not node.LFS then -- assume we run on host, not on MCU. node is already defined by NTest if running on host
|
||||
cbWrap = function(cb)
|
||||
return function(...)
|
||||
local ok, p1,p2,p3,p4 = pcall(cb, ...)
|
||||
if not ok then
|
||||
if errorfunc then
|
||||
errorfunc(p1)
|
||||
if node.Host_Error_Func then -- luacheck: ignore 143
|
||||
node.Host_Error_Func(p1) -- luacheck: ignore 143
|
||||
else
|
||||
print(p1, "::::::::::::: reboot :::::::::::::")
|
||||
end
|
||||
|
@ -535,6 +505,12 @@ local function drain_async_queue()
|
|||
end
|
||||
|
||||
metatest = function(name, f, expectedPassed, expectedFailed, expectedExcept, asyncMode)
|
||||
table.insert(expected, {
|
||||
name = name,
|
||||
pass = expectedPassed,
|
||||
fail = expectedFailed,
|
||||
except = expectedExcept or {}
|
||||
})
|
||||
local ff = f
|
||||
if asyncMode then
|
||||
ff = function(...)
|
||||
|
@ -549,15 +525,7 @@ metatest = function(name, f, expectedPassed, expectedFailed, expectedExcept, asy
|
|||
else
|
||||
N.test(name, ff)
|
||||
end
|
||||
table.insert(expected, {
|
||||
name = name,
|
||||
pass = expectedPassed,
|
||||
fail = expectedFailed,
|
||||
except = expectedExcept or {}
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
load_tests()
|
||||
|
||||
drain_post_queue()
|
||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue