Windows copy function no longer uses /E when used on a file

* Added some basic tests to ensure combinations work
* Fixes: #124
This commit is contained in:
Sam Surtees 2015-08-26 23:47:43 +10:00
parent b44a08ee55
commit 0f3972c914
2 changed files with 58 additions and 6 deletions

View File

@ -497,7 +497,15 @@
return "chdir " .. path.translate(v) return "chdir " .. path.translate(v)
end, end,
copy = function(v) copy = function(v)
return "xcopy /Q /E /Y /I " .. path.translate(v) .. " > nul" v = path.translate(v)
-- Detect if there's multiple parts to the input, if there is grab the first part else grab the whole thing
local src = string.match(v, '^".-"') or string.match(v, '^.- ') or v
-- Strip the trailing space from the second condition so that we don't have a space between src and '\\NUL'
src = string.match(src, '^.*%S')
return "IF EXIST " .. src .. "\\ (xcopy /Q /E /Y /I " .. v .. " > nul) ELSE (xcopy /Q /Y /I " .. v .. " > nul)"
end, end,
delete = function(v) delete = function(v)
return "del " .. path.translate(v) return "del " .. path.translate(v)

View File

@ -176,3 +176,47 @@
} }
test.isequal("test a b", os.translateCommands("{COPY} a b", "test")) test.isequal("test a b", os.translateCommands("{COPY} a b", "test"))
end end
--
-- os.translateCommand() windows COPY tests
--
function suite.translateCommand_windowsCopyNoDst()
test.isequal('IF EXIST a\\ (xcopy /Q /E /Y /I a > nul) ELSE (xcopy /Q /Y /I a > nul)', os.translateCommands('{COPY} a', "windows"))
end
function suite.translateCommand_windowsCopyNoDst_ExtraSpace()
test.isequal('IF EXIST a\\ (xcopy /Q /E /Y /I a > nul) ELSE (xcopy /Q /Y /I a > nul)', os.translateCommands('{COPY} a ', "windows"))
end
function suite.translateCommand_windowsCopyNoQuotes()
test.isequal('IF EXIST a\\ (xcopy /Q /E /Y /I a b > nul) ELSE (xcopy /Q /Y /I a b > nul)', os.translateCommands('{COPY} a b', "windows"))
end
function suite.translateCommand_windowsCopyNoQuotes_ExtraSpace()
test.isequal('IF EXIST a\\ (xcopy /Q /E /Y /I a b > nul) ELSE (xcopy /Q /Y /I a b > nul)', os.translateCommands('{COPY} a b ', "windows"))
end
function suite.translateCommand_windowsCopyQuotes()
test.isequal('IF EXIST "a a"\\ (xcopy /Q /E /Y /I "a a" "b" > nul) ELSE (xcopy /Q /Y /I "a a" "b" > nul)', os.translateCommands('{COPY} "a a" "b"', "windows"))
end
function suite.translateCommand_windowsCopyQuotes_ExtraSpace()
test.isequal('IF EXIST "a a"\\ (xcopy /Q /E /Y /I "a a" "b" > nul) ELSE (xcopy /Q /Y /I "a a" "b" > nul)', os.translateCommands('{COPY} "a a" "b" ', "windows"))
end
function suite.translateCommand_windowsCopyNoQuotesDst()
test.isequal('IF EXIST "a a"\\ (xcopy /Q /E /Y /I "a a" b > nul) ELSE (xcopy /Q /Y /I "a a" b > nul)', os.translateCommands('{COPY} "a a" b', "windows"))
end
function suite.translateCommand_windowsCopyNoQuotesDst_ExtraSpace()
test.isequal('IF EXIST "a a"\\ (xcopy /Q /E /Y /I "a a" b > nul) ELSE (xcopy /Q /Y /I "a a" b > nul)', os.translateCommands('{COPY} "a a" b ', "windows"))
end
function suite.translateCommand_windowsCopyNoQuotesSrc()
test.isequal('IF EXIST a\\ (xcopy /Q /E /Y /I a "b" > nul) ELSE (xcopy /Q /Y /I a "b" > nul)', os.translateCommands('{COPY} a "b"', "windows"))
end
function suite.translateCommand_windowsCopyNoQuotesSrc_ExtraSpace()
test.isequal('IF EXIST a\\ (xcopy /Q /E /Y /I a "b" > nul) ELSE (xcopy /Q /Y /I a "b" > nul)', os.translateCommands('{COPY} a "b" ', "windows"))
end