Skip to content

Commit

Permalink
Add tests to verify overwrite/delete behavior
Browse files Browse the repository at this point in the history
This new tests verify the claims made in the readme that:

 - When installing a package `stowsh` will never overwrite existing files.

 - When uninstalling a package stowsh will never delete files that are
   not symlinks to the expected place in the package."
  • Loading branch information
mikepqr committed Mar 15, 2021
1 parent bd56961 commit 3301908
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ Usage: stowsh [-D] [-n] [-s] [-g] [-v[v]] [-t TARGET] PACKAGES...
- `-s` skip (skip errors rather than abort)
When installing a package `stowsh` will never overwrite existing files. When
unsintalling a package `stowsh` will never delete files that are not symlinks to
the expected place in the package.
uninstalling a package `stowsh` will never delete files that are not symlinks
to the expected place in the package.
By default `stowsh` will abort without making _any_ changes if either of these
errors occurs. This is done to avoid being left with a broken half installed
Expand Down
Empty file.
Empty file.
1 change: 1 addition & 0 deletions tests/overwrites/installed/.vimrc
Empty file.
Empty file added tests/overwrites/pkg/.vimrc
Empty file.
39 changes: 39 additions & 0 deletions tests/overwrites/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

stowsh=../../stowsh

fail=0
rm -rf "dest"
cp -r "uninstalled" "dest"

# This block verifies the claim "When installing a package stowsh will never
# overwrite existing files."
#
# This should fail because .bash_profile already exists at dest
$stowsh -vv -t "dest" "pkg" && fail=1
# This file should not exist because the previous command should not have set up
# any links
[ -f "dest/.vimrc" ] && fail=1

# This should now work thanks to -s
$stowsh -vv -s -t "dest" "pkg" || fail=1
diff -qr "dest" "installed" || fail=1

# This block verifies the claim "When unsintalling a package stowsh will never
# delete files that are not symlinks to the expected place in the package."
# This should fail because the existing .bash_profile is not a link to the pkg
# .bash_profile
$stowsh -vv -D -t "dest" "pkg" && fail=1

# This should now work thanks to -s
$stowsh -vv -s -D -t "dest" "pkg" || fail=1
diff -qr "dest" "uninstalled" || fail=1

if [[ $fail == 1 ]]; then
echo "FAIL"
exit 1
else
echo "OK"
rm -rf "dest"
exit 0
fi
Empty file.
Empty file.

0 comments on commit 3301908

Please sign in to comment.