diff options
Diffstat (limited to 'tests/test/script/builtin/cp.testscript')
-rw-r--r-- | tests/test/script/builtin/cp.testscript | 367 |
1 files changed, 45 insertions, 322 deletions
diff --git a/tests/test/script/builtin/cp.testscript b/tests/test/script/builtin/cp.testscript index 60497b1..802cfee 100644 --- a/tests/test/script/builtin/cp.testscript +++ b/tests/test/script/builtin/cp.testscript @@ -4,109 +4,29 @@ .include ../common.testscript -: unknown-option -: -$c <<EOI && $b -cp -u 2>"cp: unknown option '-u'" == 1 -EOI - -: 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 + : cleanup : { - : to-non-existing - : - $c <<EOI && $b - touch a; - cp a b && test -f b - EOI - - : to-existing + : enabled : $c <<EOI && $b - touch a b; - cp a b - EOI + touch a; + cp a b + EOI - : to-dir + : disabled : $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 - } + touch a; + cp --no-cleanup a b; + rm b + EOI - : cleanup - : - { : existing : : Test that copy over an existing file does not register cleanup. If it @@ -114,12 +34,12 @@ EOI : and so the cleanup registered by the outer touch would fail. : $c <<EOI && $b - +touch b - { - touch a; - cp a ../b - } - EOI + +touch b + { + touch a; + cp a ../b + } + EOI } } @@ -128,66 +48,22 @@ EOI : Test synopsis 2: make a directory copy at the specified path. : { - : existing + : cleanup : - { - : 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 + $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 + touch a/b; + cp -r a b EOI - } - : non-dir + : no-cleanup : - { - $c <<EOI && $b - touch a; - cp -r a b 2>>/~%EOE% != 0 - %cp: unable to copy directory '.+/a' to '.+/b': .+% - EOE + $c <<EOI && $b + mkdir a; + touch a/b; + cp --no-cleanup -r a b; + rm -r b EOI - } } : files @@ -195,83 +71,22 @@ EOI : Test synopsis 3: copy files into the specified directory. : { - : existing + : cleanup : - { - : 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 + $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 + cp a b c/ 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 + : no-cleanup : - { $c <<EOI && $b - mkdir a b; - cp a b/ 2>>/~%EOE% != 0 - %cp: unable to copy file '.+/a' to '.+/b/a': .+% - EOE - EOI - } + touch a b; + mkdir c; + cp --no-cleanup a b c/; + rm c/a c/b + EOI } : filesystem-entries @@ -279,112 +94,20 @@ EOI : Test synopsis 4: copy filesystem entries into the specified directory. : { - : file + : cleanup : - { - $c <<EOI && $b - mkdir b; - touch a; - cp -R a b/ && test -f b/a + $c <<EOI && $b + mkdir a b; + touch c a/c; + cp -R a c b/ EOI - } - : dir + : no-cleanup : - { - : over-non-existing - : - $c <<EOI && $b + $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 + touch c a/c; + cp --no-cleanup -R a c b/; + rm -r b/a/ b/c EOI - } -} - -: attrs -: -if ($cxx.target.class != 'windows') -{ - fs = 's/.+ (\S+\s+\S+\s+\S+)\s+cp-file/\1/p' - ds = 's/.+ (\S+\s+\S+\s+\S+)\s+cp-dir/\1/p' - - : copy - : - { - : file - : - { - $c <<"EOI" && $b - ls -l $src_base/cp-dir | sed -n -e '$fs' | \ - set t; - - cp -p $src_base/cp-dir/cp-file ./; - ls -l | sed -n -e '$fs' >"\$t" - EOI - } - - : dir - : - { - $c <<"EOI" && $b - ls -l $src_base | sed -n -e '$ds' | \ - set t; - - cp -pr $src_base/cp-dir ./; - ls -l | sed -n -e '$ds' >"\$t" - EOI - } - } - - : no-copy - : - { - : file - : - { - $c <<"EOI" && $b 2>>~%EOE% != 0 - ls -l $src_base/cp-dir | sed -n -e '$fs' | \ - set t; - - cp $src_base/cp-dir/cp-file ./; - ls -l | sed -n -e '$fs' >"\$t" - EOI - %.+ error: sed stdout doesn't match expected% - %.+ - EOE - } - - : dir - : - : Note that the `ls -l` command by default displays the filesystem entry - : modification time with the minute resolution and the build2 dist - : meta-operation (involved when we fetch from the git repository - : location) doesn't preserve the directory modification time. That's why - : we also pass --full-time and enable the test for only platforms where ls - : supports this option. - : - if ($cxx.target.class == 'linux') - { - $c <<"EOI" && $b 2>>~%EOE% != 0 - ls -l --full-time $src_base | sed -n -e '$ds' | \ - set t; - - cp -r $src_base/cp-dir ./; - ls -l --full-time | sed -n -e '$ds' >"\$t" - EOI - %.+ error: sed stdout doesn't match expected% - %.+ - EOE - } - } } |