|
| 1 | +/* |
| 2 | + * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 3 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 3 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 3 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | +package com.oracle.truffle.r.test.builtins; |
| 24 | + |
| 25 | +import org.junit.Test; |
| 26 | + |
| 27 | +import com.oracle.truffle.r.test.TestBase; |
| 28 | + |
| 29 | +// Checkstyle: stop line length check |
| 30 | +public class TestBuiltin_filecopy extends TestBase { |
| 31 | + |
| 32 | + @Test |
| 33 | + public void testfilecopy() { |
| 34 | + // Copy file into existing destination dir |
| 35 | + assertEval("baseD<-paste0(tempdir(), '/file.copy.test'); nameF<-'/srcFile.txt'; srcF<-paste0(baseD, nameF); dstD<-paste0(baseD, '/dst'); dstF<-paste0(dstD, nameF); " + |
| 36 | + "tryCatch({dir.create(dstD, rec=TRUE); cat('Hello\\n', file=srcF); print(file.copy(from=srcF, to=dstD)); print(readLines(dstF)) }, finally=unlink(baseD, recursive=TRUE))"); |
| 37 | + // Copy file into destination dir where target file exists (overwrite=FALSE => original file |
| 38 | + // retained) |
| 39 | + assertEval("baseD<-paste0(tempdir(), '/file.copy.test'); nameF<-'/srcFile.txt'; srcF<-paste0(baseD, nameF); dstD<-paste0(baseD, '/dst'); dstF<-paste0(dstD, nameF); " + |
| 40 | + "tryCatch({dir.create(dstD, rec=TRUE); cat('New\\n', file=srcF); cat('Old\\n', file=dstF); print(file.copy(from=srcF, to=dstD)); print(readLines(dstF)) }, finally=unlink(baseD, recursive=TRUE))"); |
| 41 | + // Copy file into destination dir where target file exists (overwrite=TRUE => original file |
| 42 | + // overwritten) |
| 43 | + assertEval("baseD<-paste0(tempdir(), '/file.copy.test'); nameF<-'/srcFile.txt'; srcF<-paste0(baseD, nameF); dstD<-paste0(baseD, '/dst'); dstF<-paste0(dstD, nameF); " + |
| 44 | + "tryCatch({dir.create(dstD, rec=TRUE); cat('New\\n', file=srcF); cat('Old\\n', file=dstF); print(file.copy(from=srcF, to=dstD, overwrite=TRUE)); print(readLines(dstF)) }, finally=unlink(baseD, recursive=TRUE))"); |
| 45 | + // Copy src dir with a file into existing destination dir - no recursive flag |
| 46 | + assertEval("baseD<-paste0(tempdir(), '/file.copy.test'); nameF<-'/srcFile.txt'; srcD<-paste0(baseD, '/src'); srcF<-paste0(srcD, nameF); dstD<-paste0(baseD, '/dst'); dstF<-paste0(dstD, nameF); " + |
| 47 | + "tryCatch({dir.create(dstD, rec=TRUE); dir.create(srcD, rec=TRUE); cat('Hello\\n', file=srcF); print(file.copy(from=srcD, to=dstD)); print(file.exists(dstF)) }, finally=unlink(baseD, recursive=TRUE))"); |
| 48 | + // Copy src dir with a file into existing destination dir - recursive flag |
| 49 | + assertEval("baseD<-paste0(tempdir(), '/file.copy.test'); nameF<-'/srcFile.txt'; srcD<-paste0(baseD, '/src'); srcF<-paste0(srcD, nameF); dstD<-paste0(baseD, '/dst'); dstSrcD<-paste0(dstD, '/src'); dstSrcF<-paste0(dstSrcD, nameF); " + |
| 50 | + "tryCatch({dir.create(dstD, rec=TRUE); dir.create(srcD, rec=TRUE); cat('Hello\\n', file=srcF); print(file.copy(from=srcD, to=dstD, rec=TRUE)); print(file.exists(dstSrcD)); print(readLines(dstSrcF)); }, finally=unlink(baseD, recursive=TRUE))"); |
| 51 | + // Copy src dir with a file into destination dir - recursive flag and no overwrite flag |
| 52 | + assertEval("baseD<-paste0(tempdir(), '/file.copy.test'); nameF<-'/srcFile.txt'; srcD<-paste0(baseD, '/src'); srcF<-paste0(srcD, nameF); dstD<-paste0(baseD, '/dst'); dstF<-paste0(dstD, '/src', nameF); " + |
| 53 | + "tryCatch({dir.create(paste0(dstD, '/src'), rec=TRUE); dir.create(srcD, rec=TRUE); cat('New\\n', file=srcF); cat('Old\\n', file=dstF); print(file.copy(from=srcD, to=dstD, recursive=TRUE, overwrite=FALSE)); print(readLines(dstF)); }, finally=unlink(baseD, recursive=TRUE))"); |
| 54 | + // Copy src dir with a file into destination dir - recursive flag and no overwrite flag; one |
| 55 | + // file exists at the destination another not |
| 56 | + assertEval("baseD<-paste0(tempdir(), '/file.copy.test'); nameF<-'/srcFile.txt'; srcD<-paste0(baseD, '/src'); srcF<-paste0(srcD, nameF); srcF2<-paste0(srcD, nameF, '2'); dstD<-paste0(baseD, '/dst'); dstF<-paste0(dstD, '/src', nameF); dstF2<-paste0(dstD, '/src', nameF, '2');" + |
| 57 | + "tryCatch({dir.create(paste0(dstD, '/src'), rec=TRUE); dir.create(srcD, rec=TRUE); cat('New\\n', file=srcF); cat('New2\\n', file=srcF2); cat('Old\\n', file=dstF); print(file.copy(from=srcD, to=dstD, recursive=TRUE, overwrite=FALSE)); print(readLines(dstF)); print(readLines(dstF2)) }, finally=unlink(baseD, recursive=TRUE))"); |
| 58 | + // Copy src dir with a file into destination dir (overwrite=FALSE => original file retained) |
| 59 | + assertEval("baseD<-paste0(tempdir(), '/file.copy.test'); nameF<-'/srcFile.txt'; srcD<-paste0(baseD, '/src'); srcF<-paste0(srcD, nameF); dstD<-paste0(baseD, '/dst'); dstF<-paste0(dstD, '/src', nameF); " + |
| 60 | + "tryCatch({dir.create(paste0(dstD, '/src'), rec=TRUE); dir.create(srcD, rec=TRUE); cat('New\\n', file=srcF); cat('Old\\n', file=dstF); print(file.copy(from=srcD, to=dstD, recursive=TRUE, overwrite=TRUE)); print(readLines(dstF)) }, finally=unlink(baseD, recursive=TRUE))"); |
| 61 | + // Copy src dir with a file into destination dir (overwrite=TRUE => original file |
| 62 | + // overwritten) |
| 63 | + } |
| 64 | + |
| 65 | +} |
0 commit comments