Calling os.exit() from within a test is not protected
To reproduce:
describe("tests", function()
it("will exit early", function()
os.exit(42)
end)
it("will never be run", function()
print("here be dragons")
end)
end)
I was blindsided by this while integration testing a CLI program, because busted never got to offer feedback on why my program had stopped prematurely.
It seems most useful for busted to consider a test that calls os.exit() with a non-zero exit code to have triggered an error, but the question on what to do about an exit code of zero is a little thorny. example:
local function application_code() os.exit(0) end
it("should this succeed or fail?", function()
assert.equal(true, true)
application_code()
assert.equal(true, false)
end)
If os.exit(0) just causes a test to complete early, then a test writer who doesn't know that the os.exit() call exists might expect this test to fail when it doesn't.
If os.exit() causes an error no matter what, then a user that is expecting code to fall-through using os.exit() can guard for it, and the user that doesn't expect it can be informed in a safe way.
os.exit is not the only thing that might do this (e.g. C libraries, segfaults, etc).
The proper solution would be to run tests in a subprocess.
However that is a lot of complexity.
I advise closing this as WONTFIX.