Add tests for local uuid and os.clock

To get execution coverage of bc.lua to 100%, add two more tests:

1. The first one ensures that os.clock is used properly when
   computer.uptime() is not available.
2. The second one tests the fallback implementation of uuid generation
   when uuid.next() is not available.
main
rahix 3 years ago
parent c4e0d9dfe7
commit 6f5e8386eb

@ -13,6 +13,7 @@ test_sources = {
"tests/local.lua", "tests/local.lua",
"tests/network.lua", "tests/network.lua",
"tests/timeout.lua", "tests/timeout.lua",
"tests/misc.lua",
} }
for _, source in ipairs(test_sources) do for _, source in ipairs(test_sources) do
loadfile("./tests/"..source)() loadfile("./tests/"..source)()

@ -0,0 +1,59 @@
local test = require("u-test")
local serialization = require("serialization")
local computer = require("computer")
local uuid = require("uuid")
local computer_uptime_saved
function test.os_clock.start_up()
computer_uptime_saved = computer.uptime
computer.uptime = nil
end
function test.os_clock.tear_down()
computer.uptime = computer_uptime_saved
-- Force reload of the module
package.loaded.bc = nil
local BaseControl = require("bc")
end
function test.os_clock.test_monkeypatched()
-- Force reload of the module
package.loaded.bc = nil
local BaseControl = require("bc")
-- Test a timeout to prove it works
local bc1 = BaseControl:new()
test.error_raised(function()
bc1:finalize({"to_final1"}, 0.1)
end, "timeout")
end
local uuid_next_saved
function test.uuid.start_up()
uuid_next_saved = uuid.next
uuid.next = nil
end
function test.uuid.tear_down()
uuid.next = uuid_next_saved
-- Force reload of the module
package.loaded.bc = nil
local BaseControl = require("bc")
end
function test.uuid.test_monkeypatched()
-- Force reload of the module
package.loaded.bc = nil
local BaseControl = require("bc")
-- Test a listener as this will use a uuid
local bc = BaseControl:new()
bc:register("lisuuid1", 1234)
bc:finalize()
local id1 = bc:listen(
"lisuuid1", bc.Query.Change, function(new) end)
local id2 = bc:listen(
"lisuuid1", bc.Query.Change, function(new) end)
test.not_equal(id1, id2, "uuid collision")
end
Loading…
Cancel
Save