Skip to content

Commit

Permalink
add the test file
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed May 28, 2024
1 parent 498c686 commit 44915a8
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/no_luasocket.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
-- make sure we are pointing to the local copas first
package.path = string.format("../src/?.lua;%s", package.path)

print([[
Testing to run Copas without LuaSocket, just LuaSystem
=============================================================================
]])

-- patch require to no longer load luasocket
local _require = require
_G.require = function(name)
if name == "socket" then
error("luasocket is not allowed in this test")
end
return _require(name)
end


local copas = require "copas"
local timer = copas.timer

local successes = 0

local t1 -- luacheck: ignore

copas.loop(function()

t1 = timer.new({
delay = 0.1,
recurring = true,
callback = function(timer_obj, params)
successes = successes + 1 -- 6 to come
if successes == 6 then
timer_obj:cancel()
end
end,
})
-- succes count = 6

end)


assert(successes == 6, "number of successes didn't match! got: "..successes)
print("test success!")

0 comments on commit 44915a8

Please sign in to comment.