Skip to content

Commit

Permalink
tests: add dynamic require tests.
Browse files Browse the repository at this point in the history
See #688.
  • Loading branch information
hishamhm committed Aug 15, 2024
1 parent bd48be0 commit ae53d4d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions spec/stdlib/require_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -969,5 +969,25 @@ describe("require", function()
assert.same({}, result.env.loaded["./types/house.tl"].type_errors)
assert.same({}, result.env.loaded["./types/person.tl"].type_errors)
end)

it("dynamic require resolves to 'any', which can then be casted", util.check_type_error([[
local record Mod
f: function()
end
local m1 = require("module_nr_" .. tostring(math.random(10))) as Mod
local pok1, m2 = pcall(require, "module_nr_" .. tostring(math.random(10))) as (boolean, Mod)
local n1 = require("module_nr_" .. tostring(math.random(10)))
local pok2, n2 = pcall(require, "module_nr_" .. tostring(math.random(10)))
local x: Mod = n1
local y: Mod = n2
]], {
{ y = 13, msg = "got <any type>, expected Mod" },
{ y = 14, msg = "got <any type>, expected Mod" },
}))
end)
end)

0 comments on commit ae53d4d

Please sign in to comment.