nodemcu-firmware/tests/utils/NTestTapOut.lua
Nathaniel Wesley Filardo 6316b33296
More NTest prep work for eventual test harness (#3353)
* Rename to tests/README.md

* Expand tests/README.md a bit

* NTest: remove report() in favor of named fields

Use a metatable to provide defaults which can be shadowed by the calling
code.

* NTest: remove old interface flag

I think we have few enough tests that we can verify not needing this
alert for ourselves.

* NTest tests: new standard prelude

Allow for NTest constructor to be passed in to the test itself.
The test harness can use this to provide a wrapper that will
pre-configure NTest itself.

* NTest output handler for TAP messages

* expect tests: core library functions

* expect tests: file xfer TCL module

* expect tests: add TAP-based test runner

* Begin documenting TCL goo

* Add .gitattributes to make sure lineends are correct ...

... if checked out under windows and executed under linux (say docker)

* tests/README: enumerate dependencies

* tests: more README.md

Co-authored-by: Gregor Hartmann <HHHartmann@users.noreply.github.com>
2021-01-16 21:26:22 +00:00

31 lines
1.1 KiB
Lua

-- This is a NTest output handler that formats its output in a way that
-- resembles the Test Anything Protocol (though prefixed with "TAP: " so we can
-- more readily find it in comingled output streams).
local nrun
return function(e, test, msg, err)
msg = msg or ""
err = err or ""
if e == "pass" then
print(("\nTAP: ok %d %s # %s"):format(nrun, test, msg))
nrun = nrun + 1
elseif e == "fail" then
print(("\nTAP: not ok %d %s # %s: %s"):format(nrun, test, msg, err))
nrun = nrun + 1
elseif e == "except" then
print(("\nTAP: not ok %d %s # exn; %s: %s"):format(nrun, test, msg, err))
nrun = nrun + 1
elseif e == "abort" then
print(("\nTAP: Bail out! %d %s # exn; %s: %s"):format(nrun, test, msg, err))
elseif e == "start" then
-- We don't know how many tests we plan to run, so emit a comment instead
print(("\nTAP: # STARTUP %s"):format(test))
nrun = 1
elseif e == "finish" then
-- Ah, now, here we go; we know how many tests we ran, so signal completion
print(("\nTAP: POST 1..%d"):format(nrun))
elseif #msg ~= 0 or #err ~= 0 then
print(("\nTAP: # %s: %s: %s"):format(test, msg, err))
end
end