2016-12-10 12:54:22 -07:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load test_helpers
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
setup_asdf_dir
|
|
|
|
install_dummy_plugin
|
|
|
|
|
|
|
|
PROJECT_DIR="$HOME/project"
|
|
|
|
mkdir -p "$PROJECT_DIR"
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
clean_asdf_dir
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "uninstall_command should fail when no such version is installed" {
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf uninstall dummy 3.14
|
2016-12-10 12:54:22 -07:00
|
|
|
[ "$output" = "No such version" ]
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "uninstall_command should remove the plugin with that version from asdf" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 1.1.0
|
2016-12-10 12:54:22 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2020-09-18 22:37:52 -07:00
|
|
|
[ "$(cat "$ASDF_DIR/installs/dummy/1.1.0/version")" = "1.1.0" ]
|
|
|
|
run asdf uninstall dummy 1.1.0
|
2022-06-24 02:20:27 -07:00
|
|
|
[ ! -f "$ASDF_DIR/installs/dummy/1.1.0/version" ]
|
2016-12-10 12:54:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "uninstall_command should invoke the plugin bin/uninstall if available" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 1.1.0
|
2016-12-10 12:54:22 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
mkdir -p "$ASDF_DIR/plugins/dummy/bin"
|
2023-04-10 20:58:58 -07:00
|
|
|
printf '%s\n' "echo custom uninstall" >"$ASDF_DIR/plugins/dummy/bin/uninstall"
|
2016-12-10 12:54:22 -07:00
|
|
|
chmod 755 "$ASDF_DIR/plugins/dummy/bin/uninstall"
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf uninstall dummy 1.1.0
|
2016-12-10 12:54:22 -07:00
|
|
|
[ "$output" = "custom uninstall" ]
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "uninstall_command should remove the plugin shims if no other version is installed" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 1.1.0
|
2016-12-10 12:54:22 -07:00
|
|
|
[ -f "$ASDF_DIR/shims/dummy" ]
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf uninstall dummy 1.1.0
|
2016-12-10 12:54:22 -07:00
|
|
|
[ ! -f "$ASDF_DIR/shims/dummy" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "uninstall_command should leave the plugin shims if other version is installed" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 1.0.0
|
|
|
|
[ -f "$ASDF_DIR/installs/dummy/1.0.0/bin/dummy" ]
|
2016-12-10 12:54:22 -07:00
|
|
|
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 1.1.0
|
|
|
|
[ -f "$ASDF_DIR/installs/dummy/1.1.0/bin/dummy" ]
|
2016-12-10 12:54:22 -07:00
|
|
|
|
|
|
|
[ -f "$ASDF_DIR/shims/dummy" ]
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf uninstall dummy 1.0.0
|
2016-12-10 12:54:22 -07:00
|
|
|
[ -f "$ASDF_DIR/shims/dummy" ]
|
|
|
|
}
|
|
|
|
|
2019-01-19 03:12:52 -07:00
|
|
|
@test "uninstall_command should remove relevant asdf-plugin metadata" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 1.0.0
|
|
|
|
[ -f "$ASDF_DIR/installs/dummy/1.0.0/bin/dummy" ]
|
2017-07-26 13:00:55 -07:00
|
|
|
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 1.1.0
|
|
|
|
[ -f "$ASDF_DIR/installs/dummy/1.1.0/bin/dummy" ]
|
2017-07-26 13:00:55 -07:00
|
|
|
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf uninstall dummy 1.0.0
|
|
|
|
run grep "asdf-plugin: dummy 1.1.0" "$ASDF_DIR/shims/dummy"
|
2017-07-26 13:00:55 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2020-09-18 22:37:52 -07:00
|
|
|
run grep "asdf-plugin: dummy 1.0.0" "$ASDF_DIR/shims/dummy"
|
2017-07-26 13:00:55 -07:00
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
}
|
|
|
|
|
2024-10-07 06:06:50 -07:00
|
|
|
# Disabled as this test represents an invalid state. A shim (`gummy`) should
|
|
|
|
# never exist unless it referenced an existing tool and version.
|
|
|
|
#
|
|
|
|
#@test "uninstall_command should not remove other unrelated shims" {
|
|
|
|
# run asdf install dummy 1.0.0
|
|
|
|
# [ -f "$ASDF_DIR/shims/dummy" ]
|
|
|
|
|
|
|
|
# touch "$ASDF_DIR/shims/gummy"
|
|
|
|
# [ -f "$ASDF_DIR/shims/gummy" ]
|
|
|
|
|
|
|
|
# run asdf uninstall dummy 1.0.0
|
|
|
|
# [ -f "$ASDF_DIR/shims/gummy" ]
|
|
|
|
#}
|
2019-01-19 12:48:21 -07:00
|
|
|
|
|
|
|
@test "uninstall command executes configured pre hook" {
|
2022-06-24 02:20:27 -07:00
|
|
|
cat >"$HOME/.asdfrc" <<-'EOM'
|
2019-01-19 12:48:21 -07:00
|
|
|
pre_asdf_uninstall_dummy = echo will uninstall dummy $1
|
|
|
|
EOM
|
|
|
|
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 1.0.0
|
|
|
|
run asdf uninstall dummy 1.0.0
|
|
|
|
[ "$output" = "will uninstall dummy 1.0.0" ]
|
2019-01-19 12:48:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "uninstall command executes configured post hook" {
|
2022-06-24 02:20:27 -07:00
|
|
|
cat >"$HOME/.asdfrc" <<-'EOM'
|
2019-01-19 12:48:21 -07:00
|
|
|
post_asdf_uninstall_dummy = echo removed dummy $1
|
|
|
|
EOM
|
|
|
|
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 1.0.0
|
|
|
|
run asdf uninstall dummy 1.0.0
|
|
|
|
[ "$output" = "removed dummy 1.0.0" ]
|
2019-01-19 12:48:21 -07:00
|
|
|
}
|