mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-12 03:00:30 +00:00
Add Checks to copy.lua
This commit is contained in:
parent
309cbdb8be
commit
81daf82647
@ -15,6 +15,10 @@ if #tFiles > 0 then
|
|||||||
elseif #tFiles == 1 then
|
elseif #tFiles == 1 then
|
||||||
if fs.exists( sDest ) then
|
if fs.exists( sDest ) then
|
||||||
printError( "Destination exists" )
|
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
|
else
|
||||||
fs.copy( sFile, sDest )
|
fs.copy( sFile, sDest )
|
||||||
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: cp <source> <destination>\n", error = "" }
|
||||||
|
end)
|
||||||
|
end)
|
Loading…
Reference in New Issue
Block a user