-
Notifications
You must be signed in to change notification settings - Fork 284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add tests for local wsh file copy cmd #1911
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# copy a file to one with a different name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Missing Shebang Directive 🧰 Tools🪛 Shellcheck (0.10.0)[error] 1-1: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. (SC2148) |
||
# 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 |
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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Quote Variables in Conditional Check Proposed change: -if [ $FOO_MD5 != $BAR_MD5 ]; then
+if [ "$FOO_MD5" != "$BAR_MD5" ]; then 📝 Committable suggestion
Suggested change
|
||||||
echo "files are not the same" | ||||||
echo "FOO_MD5 is $FOO_MD5" | ||||||
echo "BAR_MD5 is $BAR_MD5" | ||||||
exit 1 | ||||||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# copy a file where source starts with ./ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Missing Shebang Directive 🧰 Tools🪛 Shellcheck (0.10.0)[error] 1-1: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. (SC2148) |
||
# 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# copy a file where source starts with ./ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Missing Shebang Directive 🧰 Tools🪛 Shellcheck (0.10.0)[error] 1-1: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. (SC2148) |
||
# 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 |
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 | ||
|
||
Comment on lines
+1
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add Shebang for Script Clarity 🧰 Tools🪛 Shellcheck (0.10.0)[error] 1-1: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive. (SC2148) |
||
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 |
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 |
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 | ||||||||||||||||||||||||||
Comment on lines
+10
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve validation checks for copy success For example, you could add the following snippet after line 9: +if [ ! -f bar.txt ]; then
+ echo "bar.txt does not exist"
+ exit 1
+fi 📝 Committable suggestion
Suggested change
|
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Missing Shebang Directive
Consider adding a shebang (e.g., #!/bin/bash) at the beginning of the file to specify the shell interpreter and improve portability.
🧰 Tools
🪛 Shellcheck (0.10.0)
[error] 1-1: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.
(SC2148)