mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-04 23:40:00 +00:00
Fixed error handling in scale subcommand (#816)
This commit is contained in:
parent
97faa1b3bc
commit
53efd6b303
@ -7,7 +7,7 @@ local function printUsage()
|
||||
end
|
||||
|
||||
local tArgs = { ... }
|
||||
if #tArgs < 2 then
|
||||
if #tArgs < 2 or tArgs[1] == "scale" and #tArgs < 3 then
|
||||
printUsage()
|
||||
return
|
||||
end
|
||||
@ -21,7 +21,7 @@ if tArgs[1] == "scale" then
|
||||
|
||||
local nRes = tonumber(tArgs[3])
|
||||
if nRes == nil or nRes < 0.5 or nRes > 5 then
|
||||
print("Invalid scale: " .. nRes)
|
||||
print("Invalid scale: " .. tArgs[3])
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -21,4 +21,24 @@ describe("The monitor program", function()
|
||||
:matches { ok = true, output = "", error = "" }
|
||||
expect(r):equals(0.5)
|
||||
end)
|
||||
|
||||
it("displays correct error messages", function()
|
||||
local r = 1
|
||||
stub(peripheral, "call", function(s, f, t) r = t end)
|
||||
stub(peripheral, "getType", function(side) return side == "left" and "monitor" or nil end)
|
||||
expect(capture(stub, "monitor", "scale", "left"))
|
||||
:matches {
|
||||
ok = true,
|
||||
output =
|
||||
"Usage:\n" ..
|
||||
" monitor <name> <program> <arguments>\n" ..
|
||||
" monitor scale <name> <scale>\n",
|
||||
error = "",
|
||||
}
|
||||
expect(capture(stub, "monitor", "scale", "top", "0.5"))
|
||||
:matches { ok = true, output = "No monitor named top\n", error = "" }
|
||||
expect(capture(stub, "monitor", "scale", "left", "aaa"))
|
||||
:matches { ok = true, output = "Invalid scale: aaa\n", error = "" }
|
||||
expect(r):equals(1)
|
||||
end)
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user