aboutsummaryrefslogtreecommitdiff
path: root/tests/test/script
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test/script')
-rw-r--r--tests/test/script/builtin/buildfile2
-rw-r--r--tests/test/script/builtin/cp.test306
2 files changed, 307 insertions, 1 deletions
diff --git a/tests/test/script/builtin/buildfile b/tests/test/script/builtin/buildfile
index 2a57c54..f72688d 100644
--- a/tests/test/script/builtin/buildfile
+++ b/tests/test/script/builtin/buildfile
@@ -2,4 +2,4 @@
# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
# license : MIT; see accompanying LICENSE file
-./: test{cat echo mkdir rm rmdir sed test touch} $b
+./: test{cat cp echo mkdir rm rmdir sed test touch} $b
diff --git a/tests/test/script/builtin/cp.test b/tests/test/script/builtin/cp.test
new file mode 100644
index 0000000..4709459
--- /dev/null
+++ b/tests/test/script/builtin/cp.test
@@ -0,0 +1,306 @@
+# file : tests/test/script/builtin/cp.test
+# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+.include ../common.test
+
+: args
+:
+{
+ : none
+ :
+ $c <'cp 2>"cp: missing arguments" == 1' && $b
+
+ : no-source
+ :
+ $c <'cp -R a 2>"cp: missing source path" == 1' && $b
+
+ : no-trailing-sep
+ :
+ $c <<EOI && $b
+ cp a b c 2>"cp: multiple source paths without trailing separator for destination directory" == 1
+ EOI
+
+ : empty
+ :
+ {
+ : dest
+ :
+ $c <<EOI && $b
+ cp '' 2>"cp: invalid path ''" == 1
+ EOI
+
+ : src1
+ :
+ $c <<EOI && $b
+ cp '' a 2>"cp: invalid path ''" == 1
+ EOI
+
+ : src2
+ :
+ $c <<EOI && $b
+ cp '' a b/ 2>"cp: invalid path ''" == 1
+ EOI
+ }
+}
+
+: file
+:
+: Test synopsis 1: make a file copy at the specified path.
+:
+{
+ : existing
+ :
+ {
+ : to-non-existing
+ :
+ $c <<EOI && $b
+ touch a;
+ cp a b && test -f b
+ EOI
+
+ : to-existing
+ :
+ $c <<EOI && $b
+ touch a b;
+ cp a b
+ EOI
+
+ : to-dir
+ :
+ $c <<EOI && $b
+ touch a;
+ mkdir b;
+ cp a b 2>>/~%EOE% != 0
+ %cp: unable to copy file '.+/a' to '.+/b': .+%
+ EOE
+ EOI
+ }
+
+ : non-existing
+ :
+ {
+ $c <<EOI && $b
+ cp a b 2>>/~%EOE% != 0
+ %cp: unable to copy file '.+/a' to '.+/b': .+%
+ EOE
+ EOI
+ }
+
+ : non-file
+ :
+ {
+ $c <<EOI && $b
+ mkdir a;
+ cp a b 2>>/~%EOE% != 0
+ %cp: unable to copy file '.+/a' to '.+/b': .+%
+ EOE
+ EOI
+ }
+
+ : cleanup
+ :
+ {
+ : existing
+ :
+ : Test that copy over an existing file doesn't register cleanup. If it does
+ : then the file would be removed while leaving the embedded scope, and so
+ : the cleanup registered by the outer touch would fail.
+ :
+ $c <<EOI && $b
+ +touch b
+ {
+ touch a;
+ cp a ../b
+ }
+ EOI
+ }
+}
+
+: dir
+:
+: Test synopsis 2: make a directory copy at the specified path.
+:
+{
+ : existing
+ :
+ {
+ : to-non-existing
+ :
+ $c <<EOI && $b
+ mkdir a;
+ cp -r a b && test -d b
+ EOI
+
+ : to-existing
+ :
+ $c <<EOI && $b
+ mkdir a b;
+ cp -R a b 2>>/~%EOE% != 0
+ %cp: unable to copy directory '.+/a' to '.+/b': .+%
+ EOE
+ EOI
+
+ : to-file
+ :
+ $c <<EOI && $b
+ mkdir a;
+ touch b;
+ cp -r a b 2>>/~%EOE% != 0
+ %cp: unable to copy directory '.+/a' to '.+/b': .+%
+ EOE
+ EOI
+
+ : recursively
+ :
+ {
+ $c <<EOI && $b
+ mkdir -p a/b/c;
+ touch a/x a/b/y;
+ cp -r a d && test -d d/b/c && test -f d/x && test -f d/b/y
+ EOI
+ }
+ }
+
+ : non-existing
+ :
+ {
+ $c <<EOI && $b
+ cp -r a b 2>>/~%EOE% != 0
+ %cp: unable to copy directory '.+/a' to '.+/b': .+%
+ EOE
+ EOI
+ }
+
+ : non-dir
+ :
+ {
+ $c <<EOI && $b
+ touch a;
+ cp -r a b 2>>/~%EOE% != 0
+ %cp: unable to copy directory '.+/a' to '.+/b': .+%
+ EOE
+ EOI
+ }
+}
+
+: files
+:
+: Test synopsis 3: copy files into the specified directory.
+:
+{
+ : existing
+ :
+ {
+ : into-dir
+ :
+ {
+ : over-non-existing
+ :
+ $c <<EOI && $b
+ mkdir b;
+ touch a;
+ cp a b/ && test -f b/a
+ EOI
+
+ : over-dir
+ :
+ $c <<EOI && $b
+ mkdir -p b/a;
+ touch a;
+ cp a b/ 2>>/~%EOE% != 0
+ %cp: unable to copy file '.+/a' to '.+/b/a': .+%
+ EOE
+ EOI
+
+ : multiple
+ :
+ $c <<EOI && $b
+ touch a b;
+ mkdir c;
+ cp a b c/ && test -f c/a && test -f c/b
+ EOI
+ }
+
+ : into-non-existing-dir
+ :
+ {
+ $c <<EOI && $b
+ touch a;
+ cp a b/ 2>>/~%EOE% != 0
+ %cp: unable to copy file '.+/a' to '.+/b/a': .+%
+ EOE
+ EOI
+ }
+
+ : into-non-dir
+ :
+ {
+ $c <<EOI && $b
+ touch a b;
+ cp a b/ 2>>/~%EOE% != 0
+ %cp: unable to copy file '.+/a' to '.+/b/a': .+%
+ EOE
+ EOI
+ }
+ }
+
+ : non-existing
+ :
+ {
+ $c <<EOI && $b
+ mkdir b;
+ cp a b/ 2>>/~%EOE% != 0
+ %cp: unable to copy file '.+/a' to '.+/b/a': .+%
+ EOE
+ EOI
+ }
+
+ : non-file
+ :
+ {
+ $c <<EOI && $b
+ mkdir a b;
+ cp a b/ 2>>/~%EOE% != 0
+ %cp: unable to copy file '.+/a' to '.+/b/a': .+%
+ EOE
+ EOI
+ }
+}
+
+: filesystem-entries
+:
+: Test synopsis 4: copy filesystem entries into the specified directory.
+:
+{
+ : file
+ :
+ {
+ $c <<EOI && $b
+ mkdir b;
+ touch a;
+ cp -R a b/ && test -f b/a
+ EOI
+ }
+
+ : dir
+ :
+ {
+ : over-non-existing
+ :
+ $c <<EOI && $b
+ mkdir a b;
+ touch a/c;
+ cp -R a b/ && test -f b/a/c
+ EOI
+
+ : over-existing
+ :
+ $c <<EOI && $b
+ mkdir -p a b/a;
+ cp -R a b/ 2>>/~%EOE% != 0
+ %cp: unable to copy directory '.+/a' to '.+/b/a': .+%
+ EOE
+ EOI
+ }
+}