mirror of
https://github.com/nodemcu/nodemcu-firmware.git
synced 2025-01-16 20:52:57 +08:00
6316b33296
* 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>
100 lines
2.2 KiB
Lua
100 lines
2.2 KiB
Lua
local N = ...
|
|
N = (N or require "NTest")("tmr")
|
|
|
|
N.testasync('SINGLE alarm', function(next)
|
|
local t = tmr.create();
|
|
local count = 0
|
|
t:alarm(200, tmr.ALARM_SINGLE,
|
|
function()
|
|
count = count + 1
|
|
ok(count <= 1, "only 1 invocation")
|
|
next()
|
|
end)
|
|
|
|
ok(true, "sync end")
|
|
end)
|
|
|
|
N.testasync('SEMI alarm', function(next)
|
|
local t = tmr.create();
|
|
local count = 0
|
|
t:alarm(200, tmr.ALARM_SEMI,
|
|
function(tp)
|
|
count = count + 1
|
|
if count <= 1 then
|
|
tp:start()
|
|
return
|
|
end
|
|
ok(eq(count, 2), "only 2 invocations")
|
|
next()
|
|
end)
|
|
ok(true, "sync end")
|
|
end)
|
|
|
|
N.testasync('AUTO alarm', function(next)
|
|
local t = tmr.create();
|
|
local count = 0
|
|
t:alarm(200, tmr.ALARM_AUTO,
|
|
function(tp)
|
|
count = count + 1
|
|
if count == 2 then
|
|
tp:stop()
|
|
return next()
|
|
end
|
|
ok(count < 2, "only 2 invocations")
|
|
end)
|
|
ok(true, "sync end")
|
|
end)
|
|
|
|
N.testco('SINGLE alarm coroutine', function(getCB, waitCB)
|
|
local t = tmr.create();
|
|
t:alarm(200, tmr.ALARM_SINGLE, getCB("timer"))
|
|
|
|
local name, timer = waitCB()
|
|
ok(eq("timer", name), "CB name matches")
|
|
ok(eq(t, timer), "CB tmr instance matches")
|
|
|
|
ok(true, "coroutine end")
|
|
end)
|
|
|
|
N.testco('SEMI alarm coroutine', function(getCB, waitCB)
|
|
local t = tmr.create();
|
|
t:alarm(200, tmr.ALARM_SEMI, getCB("timer"))
|
|
|
|
local name, timer = waitCB()
|
|
ok(eq("timer", name), "CB name matches")
|
|
ok(eq(t, timer), "CB tmr instance matches")
|
|
|
|
timer:start()
|
|
|
|
name, timer = waitCB()
|
|
ok(eq("timer", name), "CB name matches again")
|
|
ok(eq(t, timer), "CB tmr instance matches again")
|
|
|
|
ok(true, "coroutine end")
|
|
end)
|
|
|
|
N.testco('AUTO alarm coroutine', function(getCB, waitCB)
|
|
local t = tmr.create();
|
|
t:alarm(200, tmr.ALARM_AUTO, getCB("timer"))
|
|
|
|
local name, timer = waitCB()
|
|
ok(eq("timer", name), "CB name matches")
|
|
ok(eq(t, timer), "CB tmr instance matches")
|
|
|
|
name, timer = waitCB()
|
|
ok(eq("timer", name), "CB name matches again")
|
|
ok(eq(t, timer), "CB tmr instance matches again")
|
|
|
|
timer:stop()
|
|
|
|
ok(true, "coroutine end")
|
|
end)
|
|
|
|
N.test('softwd set positive and negative values', function()
|
|
tmr.softwd(22)
|
|
tmr.softwd(0)
|
|
tmr.softwd(-1) -- disable it again
|
|
tmr.softwd(-22) -- disable it again
|
|
end)
|
|
|