From 4023df7e60d861f7167ed61145717ef23048d794 Mon Sep 17 00:00:00 2001 From: Gregor Hartmann Date: Sat, 9 Jan 2021 22:25:22 +0100 Subject: [PATCH] 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 --- .github/workflows/build.yml | 14 ++++++++++ app/lua/lauxlib.c | 2 +- tests/NTest/NTest.lua | 34 ++++++++++++++++++++++++ tests/NTest/NTest_NTest.lua | 52 +++++++------------------------------ tests/NTest_lua.lua | 6 +++++ 5 files changed, 65 insertions(+), 43 deletions(-) create mode 100644 tests/NTest_lua.lua diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 90173656..b0dcee5a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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: diff --git a/app/lua/lauxlib.c b/app/lua/lauxlib.c index 73b971f3..efb89843 100644 --- a/app/lua/lauxlib.c +++ b/app/lua/lauxlib.c @@ -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); } diff --git a/tests/NTest/NTest.lua b/tests/NTest/NTest.lua index 1576d282..32e5205e 100644 --- a/tests/NTest/NTest.lua +++ b/tests/NTest/NTest.lua @@ -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 = ""} @@ -233,6 +266,7 @@ local function NTest(testrunname, failoldinterface) table.insert(pendingtests, testfn) if #pendingtests == 1 then runpending() + drain_post_queue() end end diff --git a/tests/NTest/NTest_NTest.lua b/tests/NTest/NTest_NTest.lua index 0e4a2820..0701c681 100644 --- a/tests/NTest/NTest_NTest.lua +++ b/tests/NTest/NTest_NTest.lua @@ -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 @@ -465,7 +435,7 @@ end local pass -- Set meta test handler N.report(function(e, test, msg, errormsg) - local function consumemsg(msg, area) -- luacheck: ignore + local function consumemsg(msg, area) -- luacheck: ignore if not expected[1][area][1] then print("--- FAIL "..expected[1].name..' ('..area..'ed): unexpected "'.. msg..'"') @@ -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() diff --git a/tests/NTest_lua.lua b/tests/NTest_lua.lua new file mode 100644 index 00000000..13ebe346 --- /dev/null +++ b/tests/NTest_lua.lua @@ -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)