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
parent
c4e0d9dfe7
commit
6f5e8386eb
@ -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…
Reference in new issue