-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
2aa3e4b
commit 9e79df0
Showing
55 changed files
with
780 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.