lune/tests/globals/pcall.luau

35 lines
865 B
Text
Raw Normal View History

local net = require("@lune/net")
local task = require("@lune/task")
2023-02-17 18:20:17 +00:00
local PORT = 9090 -- NOTE: This must be different from
-- net tests to let them run in parallel with this file
local function test(f, ...)
local success, message = pcall(f, ...)
assert(not success, "Function did not throw an error")
assert(
type(message) == "string" or type(message) == "userdata",
"Pcall did not return a proper error"
)
end
-- These are not async but should be pcallable
test(error, "Test error", 2)
-- Net request is async and will throw a DNS error here for the weird address
test(net.request, "https://wxyz.google.com")
-- Net serve is async and will throw an OS error when trying to serve twice on the same port
2023-02-17 18:20:17 +00:00
local handle = net.serve(PORT, function()
return ""
end)
task.delay(0.25, function()
handle.stop()
end)
2023-02-17 18:20:17 +00:00
test(net.serve, PORT, function() end)