Skip to content

Commit

Permalink
feat: add tests for local wsh file copy cmd (#1911)
Browse files Browse the repository at this point in the history
This adds tests for the corner cases of the `wsh file copy` command. At
the moment, these focus on local copies since they are more easily
replicated.

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
oneirocosm and coderabbitai[bot] authored Feb 6, 2025
1 parent 2aa3e4b commit 9e79df0
Show file tree
Hide file tree
Showing 55 changed files with 780 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/copytests/cases/test000.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions tests/copytests/cases/test001.sh
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions tests/copytests/cases/test002.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions tests/copytests/cases/test003.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions tests/copytests/cases/test004.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/copytests/cases/test005.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/copytests/cases/test006.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/copytests/cases/test007.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/copytests/cases/test008.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/copytests/cases/test009.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/copytests/cases/test010.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/copytests/cases/test011.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/copytests/cases/test012.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/copytests/cases/test013.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/copytests/cases/test014.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/copytests/cases/test015.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/copytests/cases/test016.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/copytests/cases/test017.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/copytests/cases/test018.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/copytests/cases/test019.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/copytests/cases/test020.sh
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions tests/copytests/cases/test021.sh
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions tests/copytests/cases/test022.sh
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions tests/copytests/cases/test023.sh
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions tests/copytests/cases/test024.sh
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions tests/copytests/cases/test025.sh
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions tests/copytests/cases/test026.sh
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 9e79df0

Please sign in to comment.