Skip to content

Commit

Permalink
Add Luacheck as a linting tool.
Browse files Browse the repository at this point in the history
For #4
  • Loading branch information
mblayman committed Jul 16, 2023
1 parent a1b2966 commit 292189a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repos:
- repo: https://github.com/lunarmodules/luacheck
rev: "v1.1.1"
hooks:
- id: luacheck
4 changes: 2 additions & 2 deletions lua/luatest/reporter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ function Reporter._read_stderr(self) return self._stderr_stringio:value() end
-- with the other diagnostic information when failures occur.
function Reporter.capture_standard_files(self)
if self:_should_capture() then
io.stdout = self._stdout_stringio
io.stderr = self._stderr_stringio
io.stdout = self._stdout_stringio -- luacheck: ignore 122
io.stderr = self._stderr_stringio -- luacheck: ignore 122

-- print seems to operate separately from io.stdout|stderr.
-- Replace the global print function with a function that writes
Expand Down
8 changes: 5 additions & 3 deletions tests/test_collection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ function tests.test_module_does_not_have_test()
tests = {["test_does_not_exist"] = true}
}, test_modules, reporter)

assert.spy(reporter.error).was_called_with(reporter,
"tests/demo/something_test.lua has no test function named test_does_not_exist")
local expected =
"tests/demo/something_test.lua has no test function named test_does_not_exist"
assert.spy(reporter.error).was_called_with(reporter, expected)

end

-- A module that doesn't look like a table of functions triggers a warning.
Expand Down Expand Up @@ -129,7 +131,7 @@ function tests.test_reports_errors()
spy.on(reporter, "error")
spy.on(reporter, "fatal")

local test_count = collection.report_errors(errors, reporter)
collection.report_errors(errors, reporter)

assert.spy(reporter.error).was_called_with(reporter,
"Houston, we have a problem.")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_reporter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function tests.test_fatal()
assert.is_equal("\x1B[0m\x1B[31ma fatal error\x1B[0m\n", get_content(file))
assert.stub(os.exit).was_called_with(1)

os.exit:revert()
os.exit:revert() -- luacheck: ignore 143
end

-- Start collection reports the tests directory.
Expand Down

0 comments on commit 292189a

Please sign in to comment.