From 3301908fc1ecd0cd874e7e75ffaf28064733a45e Mon Sep 17 00:00:00 2001 From: Mike Lee Williams Date: Sat, 13 Mar 2021 22:13:13 -0800 Subject: [PATCH] Add tests to verify overwrite/delete behavior 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." --- README.md | 4 +-- tests/overwrites/installed/.bash_history | 0 tests/overwrites/installed/.bash_profile | 0 tests/overwrites/installed/.vimrc | 1 + tests/overwrites/pkg/.bash_profile | 0 tests/overwrites/pkg/.vimrc | 0 tests/overwrites/run | 39 ++++++++++++++++++++++ tests/overwrites/uninstalled/.bash_history | 0 tests/overwrites/uninstalled/.bash_profile | 0 9 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 tests/overwrites/installed/.bash_history create mode 100644 tests/overwrites/installed/.bash_profile create mode 120000 tests/overwrites/installed/.vimrc create mode 100644 tests/overwrites/pkg/.bash_profile create mode 100644 tests/overwrites/pkg/.vimrc create mode 100755 tests/overwrites/run create mode 100644 tests/overwrites/uninstalled/.bash_history create mode 100644 tests/overwrites/uninstalled/.bash_profile diff --git a/README.md b/README.md index a753029..317fe4f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/tests/overwrites/installed/.bash_history b/tests/overwrites/installed/.bash_history new file mode 100644 index 0000000..e69de29 diff --git a/tests/overwrites/installed/.bash_profile b/tests/overwrites/installed/.bash_profile new file mode 100644 index 0000000..e69de29 diff --git a/tests/overwrites/installed/.vimrc b/tests/overwrites/installed/.vimrc new file mode 120000 index 0000000..e816a1e --- /dev/null +++ b/tests/overwrites/installed/.vimrc @@ -0,0 +1 @@ +../pkg/.vimrc \ No newline at end of file diff --git a/tests/overwrites/pkg/.bash_profile b/tests/overwrites/pkg/.bash_profile new file mode 100644 index 0000000..e69de29 diff --git a/tests/overwrites/pkg/.vimrc b/tests/overwrites/pkg/.vimrc new file mode 100644 index 0000000..e69de29 diff --git a/tests/overwrites/run b/tests/overwrites/run new file mode 100755 index 0000000..ec2db3e --- /dev/null +++ b/tests/overwrites/run @@ -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 diff --git a/tests/overwrites/uninstalled/.bash_history b/tests/overwrites/uninstalled/.bash_history new file mode 100644 index 0000000..e69de29 diff --git a/tests/overwrites/uninstalled/.bash_profile b/tests/overwrites/uninstalled/.bash_profile new file mode 100644 index 0000000..e69de29