Skip to content

Commit

Permalink
spec: Add basic test of reporting unread variables
Browse files Browse the repository at this point in the history
  • Loading branch information
euclidianAce authored and hishamhm committed Dec 18, 2024
1 parent cff525e commit 3ac7a50
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions spec/lang/error_reporting/warning_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,25 @@ describe("warnings", function()
{ y = 1, msg = [[unused variable foo: string]] }
}))

it("reports unread (but written) variables", util.check_warnings([[
local foo = "bar"
foo = "baz"
]], {
{ y = 1, msg = [[variable foo (of type string) is never read]] }
}))

it("does not report variable shadows previous declaration ofs prefixed with '_'", util.check_warnings([[
local _ = 1
print(_) -- ensure usage
local _ = 2
print(_)
]], { }))

it("does not report unread (but written) variables prefixed with '_'", util.check_warnings([[
local _foo = "bar"
_foo = "baz"
]], { }))

it("does not report unused global variables", util.check_warnings([[
global foo = "bar"
]], { }))
Expand Down

0 comments on commit 3ac7a50

Please sign in to comment.