Skip to content

Commit

Permalink
fix: reenable accidentally disabled tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamhm committed Jul 23, 2024
1 parent add0bd7 commit 48bca4d
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 31 deletions.
18 changes: 9 additions & 9 deletions spec/declaration/global_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe("global", function()
util.mock_io(finally, {
["foo.tl"] = "global x: number = 1"
})
util.check([[
util.run_check([[
local foo = require("foo")
global x: number
x = 2
Expand All @@ -148,7 +148,7 @@ describe("global", function()
util.mock_io(finally, {
["foo.tl"] = "global x <const>: number = 1"
})
util.check([[
util.run_check([[
local foo = require("foo")
global x <const>: number
]])
Expand All @@ -158,7 +158,7 @@ describe("global", function()
util.mock_io(finally, {
["foo.tl"] = "global x <const>: number = 1"
})
util.check_type_error([[
util.run_check_type_error([[
local foo = require("foo")
global x <const>: number = 9
]], {
Expand All @@ -170,7 +170,7 @@ describe("global", function()
util.mock_io(finally, {
["foo.tl"] = "global x: number"
})
util.check_type_error([[
util.run_check_type_error([[
local foo = require("foo")
global x <const>: number
]], {
Expand All @@ -182,7 +182,7 @@ describe("global", function()
util.mock_io(finally, {
["foo.tl"] = "global x <const>: number"
})
util.check_type_error([[
util.run_check_type_error([[
local foo = require("foo")
global x: number
]], {
Expand All @@ -194,7 +194,7 @@ describe("global", function()
util.mock_io(finally, {
["foo.tl"] = "global x, y: number, string = 1, 'hello'"
})
util.check_type_error([[
util.run_check_type_error([[
local foo = require("foo")
global x: string
x = 2
Expand All @@ -213,7 +213,7 @@ describe("global", function()
global type Building
global type Person
global record Person
residence: Building
end
Expand All @@ -224,14 +224,14 @@ describe("global", function()
global type Person
global type Building
global record Building
owner: Person
end
return building
]],
})
util.check([[
util.run_check([[
local person = require("person")
local building = require("building")
local b: Building = {}
Expand Down
24 changes: 15 additions & 9 deletions spec/declaration/record_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ for i, name in ipairs({"records", "arrayrecords", "interfaces", "arrayinterfaces
it("can be nested", function()
util.mock_io(finally, {
["req.d.tl"] = [[
local type requests = ]]..statement..[[ ]]..array(i, "{requests}")..[[
local type requests = record
type RequestOpts = ]]..statement..[[ --
{string}
Expand All @@ -265,21 +265,24 @@ for i, name in ipairs({"records", "arrayrecords", "interfaces", "arrayinterfaces
return requests
]],
})
util.check_type_error([[
util.run_check_type_error([[
local req = require("req")
local r = req.get("http://example.com")
print(r.status_code)
print(r.status_coda)
]], {
{ msg = "invalid key 'status_coda' in "..statement.." 'r' of type Response" }
{ msg = (statement == "interface")
and "invalid key 'status_coda' in 'r' of interface type Response"
or "invalid key 'status_coda' in record 'r' of type Response"
}
})
end)

it("can be nested with shorthand syntax", function()
util.mock_io(finally, {
["req.d.tl"] = [[
local type requests = ]]..statement..[[ ]]..array(i, "{requests}")..[[
local type requests = record
]]..statement..[[ RequestOpts
{string}
Expand All @@ -298,14 +301,17 @@ for i, name in ipairs({"records", "arrayrecords", "interfaces", "arrayinterfaces
return requests
]],
})
util.check_type_error([[
util.run_check_type_error([[
local req = require("req")
local r = req.get("http://example.com")
print(r.status_code)
print(r.status_coda)
]], {
{ msg = "invalid key 'status_coda' in "..statement.." 'r' of type Response" }
{ msg = (statement == "interface")
and "invalid key 'status_coda' in 'r' of interface type Response"
or "invalid key 'status_coda' in record 'r' of type Response"
}
})
end)

Expand Down Expand Up @@ -519,7 +525,7 @@ for i, name in ipairs({"records", "arrayrecords", "interfaces", "arrayinterfaces
it("can export types as nested " .. name, function()
util.mock_io(finally, {
["req.d.tl"] = [[
local type requests = ]]..statement..[[ ]]..array(i, "{requests}")..[[
local record requests
type RequestOpts = ]]..statement..[[
{string}
Expand All @@ -538,15 +544,15 @@ for i, name in ipairs({"records", "arrayrecords", "interfaces", "arrayinterfaces
return requests
]],
})
util.check([[
return util.check([[
local req = require("req")
local function f(): req.Response
return req.get("http://example.com")
end
print(f().status_code)
]])
]])()
end)

it("resolves aliasing of nested " .. name .. " (see #400)", util.check([[
Expand Down
20 changes: 10 additions & 10 deletions spec/error_reporting/typecheck_error_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ describe("typecheck errors", function()
util.mock_io(finally, {
["bar.tl"] = "local x: string = 1",
})
util.check_type_error([[
util.run_check_type_error([[
local bar = require "bar"
]], {
{ filename = "./bar.tl" }
})()
})
end)

it("unknowns include filename", util.lax_check([[
Expand All @@ -28,11 +28,11 @@ describe("typecheck errors", function()
util.mock_io(finally, {
["bar.lua"] = "local x: string = b"
})
util.lax_check([[
util.run_lax_check([[
local bar = require "bar"
]], {
{ msg = "b", filename = "./bar.lua" }
})()
})
end)

it("type mismatches across modules report their module names", function ()
Expand All @@ -54,7 +54,7 @@ describe("typecheck errors", function()
return bbb
]]
})
util.check_type_error([[
util.run_check_type_error([[
local aaa = require("aaa")
local bbb = require("bbb")
Expand All @@ -67,7 +67,7 @@ describe("typecheck errors", function()
myfunc(b)
]], {
{ msg = "bbb.Thing is not a aaa.Thing" }
})()
})
end)

it("localized type mismatches across module report their filenames", function ()
Expand Down Expand Up @@ -96,7 +96,7 @@ describe("typecheck errors", function()
return bbb
]]
})
util.check_type_error([[
util.run_check_type_error([[
local aaa = require("aaa")
local bbb = require("bbb")
Expand All @@ -107,7 +107,7 @@ describe("typecheck errors", function()
aaa.myfunc(b)
]], {
{ msg = "argument 1: Thing (defined in ./bbb.tl:4) is not a Thing (defined in ./aaa.tl:1)" }
})()
})
end)

it("type mismatches across local type names report their provenance", function ()
Expand Down Expand Up @@ -141,7 +141,7 @@ describe("typecheck errors", function()
return bbb
]]
})
util.check_type_error([[
util.run_check_type_error([[
local aaa = require("aaa")
local bbb = require("bbb")
Expand All @@ -150,7 +150,7 @@ describe("typecheck errors", function()
aaa.myfunc(b)
]], {
{ msg = "argument 1: Thing (defined in ./bbb.tl:1) is not a Thing (defined in ./aaa.tl:1)" }
})()
})
end)

end)
2 changes: 1 addition & 1 deletion spec/lexer/literals_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ describe("lexer", function()
end
local input = table.concat(code, "\n")

util.check(input)
util.run_check(input)
end)
end)
12 changes: 12 additions & 0 deletions spec/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -616,4 +616,16 @@ function util.gen(code, expected, gen_target)
return gen(false, code, expected, gen_target)
end

function util.run_check_type_error(...)
return util.check_type_error(...)()
end

function util.run_check(...)
return util.check(...)()
end

function util.run_lax_check(...)
return util.lax_check(...)()
end

return util
6 changes: 5 additions & 1 deletion tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9215,7 +9215,11 @@ a.types[i], b.types[i]), }
end

if rec.kind == "variable" then
return nil, "invalid key '" .. key .. "' in record '" .. rec.tk .. "' of type %s"
if tbl.typename == "interface" then
return nil, "invalid key '" .. key .. "' in '" .. rec.tk .. "' of interface type %s"
else
return nil, "invalid key '" .. key .. "' in record '" .. rec.tk .. "' of type %s"
end
else
return nil, "invalid key '" .. key .. "' in type %s"
end
Expand Down
6 changes: 5 additions & 1 deletion tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -9215,7 +9215,11 @@ do
end

if rec.kind == "variable" then
return nil, "invalid key '" .. key .. "' in record '" .. rec.tk .. "' of type %s"
if tbl is InterfaceType then
return nil, "invalid key '" .. key .. "' in '" .. rec.tk .. "' of interface type %s"
else
return nil, "invalid key '" .. key .. "' in record '" .. rec.tk .. "' of type %s"
end
else
return nil, "invalid key '" .. key .. "' in type %s"
end
Expand Down

0 comments on commit 48bca4d

Please sign in to comment.