Skip to content

Commit

Permalink
Merge pull request #83 from antonv6/make-exit-code-useful-again
Browse files Browse the repository at this point in the history
Set exit code bits depending on severity
  • Loading branch information
mpeterv committed Nov 22, 2016
2 parents 3401785 + 9cd95a3 commit b064b50
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
10 changes: 5 additions & 5 deletions spec/cli_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Checking spec/samples/bad_code.lua 5 warnings
Total: 5 warnings / 0 errors in 1 file
]], get_output "spec/samples/bad_code.lua --no-config")
assert.equal(5, get_exitcode "spec/samples/bad_code.lua --no-config")
assert.equal(1, get_exitcode "spec/samples/bad_code.lua --no-config")
end)

it("detects whitespace issues", function()
Expand All @@ -135,7 +135,7 @@ Checking spec/samples/bad_whitespace.lua 8 warnings
Total: 8 warnings / 0 errors in 1 file
]], get_output "spec/samples/bad_whitespace.lua --no-config")
assert.equal(8, get_exitcode "spec/samples/bad_whitespace.lua --no-config")
assert.equal(1, get_exitcode "spec/samples/bad_whitespace.lua --no-config")
end)

it("works for incorrect patterns in options", function()
Expand Down Expand Up @@ -386,7 +386,7 @@ Checking s/samples/absent_code.lua I/O error
Total: 0 warnings / 1 error in 1 file, couldn't check 1 file
]], get_output "spec/samples/python_code.lua s/samples/absent_code.lua --no-config")
assert.equal(2, get_exitcode "spec/samples/python_code.lua spec/samples/absent_code.lua --no-config")
assert.equal(6, get_exitcode "spec/samples/python_code.lua spec/samples/absent_code.lua --no-config")
end)

it("expands rockspecs", function()
Expand Down Expand Up @@ -1216,11 +1216,11 @@ Critical error: Couldn't find configuration file spec/configs/config_404.luachec

describe("overwriting", function()
it("prioritizes CLI options over config", function()
assert.is_true(get_exitcode "spec/samples/compat.lua --config=spec/configs/cli_override_config.luacheckrc --new-globals foo" > 0)
assert.equal(1, get_exitcode "spec/samples/compat.lua --config=spec/configs/cli_override_config.luacheckrc --new-globals foo")
end)

it("prioritizes CLI options over config overrides", function()
assert.is_true(get_exitcode "spec/samples/compat.lua --config=spec/configs/cli_override_file_config.luacheckrc --new-globals foo" > 0)
assert.equal(1, get_exitcode "spec/samples/compat.lua --config=spec/configs/cli_override_file_config.luacheckrc --new-globals foo")
end)

it("concats array-like options from config and CLI", function()
Expand Down
13 changes: 12 additions & 1 deletion src/luacheck/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,18 @@ patterns.]])

io.stdout:write(output)

local exit_code = math.min(report.fatals + report.errors + report.warnings, 255)
local exit_code = 0

if report.fatals > 0 then
exit_code = exit_code + 4
end
if report.errors > 0 then
exit_code = exit_code + 2
end
if report.warnings > 0 then
exit_code = exit_code + 1
end

os.exit(exit_code)
end

Expand Down

0 comments on commit b064b50

Please sign in to comment.