2017-03-15 09:37:41 -07:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load test_helpers
|
|
|
|
|
|
|
|
setup() {
|
2019-11-27 01:24:29 -07:00
|
|
|
BASE_DIR=$(mktemp -dt asdf.XXXX)
|
|
|
|
HOME=$BASE_DIR/home
|
|
|
|
ASDF_DIR=$HOME/.asdf
|
|
|
|
git clone -o local "$(dirname "$BATS_TEST_DIRNAME")" "$ASDF_DIR"
|
|
|
|
git --git-dir "$ASDF_DIR/.git" remote add origin https://github.com/asdf-vm/asdf.git
|
|
|
|
mkdir -p "$ASDF_DIR/plugins"
|
|
|
|
mkdir -p "$ASDF_DIR/installs"
|
|
|
|
mkdir -p "$ASDF_DIR/shims"
|
|
|
|
mkdir -p "$ASDF_DIR/tmp"
|
|
|
|
ASDF_BIN="$ASDF_DIR/bin"
|
2017-03-15 09:37:41 -07:00
|
|
|
|
2019-11-27 01:24:29 -07:00
|
|
|
# shellcheck disable=SC2031
|
|
|
|
PATH=$ASDF_BIN:$ASDF_DIR/shims:$PATH
|
|
|
|
install_dummy_plugin
|
2017-03-15 09:37:41 -07:00
|
|
|
|
|
|
|
PROJECT_DIR=$HOME/project
|
|
|
|
mkdir $PROJECT_DIR
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
clean_asdf_dir
|
|
|
|
}
|
|
|
|
|
2019-11-27 01:24:29 -07:00
|
|
|
@test "asdf update --head should checkout the master branch" {
|
|
|
|
run asdf update --head
|
2017-03-15 09:37:41 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
cd $ASDF_DIR
|
2018-12-01 19:05:58 -07:00
|
|
|
[ $(git rev-parse --abbrev-ref HEAD) = "master" ]
|
2017-03-15 09:37:41 -07:00
|
|
|
}
|
|
|
|
|
2019-11-27 01:24:29 -07:00
|
|
|
@test "asdf update should checkout the latest non-RC tag" {
|
2019-12-30 14:25:56 -07:00
|
|
|
local tag=$(git tag | grep -vi "rc" | tail -1)
|
2022-07-12 22:28:47 -07:00
|
|
|
if [ -n "$tag" ]; then
|
|
|
|
run asdf update
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
cd $ASDF_DIR
|
|
|
|
git tag | grep $tag
|
|
|
|
[ "$?" -eq 0 ]
|
|
|
|
fi
|
2019-03-24 15:24:19 -07:00
|
|
|
}
|
|
|
|
|
2019-11-27 01:24:29 -07:00
|
|
|
@test "asdf update should checkout the latest tag when configured with use_release_candidates = yes" {
|
2019-12-30 14:25:56 -07:00
|
|
|
local tag=$(git tag | tail -1)
|
2022-07-12 22:28:47 -07:00
|
|
|
if [ -n "$tag" ]; then
|
|
|
|
export ASDF_CONFIG_DEFAULT_FILE=$BATS_TMPDIR/asdfrc_defaults
|
|
|
|
echo "use_release_candidates = yes" >$ASDF_CONFIG_DEFAULT_FILE
|
|
|
|
run asdf update
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
cd $ASDF_DIR
|
|
|
|
git tag | grep $tag
|
|
|
|
[ "$?" -eq 0 ]
|
|
|
|
fi
|
2017-03-15 09:37:41 -07:00
|
|
|
}
|
|
|
|
|
2020-03-12 04:04:19 -07:00
|
|
|
@test "asdf update is a noop for when updates are disabled" {
|
|
|
|
touch $ASDF_DIR/asdf_updates_disabled
|
|
|
|
run asdf update
|
|
|
|
[ "$status" -eq 42 ]
|
|
|
|
[ "$(echo -e "Update command disabled. Please use the package manager that you used to install asdf to upgrade asdf.")" == "$output" ]
|
|
|
|
}
|
|
|
|
|
2019-11-27 01:24:29 -07:00
|
|
|
@test "asdf update is a noop for non-git repos" {
|
2020-01-29 07:58:59 -07:00
|
|
|
rm -rf $ASDF_DIR/.git/
|
2019-11-27 01:24:29 -07:00
|
|
|
run asdf update
|
2020-03-12 04:04:19 -07:00
|
|
|
[ "$status" -eq 42 ]
|
2018-12-01 19:07:44 -07:00
|
|
|
[ "$(echo -e "Update command disabled. Please use the package manager that you used to install asdf to upgrade asdf.")" == "$output" ]
|
|
|
|
}
|
|
|
|
|
2020-03-12 04:04:19 -07:00
|
|
|
@test "asdf update fails with exit code 1" {
|
|
|
|
git --git-dir "$ASDF_DIR/.git" remote set-url origin https://this-host-does-not-exist.xyz
|
|
|
|
run asdf update
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
}
|
|
|
|
|
2019-11-27 01:24:29 -07:00
|
|
|
@test "asdf update should not remove plugin versions" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 1.1.0
|
2017-03-15 09:37:41 -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" ]
|
2019-11-27 01:24:29 -07:00
|
|
|
run asdf update
|
2017-03-15 09:37:41 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2020-09-18 22:37:52 -07:00
|
|
|
[ -f $ASDF_DIR/installs/dummy/1.1.0/version ]
|
2019-11-27 01:24:29 -07:00
|
|
|
run asdf update --head
|
2017-03-15 09:37:41 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2020-09-18 22:37:52 -07:00
|
|
|
[ -f $ASDF_DIR/installs/dummy/1.1.0/version ]
|
2017-03-15 09:37:41 -07:00
|
|
|
}
|
|
|
|
|
2019-11-27 01:24:29 -07:00
|
|
|
@test "asdf update should not remove plugins" {
|
2017-03-15 09:37:41 -07:00
|
|
|
# dummy plugin is already installed
|
2019-11-27 01:24:29 -07:00
|
|
|
run asdf update
|
2017-03-15 09:37:41 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ -d $ASDF_DIR/plugins/dummy ]
|
2019-11-27 01:24:29 -07:00
|
|
|
run asdf update --head
|
2017-03-15 09:37:41 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ -d $ASDF_DIR/plugins/dummy ]
|
|
|
|
}
|
|
|
|
|
2019-11-27 01:24:29 -07:00
|
|
|
@test "asdf update should not remove shims" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 1.1.0
|
2017-03-15 09:37:41 -07:00
|
|
|
[ -f $ASDF_DIR/shims/dummy ]
|
2019-11-27 01:24:29 -07:00
|
|
|
run asdf update
|
2017-03-15 09:37:41 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ -f $ASDF_DIR/shims/dummy ]
|
2019-11-27 01:24:29 -07:00
|
|
|
run asdf update --head
|
2017-03-15 09:37:41 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ -f $ASDF_DIR/shims/dummy ]
|
|
|
|
}
|