Skip to content

Commit

Permalink
tests: add testcase for tl types -p if-block
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamhm committed Sep 19, 2024
1 parent d8965fa commit b618edb
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions spec/cli/types_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,39 @@ describe("#cli tl types works like check", function()
assert(type(types["y"]) == "nil")
end)

it("reports end of if-block correctly", function()
local filename = util.write_tmp_file(finally, [[
-- test.tl
local function hello(): number
return 1
end
if 1 == 1 then
local abc = hello()
local def = abc
def = abc
end
]])
local pd = io.popen(util.tl_cmd("types", "-p", "12:1", filename), "r")
local output = pd:read("*a")
util.assert_popen_close(0, pd:close())
local types = json.decode(output)
local n = 0
for _ in pairs(types) do
n = n + 1
end
assert(n == 3)
assert(type(types["abc"]) == "number")
assert(type(types["def"]) == "number")
assert(type(types["hello"]) == "number")
end)

it("reports number of errors in stderr and code 1 on syntax errors", function()
local name = util.write_tmp_file(finally, [[
print(add("string", 20))))))
Expand Down

0 comments on commit b618edb

Please sign in to comment.