Skip to content

Commit 9e79df0

Browse files
feat: add tests for local wsh file copy cmd (#1911)
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>
1 parent 2aa3e4b commit 9e79df0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+780
-0
lines changed

tests/copytests/cases/test000.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# copy a file to one with a different name
2+
# ensure that the original exists
3+
set -e
4+
cd "$HOME/testcp"
5+
touch foo.txt
6+
7+
wsh file copy foo.txt bar.txt
8+
9+
if [ ! -f foo.txt ]; then
10+
echo "foo.txt does not exist"
11+
exit 1
12+
fi

tests/copytests/cases/test001.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# copy a file to one with a different name
2+
# ensure that the destination file exists
3+
set -e
4+
cd "$HOME/testcp"
5+
touch foo.txt
6+
7+
wsh file copy foo.txt bar.txt
8+
9+
if [ ! -f bar.txt ]; then
10+
echo "bar.txt does not exist"
11+
exit 1
12+
fi

tests/copytests/cases/test002.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# copy a file with contents
2+
# ensure the contents are the same
3+
set -e
4+
cd "$HOME/testcp"
5+
touch foo.txt
6+
echo "The quick brown fox jumps over the lazy dog" > foo.txt
7+
8+
wsh file copy foo.txt bar.txt
9+
10+
11+
FOO_MD5=$(md5sum foo.txt | cut -d " " -f1)
12+
BAR_MD5=$(md5sum bar.txt | cut -d " " -f1)
13+
if [ $FOO_MD5 != $BAR_MD5 ]; then
14+
echo "files are not the same"
15+
echo "FOO_MD5 is $FOO_MD5"
16+
echo "BAR_MD5 is $BAR_MD5"
17+
exit 1
18+
fi

tests/copytests/cases/test003.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# copy a file where source starts with ./
2+
# ensure the source file exists
3+
set -e
4+
cd "$HOME/testcp"
5+
touch foo.txt
6+
7+
wsh file copy ./foo.txt bar.txt
8+
9+
if [ ! -f foo.txt ]; then
10+
echo "foo.txt does not exist"
11+
exit 1
12+
fi

tests/copytests/cases/test004.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# copy a file where source starts with ./
2+
# ensure the destination file exists
3+
set -e
4+
cd "$HOME/testcp"
5+
touch foo.txt
6+
7+
wsh file copy ./foo.txt bar.txt
8+
9+
if [ ! -f bar.txt ]; then
10+
echo "bar.txt does not exist"
11+
exit 1
12+
fi

tests/copytests/cases/test005.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# copy a file where destination starts with ./
2+
# ensure the source file exists
3+
4+
set -e
5+
cd "$HOME/testcp"
6+
touch foo.txt
7+
8+
wsh file copy foo.txt ./bar.txt
9+
10+
if [ ! -f foo.txt ]; then
11+
echo "foo.txt does not exist"
12+
exit 1
13+
fi

tests/copytests/cases/test006.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# copy a file where destination starts with ./
2+
# ensure the destination file exists
3+
4+
set -e
5+
cd "$HOME/testcp"
6+
touch foo.txt
7+
8+
wsh file copy foo.txt ./bar.txt
9+
10+
if [ ! -f bar.txt ]; then
11+
echo "bar.txt does not exist"
12+
exit 1
13+
fi

tests/copytests/cases/test007.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# copy a file where source and destination start with ./
2+
# ensure the source file exists
3+
4+
set -e
5+
cd "$HOME/testcp"
6+
touch foo.txt
7+
8+
wsh file copy ./foo.txt ./bar.txt
9+
10+
if [ ! -f foo.txt ]; then
11+
echo "foo.txt does not exist"
12+
exit 1
13+
fi

tests/copytests/cases/test008.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# copy a file where source and destination start with ./
2+
# ensure the destination file exists
3+
4+
set -e
5+
cd "$HOME/testcp"
6+
touch foo.txt
7+
8+
wsh file copy ./foo.txt ./bar.txt
9+
10+
if [ ! -f bar.txt ]; then
11+
echo "bar.txt does not exist"
12+
exit 1
13+
fi

tests/copytests/cases/test009.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# copy a file to itself with the same literal name
2+
# ensure the operation fails and the file still exists
3+
4+
set -e
5+
cd "$HOME/testcp"
6+
touch foo.txt
7+
8+
wsh file copy foo.txt foo.txt >/dev/null 2>&1 && echo "copy should have failed" && exit 1
9+
10+
if [ ! -f foo.txt ]; then
11+
echo "foo.txt does not exist"
12+
exit 1
13+
fi

tests/copytests/cases/test010.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# copy a file to itself with a different literal name
2+
# ensure the copy fails and the file still exists
3+
4+
set -e
5+
cd "$HOME/testcp"
6+
touch foo.txt
7+
8+
wsh file copy foo.txt ./foo.txt >/dev/null 2>&1 && echo "copy should have failed" && exit 1
9+
10+
if [ ! -f foo.txt ]; then
11+
echo "foo.txt does not exist"
12+
exit 1
13+
fi

tests/copytests/cases/test011.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# copy a file with ~ used to resolve the source
2+
# ensure the source still exists
3+
4+
set -e
5+
cd "$HOME/testcp"
6+
touch foo.txt
7+
8+
wsh file copy ~/testcp/foo.txt bar.txt
9+
10+
if [ ! -f foo.txt ]; then
11+
echo "foo.txt does not exist"
12+
exit 1
13+
fi

tests/copytests/cases/test012.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# copy a file with ~ used to resolve the source
2+
# ensure the destination exists
3+
4+
set -e
5+
cd "$HOME/testcp"
6+
touch foo.txt
7+
8+
wsh file copy ~/testcp/foo.txt bar.txt
9+
10+
if [ ! -f bar.txt ]; then
11+
echo "bar.txt does not exist"
12+
exit 1
13+
fi

tests/copytests/cases/test013.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# copy a file with ~ used to resolve the destination
2+
# ensure the source exists
3+
4+
set -e
5+
cd "$HOME/testcp"
6+
touch foo.txt
7+
8+
wsh file copy foo.txt ~/testcp/bar.txt
9+
10+
if [ ! -f foo.txt ]; then
11+
echo "foo.txt does not exist"
12+
exit 1
13+
fi

tests/copytests/cases/test014.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# copy a file with ~ used to resolve the destination
2+
# ensure the destination exists
3+
4+
set -e
5+
cd "$HOME/testcp"
6+
touch foo.txt
7+
8+
wsh file copy foo.txt ~/testcp/bar.txt
9+
10+
if [ ! -f bar.txt ]; then
11+
echo "bar.txt does not exist"
12+
exit 1
13+
fi

tests/copytests/cases/test015.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# copy a file where source and destination are resolved with ~
2+
# ensure the source file exists
3+
4+
set -e
5+
cd "$HOME/testcp"
6+
touch foo.txt
7+
8+
wsh file copy ~/testcp/foo.txt ~/testcp/bar.txt
9+
10+
if [ ! -f foo.txt ]; then
11+
echo "foo.txt does not exist"
12+
exit 1
13+
fi

tests/copytests/cases/test016.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# copy a file where source and destination are resolved with ~
2+
# ensure the destination file exists
3+
4+
set -e
5+
cd "$HOME/testcp"
6+
touch foo.txt
7+
8+
wsh file copy ~/testcp/foo.txt ~/testcp/bar.txt
9+
10+
if [ ! -f bar.txt ]; then
11+
echo "bar.txt does not exist"
12+
exit 1
13+
fi

tests/copytests/cases/test017.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# copy a file to itself with ~ for destination resolution
2+
# ensure that the operation fails and the file still exists
3+
4+
set -e
5+
cd "$HOME/testcp"
6+
touch foo.txt
7+
8+
wsh file copy foo.txt ~/testcp/foo.txt >/dev/null 2>&1 && echo "copy should have failed" && exit 1
9+
10+
if [ ! -f foo.txt ]; then
11+
echo "foo.txt does not exist"
12+
exit 1
13+
fi

tests/copytests/cases/test018.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# copy a file to itself with ~ for source resolution
2+
# ensure that the operation fails and the file still exists
3+
4+
set -e
5+
cd "$HOME/testcp"
6+
touch foo.txt
7+
8+
wsh file copy ~/testcp/foo.txt foo.txt >/dev/null 2>&1 && echo "copy should have failed" && exit 1
9+
10+
if [ ! -f foo.txt ]; then
11+
echo "foo.txt does not exist"
12+
exit 1
13+
fi

tests/copytests/cases/test019.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# copy a file to itself with env var expansion in destination
2+
# ensure the operation fails and the file still exists
3+
4+
set -e
5+
cd "$HOME/testcp"
6+
touch foo.txt
7+
8+
wsh file copy foo.txt "${HOME}"/testcp/foo.txt >/dev/null 2>&1 && echo "copy should have failed" && exit 1
9+
10+
if [ ! -f foo.txt ]; then
11+
echo "foo.txt does not exist"
12+
exit 1
13+
fi

tests/copytests/cases/test020.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# copy a file to itself with env var expansion in source
2+
# ensure the operation fails and the file still exists
3+
4+
set -e
5+
cd "$HOME/testcp"
6+
touch foo.txt
7+
8+
wsh file copy "${HOME}"/testcp/foo.txt foo.txt >/dev/null 2>&1 && echo "copy should have failed" && exit 1
9+
10+
if [ ! -f foo.txt ]; then
11+
echo "foo.txt does not exist"
12+
exit 1
13+
fi

tests/copytests/cases/test021.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# copy to a deeper directory and rename
2+
# ensure the destination file exists
3+
4+
set -e
5+
cd "$HOME/testcp"
6+
touch foo.txt
7+
mkdir baz
8+
9+
wsh file copy foo.txt baz/bar.txt
10+
11+
if [ ! -f baz/bar.txt ]; then
12+
echo "baz/bar.txt does not exist"
13+
exit 1
14+
fi

tests/copytests/cases/test022.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# copy a file to a deeper directory with the same base name
2+
# ensure the destination file exists
3+
4+
set -e
5+
cd "$HOME/testcp"
6+
touch foo.txt
7+
mkdir baz
8+
9+
wsh file copy foo.txt baz/foo.txt
10+
11+
if [ ! -f baz/foo.txt ]; then
12+
echo "baz/foo.txt does not exist"
13+
exit 1
14+
fi

tests/copytests/cases/test023.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# copy into an existing directory ending in /
2+
# ensure the file is inserted in the directory
3+
4+
set -e
5+
cd "$HOME/testcp"
6+
touch foo.txt
7+
mkdir baz
8+
9+
wsh file copy foo.txt baz/
10+
11+
if [ ! -f baz/foo.txt ]; then
12+
echo "baz/foo.txt does not exist"
13+
exit 1
14+
fi

tests/copytests/cases/test024.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# copy into an existing directory not ending in /
2+
# ensure the file is inserted in the directory
3+
4+
set -e
5+
cd "$HOME/testcp"
6+
touch foo.txt
7+
mkdir baz
8+
9+
wsh file copy foo.txt baz
10+
11+
if [ ! -f baz/foo.txt ]; then
12+
echo "baz/foo.txt does not exist"
13+
exit 1
14+
fi

tests/copytests/cases/test025.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# copy into an non-existing directory where file has the same base name
2+
# ensure the file is copied to a file inside the directory
3+
# note that this is not regular cp behavior
4+
5+
set -e
6+
cd "$HOME/testcp"
7+
touch foo.txt
8+
9+
# this is different from cp behavior
10+
wsh file copy foo.txt baz/foo.txt
11+
12+
if [ ! -f baz/foo.txt ]; then
13+
echo "baz/foo.txt does not exist"
14+
exit 1
15+
fi

tests/copytests/cases/test026.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# copy into an non-existing directory ending with a /
2+
# ensure the file is copied to a file inside the directory
3+
# note that this is not regular cp behavior
4+
5+
set -e
6+
cd "$HOME/testcp"
7+
touch foo.txt
8+
9+
# this is different from cp behavior
10+
wsh file copy foo.txt baz/ >/dev/null 2>&1 && echo "command should have failed" && exit 1
11+
12+
if [ -f baz/foo.txt ]; then
13+
echo "baz/foo.txt should not exist"
14+
exit 1
15+
fi

0 commit comments

Comments
 (0)