Hi Michael...
On Mon, 14 Apr 2025 at 23:51, Michael Bonnet <
maab...@gmail.com> wrote:
....
> My question is, how might I go about unit testing the Lua scripts (that are using the custom C backend) themselves? Can something like busted or luaunit do it? If so, how would I configure the testing tool to use these custom C functions?
I use testy for my tests, in a similar case, a lua interpreter embeded
in a module for the yate telephony server. What I do is just invoke it
by collecting the neede test file names in the global "arg" and
pcalling...
local oldarg=arg
arg = {}
-- unisteresting matching and popening of ls to get filenames in arg zapped...
local os_exit=os.exit -- Testy calls this on fails!
os.exit=function(code, close)
io.stderr:write(string.format("Testy exit(%s,%s)\n",code,close))
end
io.stderr:write("-----TESTY START--------\n")
io.stderr:write(string.format("Calling testy with %s\n", table.concat(arg)));
local ok,err = xpcall(dofile,debug.traceback,"testy.lua")
arg=oldarg
os.exit=os_exit
if (not ok) then
io.stderr:write(string.format("Testy errored: %s\n", err))
end
io.stderr:write("-----TESTY END----------\n")
I invoke this by either a telnet command handler built in lua or by a
special command in my init code. The test results end up on screen or
in the server log, where stderr is redirected when daemonized. Having
a mocked global arg and a mocked os.exit is enough to make testy
happy.
I just have two test dirs, one with the lua-only modules, other with
the server-specific. This way I can run testy fast on the command line
for the lua-only and run both on the server ( lua-ones are rechecked
because I have a stub module for the server for mockable things so I
can test logic, but some objects like http client/servers, thread
pools, posix extensions and other things are only available on the
server interpreter, and I have a lot of mocked things which need to be
rechecked on the server )
Francisco Olarte.