diff --git a/tests/copytests/cases/test000.sh b/tests/copytests/cases/test000.sh new file mode 100755 index 000000000..e1665b121 --- /dev/null +++ b/tests/copytests/cases/test000.sh @@ -0,0 +1,12 @@ +# copy a file to one with a different name +# ensure that the original exists +set -e +cd "$HOME/testcp" +touch foo.txt + +wsh file copy foo.txt bar.txt + +if [ ! -f foo.txt ]; then + echo "foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test001.sh b/tests/copytests/cases/test001.sh new file mode 100755 index 000000000..78a8b67bf --- /dev/null +++ b/tests/copytests/cases/test001.sh @@ -0,0 +1,12 @@ +# copy a file to one with a different name +# ensure that the destination file exists +set -e +cd "$HOME/testcp" +touch foo.txt + +wsh file copy foo.txt bar.txt + +if [ ! -f bar.txt ]; then + echo "bar.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test002.sh b/tests/copytests/cases/test002.sh new file mode 100755 index 000000000..b4df0c36e --- /dev/null +++ b/tests/copytests/cases/test002.sh @@ -0,0 +1,18 @@ +# copy a file with contents +# ensure the contents are the same +set -e +cd "$HOME/testcp" +touch foo.txt +echo "The quick brown fox jumps over the lazy dog" > foo.txt + +wsh file copy foo.txt bar.txt + + +FOO_MD5=$(md5sum foo.txt | cut -d " " -f1) +BAR_MD5=$(md5sum bar.txt | cut -d " " -f1) +if [ $FOO_MD5 != $BAR_MD5 ]; then + echo "files are not the same" + echo "FOO_MD5 is $FOO_MD5" + echo "BAR_MD5 is $BAR_MD5" + exit 1 +fi diff --git a/tests/copytests/cases/test003.sh b/tests/copytests/cases/test003.sh new file mode 100755 index 000000000..c15357f3f --- /dev/null +++ b/tests/copytests/cases/test003.sh @@ -0,0 +1,12 @@ +# copy a file where source starts with ./ +# ensure the source file exists +set -e +cd "$HOME/testcp" +touch foo.txt + +wsh file copy ./foo.txt bar.txt + +if [ ! -f foo.txt ]; then + echo "foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test004.sh b/tests/copytests/cases/test004.sh new file mode 100755 index 000000000..791d7f8e2 --- /dev/null +++ b/tests/copytests/cases/test004.sh @@ -0,0 +1,12 @@ +# copy a file where source starts with ./ +# ensure the destination file exists +set -e +cd "$HOME/testcp" +touch foo.txt + +wsh file copy ./foo.txt bar.txt + +if [ ! -f bar.txt ]; then + echo "bar.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test005.sh b/tests/copytests/cases/test005.sh new file mode 100755 index 000000000..84e1ddb1e --- /dev/null +++ b/tests/copytests/cases/test005.sh @@ -0,0 +1,13 @@ +# copy a file where destination starts with ./ +# ensure the source file exists + +set -e +cd "$HOME/testcp" +touch foo.txt + +wsh file copy foo.txt ./bar.txt + +if [ ! -f foo.txt ]; then + echo "foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test006.sh b/tests/copytests/cases/test006.sh new file mode 100755 index 000000000..5522de491 --- /dev/null +++ b/tests/copytests/cases/test006.sh @@ -0,0 +1,13 @@ +# copy a file where destination starts with ./ +# ensure the destination file exists + +set -e +cd "$HOME/testcp" +touch foo.txt + +wsh file copy foo.txt ./bar.txt + +if [ ! -f bar.txt ]; then + echo "bar.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test007.sh b/tests/copytests/cases/test007.sh new file mode 100755 index 000000000..8a50db9fd --- /dev/null +++ b/tests/copytests/cases/test007.sh @@ -0,0 +1,13 @@ +# copy a file where source and destination start with ./ +# ensure the source file exists + +set -e +cd "$HOME/testcp" +touch foo.txt + +wsh file copy ./foo.txt ./bar.txt + +if [ ! -f foo.txt ]; then + echo "foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test008.sh b/tests/copytests/cases/test008.sh new file mode 100755 index 000000000..e4b4032f8 --- /dev/null +++ b/tests/copytests/cases/test008.sh @@ -0,0 +1,13 @@ +# copy a file where source and destination start with ./ +# ensure the destination file exists + +set -e +cd "$HOME/testcp" +touch foo.txt + +wsh file copy ./foo.txt ./bar.txt + +if [ ! -f bar.txt ]; then + echo "bar.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test009.sh b/tests/copytests/cases/test009.sh new file mode 100755 index 000000000..22251050e --- /dev/null +++ b/tests/copytests/cases/test009.sh @@ -0,0 +1,13 @@ +# copy a file to itself with the same literal name +# ensure the operation fails and the file still exists + +set -e +cd "$HOME/testcp" +touch foo.txt + +wsh file copy foo.txt foo.txt >/dev/null 2>&1 && echo "copy should have failed" && exit 1 + +if [ ! -f foo.txt ]; then + echo "foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test010.sh b/tests/copytests/cases/test010.sh new file mode 100755 index 000000000..c35841f59 --- /dev/null +++ b/tests/copytests/cases/test010.sh @@ -0,0 +1,13 @@ +# copy a file to itself with a different literal name +# ensure the copy fails and the file still exists + +set -e +cd "$HOME/testcp" +touch foo.txt + +wsh file copy foo.txt ./foo.txt >/dev/null 2>&1 && echo "copy should have failed" && exit 1 + +if [ ! -f foo.txt ]; then + echo "foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test011.sh b/tests/copytests/cases/test011.sh new file mode 100755 index 000000000..90768b774 --- /dev/null +++ b/tests/copytests/cases/test011.sh @@ -0,0 +1,13 @@ +# copy a file with ~ used to resolve the source +# ensure the source still exists + +set -e +cd "$HOME/testcp" +touch foo.txt + +wsh file copy ~/testcp/foo.txt bar.txt + +if [ ! -f foo.txt ]; then + echo "foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test012.sh b/tests/copytests/cases/test012.sh new file mode 100755 index 000000000..8397f199f --- /dev/null +++ b/tests/copytests/cases/test012.sh @@ -0,0 +1,13 @@ +# copy a file with ~ used to resolve the source +# ensure the destination exists + +set -e +cd "$HOME/testcp" +touch foo.txt + +wsh file copy ~/testcp/foo.txt bar.txt + +if [ ! -f bar.txt ]; then + echo "bar.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test013.sh b/tests/copytests/cases/test013.sh new file mode 100755 index 000000000..a51104c09 --- /dev/null +++ b/tests/copytests/cases/test013.sh @@ -0,0 +1,13 @@ +# copy a file with ~ used to resolve the destination +# ensure the source exists + +set -e +cd "$HOME/testcp" +touch foo.txt + +wsh file copy foo.txt ~/testcp/bar.txt + +if [ ! -f foo.txt ]; then + echo "foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test014.sh b/tests/copytests/cases/test014.sh new file mode 100755 index 000000000..929549772 --- /dev/null +++ b/tests/copytests/cases/test014.sh @@ -0,0 +1,13 @@ +# copy a file with ~ used to resolve the destination +# ensure the destination exists + +set -e +cd "$HOME/testcp" +touch foo.txt + +wsh file copy foo.txt ~/testcp/bar.txt + +if [ ! -f bar.txt ]; then + echo "bar.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test015.sh b/tests/copytests/cases/test015.sh new file mode 100755 index 000000000..aa9196fbf --- /dev/null +++ b/tests/copytests/cases/test015.sh @@ -0,0 +1,13 @@ +# copy a file where source and destination are resolved with ~ +# ensure the source file exists + +set -e +cd "$HOME/testcp" +touch foo.txt + +wsh file copy ~/testcp/foo.txt ~/testcp/bar.txt + +if [ ! -f foo.txt ]; then + echo "foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test016.sh b/tests/copytests/cases/test016.sh new file mode 100755 index 000000000..2c98952c9 --- /dev/null +++ b/tests/copytests/cases/test016.sh @@ -0,0 +1,13 @@ +# copy a file where source and destination are resolved with ~ +# ensure the destination file exists + +set -e +cd "$HOME/testcp" +touch foo.txt + +wsh file copy ~/testcp/foo.txt ~/testcp/bar.txt + +if [ ! -f bar.txt ]; then + echo "bar.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test017.sh b/tests/copytests/cases/test017.sh new file mode 100755 index 000000000..3047aae2e --- /dev/null +++ b/tests/copytests/cases/test017.sh @@ -0,0 +1,13 @@ +# copy a file to itself with ~ for destination resolution +# ensure that the operation fails and the file still exists + +set -e +cd "$HOME/testcp" +touch foo.txt + +wsh file copy foo.txt ~/testcp/foo.txt >/dev/null 2>&1 && echo "copy should have failed" && exit 1 + +if [ ! -f foo.txt ]; then + echo "foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test018.sh b/tests/copytests/cases/test018.sh new file mode 100755 index 000000000..acf81442c --- /dev/null +++ b/tests/copytests/cases/test018.sh @@ -0,0 +1,13 @@ +# copy a file to itself with ~ for source resolution +# ensure that the operation fails and the file still exists + +set -e +cd "$HOME/testcp" +touch foo.txt + +wsh file copy ~/testcp/foo.txt foo.txt >/dev/null 2>&1 && echo "copy should have failed" && exit 1 + +if [ ! -f foo.txt ]; then + echo "foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test019.sh b/tests/copytests/cases/test019.sh new file mode 100755 index 000000000..4d4816b06 --- /dev/null +++ b/tests/copytests/cases/test019.sh @@ -0,0 +1,13 @@ +# copy a file to itself with env var expansion in destination +# ensure the operation fails and the file still exists + +set -e +cd "$HOME/testcp" +touch foo.txt + +wsh file copy foo.txt "${HOME}"/testcp/foo.txt >/dev/null 2>&1 && echo "copy should have failed" && exit 1 + +if [ ! -f foo.txt ]; then + echo "foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test020.sh b/tests/copytests/cases/test020.sh new file mode 100755 index 000000000..8b8f6877b --- /dev/null +++ b/tests/copytests/cases/test020.sh @@ -0,0 +1,13 @@ +# copy a file to itself with env var expansion in source +# ensure the operation fails and the file still exists + +set -e +cd "$HOME/testcp" +touch foo.txt + +wsh file copy "${HOME}"/testcp/foo.txt foo.txt >/dev/null 2>&1 && echo "copy should have failed" && exit 1 + +if [ ! -f foo.txt ]; then + echo "foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test021.sh b/tests/copytests/cases/test021.sh new file mode 100755 index 000000000..0099897d6 --- /dev/null +++ b/tests/copytests/cases/test021.sh @@ -0,0 +1,14 @@ +# copy to a deeper directory and rename +# ensure the destination file exists + +set -e +cd "$HOME/testcp" +touch foo.txt +mkdir baz + +wsh file copy foo.txt baz/bar.txt + +if [ ! -f baz/bar.txt ]; then + echo "baz/bar.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test022.sh b/tests/copytests/cases/test022.sh new file mode 100755 index 000000000..d9186fa01 --- /dev/null +++ b/tests/copytests/cases/test022.sh @@ -0,0 +1,14 @@ +# copy a file to a deeper directory with the same base name +# ensure the destination file exists + +set -e +cd "$HOME/testcp" +touch foo.txt +mkdir baz + +wsh file copy foo.txt baz/foo.txt + +if [ ! -f baz/foo.txt ]; then + echo "baz/foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test023.sh b/tests/copytests/cases/test023.sh new file mode 100755 index 000000000..4a16f3d81 --- /dev/null +++ b/tests/copytests/cases/test023.sh @@ -0,0 +1,14 @@ +# copy into an existing directory ending in / +# ensure the file is inserted in the directory + +set -e +cd "$HOME/testcp" +touch foo.txt +mkdir baz + +wsh file copy foo.txt baz/ + +if [ ! -f baz/foo.txt ]; then + echo "baz/foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test024.sh b/tests/copytests/cases/test024.sh new file mode 100755 index 000000000..bcf207670 --- /dev/null +++ b/tests/copytests/cases/test024.sh @@ -0,0 +1,14 @@ +# copy into an existing directory not ending in / +# ensure the file is inserted in the directory + +set -e +cd "$HOME/testcp" +touch foo.txt +mkdir baz + +wsh file copy foo.txt baz + +if [ ! -f baz/foo.txt ]; then + echo "baz/foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test025.sh b/tests/copytests/cases/test025.sh new file mode 100755 index 000000000..1de62ccd5 --- /dev/null +++ b/tests/copytests/cases/test025.sh @@ -0,0 +1,15 @@ +# copy into an non-existing directory where file has the same base name +# ensure the file is copied to a file inside the directory +# note that this is not regular cp behavior + +set -e +cd "$HOME/testcp" +touch foo.txt + +# this is different from cp behavior +wsh file copy foo.txt baz/foo.txt + +if [ ! -f baz/foo.txt ]; then + echo "baz/foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test026.sh b/tests/copytests/cases/test026.sh new file mode 100755 index 000000000..e6bfcb361 --- /dev/null +++ b/tests/copytests/cases/test026.sh @@ -0,0 +1,15 @@ +# copy into an non-existing directory ending with a / +# ensure the file is copied to a file inside the directory +# note that this is not regular cp behavior + +set -e +cd "$HOME/testcp" +touch foo.txt + +# this is different from cp behavior +wsh file copy foo.txt baz/ >/dev/null 2>&1 && echo "command should have failed" && exit 1 + +if [ -f baz/foo.txt ]; then + echo "baz/foo.txt should not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test027.sh b/tests/copytests/cases/test027.sh new file mode 100755 index 000000000..52e906536 --- /dev/null +++ b/tests/copytests/cases/test027.sh @@ -0,0 +1,13 @@ +# copy into an non-existing file name not-ending with a / +# ensure the file is copied to a file instead of a directory + +set -e +cd "$HOME/testcp" +touch foo.txt + +wsh file copy foo.txt baz + +if [ ! -f baz ]; then + echo "baz does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test028.sh b/tests/copytests/cases/test028.sh new file mode 100755 index 000000000..c208f5a38 --- /dev/null +++ b/tests/copytests/cases/test028.sh @@ -0,0 +1,16 @@ +# copy from relative .. source to current directory . +# ensure the file is copied correctly + +set -e +cd "$HOME/testcp" +touch foo.txt +mkdir baz +cd baz + +wsh file copy ../foo.txt . +cd .. + +if [ ! -f baz/foo.txt ]; then + echo "baz/foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test029.sh b/tests/copytests/cases/test029.sh new file mode 100755 index 000000000..2e2a23bc0 --- /dev/null +++ b/tests/copytests/cases/test029.sh @@ -0,0 +1,17 @@ +# copy from the current directory to a relative directory .. +# ensure the file is copied correctly + +set -e +cd "$HOME/testcp" +mkdir baz +cd baz +touch foo.txt + + +wsh file copy foo.txt .. +cd .. + +if [ ! -f foo.txt ]; then + echo "foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test030.sh b/tests/copytests/cases/test030.sh new file mode 100755 index 000000000..39e4292fa --- /dev/null +++ b/tests/copytests/cases/test030.sh @@ -0,0 +1,14 @@ +# copy from a deeper directory to the current directory . +# ensure the file is copied correctly + +set -e +cd "$HOME/testcp" +mkdir baz +touch baz/foo.txt + +wsh file copy baz/foo.txt . + +if [ ! -f foo.txt ]; then + echo "foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test031.sh b/tests/copytests/cases/test031.sh new file mode 100755 index 000000000..4955fd0f5 --- /dev/null +++ b/tests/copytests/cases/test031.sh @@ -0,0 +1,13 @@ +# copy an empty directory to a non-existing directory without -r flag +# ensure the operation fails and the new file doesn't exist + +set -e +cd "$HOME/testcp" +mkdir foo + +wsh file copy foo bar >/dev/null 2>&1 && echo "the command should have failed" && exit 1 + +if [ -d bar ]; then + echo "bar should not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test032.sh b/tests/copytests/cases/test032.sh new file mode 100755 index 000000000..b32104375 --- /dev/null +++ b/tests/copytests/cases/test032.sh @@ -0,0 +1,13 @@ +# copy an empty directory to a non-existing directory with -r flag +# ensure the empty directory is copied to one with the new name + +set -e +cd "$HOME/testcp" +mkdir foo + +wsh file copy -r foo bar + +if [ ! -d bar ]; then + echo "bar does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test033.sh b/tests/copytests/cases/test033.sh new file mode 100755 index 000000000..de4bdcf66 --- /dev/null +++ b/tests/copytests/cases/test033.sh @@ -0,0 +1,13 @@ +# copy an empty directory ending with / to a non-existing directory without -r flag +# ensure the copy fails and the new directory doesn't exist + +set -e +cd "$HOME/testcp" +mkdir bar + +wsh file copy bar/ baz >/dev/null 2>&1 && echo "this command was supposed to fail" && exit 1 + +if [ -d baz ]; then + echo "baz should not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test034.sh b/tests/copytests/cases/test034.sh new file mode 100755 index 000000000..8fa375634 --- /dev/null +++ b/tests/copytests/cases/test034.sh @@ -0,0 +1,12 @@ +# copy an empty directory ending with / to a non-existing directory with -r flag +# ensure the copy succeeds and the new directory exists + +set -e +cd "$HOME/testcp" +mkdir bar + +wsh file copy -r bar/ baz +if [ ! -d baz ]; then + echo "baz does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test035.sh b/tests/copytests/cases/test035.sh new file mode 100755 index 000000000..c2f0f0168 --- /dev/null +++ b/tests/copytests/cases/test035.sh @@ -0,0 +1,12 @@ +# copy an empty directory to a non-existing directory ending with / without -r flag +# ensure the copy fails and the new directory doesn't exist + +set -e +cd "$HOME/testcp" +mkdir bar + +wsh file copy bar baz/ >/dev/null 2>&1 && echo "this command was supposed to fail" && exit 1 +if [ -d baz ]; then + echo "baz should not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test036.sh b/tests/copytests/cases/test036.sh new file mode 100755 index 000000000..c8505c5a9 --- /dev/null +++ b/tests/copytests/cases/test036.sh @@ -0,0 +1,13 @@ +# copy an empty directory to a non-existing directory ending with / with -r flag +# ensure the copy succeeds and the new directory exists + +set -e +cd "$HOME/testcp" +mkdir bar + +wsh file copy -r bar baz/ + +if [ ! -d baz ]; then + echo "baz does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test037.sh b/tests/copytests/cases/test037.sh new file mode 100755 index 000000000..791a7f8c1 --- /dev/null +++ b/tests/copytests/cases/test037.sh @@ -0,0 +1,13 @@ +# copy an empty directory ending with // to a non-existing directory with -r flag +# ensure the copy succeeds and the new directory exists + +set -e +cd "$HOME/testcp" +mkdir bar + +wsh file copy -r bar// baz + +if [ ! -d baz ]; then + echo "baz does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test038.sh b/tests/copytests/cases/test038.sh new file mode 100755 index 000000000..e58de121a --- /dev/null +++ b/tests/copytests/cases/test038.sh @@ -0,0 +1,13 @@ +# copy an empty directory to a non-existing directory ending with // with -r flag +# ensure the copy succeeds and the new directory exists + +set -e +cd "$HOME/testcp" +mkdir bar + +wsh file copy -r bar baz// + +if [ ! -d baz ]; then + echo "baz does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test039.sh b/tests/copytests/cases/test039.sh new file mode 100755 index 000000000..149607a2a --- /dev/null +++ b/tests/copytests/cases/test039.sh @@ -0,0 +1,14 @@ +# copy a directory containing a file to a new directory without -r flag +# ensure this fails and the new files don't exist + +set -e +cd "$HOME/testcp" +mkdir bar +touch bar/foo.txt + +wsh file copy bar baz >/dev/null 2>&1 && echo "this command should have failed" && exit 1 + +if [ -f baz/foo.txt ]; then + echo "baz/foo.txt should not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test040.sh b/tests/copytests/cases/test040.sh new file mode 100755 index 000000000..1414635fc --- /dev/null +++ b/tests/copytests/cases/test040.sh @@ -0,0 +1,14 @@ +# copy a directory containing a file to a new directory with -r flag +# ensure this succeeds and the new files exist + +set -e +cd "$HOME/testcp" +mkdir bar +touch bar/foo.txt + +wsh file copy -r bar baz + +if [ ! -f baz/foo.txt ]; then + echo "baz/foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test041.sh b/tests/copytests/cases/test041.sh new file mode 100755 index 000000000..1e04d917d --- /dev/null +++ b/tests/copytests/cases/test041.sh @@ -0,0 +1,15 @@ +# copy a directory containing a file to an existing directory with -r flag +# ensure this succeeds and the new files are nested in the existing directory + +set -e +cd "$HOME/testcp" +mkdir bar +touch bar/foo.txt +mkdir baz + +wsh file -r bar baz + +if [ ! -f baz/bar/foo.txt ]; then + echo "baz/bar/foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test042.sh b/tests/copytests/cases/test042.sh new file mode 100755 index 000000000..29831e987 --- /dev/null +++ b/tests/copytests/cases/test042.sh @@ -0,0 +1,15 @@ +# copy a directory containing a file to an existing directory ending with / with -r flag +# ensure this succeeds and the new files are nested in the existing directory + +set -e +cd "$HOME/testcp" +mkdir bar +touch bar/foo.txt +mkdir baz + +wsh file copy -r bar baz/ + +if [ ! -f baz/bar/foo.txt ]; then + echo "baz/bar/foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test043.sh b/tests/copytests/cases/test043.sh new file mode 100755 index 000000000..87160c68f --- /dev/null +++ b/tests/copytests/cases/test043.sh @@ -0,0 +1,15 @@ +# copy a directory containing a file to an existing directory ending with /. with -r flag +# ensure this succeeds and the new files are nested in the existing directory + +set -e +cd "$HOME/testcp" +mkdir bar +touch bar/foo.txt +mkdir baz + +wsh file copy -r bar baz/. + +if [ ! -f baz/bar/foo.txt ]; then + echo "baz/bar/foo.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test044.sh b/tests/copytests/cases/test044.sh new file mode 100755 index 000000000..9a03245ce --- /dev/null +++ b/tests/copytests/cases/test044.sh @@ -0,0 +1,15 @@ +# copy a doubly nested directory containing a file to a non-existant directory with the -r flag +# ensure this succeeds and the new files exist with the first directory renamed + +set -e +cd "$HOME/testcp" +mkdir foo +mkdir foo/bar +touch foo/bar/baz.txt + +wsh file copy -r foo qux + +if [ ! -f qux/bar/baz.txt ]; then + echo "qux/bar/baz.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test045.sh b/tests/copytests/cases/test045.sh new file mode 100755 index 000000000..2dd232fb4 --- /dev/null +++ b/tests/copytests/cases/test045.sh @@ -0,0 +1,16 @@ +# copy a doubly nested directory containing a file to an existing directory with the -r flag +# ensure this succeeds and the new files exist and are nested in the existing directory + +set -e +cd "$HOME/testcp" +mkdir foo +mkdir foo/bar +touch foo/bar/baz.txt +mkdir qux + +wsh file copy -r foo qux + +if [ ! -f qux/foo/bar/baz.txt ]; then + echo "qux/foo/bar/baz.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test046.sh b/tests/copytests/cases/test046.sh new file mode 100755 index 000000000..5b4a9895d --- /dev/null +++ b/tests/copytests/cases/test046.sh @@ -0,0 +1,14 @@ +# copy a file with /// separating directory and file +# ensure the copy succeeds and the file exists + +set -e +cd "$HOME/testcp" +mkdir foo +touch foo/bar.txt + +wsh file copy foo///bar.txt . + +if [ ! -f bar.txt ]; then + echo "bar.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test047.sh b/tests/copytests/cases/test047.sh new file mode 100755 index 000000000..609cffc0c --- /dev/null +++ b/tests/copytests/cases/test047.sh @@ -0,0 +1,15 @@ +# copy a file with /// to a file with // +# ensure the copy succeeds and the file exists + +set -e +cd "$HOME/testcp" +mkdir foo +touch foo/bar.txt +mkdir baz + +wsh file copy foo///bar.txt baz//qux.txt + +if [ ! -f baz/qux.txt ]; then + echo "baz/qux.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test048.sh b/tests/copytests/cases/test048.sh new file mode 100755 index 000000000..c0001f263 --- /dev/null +++ b/tests/copytests/cases/test048.sh @@ -0,0 +1,16 @@ +# copy the current directory into an existing directory without the -r flag +# ensure the copy fails and the output doesn't exist + +set -e +cd "$HOME/testcp" +mkdir foo +touch foo/bar.txt +mkdir baz +cd foo + +wsh file copy . ../baz >/dev/null 2>&1 && echo "command should have failed" && exit 1 + +if [ -f baz/bar.txt ]; then + echo "baz/bar.txt should not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test049.sh b/tests/copytests/cases/test049.sh new file mode 100755 index 000000000..2f3f94371 --- /dev/null +++ b/tests/copytests/cases/test049.sh @@ -0,0 +1,17 @@ +# copy the current directory into an existing directory with the -r flag +# ensure the copy succeeds and the output exists + +set -e +cd "$HOME/testcp" +mkdir foo +touch foo/bar.txt +mkdir baz +cd foo + +wsh file copy -r . ../baz +cd .. + +if [ ! -f baz/bar.txt ]; then + echo "baz/bar.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test050.sh b/tests/copytests/cases/test050.sh new file mode 100755 index 000000000..7b7bebd06 --- /dev/null +++ b/tests/copytests/cases/test050.sh @@ -0,0 +1,15 @@ +# copy the current directory into a non-existing directory without the -r flag +# ensure the copy fails and the output does not exist + +set -e +cd "$HOME/testcp" +mkdir foo +touch foo/bar.txt +cd foo + +wsh file copy . ../baz >/dev/null 2>&1 && echo "command should have failed" && exit 1 + +if [ -f baz/bar.txt ]; then + echo "baz/bar.txt should not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test051.sh b/tests/copytests/cases/test051.sh new file mode 100755 index 000000000..0d625b660 --- /dev/null +++ b/tests/copytests/cases/test051.sh @@ -0,0 +1,16 @@ +# copy the current directory into a non-existing directory with the -r flag +# ensure the copy succeeds and the output exists + +set -e +cd "$HOME/testcp" +mkdir foo +touch foo/bar.txt +cd foo + +wsh file copy -r . ../baz +cd .. + +if [ ! -f baz/bar.txt ]; then + echo "baz/bar.txt does not exist" + exit 1 +fi diff --git a/tests/copytests/cases/test052.sh b/tests/copytests/cases/test052.sh new file mode 100755 index 000000000..5010c3305 --- /dev/null +++ b/tests/copytests/cases/test052.sh @@ -0,0 +1,33 @@ +# copy a directory with contents +# ensure the contents are the same +set -e +cd "$HOME/testcp" +mkdir foo +mkdir foo/bar +touch foo/bar/baz.txt +mkdir foo/bar/qux +touch foo/bar/qux/quux.txt +echo "The quick brown fox jumps over the lazy dog." > foo/bar/baz.txt +echo "Sphinx of black quartz, judge my vow." > foo/bar/qux/quux.txt +mkdir corge + +# we need a nested corge/foo so the foo.zip contains the same exact file names +# in other words, if one file was named foo and the other was corge, they would +# not match. this allows them to be the same. +wsh file copy -r foo corge/foo + + +zip -r foo.zip foo >/dev/null 2>&1 +FOO_MD5=$(md5sum foo.zip | cut -d " " -f1) + +cd corge +zip -r foo.zip foo >/dev/null 2>&1 +CORGE_MD5=$(md5sum foo.zip | cut -d " " -f1) + +if [ $FOO_MD5 != $CORGE_MD5 ]; then + echo "directories are not the same" + echo "FOO_MD5 is $FOO_MD5" + echo "CORGE_MD5 is $CORGE_MD5" + exit 1 +fi + diff --git a/tests/copytests/runner.sh b/tests/copytests/runner.sh new file mode 100755 index 000000000..d48e3415a --- /dev/null +++ b/tests/copytests/runner.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +cd "$(dirname "$0")" +source testutil.sh + +for fname in cases/*.sh; do + setup_testcp + #"${fname}" | read outerr && printf "\e[32mPASS $fname\n\n\e[0m" || printf "\e[31mFAIL $fname: $outerr \n\n\e[0m" + if ! outerr=$("${fname}" 2>&1); then + printf "\e[31mFAIL $fname:\n$outerr \n\n\e[0m" + else + printf "\e[32mPASS $fname\n\n\e[0m" + fi + cleanup_testcp +done \ No newline at end of file diff --git a/tests/copytests/testutil.sh b/tests/copytests/testutil.sh new file mode 100755 index 000000000..3ac29608c --- /dev/null +++ b/tests/copytests/testutil.sh @@ -0,0 +1,13 @@ +setup_testcp () { + if [ -d "$HOME/testcp" ]; then + echo "Test cannot run if testcp already exists" + exit 1 + fi + + mkdir ~/testcp +} + + +cleanup_testcp () { + rm -rf "$HOME/testcp" || rmdir "$HOME/testcp" +} \ No newline at end of file