1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-25 06:33:23 +00:00

Add Checks to copy.lua

This commit is contained in:
JakobDev 2019-06-10 15:59:24 +02:00 committed by SquidDev
parent 309cbdb8be
commit 81daf82647
2 changed files with 44 additions and 0 deletions

View File

@ -15,6 +15,10 @@ if #tFiles > 0 then
elseif #tFiles == 1 then
if fs.exists( sDest ) then
printError( "Destination exists" )
elseif fs.isReadOnly( sDest ) then
printError( "Destination is read-only" )
elseif fs.getFreeSpace( sDest ) < fs.getSize( sFile ) then
printError( "Not enough space" )
else
fs.copy( sFile, sDest )
end

View 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: cp <source> <destination>\n", error = "" }
end)
end)