Skip to content

Commit

Permalink
Merge pull request #400 from masatake/add-uninstall-script
Browse files Browse the repository at this point in the history
Add a script for uninstalling
  • Loading branch information
martin-schulze-vireso committed May 1, 2021
2 parents fba8ff6 + cf1c853 commit c355d0b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
24 changes: 23 additions & 1 deletion test/install.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ load test_helper

INSTALL_DIR=
PATH_TO_INSTALL_SHELL=
PATH_TO_UNINSTALL_SHELL=

setup() {
make_bats_test_suite_tmpdir
INSTALL_DIR="$BATS_TEST_SUITE_TMPDIR/bats-core"
PATH_TO_INSTALL_SHELL="${BATS_TEST_DIRNAME%/*}/install.sh"
PATH_TO_UNINSTALL_SHELL="${BATS_TEST_DIRNAME%/*}/uninstall.sh"
}

@test "install.sh creates a valid installation" {
@test "install.sh creates a valid installation, and uninstall.sh undos it" {
run "$PATH_TO_INSTALL_SHELL" "$INSTALL_DIR"
[ "$status" -eq 0 ]
[ "$output" == "Installed Bats to $INSTALL_DIR/bin/bats" ]
Expand All @@ -28,6 +30,26 @@ setup() {
run "$INSTALL_DIR/bin/bats" -v
[ "$status" -eq 0 ]
[ "${output%% *}" == 'Bats' ]

run "$PATH_TO_UNINSTALL_SHELL" "$INSTALL_DIR"
[ "$status" -eq 0 ]
[ ! -x "$INSTALL_DIR/bin/bats" ]
[ ! -x "$INSTALL_DIR/libexec/bats-core/bats" ]
[ ! -x "$INSTALL_DIR/libexec/bats-core/bats-exec-suite" ]
[ ! -x "$INSTALL_DIR/libexec/bats-core/bats-exec-test" ]
[ ! -x "$INSTALL_DIR/libexec/bats-core/bats-format-junit" ]
[ ! -x "$INSTALL_DIR/libexec/bats-core/bats-format-pretty" ]
[ ! -x "$INSTALL_DIR/libexec/bats-core/bats-preprocess" ]
[ ! -x "$INSTALL_DIR/libexec/bats-core" ]
[ ! -x "$INSTALL_DIR/share/man/man1/bats.1" ]
[ ! -x "$INSTALL_DIR/share/man/man7/bats.7" ]
}

@test "uninstall.sh works even if nothing is installed" {
mkdir "$INSTALL_DIR"/tmp
run "$PATH_TO_UNINSTALL_SHELL" "$INSTALL_DIR"
[ "$status" -eq 0 ]
rmdir "$INSTALL_DIR"/tmp
}

@test "install.sh only updates permissions for Bats files" {
Expand Down
38 changes: 38 additions & 0 deletions uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

set -e

BATS_ROOT="${0%/*}"
PREFIX="$1"

if [[ -z "$PREFIX" ]]; then
printf '%s\n' \
"usage: $0 <prefix>" \
" e.g. $0 /usr/local" >&2
exit 1
fi

d="$PREFIX/bin"
for elt in "$BATS_ROOT/bin"/*; do
elt=${elt##*/}
rm -f "$d/$elt"
done

d="$PREFIX/libexec/bats-core"
for elt in "$BATS_ROOT/libexec/bats-core"/*; do
elt=${elt##*/}
rm -f "$d/$elt"
done
[[ -d "$d" ]] && rmdir "$d"

d="$PREFIX/lib/bats-core"
for elt in "$BATS_ROOT/lib/bats-core"/*; do
elt=${elt##*/}
rm -f "$d/$elt"
done
[[ -d "$d" ]] && rmdir "$d"

rm -f "$PREFIX"/share/man/man1/bats.1
rm -f "$PREFIX"/share/man/man7/bats.7

echo "Uninstalled Bats from $PREFIX/bin/bats"

0 comments on commit c355d0b

Please sign in to comment.