mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-29 04:47:39 +00:00
- Define an expect(index, actual_value, types...) helper function which takes an argument index, value and list of permissable types and ensures the value is of one of those types. If not, it will produce an error message with the expected and actual type, as well as the argument number and (if available) the function name. - Expose expect in the global scope as _G["~expect"], hopefully making it clear it is internal. - Replace most manual type checks with this helper method. - Write tests to ensure this argument validation works as expected Also fix a couple of bugs exposed by this refactor and the subsequent tests: - Make rednet checks a little more strict - rednet.close(false) is no longer valid. - Error when attempting to redirect the terminal to itself (term.redirect(term)).
13 lines
455 B
Lua
13 lines
455 B
Lua
describe("The term library", function()
|
|
describe("term.redirect", function()
|
|
it("validates arguments", function()
|
|
expect.error(term.redirect, nil):eq("bad argument #1 (expected table, got nil)")
|
|
end)
|
|
|
|
it("prevents redirecting to term", function()
|
|
expect.error(term.redirect, term)
|
|
:eq("term is not a recommended redirect target, try term.current() instead")
|
|
end)
|
|
end)
|
|
end)
|