mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-06-25 22:53:22 +00:00
![SquidDev](/assets/img/avatar_default.png)
- Make mcfly's stubbing system a little more fault-tolerant. - Add a small utility function which redirects print, printError and write to capture their output, rather than printing to the terminal. This can then be matched against in order to determine a program's output. It's a little flakey - you can't use it multiple times in an it block, etc... but it's a nice feature. - Add a small couple of tests to delete as a proof-of-concept.
48 lines
1.4 KiB
Lua
48 lines
1.4 KiB
Lua
local capture = require "test_helpers".capture_program
|
|
|
|
describe("The rm program", function()
|
|
local function touch(file)
|
|
io.open(file, "w"):close()
|
|
end
|
|
|
|
it("deletes one file", function()
|
|
touch("/test-files/a.txt")
|
|
|
|
shell.run("rm /test-files/a.txt")
|
|
|
|
expect(fs.exists("/test-files/a.txt")):eq(false)
|
|
end)
|
|
|
|
it("deletes many files", function()
|
|
touch("/test-files/a.txt")
|
|
touch("/test-files/b.txt")
|
|
touch("/test-files/c.txt")
|
|
|
|
shell.run("rm /test-files/a.txt /test-files/b.txt")
|
|
|
|
expect(fs.exists("/test-files/a.txt")):eq(false)
|
|
expect(fs.exists("/test-files/b.txt")):eq(false)
|
|
expect(fs.exists("/test-files/c.txt")):eq(true)
|
|
end)
|
|
|
|
it("deletes a glob", function()
|
|
touch("/test-files/a.txt")
|
|
touch("/test-files/b.txt")
|
|
|
|
shell.run("rm /test-files/*.txt")
|
|
|
|
expect(fs.exists("/test-files/a.txt")):eq(false)
|
|
expect(fs.exists("/test-files/b.txt")):eq(false)
|
|
end)
|
|
|
|
it("displays the usage with no arguments", function()
|
|
expect(capture(stub, "rm"))
|
|
:matches { ok = true, output = "Usage: rm <paths>\n", error = "" }
|
|
end)
|
|
|
|
it("errors when a glob fails to match", function()
|
|
expect(capture(stub, "rm", "never-existed"))
|
|
:matches { ok = true, output = "", error = "never-existed: No matching files\n" }
|
|
end)
|
|
end)
|