From 7335a892b5742f7879a4ca07f059cd7b8136aa3a Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Tue, 24 Jan 2023 18:27:30 +0000 Subject: [PATCH] Expose test methods to required libraries This allows us to use stub everywhere, rather than having to pass it around as an argument. --- .../core/ComputerTestDelegate.java | 6 +++- .../src/test/resources/test-rom/mcfly.lua | 30 +++++++++---------- .../spec/programs/advanced/bg_spec.lua | 2 +- .../spec/programs/advanced/fg_spec.lua | 2 +- .../test-rom/spec/programs/alias_spec.lua | 8 ++--- .../test-rom/spec/programs/cd_spec.lua | 6 ++-- .../test-rom/spec/programs/clear_spec.lua | 2 +- .../spec/programs/command/commands_spec.lua | 4 +-- .../spec/programs/command/exec_spec.lua | 8 ++--- .../test-rom/spec/programs/copy_spec.lua | 8 ++--- .../test-rom/spec/programs/delete_spec.lua | 8 ++--- .../test-rom/spec/programs/drive_spec.lua | 4 +-- .../test-rom/spec/programs/edit_spec.lua | 2 +- .../test-rom/spec/programs/eject_spec.lua | 4 +-- .../test-rom/spec/programs/exit_spec.lua | 2 +- .../spec/programs/fun/advanced/paint_spec.lua | 2 +- .../test-rom/spec/programs/fun/dj_spec.lua | 4 +-- .../test-rom/spec/programs/fun/hello_spec.lua | 2 +- .../test-rom/spec/programs/gps_spec.lua | 6 ++-- .../test-rom/spec/programs/help_spec.lua | 2 +- .../spec/programs/http/pastebin_spec.lua | 10 +++---- .../test-rom/spec/programs/http/wget_spec.lua | 12 ++++---- .../test-rom/spec/programs/id_spec.lua | 2 +- .../test-rom/spec/programs/label_spec.lua | 10 +++---- .../test-rom/spec/programs/list_spec.lua | 6 ++-- .../test-rom/spec/programs/monitor_spec.lua | 10 +++---- .../test-rom/spec/programs/motd_spec.lua | 10 +++---- .../test-rom/spec/programs/move_spec.lua | 16 +++++----- .../spec/programs/peripherals_spec.lua | 2 +- .../spec/programs/pocket/equip_spec.lua | 6 ++-- .../spec/programs/pocket/unequip_spec.lua | 6 ++-- .../test-rom/spec/programs/programs_spec.lua | 2 +- .../test-rom/spec/programs/reboot_spec.lua | 2 +- .../test-rom/spec/programs/redstone_spec.lua | 2 +- .../test-rom/spec/programs/rename_spec.lua | 12 ++++---- .../test-rom/spec/programs/set_spec.lua | 14 ++++----- .../test-rom/spec/programs/shutdown_spec.lua | 2 +- .../test-rom/spec/programs/time_spec.lua | 2 +- .../spec/programs/turtle/craft_spec.lua | 16 +++++----- .../spec/programs/turtle/equip_spec.lua | 20 ++++++------- .../spec/programs/turtle/refuel_spec.lua | 12 ++++---- .../spec/programs/turtle/unequip_spec.lua | 16 +++++----- .../test-rom/spec/programs/type_spec.lua | 8 ++--- .../resources/test-rom/spec/test_helpers.lua | 2 +- 44 files changed, 158 insertions(+), 154 deletions(-) diff --git a/projects/core/src/test/java/dan200/computercraft/core/ComputerTestDelegate.java b/projects/core/src/test/java/dan200/computercraft/core/ComputerTestDelegate.java index a4ae43457..323115d04 100644 --- a/projects/core/src/test/java/dan200/computercraft/core/ComputerTestDelegate.java +++ b/projects/core/src/test/java/dan200/computercraft/core/ComputerTestDelegate.java @@ -213,7 +213,11 @@ DynamicNodeBuilder get(String name) { void runs(String name, String uri, Executable executor) { if (this.executor != null) throw new IllegalStateException(name + " is leaf node"); - if (children.containsKey(name)) throw new IllegalStateException("Duplicate key for " + name); + if (children.containsKey(name)) { + var i = 1; + while (children.containsKey(name + i)) i++; + name = name + i; + } children.put(name, new DynamicNodeBuilder(name, uri, executor)); } diff --git a/projects/core/src/test/resources/test-rom/mcfly.lua b/projects/core/src/test/resources/test-rom/mcfly.lua index ab4019102..9eb79875a 100644 --- a/projects/core/src/test/resources/test-rom/mcfly.lua +++ b/projects/core/src/test/resources/test-rom/mcfly.lua @@ -182,8 +182,12 @@ end -- @treturn string The formatted value local function format(value) -- TODO: Look into something like mbs's pretty printer. - local ok, res = pcall(textutils.serialise, value) - if ok then return res else return tostring(value) end + if type(value) == "string" and value:find("\n") then + return "<<<\n" .. value .. "\n>>>" + else + local ok, res = pcall(textutils.serialise, value) + if ok then return res else return tostring(value) end + end end local expect_mt = {} @@ -513,6 +517,7 @@ end local function before_each(body) check('it', 1, 'function', body) + if tests_locked then error("Cannot define before_each while running tests", 2) end local n = before_each_fns.n + 1 before_each_fns[n], before_each_fns.n = body, n @@ -560,16 +565,11 @@ end package.path = ("/%s/?.lua;/%s/?/init.lua;%s"):format(root_dir, root_dir, package.path) do - -- Load in the tests from all our files - local env = setmetatable({}, { __index = _ENV }) - - local function set_env(tbl) - for k in pairs(env) do env[k] = nil end - for k, v in pairs(tbl) do env[k] = v end - end - - -- When declaring tests, you shouldn't be able to use test methods - set_env { describe = describe, it = it, pending = pending, before_each = before_each } + -- Add our new functions to the current environment. + for k, v in pairs { + describe = describe, it = it, pending = pending, before_each = before_each, + expect = expect, fail = fail, + } do _ENV[k] = v end local suffix = "_spec.lua" local function run_in(sub_dir) @@ -578,7 +578,7 @@ do if fs.isDir(file) then run_in(file) elseif file:sub(-#suffix) == suffix then - local fun, err = loadfile(file, nil, env) + local fun, err = loadfile(file, nil, _ENV) if not fun then do_test { name = file:sub(#root_dir + 2), error = { message = err } } else @@ -591,8 +591,8 @@ do run_in(root_dir) - -- When running tests, you shouldn't be able to declare new ones. - set_env { expect = expect, fail = fail, stub = stub } + -- Add stub later on, so its not available when running tests + _ENV.stub = stub end -- Error if we've found no tests diff --git a/projects/core/src/test/resources/test-rom/spec/programs/advanced/bg_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/advanced/bg_spec.lua index a53dc2f2d..0a8ff77f4 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/advanced/bg_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/advanced/bg_spec.lua @@ -4,7 +4,7 @@ describe("The bg program", function() it("opens a tab in the background", function() local openTab = stub(shell, "openTab", function() return 12 end) local switchTab = stub(shell, "switchTab") - capture(stub, "bg") + capture("bg") expect(openTab):called_with("shell") expect(switchTab):called(0) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/advanced/fg_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/advanced/fg_spec.lua index 8e5cc4f26..de842ede4 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/advanced/fg_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/advanced/fg_spec.lua @@ -4,7 +4,7 @@ describe("The fg program", function() it("opens the shell in the foreground", function() local openTab = stub(shell, "openTab", function() return 12 end) local switchTab = stub(shell, "switchTab") - capture(stub, "fg") + capture("fg") expect(openTab):called_with("shell") expect(switchTab):called_with(12) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/alias_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/alias_spec.lua index 95a2c2556..37a1ae5e6 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/alias_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/alias_spec.lua @@ -2,27 +2,27 @@ local capture = require "test_helpers".capture_program describe("The alias program", function() it("displays its usage when given too many arguments", function() - expect(capture(stub, "alias a b c")) + expect(capture("alias a b c")) :matches { ok = true, output = "Usage: alias \n", error = "" } end) it("lists aliases", function() local pagedTabulate = stub(textutils, "pagedTabulate", function(x) print(table.unpack(x)) end) stub(shell, "aliases", function() return { cp = "copy" } end) - expect(capture(stub, "alias")) + expect(capture("alias")) :matches { ok = true, output = "cp:copy\n", error = "" } expect(pagedTabulate):called_with_matching({ "cp:copy" }) end) it("sets an alias", function() local setAlias = stub(shell, "setAlias") - capture(stub, "alias test Hello") + capture("alias test Hello") expect(setAlias):called_with("test", "Hello") end) it("clears an alias", function() local clearAlias = stub(shell, "clearAlias") - capture(stub, "alias test") + capture("alias test") expect(clearAlias):called_with("test") end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/cd_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/cd_spec.lua index 348d62944..2a8713b05 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/cd_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/cd_spec.lua @@ -3,17 +3,17 @@ local capture = require "test_helpers".capture_program describe("The cd program", function() it("changes into a directory", function() local setDir = stub(shell, "setDir") - capture(stub, "cd /rom/programs") + capture("cd /rom/programs") expect(setDir):called_with("rom/programs") end) it("does not move into a non-existent directory", function() - expect(capture(stub, "cd /rom/nothing")) + expect(capture("cd /rom/nothing")) :matches { ok = true, output = "Not a directory\n", error = "" } end) it("displays the usage when given no arguments", function() - expect(capture(stub, "cd")) + expect(capture("cd")) :matches { ok = true, output = "Usage: cd \n", error = "" } end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/clear_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/clear_spec.lua index f339c83ce..0255bcaa7 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/clear_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/clear_spec.lua @@ -5,7 +5,7 @@ describe("The clear program", function() local clear = stub(term, "clear") local setCursorPos = stub(term, "setCursorPos") - capture(stub, "clear") + capture("clear") expect(clear):called(1) expect(setCursorPos):called_with(1, 1) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/command/commands_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/command/commands_spec.lua index 6c9d87cdc..82056b450 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/command/commands_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/command/commands_spec.lua @@ -3,7 +3,7 @@ local capture = require "test_helpers".capture_program describe("The commands program", function() it("displays an error without the commands api", function() stub(_G, "commands", nil) - expect(capture(stub, "/rom/programs/command/commands.lua")) + expect(capture("/rom/programs/command/commands.lua")) :matches { ok = true, output = "", error = "Requires a Command Computer.\n" } end) @@ -13,7 +13,7 @@ describe("The commands program", function() list = function() return { "computercraft" } end, }) - expect(capture(stub, "/rom/programs/command/commands.lua")) + expect(capture("/rom/programs/command/commands.lua")) :matches { ok = true, output = "Available commands:\ncomputercraft\n", error = "" } expect(pagedTabulate):called_with_matching({ "computercraft" }) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/command/exec_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/command/exec_spec.lua index f5eecd3d3..ef8eb8763 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/command/exec_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/command/exec_spec.lua @@ -3,13 +3,13 @@ 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")) + expect(capture("/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")) + expect(capture("/rom/programs/command/exec.lua")) :matches { ok = true, output = "", error = "Usage: /rom/programs/command/exec.lua \n" } end) @@ -18,7 +18,7 @@ describe("The exec program", function() exec = function() return true, { "Hello World!" } end, }) - expect(capture(stub, "/rom/programs/command/exec.lua computercraft")) + expect(capture("/rom/programs/command/exec.lua computercraft")) :matches { ok = true, output = "Success\nHello World!\n", error = "" } end) @@ -27,7 +27,7 @@ describe("The exec program", function() exec = function() return false, { "Hello World!" } end, }) - expect(capture(stub, "/rom/programs/command/exec.lua computercraft")) + expect(capture("/rom/programs/command/exec.lua computercraft")) :matches { ok = true, output = "Hello World!\n", error = "Failed\n" } end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/copy_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/copy_spec.lua index 5bcdda8b0..791752a53 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/copy_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/copy_spec.lua @@ -15,26 +15,26 @@ describe("The copy program", function() end) it("fails when copying a non-existent file", function() - expect(capture(stub, "copy nothing destination")) + expect(capture("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")) + expect(capture("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")) + expect(capture("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")) + expect(capture("copy")) :matches { ok = true, output = "Usage: copy \n", error = "" } end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/delete_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/delete_spec.lua index 18a01c5c0..450aa9fc9 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/delete_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/delete_spec.lua @@ -36,17 +36,17 @@ describe("The rm program", function() end) it("displays the usage with no arguments", function() - expect(capture(stub, "rm")) + expect(capture("rm")) :matches { ok = true, output = "Usage: rm \n", error = "" } end) it("errors when trying to delete a read-only file", function() - expect(capture(stub, "rm /rom/startup.lua")) + expect(capture("rm /rom/startup.lua")) :matches { ok = true, output = "", error = "Cannot delete read-only file /rom/startup.lua\n" } end) it("errors when trying to delete the root mount", function() - expect(capture(stub, "rm /")):matches { + expect(capture("rm /")):matches { ok = true, output = "To delete its contents run rm /*\n", error = "Cannot delete mount /\n", @@ -54,7 +54,7 @@ describe("The rm program", function() end) it("errors when a glob fails to match", function() - expect(capture(stub, "rm", "never-existed")) + expect(capture("rm", "never-existed")) :matches { ok = true, output = "", error = "never-existed: No matching files\n" } end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/drive_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/drive_spec.lua index d175a60f7..d0c2fa819 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/drive_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/drive_spec.lua @@ -4,13 +4,13 @@ describe("The drive program", function() it("run the program", function() local getFreeSpace = stub(fs, "getFreeSpace", function() return 1234e4 end) - expect(capture(stub, "drive")) + expect(capture("drive")) :matches { ok = true, output = "hdd (12.3MB remaining)\n", error = "" } expect(getFreeSpace):called(1):called_with("") end) it("fails on a non-existent path", function() - expect(capture(stub, "drive /rom/nothing")) + expect(capture("drive /rom/nothing")) :matches { ok = true, output = "No such path\n", error = "" } end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/edit_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/edit_spec.lua index e58938e23..21f0eb2ce 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/edit_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/edit_spec.lua @@ -3,7 +3,7 @@ local capture = require "test_helpers".capture_program describe("The edit program", function() it("displays its usage when given no argument", function() - expect(capture(stub, "edit")) + expect(capture("edit")) :matches { ok = true, output = "Usage: edit \n", error = "" } end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/eject_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/eject_spec.lua index e524a8625..74c71073b 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/eject_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/eject_spec.lua @@ -2,12 +2,12 @@ local capture = require "test_helpers".capture_program describe("The eject program", function() it("displays its usage when given no argument", function() - expect(capture(stub, "eject")) + expect(capture("eject")) :matches { ok = true, output = "Usage: eject \n", error = "" } end) it("fails when trying to eject a non-drive", function() - expect(capture(stub, "eject /rom")) + expect(capture("eject /rom")) :matches { ok = true, output = "Nothing in /rom drive\n", error = "" } end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/exit_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/exit_spec.lua index 301461087..7d6419b58 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/exit_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/exit_spec.lua @@ -3,7 +3,7 @@ local capture = require "test_helpers".capture_program describe("The exit program", function() it("exits the shell", function() local exit = stub(shell, "exit") - expect(capture(stub, "exit")):matches { ok = true, combined = "" } + expect(capture("exit")):matches { ok = true, combined = "" } expect(exit):called(1) end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/fun/advanced/paint_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/fun/advanced/paint_spec.lua index 086404add..72bfb76b9 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/fun/advanced/paint_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/fun/advanced/paint_spec.lua @@ -2,7 +2,7 @@ local capture = require "test_helpers".capture_program describe("The paint program", function() it("displays its usage when given no arguments", function() - expect(capture(stub, "paint")) + expect(capture("paint")) :matches { ok = true, output = "Usage: paint \n", error = "" } end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/fun/dj_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/fun/dj_spec.lua index 4464d4e8c..e15b81753 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/fun/dj_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/fun/dj_spec.lua @@ -2,12 +2,12 @@ local capture = require "test_helpers".capture_program describe("The dj program", function() it("displays its usage when given too many arguments", function() - expect(capture(stub, "dj a b c")) + expect(capture("dj a b c")) :matches { ok = true, output = "Usages:\ndj play\ndj play \ndj stop\n", error = "" } end) it("fails when no disks are present", function() - expect(capture(stub, "dj")) + expect(capture("dj")) :matches { ok = true, output = "No Music Discs in attached disk drives\n", error = "" } end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/fun/hello_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/fun/hello_spec.lua index 25db085bc..10e2c2f2e 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/fun/hello_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/fun/hello_spec.lua @@ -3,7 +3,7 @@ local capture = require "test_helpers".capture_program describe("The hello program", function() it("says hello", function() local slowPrint = stub(textutils, "slowPrint", function(...) return print(...) end) - expect(capture(stub, "hello")) + expect(capture("hello")) :matches { ok = true, output = "Hello World!\n", error = "" } expect(slowPrint):called(1) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/gps_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/gps_spec.lua index 245f259c9..5bafdd065 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/gps_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/gps_spec.lua @@ -2,21 +2,21 @@ local capture = require "test_helpers".capture_program describe("The gps program", function() it("displays its usage when given no arguments", function() - expect(capture(stub, "gps")) + expect(capture("gps")) :matches { ok = true, output = "Usages:\ngps host\ngps host \ngps locate\n", error = "" } end) it("fails on a pocket computer", function() stub(_G, "pocket", {}) - expect(capture(stub, "gps host")) + expect(capture("gps host")) :matches { ok = true, output = "GPS Hosts must be stationary\n", error = "" } end) it("can locate the computer", function() local locate = stub(gps, "locate", function() print("Some debugging information.") end) - expect(capture(stub, "gps locate")) + expect(capture("gps locate")) :matches { ok = true, output = "Some debugging information.\n", error = "" } expect(locate):called_with(2, true) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/help_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/help_spec.lua index 9ce15a102..87195dcaa 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/help_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/help_spec.lua @@ -20,7 +20,7 @@ describe("The help program", function() end it("errors when there is no such help file", function() - expect(capture(stub, "help nothing")) + expect(capture("help nothing")) :matches { ok = true, error = "No help available\n", output = "" } end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/http/pastebin_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/http/pastebin_spec.lua index 192ba7007..8b3611e3c 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/http/pastebin_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/http/pastebin_spec.lua @@ -34,7 +34,7 @@ describe("The pastebin program", function() it("downloads one file", function() setup_request() - capture(stub, "pastebin", "get", "abcde", "testdown") + capture("pastebin", "get", "abcde", "testdown") expect(fs.exists("/testdown")):eq(true) end) @@ -42,7 +42,7 @@ describe("The pastebin program", function() it("runs a program from the internet", function() setup_request() - expect(capture(stub, "pastebin", "run", "abcde", "a", "b", "c")) + expect(capture("pastebin", "run", "abcde", "a", "b", "c")) :matches { ok = true, output = "Connecting to pastebin.com... Success.\nHello a b c\n", error = "" } end) @@ -52,21 +52,21 @@ describe("The pastebin program", function() local file = fs.open("testup", "w") file.close() - expect(capture(stub, "pastebin", "put", "testup")) + expect(capture("pastebin", "put", "testup")) :matches { ok = true, output = "Connecting to pastebin.com... Success.\nUploaded as https://pastebin.com/abcde\nRun \"pastebin get abcde\" to download anywhere\n", error = "" } end) it("upload a not existing program to pastebin", function() setup_request() - expect(capture(stub, "pastebin", "put", "nothing")) + expect(capture("pastebin", "put", "nothing")) :matches { ok = true, output = "No such file\n", error = "" } end) it("displays its usage when given no arguments", function() setup_request() - expect(capture(stub, "pastebin")) + expect(capture("pastebin")) :matches { ok = true, output = "Usages:\npastebin put \npastebin get \npastebin run \n", error = "" } end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/http/wget_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/http/wget_spec.lua index c4b28dc53..693970010 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/http/wget_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/http/wget_spec.lua @@ -23,7 +23,7 @@ describe("The wget program", function() fs.delete("/example.com") setup_request(default_contents) - capture(stub, "wget", "https://example.com") + capture("wget", "https://example.com") expect(fs.exists("/example.com")):eq(true) end) @@ -32,7 +32,7 @@ describe("The wget program", function() fs.delete("/test-files/download") setup_request(default_contents) - capture(stub, "wget", "https://example.com /test-files/download") + capture("wget", "https://example.com /test-files/download") expect(fs.exists("/test-files/download")):eq(true) end) @@ -41,7 +41,7 @@ describe("The wget program", function() fs.delete("/test-files/download") setup_request(nil) - capture(stub, "wget", "https://example.com", "/test-files/download") + capture("wget", "https://example.com", "/test-files/download") expect(fs.exists("/test-files/download")):eq(true) expect(fs.getSize("/test-files/download")):eq(0) @@ -50,7 +50,7 @@ describe("The wget program", function() it("cannot save to rom", function() setup_request(default_contents) - expect(capture(stub, "wget", "https://example.com", "/rom/a-file.txt")):matches { + expect(capture("wget", "https://example.com", "/rom/a-file.txt")):matches { ok = true, output = "Connecting to https://example.com... Success.\n", error = "Cannot save file: /rom/a-file.txt: Access denied\n", @@ -60,14 +60,14 @@ describe("The wget program", function() it("runs a program from the internet", function() setup_request(default_contents) - expect(capture(stub, "wget", "run", "http://test.com", "a", "b", "c")) + expect(capture("wget", "run", "http://test.com", "a", "b", "c")) :matches { ok = true, output = "Connecting to http://test.com... Success.\nHello a b c\n", error = "" } end) it("displays its usage when given no arguments", function() setup_request(default_contents) - expect(capture(stub, "wget")) + expect(capture("wget")) :matches { ok = true, output = "Usage:\nwget [filename]\nwget run \n", error = "" } end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/id_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/id_spec.lua index 7c5d47da7..05b1bd52b 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/id_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/id_spec.lua @@ -5,7 +5,7 @@ describe("The id program", function() it("displays computer id", function() local id = os.getComputerID() - expect(capture(stub, "id")) + expect(capture("id")) :matches { ok = true, output = "This is computer #" .. id .. "\n", error = "" } end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/label_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/label_spec.lua index 5762f8fbe..f1dd2bcce 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/label_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/label_spec.lua @@ -2,33 +2,33 @@ local capture = require "test_helpers".capture_program describe("The label program", function() it("displays its usage when given no arguments", function() - expect(capture(stub, "label")) + expect(capture("label")) :matches { ok = true, output = "Usages:\nlabel get\nlabel get \nlabel set \nlabel set \nlabel clear\nlabel clear \n", error = "" } end) describe("displays the computer's label", function() it("when it is not labelled", function() stub(os, "getComputerLabel", function() return nil end) - expect(capture(stub, "label get")) + expect(capture("label get")) :matches { ok = true, output = "No Computer label\n", error = "" } end) it("when it is labelled", function() stub(os, "getComputerLabel", function() return "Test" end) - expect(capture(stub, "label get")) + expect(capture("label get")) :matches { ok = true, output = "Computer label is \"Test\"\n", error = "" } end) end) it("sets the computer's label", function() local setComputerLabel = stub(os, "setComputerLabel") - capture(stub, "label set Test") + capture("label set Test") expect(setComputerLabel):called_with("Test") end) it("clears the computer's label", function() local setComputerLabel = stub(os, "setComputerLabel") - capture(stub, "label clear") + capture("label clear") expect(setComputerLabel):called_with(nil) end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/list_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/list_spec.lua index f9f5f0b0b..08160e5ca 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/list_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/list_spec.lua @@ -3,7 +3,7 @@ local capture = require "test_helpers".capture_program describe("The list program", function() it("lists files", function() local pagedTabulate = stub(textutils, "pagedTabulate") - capture(stub, "list /rom") + capture("list /rom") expect(pagedTabulate):called_with_matching( colors.green, { "apis", "autorun", "help", "modules", "programs" }, colors.white, { "motd.txt", "startup.lua" } @@ -11,12 +11,12 @@ describe("The list program", function() end) it("fails on a non-existent directory", function() - expect(capture(stub, "list /rom/nothing")) + expect(capture("list /rom/nothing")) :matches { ok = true, output = "", error = "Not a directory\n" } end) it("fails on a file", function() - expect(capture(stub, "list /rom/startup.lua")) + expect(capture("list /rom/startup.lua")) :matches { ok = true, output = "", error = "Not a directory\n" } end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/monitor_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/monitor_spec.lua index ea7c8bbd7..718c5a129 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/monitor_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/monitor_spec.lua @@ -2,7 +2,7 @@ local capture = require "test_helpers".capture_program describe("The monitor program", function() it("displays its usage when given no arguments", function() - expect(capture(stub, "monitor")) + expect(capture("monitor")) :matches { ok = true, output = @@ -17,7 +17,7 @@ describe("The monitor program", function() local r = 1 stub(peripheral, "call", function(s, f, t) r = t end) stub(peripheral, "getType", function() return "monitor" end) - expect(capture(stub, "monitor", "scale", "left", "0.5")) + expect(capture("monitor", "scale", "left", "0.5")) :matches { ok = true, output = "", error = "" } expect(r):equals(0.5) end) @@ -26,7 +26,7 @@ describe("The monitor program", 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")) + expect(capture("monitor", "scale", "left")) :matches { ok = true, output = @@ -35,9 +35,9 @@ describe("The monitor program", function() " monitor scale \n", error = "", } - expect(capture(stub, "monitor", "scale", "top", "0.5")) + expect(capture("monitor", "scale", "top", "0.5")) :matches { ok = true, output = "No monitor named top\n", error = "" } - expect(capture(stub, "monitor", "scale", "left", "aaa")) + expect(capture("monitor", "scale", "left", "aaa")) :matches { ok = true, output = "Invalid scale: aaa\n", error = "" } expect(r):equals(1) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/motd_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/motd_spec.lua index 47fcfccd3..ef5383168 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/motd_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/motd_spec.lua @@ -12,31 +12,31 @@ describe("The motd program", function() file.close() settings.set("motd.path", "/motd_check.txt") - expect(capture(stub, "motd")) + expect(capture("motd")) :matches { ok = true, output = "Hello World!\n", error = "" } end) it("displays date-specific MOTD (1 Jan)", function() setup_date(1, 1) - expect(capture(stub, "motd")) + expect(capture("motd")) :matches { ok = true, output = "Happy new year!\n", error = "" } end) it("displays date-specific MOTD (28 Apr)", function() setup_date(28, 4) - expect(capture(stub, "motd")) + expect(capture("motd")) :matches { ok = true, output = "Ed Balls\n", error = "" } end) it("displays date-specific MOTD (31 Oct)", function() setup_date(31, 10) - expect(capture(stub, "motd")) + expect(capture("motd")) :matches { ok = true, output = "OOoooOOOoooo! Spooky!\n", error = "" } end) it("displays date-specific MOTD (24 Dec)", function() setup_date(24, 12) - expect(capture(stub, "motd")) + expect(capture("motd")) :matches { ok = true, output = "Merry X-mas!\n", error = "" } end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/move_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/move_spec.lua index dcc156362..3f562b81f 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/move_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/move_spec.lua @@ -21,7 +21,7 @@ describe("The move program", function() 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")) + expect(capture("move /test-files/move/a.txt /test-files/move/a")) :matches { ok = true } expect(fs.exists("/test-files/move/a.txt")):eq(false) @@ -29,7 +29,7 @@ describe("The move program", function() end) it("fails when moving a file which doesn't exist", function() - expect(capture(stub, "move nothing destination")) + expect(capture("move nothing destination")) :matches { ok = true, output = "", error = "No matching files\n" } end) @@ -37,7 +37,7 @@ describe("The move program", function() cleanup() touch("/test-files/move/a.txt") - expect(capture(stub, "move /test-files/move/a.txt /test-files/move/a.txt")) + expect(capture("move /test-files/move/a.txt /test-files/move/a.txt")) :matches { ok = true, output = "", error = "Destination exists\n" } end) @@ -45,17 +45,17 @@ describe("The move program", function() cleanup() touch("/test-files/move/a.txt") - expect(capture(stub, "move /test-files/move/a.txt /rom/test.txt")) + expect(capture("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")) + expect(capture("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")) + expect(capture("move /rom /test-files/move/rom")) :matches { ok = true, output = "", error = "Cannot move mount /rom\n" } end) @@ -63,12 +63,12 @@ describe("The move program", 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")) + expect(capture("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")) + expect(capture("move")) :matches { ok = true, output = "Usage: move \n", error = "" } end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/peripherals_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/peripherals_spec.lua index 68762e79f..338495448 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/peripherals_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/peripherals_spec.lua @@ -3,7 +3,7 @@ local capture = require "test_helpers".capture_program describe("The peripherals program", function() it("says when there are no peripherals", function() stub(peripheral, 'getNames', function() return {} end) - expect(capture(stub, "peripherals")) + expect(capture("peripherals")) :matches { ok = true, output = "Attached Peripherals:\nNone\n", error = "" } end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/pocket/equip_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/pocket/equip_spec.lua index 32144051b..d5c3feb6d 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/pocket/equip_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/pocket/equip_spec.lua @@ -3,7 +3,7 @@ local capture = require "test_helpers".capture_program describe("The pocket equip program", function() it("errors when not a pocket computer", function() stub(_G, "pocket", nil) - expect(capture(stub, "/rom/programs/pocket/equip.lua")) + expect(capture("/rom/programs/pocket/equip.lua")) :matches { ok = true, output = "", error = "Requires a Pocket Computer\n" } end) @@ -12,7 +12,7 @@ describe("The pocket equip program", function() equipBack = function() return true end, }) - expect(capture(stub, "/rom/programs/pocket/equip.lua")) + expect(capture("/rom/programs/pocket/equip.lua")) :matches { ok = true, output = "Item equipped\n", error = "" } end) @@ -21,7 +21,7 @@ describe("The pocket equip program", function() equipBack = function() return false, "Cannot equip this item." end, }) - expect(capture(stub, "/rom/programs/pocket/equip.lua")) + expect(capture("/rom/programs/pocket/equip.lua")) :matches { ok = true, output = "", error = "Cannot equip this item.\n" } end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/pocket/unequip_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/pocket/unequip_spec.lua index 9cb0f7481..4b4fa69f1 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/pocket/unequip_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/pocket/unequip_spec.lua @@ -3,7 +3,7 @@ local capture = require "test_helpers".capture_program describe("The pocket unequip program", function() it("errors when not a pocket computer", function() stub(_G, "pocket", nil) - expect(capture(stub, "/rom/programs/pocket/unequip.lua")) + expect(capture("/rom/programs/pocket/unequip.lua")) :matches { ok = true, output = "", error = "Requires a Pocket Computer\n" } end) @@ -12,7 +12,7 @@ describe("The pocket unequip program", function() unequipBack = function() return true end, }) - expect(capture(stub, "/rom/programs/pocket/unequip.lua")) + expect(capture("/rom/programs/pocket/unequip.lua")) :matches { ok = true, output = "Item unequipped\n", error = "" } end) @@ -21,7 +21,7 @@ describe("The pocket unequip program", function() unequipBack = function() return false, "Nothing to remove." end, }) - expect(capture(stub, "/rom/programs/pocket/unequip.lua")) + expect(capture("/rom/programs/pocket/unequip.lua")) :matches { ok = true, output = "", error = "Nothing to remove.\n" } end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/programs_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/programs_spec.lua index 8f19bc83e..d2205eafe 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/programs_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/programs_spec.lua @@ -5,7 +5,7 @@ describe("The programs program", function() local programs = stub(shell, "programs", function() return { "some", "programs" } end) local pagedTabulate = stub(textutils, "pagedTabulate", function(x) print(table.unpack(x)) end) - expect(capture(stub, "/rom/programs/programs.lua")) + expect(capture("/rom/programs/programs.lua")) :matches { ok = true, output = "some programs\n", error = "" } expect(programs):called_with(false) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/reboot_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/reboot_spec.lua index d2a877d9d..c1f4f83ef 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/reboot_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/reboot_spec.lua @@ -5,7 +5,7 @@ describe("The reboot program", function() local sleep = stub(_G, "sleep") local reboot = stub(os, "reboot") - expect(capture(stub, "reboot")) + expect(capture("reboot")) :matches { ok = true, output = "Goodbye\n", error = "" } expect(sleep):called_with(1) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/redstone_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/redstone_spec.lua index fc687ac7e..f64bb1c7c 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/redstone_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/redstone_spec.lua @@ -2,7 +2,7 @@ local capture = require "test_helpers".capture_program describe("The redstone program", function() it("displays its usage when given no arguments", function() - expect(capture(stub, "redstone")) + expect(capture("redstone")) :matches { ok = true, output = "Usages:\nredstone probe\nredstone set \nredstone set \nredstone pulse \n", error = "" } end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/rename_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/rename_spec.lua index 437e940d3..aa93df242 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/rename_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/rename_spec.lua @@ -15,36 +15,36 @@ describe("The rename program", function() end) it("fails when renaming a file which doesn't exist", function() - expect(capture(stub, "rename nothing destination")) + expect(capture("rename nothing destination")) :matches { ok = true, output = "", error = "No matching files\n" } end) it("fails when overwriting an existing file", function() touch("/test-files/rename/c.txt") - expect(capture(stub, "rename /test-files/rename/c.txt /test-files/rename/c.txt")) + expect(capture("rename /test-files/rename/c.txt /test-files/rename/c.txt")) :matches { ok = true, output = "", error = "Destination exists\n" } end) it("fails when renaming to read-only locations", function() touch("/test-files/rename/d.txt") - expect(capture(stub, "rename /test-files/rename/d.txt /rom/test.txt")) + expect(capture("rename /test-files/rename/d.txt /rom/test.txt")) :matches { ok = true, output = "", error = "Destination is read-only\n" } end) it("fails when renaming from read-only locations", function() - expect(capture(stub, "rename /rom/startup.lua /test-files/rename/d.txt")) + expect(capture("rename /rom/startup.lua /test-files/rename/d.txt")) :matches { ok = true, output = "", error = "Source is read-only\n" } end) it("fails when renaming mounts", function() - expect(capture(stub, "rename /rom /test-files/rename/rom")) + expect(capture("rename /rom /test-files/rename/rom")) :matches { ok = true, output = "", error = "Can't rename mounts\n" } end) it("displays the usage when given no arguments", function() - expect(capture(stub, "rename")) + expect(capture("rename")) :matches { ok = true, output = "Usage: rename \n", error = "" } end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/set_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/set_spec.lua index 8d74d951e..e0018752b 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/set_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/set_spec.lua @@ -13,21 +13,21 @@ describe("The set program", function() it("displays all settings", function() setup() - expect(capture(stub, "set")) + expect(capture("set")) :matches { ok = true, output = '"test" is "Hello World!"\n"test.defined" is 456\n', error = "" } end) it("displays a single setting", function() setup() - expect(capture(stub, "set test")) + expect(capture("set test")) :matches { ok = true, output = 'test is "Hello World!"\n', error = "" } end) it("displays a single setting with description", function() setup() - expect(capture(stub, "set test")) + expect(capture("set test")) :matches { ok = true, output = 'test is "Hello World!"\n', error = "" } end) @@ -35,14 +35,14 @@ describe("The set program", function() setup() settings.set("test.defined", 123) - expect(capture(stub, "set test.defined")) + expect(capture("set test.defined")) :matches { ok = true, output = 'test.defined is 123 (default is 456)\nA description\n', error = "" } end) it("set a setting", function() setup() - expect(capture(stub, "set test Hello")) + expect(capture("set test Hello")) :matches { ok = true, output = '"test" set to "Hello"\n', error = "" } expect(settings.get("test")):eq("Hello") @@ -51,9 +51,9 @@ describe("The set program", function() it("checks the type of a setting", function() setup() - expect(capture(stub, "set test.defined Hello")) + expect(capture("set test.defined Hello")) :matches { ok = true, output = "", error = '"Hello" is not a valid number.\n' } - expect(capture(stub, "set test.defined 456")) + expect(capture("set test.defined 456")) :matches { ok = true, output = '"test.defined" set to 456\n', error = "" } end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/shutdown_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/shutdown_spec.lua index 4cfa37ba1..693822974 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/shutdown_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/shutdown_spec.lua @@ -6,7 +6,7 @@ describe("The shutdown program", function() local sleep = stub(_G, "sleep") local shutdown = stub(os, "shutdown") - expect(capture(stub, "shutdown")) + expect(capture("shutdown")) :matches { ok = true, output = "Goodbye\n", error = "" } expect(sleep):called_with(1) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/time_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/time_spec.lua index 91f82fef0..c5dbc19a8 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/time_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/time_spec.lua @@ -6,7 +6,7 @@ describe("The time program", function() local time = textutils.formatTime(os.time()) local day = os.day() - expect(capture(stub, "time")) + expect(capture("time")) :matches { ok = true, output = "The time is " .. time .. " on Day " .. day .. "\n", error = "" } end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/turtle/craft_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/turtle/craft_spec.lua index 93e4c1bb9..c78c0d001 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/turtle/craft_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/turtle/craft_spec.lua @@ -4,28 +4,28 @@ describe("The craft program", function() it("errors when not a turtle", function() stub(_G, "turtle", nil) - expect(capture(stub, "/rom/programs/turtle/craft.lua")) + expect(capture("/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")) + expect(capture("/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")) + expect(capture("/rom/programs/turtle/craft.lua")) :matches { ok = true, output = "Usage: /rom/programs/turtle/craft.lua all|\n", error = "" } end) it("displays its usage when given incorrect arguments", function() stub(_G, "turtle", { craft = function() end }) - expect(capture(stub, "/rom/programs/turtle/craft.lua a")) + expect(capture("/rom/programs/turtle/craft.lua a")) :matches { ok = true, output = "Usage: /rom/programs/turtle/craft.lua all|\n", error = "" } end) @@ -40,7 +40,7 @@ describe("The craft program", function() getSelectedSlot = function() return 1 end, }) - expect(capture(stub, "/rom/programs/turtle/craft.lua 2")) + expect(capture("/rom/programs/turtle/craft.lua 2")) :matches { ok = true, output = "2 items crafted\n", error = "" } end) @@ -55,7 +55,7 @@ describe("The craft program", function() getSelectedSlot = function() return 1 end, }) - expect(capture(stub, "/rom/programs/turtle/craft.lua 1")) + expect(capture("/rom/programs/turtle/craft.lua 1")) :matches { ok = true, output = "1 item crafted\n", error = "" } end) @@ -70,7 +70,7 @@ describe("The craft program", function() getSelectedSlot = function() return 1 end, }) - expect(capture(stub, "/rom/programs/turtle/craft.lua 1")) + expect(capture("/rom/programs/turtle/craft.lua 1")) :matches { ok = true, output = "No items crafted\n", error = "" } end) @@ -83,7 +83,7 @@ describe("The craft program", function() getSelectedSlot = function() return 1 end, }) - expect(capture(stub, "/rom/programs/turtle/craft.lua all")) + expect(capture("/rom/programs/turtle/craft.lua all")) :matches { ok = true, output = "17 items crafted\n", error = "" } end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/turtle/equip_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/turtle/equip_spec.lua index 92f75b73c..22409388d 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/turtle/equip_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/turtle/equip_spec.lua @@ -4,7 +4,7 @@ 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")) + expect(capture("/rom/programs/turtle/equip.lua")) :matches { ok = true, output = "", error = "Requires a Turtle\n" } end) @@ -12,7 +12,7 @@ describe("The turtle equip program", function() it("displays its usage when given no arguments", function() stub(_G, "turtle", {}) - expect(capture(stub, "/rom/programs/turtle/equip.lua")) + expect(capture("/rom/programs/turtle/equip.lua")) :matches { ok = true, output = "Usage: /rom/programs/turtle/equip.lua \n", error = "" } end) @@ -22,9 +22,9 @@ describe("The turtle equip program", function() getItemCount = function() return 0 end, }) - expect(capture(stub, "/rom/programs/turtle/equip.lua 1 left")) + expect(capture("/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")) + expect(capture("/rom/programs/turtle/equip.lua 1 right")) :matches { ok = true, output = "Nothing to equip\n", error = "" } end) @@ -36,9 +36,9 @@ describe("The turtle equip program", function() equipRight = function() return true end, }) - expect(capture(stub, "/rom/programs/turtle/equip.lua 1 left")) + expect(capture("/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")) + expect(capture("/rom/programs/turtle/equip.lua 1 right")) :matches { ok = true, output = "Items swapped\n", error = "" } end) @@ -61,13 +61,13 @@ describe("The turtle equip program", function() it("on the left", function() setup() - expect(capture(stub, "/rom/programs/turtle/equip.lua 1 left")) + expect(capture("/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")) + expect(capture("/rom/programs/turtle/equip.lua 1 right")) :matches { ok = true, output = "Item equipped\n", error = "" } end) end) @@ -80,9 +80,9 @@ describe("The turtle equip program", function() equipRight = function() return false end, }) - expect(capture(stub, "/rom/programs/turtle/equip.lua 1 left")) + expect(capture("/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")) + expect(capture("/rom/programs/turtle/equip.lua 1 right")) :matches { ok = true, output = "Item not equippable\n", error = "" } end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/turtle/refuel_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/turtle/refuel_spec.lua index 485a66111..4b9bea761 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/turtle/refuel_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/turtle/refuel_spec.lua @@ -24,39 +24,39 @@ describe("The refuel program", function() it("errors when not a turtle", function() stub(_G, "turtle", nil) - expect(capture(stub, "/rom/programs/turtle/refuel.lua")) + expect(capture("/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")) + expect(capture("/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")) + expect(capture("/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")) + expect(capture("/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")) + expect(capture("/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")) + expect(capture("/rom/programs/turtle/refuel.lua 5")) :matches { ok = true, output = "Fuel level is unlimited\n", error = "" } end) end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/turtle/unequip_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/turtle/unequip_spec.lua index 1d81334f6..4afd68305 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/turtle/unequip_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/turtle/unequip_spec.lua @@ -4,7 +4,7 @@ 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")) + expect(capture("/rom/programs/turtle/unequip.lua")) :matches { ok = true, output = "", error = "Requires a Turtle\n" } end) @@ -12,7 +12,7 @@ describe("The turtle unequip program", function() it("displays its usage when given no arguments", function() stub(_G, "turtle", {}) - expect(capture(stub, "/rom/programs/turtle/unequip.lua")) + expect(capture("/rom/programs/turtle/unequip.lua")) :matches { ok = true, output = "Usage: /rom/programs/turtle/unequip.lua \n", error = "" } end) @@ -24,9 +24,9 @@ describe("The turtle unequip program", function() equipLeft = function() return true end, }) - expect(capture(stub, "/rom/programs/turtle/unequip.lua left")) + expect(capture("/rom/programs/turtle/unequip.lua left")) :matches { ok = true, output = "Nothing to unequip\n", error = "" } - expect(capture(stub, "/rom/programs/turtle/unequip.lua right")) + expect(capture("/rom/programs/turtle/unequip.lua right")) :matches { ok = true, output = "Nothing to unequip\n", error = "" } end) @@ -45,10 +45,10 @@ describe("The turtle unequip program", function() end, }) - expect(capture(stub, "/rom/programs/turtle/unequip.lua left")) + expect(capture("/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")) + expect(capture("/rom/programs/turtle/unequip.lua right")) :matches { ok = true, output = "Item unequipped\n", error = "" } end) @@ -60,9 +60,9 @@ describe("The turtle unequip program", function() equipLeft = function() return true end, }) - expect(capture(stub, "/rom/programs/turtle/unequip.lua left")) + expect(capture("/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")) + expect(capture("/rom/programs/turtle/unequip.lua right")) :matches { ok = true, output = "No space to unequip item\n", error = "" } end) diff --git a/projects/core/src/test/resources/test-rom/spec/programs/type_spec.lua b/projects/core/src/test/resources/test-rom/spec/programs/type_spec.lua index 09d59ee4a..3e9f962ed 100644 --- a/projects/core/src/test/resources/test-rom/spec/programs/type_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/programs/type_spec.lua @@ -3,22 +3,22 @@ local capture = require "test_helpers".capture_program describe("The type program", function() it("displays the usage with no arguments", function() - expect(capture(stub, "type")) + expect(capture("type")) :matches { ok = true, output = "Usage: type \n", error = "" } end) it("displays the output for a file", function() - expect(capture(stub, "type /rom/startup.lua")) + expect(capture("type /rom/startup.lua")) :matches { ok = true, output = "file\n", error = "" } end) it("displays the output for a directory", function() - expect(capture(stub, "type /rom")) + expect(capture("type /rom")) :matches { ok = true, output = "directory\n", error = "" } end) it("displays the output for a not existing path", function() - expect(capture(stub, "type /rom/nothing")) + expect(capture("type /rom/nothing")) :matches { ok = true, output = "No such path\n", error = "" } end) diff --git a/projects/core/src/test/resources/test-rom/spec/test_helpers.lua b/projects/core/src/test/resources/test-rom/spec/test_helpers.lua index 7ed9dcad6..7edc5ab05 100644 --- a/projects/core/src/test/resources/test-rom/spec/test_helpers.lua +++ b/projects/core/src/test/resources/test-rom/spec/test_helpers.lua @@ -5,7 +5,7 @@ -- @tparam string ... Arguments to this program. -- @treturn { ok = boolean, output = string, error = string, combined = string } -- Whether this program terminated successfully, and the various output streams. -local function capture_program(stub, program, ...) +local function capture_program(program, ...) local output, error, combined = {}, {}, {} local function out(stream, msg)