mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-08-27 16:02:17 +00:00
use arg[0] in all usage printouts (#571)
This commit is contained in:
parent
ac452582c1
commit
d28f42e8b7
@ -275,3 +275,9 @@ matter? Nah....
|
||||
|
||||
Use blit to draw boxes, add colors.toBlit (#570)
|
||||
```
|
||||
|
||||
```
|
||||
d13bd2cce8d102ad7f61f557e707d6fe3731bc37
|
||||
|
||||
use arg[0] in all usage printouts (#571)
|
||||
```
|
||||
|
@ -1,6 +1,7 @@
|
||||
local tArgs = { ... }
|
||||
if #tArgs > 2 then
|
||||
print("Usage: alias <alias> <program>")
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usage: " .. programName .. " <alias> <program>")
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
local tArgs = { ... }
|
||||
if #tArgs < 1 then
|
||||
print("Usage: cd <path>")
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usage: " .. programName .. " <path>")
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -4,7 +4,8 @@ if not commands then
|
||||
return
|
||||
end
|
||||
if #tArgs == 0 then
|
||||
printError("Usage: exec <command>")
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
printError("Usage: " .. programName .. " <command>")
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
local tArgs = { ... }
|
||||
if #tArgs < 2 then
|
||||
print("Usage: cp <source> <destination>")
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usage: " .. programName .. " <source> <destination>")
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
local args = table.pack(...)
|
||||
|
||||
if args.n < 1 then
|
||||
print("Usage: rm <paths>")
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usage: " .. programName .. " <paths>")
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
-- Get file to edit
|
||||
local tArgs = { ... }
|
||||
if #tArgs == 0 then
|
||||
print("Usage: edit <path>")
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usage: " .. programName .. " <path>")
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
-- Get arguments
|
||||
local tArgs = { ... }
|
||||
if #tArgs == 0 then
|
||||
print("Usage: eject <drive>")
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usage: " .. programName .. " <drive>")
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -34,7 +34,8 @@ end
|
||||
-- Determines if the file exists, and can be edited on this computer
|
||||
local tArgs = { ... }
|
||||
if #tArgs == 0 then
|
||||
print("Usage: paint <path>")
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usage: " .. programName .. " <path>")
|
||||
return
|
||||
end
|
||||
local sPath = shell.resolve(tArgs[1])
|
||||
|
@ -1,10 +1,11 @@
|
||||
local tArgs = { ... }
|
||||
|
||||
local function printUsage()
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usages:")
|
||||
print("dj play")
|
||||
print("dj play <drive>")
|
||||
print("dj stop")
|
||||
print(programName .. " play")
|
||||
print(programName .. " play <drive>")
|
||||
print(programName .. " stop")
|
||||
end
|
||||
|
||||
if #tArgs > 2 then
|
||||
|
@ -1,8 +1,9 @@
|
||||
local function printUsage()
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usages:")
|
||||
print("gps host")
|
||||
print("gps host <x> <y> <z>")
|
||||
print("gps locate")
|
||||
print(programName .. " host")
|
||||
print(programName .. " host <x> <y> <z>")
|
||||
print(programName .. " locate")
|
||||
end
|
||||
|
||||
local tArgs = { ... }
|
||||
|
@ -1,8 +1,9 @@
|
||||
local function printUsage()
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usages:")
|
||||
print("pastebin put <filename>")
|
||||
print("pastebin get <code> <filename>")
|
||||
print("pastebin run <code> <arguments>")
|
||||
print(programName .. " put <filename>")
|
||||
print(programName .. " get <code> <filename>")
|
||||
print(programName .. " run <code> <arguments>")
|
||||
end
|
||||
|
||||
local tArgs = { ... }
|
||||
|
@ -1,7 +1,8 @@
|
||||
local function printUsage()
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usage:")
|
||||
print("wget <url> [filename]")
|
||||
print("wget run <url>")
|
||||
print(programName .. " <url> [filename]")
|
||||
print(programName .. " run <url>")
|
||||
end
|
||||
|
||||
local tArgs = { ... }
|
||||
|
@ -1,13 +1,15 @@
|
||||
local function printUsage()
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usages:")
|
||||
print("label get")
|
||||
print("label get <drive>")
|
||||
print("label set <text>")
|
||||
print("label set <drive> <text>")
|
||||
print("label clear")
|
||||
print("label clear <drive>")
|
||||
print(programName .. " get")
|
||||
print(programName .. " get <drive>")
|
||||
print(programName .. " set <text>")
|
||||
print(programName .. " set <drive> <text>")
|
||||
print(programName .. " clear")
|
||||
print(programName .. " clear <drive>")
|
||||
end
|
||||
|
||||
|
||||
local function checkDrive(sDrive)
|
||||
if peripheral.getType(sDrive) == "drive" then
|
||||
-- Check the disk exists
|
||||
|
@ -1,7 +1,8 @@
|
||||
local tArgs = { ... }
|
||||
|
||||
if #tArgs < 1 then
|
||||
print("Usage: mkdir <paths>")
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usage: " .. programName .. " <paths>")
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
local function printUsage()
|
||||
print("Usage: monitor <name> <program> <arguments>")
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usage: " .. programName .. " <name> <program> <arguments>")
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
local tArgs = { ... }
|
||||
if #tArgs < 2 then
|
||||
print("Usage: mv <source> <destination>")
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usage: " .. programName .. " <source> <destination>")
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -1,9 +1,10 @@
|
||||
local tArgs = { ... }
|
||||
|
||||
local function printUsage()
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usages:")
|
||||
print("chat host <hostname>")
|
||||
print("chat join <hostname> <nickname>")
|
||||
print(programName .. " host <hostname>")
|
||||
print(programName .. " join <hostname> <nickname>")
|
||||
end
|
||||
|
||||
local sOpenedModem = nil
|
||||
|
@ -1,11 +1,12 @@
|
||||
local tArgs = { ... }
|
||||
|
||||
local function printUsage()
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usages:")
|
||||
print("redstone probe")
|
||||
print("redstone set <side> <value>")
|
||||
print("redstone set <side> <color> <value>")
|
||||
print("redstone pulse <side> <count> <period>")
|
||||
print(programName .. " probe")
|
||||
print(programName .. " set <side> <value>")
|
||||
print(programName .. " set <side> <color> <value>")
|
||||
print(programName .. " pulse <side> <count> <period>")
|
||||
end
|
||||
|
||||
local sCommand = tArgs[1]
|
||||
|
@ -1,6 +1,7 @@
|
||||
local tArgs = { ... }
|
||||
if #tArgs < 2 then
|
||||
print("Usage: rename <source> <destination>")
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usage: " .. programName .. " <source> <destination>")
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
if not turtle then
|
||||
printError("Requires a Turtle")
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usage: " .. programName .. " [number]")
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -5,7 +5,8 @@ end
|
||||
|
||||
local tArgs = { ... }
|
||||
local function printUsage()
|
||||
print("Usage: equip <slot> <side>")
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usage: " .. programName .. " <slot> <side>")
|
||||
end
|
||||
|
||||
if #tArgs ~= 2 then
|
||||
|
@ -5,7 +5,8 @@ end
|
||||
|
||||
local tArgs = { ... }
|
||||
if #tArgs ~= 1 then
|
||||
print("Usage: excavate <diameter>")
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usage: " .. programName .. " <diameter>")
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -5,7 +5,8 @@ end
|
||||
|
||||
local tArgs = { ... }
|
||||
if #tArgs < 1 then
|
||||
print("Usage: go <direction> <distance>")
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usage: " .. programName .. " <direction> <distance>")
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -6,7 +6,8 @@ end
|
||||
local tArgs = { ... }
|
||||
local nLimit = 1
|
||||
if #tArgs > 1 then
|
||||
print("Usage: refuel [number]")
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usage: " .. programName .. " [number]")
|
||||
return
|
||||
elseif #tArgs > 0 then
|
||||
if tArgs[1] == "all" then
|
||||
|
@ -5,7 +5,8 @@ end
|
||||
|
||||
local tArgs = { ... }
|
||||
if #tArgs ~= 1 then
|
||||
print("Usage: tunnel <length>")
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usage: " .. programName .. " <length>")
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -5,7 +5,8 @@ end
|
||||
|
||||
local tArgs = { ... }
|
||||
if #tArgs < 1 then
|
||||
print("Usage: turn <direction> <turns>")
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usage: " .. programName .. " <direction> <turns>")
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -5,7 +5,8 @@ end
|
||||
|
||||
local tArgs = { ... }
|
||||
local function printUsage()
|
||||
print("Usage: unequip <side>")
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usage: " .. programName .. " <side>")
|
||||
end
|
||||
|
||||
if #tArgs ~= 1 then
|
||||
|
@ -1,6 +1,7 @@
|
||||
local tArgs = { ... }
|
||||
if #tArgs < 1 then
|
||||
print("Usage: type <path>")
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usage: " .. programName .. " <path>")
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -0,0 +1,33 @@
|
||||
local capture = require "test_helpers".capture_program
|
||||
|
||||
describe("The exec program", function()
|
||||
it("displays an error without the commands api", function()
|
||||
stub(_G, "commands", nil)
|
||||
expect(capture(stub, "/rom/programs/command/exec.lua"))
|
||||
:matches { ok = true, output = "", error = "Requires a Command Computer.\n" }
|
||||
end)
|
||||
|
||||
it("displays its usage when given no argument", function()
|
||||
stub(_G, "commands", {})
|
||||
expect(capture(stub, "/rom/programs/command/exec.lua"))
|
||||
:matches { ok = true, output = "", error = "Usage: /rom/programs/command/exec.lua <command>\n" }
|
||||
end)
|
||||
|
||||
it("runs a command", function()
|
||||
stub(_G, "commands", {
|
||||
exec = function() return true, { "Hello World!" } end,
|
||||
})
|
||||
|
||||
expect(capture(stub, "/rom/programs/command/exec.lua computercraft"))
|
||||
:matches { ok = true, output = "Success\nHello World!\n", error = "" }
|
||||
end)
|
||||
|
||||
it("reports command failures", function()
|
||||
stub(_G, "commands", {
|
||||
exec = function() return false, { "Hello World!" } end,
|
||||
})
|
||||
|
||||
expect(capture(stub, "/rom/programs/command/exec.lua computercraft"))
|
||||
:matches { ok = true, output = "Hello World!\n", error = "Failed\n" }
|
||||
end)
|
||||
end)
|
40
src/test/resources/test-rom/spec/programs/copy_spec.lua
Normal file
40
src/test/resources/test-rom/spec/programs/copy_spec.lua
Normal file
@ -0,0 +1,40 @@
|
||||
local capture = require "test_helpers".capture_program
|
||||
|
||||
describe("The copy program", function()
|
||||
local function touch(file)
|
||||
io.open(file, "w"):close()
|
||||
end
|
||||
|
||||
it("copies a file", function()
|
||||
touch("/test-files/copy/a.txt")
|
||||
|
||||
shell.run("copy /test-files/copy/a.txt /test-files/copy/b.txt")
|
||||
|
||||
expect(fs.exists("/test-files/copy/a.txt")):eq(true)
|
||||
expect(fs.exists("/test-files/copy/b.txt")):eq(true)
|
||||
end)
|
||||
|
||||
it("fails when copying a non-existent file", function()
|
||||
expect(capture(stub, "copy nothing destination"))
|
||||
:matches { ok = true, output = "", error = "No matching files\n" }
|
||||
end)
|
||||
|
||||
it("fails when overwriting an existing file", function()
|
||||
touch("/test-files/copy/c.txt")
|
||||
|
||||
expect(capture(stub, "copy /test-files/copy/c.txt /test-files/copy/c.txt"))
|
||||
:matches { ok = true, output = "", error = "Destination exists\n" }
|
||||
end)
|
||||
|
||||
it("fails when copying into read-only locations", function()
|
||||
touch("/test-files/copy/d.txt")
|
||||
|
||||
expect(capture(stub, "copy /test-files/copy/d.txt /rom/test.txt"))
|
||||
:matches { ok = true, output = "", error = "Destination is read-only\n" }
|
||||
end)
|
||||
|
||||
it("displays the usage when given no arguments", function()
|
||||
expect(capture(stub, "copy"))
|
||||
:matches { ok = true, output = "Usage: copy <source> <destination>\n", error = "" }
|
||||
end)
|
||||
end)
|
74
src/test/resources/test-rom/spec/programs/move_spec.lua
Normal file
74
src/test/resources/test-rom/spec/programs/move_spec.lua
Normal file
@ -0,0 +1,74 @@
|
||||
local capture = require "test_helpers".capture_program
|
||||
|
||||
describe("The move program", function()
|
||||
local function cleanup() fs.delete("/test-files/move") end
|
||||
local function touch(file)
|
||||
io.open(file, "w"):close()
|
||||
end
|
||||
|
||||
it("move a file", function()
|
||||
cleanup()
|
||||
touch("/test-files/move/a.txt")
|
||||
|
||||
shell.run("move /test-files/move/a.txt /test-files/move/b.txt")
|
||||
|
||||
expect(fs.exists("/test-files/move/a.txt")):eq(false)
|
||||
expect(fs.exists("/test-files/move/b.txt")):eq(true)
|
||||
end)
|
||||
|
||||
it("moves a file to a directory", function()
|
||||
cleanup()
|
||||
touch("/test-files/move/a.txt")
|
||||
fs.makeDir("/test-files/move/a")
|
||||
|
||||
expect(capture(stub, "move /test-files/move/a.txt /test-files/move/a"))
|
||||
:matches { ok = true }
|
||||
|
||||
expect(fs.exists("/test-files/move/a.txt")):eq(false)
|
||||
expect(fs.exists("/test-files/move/a/a.txt")):eq(true)
|
||||
end)
|
||||
|
||||
it("fails when moving a file which doesn't exist", function()
|
||||
expect(capture(stub, "move nothing destination"))
|
||||
:matches { ok = true, output = "", error = "No matching files\n" }
|
||||
end)
|
||||
|
||||
it("fails when overwriting an existing file", function()
|
||||
cleanup()
|
||||
touch("/test-files/move/a.txt")
|
||||
|
||||
expect(capture(stub, "move /test-files/move/a.txt /test-files/move/a.txt"))
|
||||
:matches { ok = true, output = "", error = "Destination exists\n" }
|
||||
end)
|
||||
|
||||
it("fails when moving to read-only locations", function()
|
||||
cleanup()
|
||||
touch("/test-files/move/a.txt")
|
||||
|
||||
expect(capture(stub, "move /test-files/move/a.txt /rom/test.txt"))
|
||||
:matches { ok = true, output = "", error = "Destination is read-only\n" }
|
||||
end)
|
||||
|
||||
it("fails when moving from read-only locations", function()
|
||||
expect(capture(stub, "move /rom/startup.lua /test-files/move/not-exist.txt"))
|
||||
:matches { ok = true, output = "", error = "Cannot move read-only file /rom/startup.lua\n" }
|
||||
end)
|
||||
|
||||
it("fails when moving mounts", function()
|
||||
expect(capture(stub, "move /rom /test-files/move/rom"))
|
||||
:matches { ok = true, output = "", error = "Cannot move mount /rom\n" }
|
||||
end)
|
||||
|
||||
it("fails when moving a file multiple times", function()
|
||||
cleanup()
|
||||
touch("/test-files/move/a.txt")
|
||||
touch("/test-files/move/b.txt")
|
||||
expect(capture(stub, "move /test-files/move/*.txt /test-files/move/c.txt"))
|
||||
:matches { ok = true, output = "", error = "Cannot overwrite file multiple times\n" }
|
||||
end)
|
||||
|
||||
it("displays the usage with no arguments", function()
|
||||
expect(capture(stub, "move"))
|
||||
:matches { ok = true, output = "Usage: move <source> <destination>\n", error = "" }
|
||||
end)
|
||||
end)
|
@ -0,0 +1,69 @@
|
||||
local capture = require "test_helpers".capture_program
|
||||
|
||||
describe("The craft program", function()
|
||||
it("errors when not a turtle", function()
|
||||
stub(_G, "turtle", nil)
|
||||
|
||||
expect(capture(stub, "/rom/programs/turtle/craft.lua"))
|
||||
:matches { ok = true, output = "", error = "Requires a Turtle\n" }
|
||||
end)
|
||||
|
||||
it("fails when turtle.craft() is unavailable", function()
|
||||
stub(_G, "turtle", {})
|
||||
|
||||
expect(capture(stub, "/rom/programs/turtle/craft.lua"))
|
||||
:matches { ok = true, output = "Requires a Crafty Turtle\n", error = "" }
|
||||
end)
|
||||
|
||||
it("displays its usage when given no arguments", function()
|
||||
stub(_G, "turtle", { craft = function() end })
|
||||
|
||||
expect(capture(stub, "/rom/programs/turtle/craft.lua"))
|
||||
:matches { ok = true, output = "Usage: /rom/programs/turtle/craft.lua [number]\n", error = "" }
|
||||
end)
|
||||
|
||||
it("crafts multiple items", function()
|
||||
local item_count = 3
|
||||
stub(_G, "turtle", {
|
||||
craft = function()
|
||||
item_count = 1
|
||||
return true
|
||||
end,
|
||||
getItemCount = function() return item_count end,
|
||||
getSelectedSlot = function() return 1 end,
|
||||
})
|
||||
|
||||
expect(capture(stub, "/rom/programs/turtle/craft.lua 2"))
|
||||
:matches { ok = true, output = "2 items crafted\n", error = "" }
|
||||
end)
|
||||
|
||||
it("craft a single item", function()
|
||||
local item_count = 2
|
||||
stub(_G, "turtle", {
|
||||
craft = function()
|
||||
item_count = 1
|
||||
return true
|
||||
end,
|
||||
getItemCount = function() return item_count end,
|
||||
getSelectedSlot = function() return 1 end,
|
||||
})
|
||||
|
||||
expect(capture(stub, "/rom/programs/turtle/craft.lua 1"))
|
||||
:matches { ok = true, output = "1 item crafted\n", error = "" }
|
||||
end)
|
||||
|
||||
it("crafts no items", function()
|
||||
local item_count = 2
|
||||
stub(_G, "turtle", {
|
||||
craft = function()
|
||||
item_count = 1
|
||||
return false
|
||||
end,
|
||||
getItemCount = function() return item_count end,
|
||||
getSelectedSlot = function() return 1 end,
|
||||
})
|
||||
|
||||
expect(capture(stub, "/rom/programs/turtle/craft.lua 1"))
|
||||
:matches { ok = true, output = "No items crafted\n", error = "" }
|
||||
end)
|
||||
end)
|
@ -0,0 +1,89 @@
|
||||
local capture = require "test_helpers".capture_program
|
||||
|
||||
describe("The turtle equip program", function()
|
||||
it("errors when not a turtle", function()
|
||||
stub(_G, "turtle", nil)
|
||||
|
||||
expect(capture(stub, "/rom/programs/turtle/equip.lua"))
|
||||
:matches { ok = true, output = "", error = "Requires a Turtle\n" }
|
||||
end)
|
||||
|
||||
|
||||
it("displays its usage when given no arguments", function()
|
||||
stub(_G, "turtle", {})
|
||||
|
||||
expect(capture(stub, "/rom/programs/turtle/equip.lua"))
|
||||
:matches { ok = true, output = "Usage: /rom/programs/turtle/equip.lua <slot> <side>\n", error = "" }
|
||||
end)
|
||||
|
||||
it("equip nothing", function()
|
||||
stub(_G, "turtle", {
|
||||
select = function() end,
|
||||
getItemCount = function() return 0 end,
|
||||
})
|
||||
|
||||
expect(capture(stub, "/rom/programs/turtle/equip.lua 1 left"))
|
||||
:matches { ok = true, output = "Nothing to equip\n", error = "" }
|
||||
expect(capture(stub, "/rom/programs/turtle/equip.lua 1 right"))
|
||||
:matches { ok = true, output = "Nothing to equip\n", error = "" }
|
||||
end)
|
||||
|
||||
it("swaps existing upgrades", function()
|
||||
stub(_G, "turtle", {
|
||||
select = function() end,
|
||||
getItemCount = function() return 1 end,
|
||||
equipLeft = function() return true end,
|
||||
equipRight = function() return true end,
|
||||
})
|
||||
|
||||
expect(capture(stub, "/rom/programs/turtle/equip.lua 1 left"))
|
||||
:matches { ok = true, output = "Items swapped\n", error = "" }
|
||||
expect(capture(stub, "/rom/programs/turtle/equip.lua 1 right"))
|
||||
:matches { ok = true, output = "Items swapped\n", error = "" }
|
||||
end)
|
||||
|
||||
describe("equips a new upgrade", function()
|
||||
local function setup()
|
||||
local item_count = 1
|
||||
stub(_G, "turtle", {
|
||||
select = function() end,
|
||||
getItemCount = function() return item_count end,
|
||||
equipLeft = function()
|
||||
item_count = 0
|
||||
return true
|
||||
end,
|
||||
equipRight = function()
|
||||
item_count = 0
|
||||
return true
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
it("on the left", function()
|
||||
setup()
|
||||
expect(capture(stub, "/rom/programs/turtle/equip.lua 1 left"))
|
||||
:matches { ok = true, output = "Item equipped\n", error = "" }
|
||||
end)
|
||||
|
||||
it("on the right", function()
|
||||
setup()
|
||||
expect(capture(stub, "/rom/programs/turtle/equip.lua 1 right"))
|
||||
:matches { ok = true, output = "Item equipped\n", error = "" }
|
||||
end)
|
||||
end)
|
||||
|
||||
it("handles when an upgrade cannot be equipped", function()
|
||||
stub(_G, "turtle", {
|
||||
select = function() end,
|
||||
getItemCount = function() return 1 end,
|
||||
equipLeft = function() return false end,
|
||||
equipRight = function() return false end,
|
||||
})
|
||||
|
||||
expect(capture(stub, "/rom/programs/turtle/equip.lua 1 left"))
|
||||
:matches { ok = true, output = "Item not equippable\n", error = "" }
|
||||
expect(capture(stub, "/rom/programs/turtle/equip.lua 1 right"))
|
||||
:matches { ok = true, output = "Item not equippable\n", error = "" }
|
||||
end)
|
||||
|
||||
end)
|
@ -0,0 +1,62 @@
|
||||
local capture = require "test_helpers".capture_program
|
||||
|
||||
describe("The refuel program", function()
|
||||
local function setup_turtle(fuel_level, fuel_limit, item_count)
|
||||
stub(_G, "turtle", {
|
||||
getFuelLevel = function()
|
||||
return fuel_level
|
||||
end,
|
||||
getItemCount = function()
|
||||
return item_count
|
||||
end,
|
||||
refuel = function(nLimit)
|
||||
item_count = item_count - nLimit
|
||||
fuel_level = fuel_level + nLimit
|
||||
end,
|
||||
select = function()
|
||||
end,
|
||||
getFuelLimit = function()
|
||||
return fuel_limit
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
it("errors when not a turtle", function()
|
||||
stub(_G, "turtle", nil)
|
||||
|
||||
expect(capture(stub, "/rom/programs/turtle/refuel.lua"))
|
||||
:matches { ok = true, output = "", error = "Requires a Turtle\n" }
|
||||
end)
|
||||
|
||||
|
||||
it("displays its usage when given too many argument", function()
|
||||
setup_turtle(0, 5, 0)
|
||||
expect(capture(stub, "/rom/programs/turtle/refuel.lua a b"))
|
||||
:matches { ok = true, output = "Usage: /rom/programs/turtle/refuel.lua [number]\n", error = "" }
|
||||
end)
|
||||
|
||||
it("requires a numeric argument", function()
|
||||
setup_turtle(0, 0, 0)
|
||||
expect(capture(stub, "/rom/programs/turtle/refuel.lua nothing"))
|
||||
:matches { ok = true, output = "Invalid limit, expected a number or \"all\"\n", error = "" }
|
||||
end)
|
||||
|
||||
it("refuels the turtle", function()
|
||||
setup_turtle(0, 10, 5)
|
||||
|
||||
expect(capture(stub, "/rom/programs/turtle/refuel.lua 5"))
|
||||
:matches { ok = true, output = "Fuel level is 5\n", error = "" }
|
||||
end)
|
||||
|
||||
it("reports when the fuel limit is reached", function()
|
||||
setup_turtle(0, 5, 5)
|
||||
expect(capture(stub, "/rom/programs/turtle/refuel.lua 5"))
|
||||
:matches { ok = true, output = "Fuel level is 5\nFuel limit reached\n", error = "" }
|
||||
end)
|
||||
|
||||
it("reports when the fuel level is unlimited", function()
|
||||
setup_turtle("unlimited", 5, 5)
|
||||
expect(capture(stub, "/rom/programs/turtle/refuel.lua 5"))
|
||||
:matches { ok = true, output = "Fuel level is unlimited\n", error = "" }
|
||||
end)
|
||||
end)
|
@ -0,0 +1,69 @@
|
||||
local capture = require "test_helpers".capture_program
|
||||
|
||||
describe("The turtle unequip program", function()
|
||||
it("errors when not a turtle", function()
|
||||
stub(_G, "turtle", nil)
|
||||
|
||||
expect(capture(stub, "/rom/programs/turtle/unequip.lua"))
|
||||
:matches { ok = true, output = "", error = "Requires a Turtle\n" }
|
||||
end)
|
||||
|
||||
|
||||
it("displays its usage when given no arguments", function()
|
||||
stub(_G, "turtle", {})
|
||||
|
||||
expect(capture(stub, "/rom/programs/turtle/unequip.lua"))
|
||||
:matches { ok = true, output = "Usage: /rom/programs/turtle/unequip.lua <side>\n", error = "" }
|
||||
end)
|
||||
|
||||
it("says when nothing was unequipped", function()
|
||||
stub(_G, "turtle", {
|
||||
select = function() end,
|
||||
getItemCount = function() return 0 end,
|
||||
equipRight = function() return true end,
|
||||
equipLeft = function() return true end,
|
||||
})
|
||||
|
||||
expect(capture(stub, "/rom/programs/turtle/unequip.lua left"))
|
||||
:matches { ok = true, output = "Nothing to unequip\n", error = "" }
|
||||
expect(capture(stub, "/rom/programs/turtle/unequip.lua right"))
|
||||
:matches { ok = true, output = "Nothing to unequip\n", error = "" }
|
||||
end)
|
||||
|
||||
it("unequips a upgrade", function()
|
||||
local item_count = 0
|
||||
stub(_G, "turtle", {
|
||||
select = function() end,
|
||||
getItemCount = function() return item_count end,
|
||||
equipRight = function()
|
||||
item_count = 1
|
||||
return true
|
||||
end,
|
||||
equipLeft = function()
|
||||
item_count = 1
|
||||
return true
|
||||
end,
|
||||
})
|
||||
|
||||
expect(capture(stub, "/rom/programs/turtle/unequip.lua left"))
|
||||
:matches { ok = true, output = "Item unequipped\n", error = "" }
|
||||
item_count = 0
|
||||
expect(capture(stub, "/rom/programs/turtle/unequip.lua right"))
|
||||
:matches { ok = true, output = "Item unequipped\n", error = "" }
|
||||
end)
|
||||
|
||||
it("fails when the turtle is full", function()
|
||||
stub(_G, "turtle", {
|
||||
select = function() end,
|
||||
getItemCount = function() return 1 end,
|
||||
equipRight = function() return true end,
|
||||
equipLeft = function() return true end,
|
||||
})
|
||||
|
||||
expect(capture(stub, "/rom/programs/turtle/unequip.lua left"))
|
||||
:matches { ok = true, output = "No space to unequip item\n", error = "" }
|
||||
expect(capture(stub, "/rom/programs/turtle/unequip.lua right"))
|
||||
:matches { ok = true, output = "No space to unequip item\n", error = "" }
|
||||
end)
|
||||
|
||||
end)
|
Loading…
x
Reference in New Issue
Block a user