Fixed error handling in scale subcommand (#816)

This commit is contained in:
JackMacWindows 2021-06-07 15:47:15 -04:00 committed by GitHub
parent 97faa1b3bc
commit 53efd6b303
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View File

@ -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

View File

@ -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)