2019-06-03 19:33:09 +00:00
|
|
|
local capture = require "test_helpers".capture_program
|
|
|
|
|
2019-05-25 08:02:42 +00:00
|
|
|
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)
|
2019-06-03 19:33:09 +00:00
|
|
|
|
|
|
|
it("displays the usage with no arguments", function()
|
|
|
|
expect(capture(stub, "rm"))
|
|
|
|
:matches { ok = true, output = "Usage: rm <paths>\n", error = "" }
|
|
|
|
end)
|
2020-01-23 15:11:50 +00:00
|
|
|
|
2019-06-06 15:43:48 +00:00
|
|
|
it("errors when trying to delete a read-only file", function()
|
|
|
|
expect(capture(stub, "rm /rom/startup.lua"))
|
2020-05-12 10:32:48 +00:00
|
|
|
: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 {
|
|
|
|
ok = true,
|
|
|
|
output = "To delete its contents run rm /*\n",
|
|
|
|
error = "Cannot delete mount /\n",
|
|
|
|
}
|
2019-06-06 15:43:48 +00:00
|
|
|
end)
|
2019-06-03 19:33:09 +00:00
|
|
|
|
|
|
|
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)
|
2019-05-25 08:02:42 +00:00
|
|
|
end)
|