Add tests for the update command. Use sed instead of tail -r to get the

latest tag from the list of sorted tags.

The setup code for these tests isn't ideal. It would be nice not to have
to worry about the remote. Without the 'origin' remote set the Travis
build would fail though.
This commit is contained in:
Trevor Brown 2017-03-15 12:37:41 -04:00
parent 8534ca2858
commit 2ca517d8c1
2 changed files with 82 additions and 6 deletions

View File

@ -6,18 +6,15 @@ update_command() {
if [ "$update_to_head" = "--head" ]; then
# Update to latest on the master branch
git checkout master || exit 1
git checkout master
# Pull down the latest changes on master
git pull origin master || exit 1
git pull origin master
echo "Updated asdf to latest on the master branch"
else
# Update to latest release
git fetch --tags || exit 1
tags=$(git tag | sort_versions | tail -r) || exit 1
# Pick the newest tag
tag=$(echo $tags | cut -d ' ' -f1)
tag=$(git tag | sort_versions | sed '$!d') || exit 1
# Update
git checkout "$tag" || exit 1

79
test/update_command.bats Normal file
View File

@ -0,0 +1,79 @@
#!/usr/bin/env bats
load test_helpers
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/update.sh
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/reshim.sh
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/install.sh
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/uninstall.sh
setup() {
setup_asdf_dir
install_dummy_plugin
# Copy over git repo so we have something to test with
cp -r . $ASDF_DIR
(
cd $ASDF_DIR
git remote remove origin
git remote add origin https://github.com/asdf-vm/asdf.git
git checkout .
)
PROJECT_DIR=$HOME/project
mkdir $PROJECT_DIR
}
teardown() {
clean_asdf_dir
}
@test "update_command --head should checkout the master branch" {
run update_command --head
[ "$status" -eq 0 ]
cd $ASDF_DIR
# TODO: Figure out why this is failing
#[ $(git rev-parse --abbrev-ref HEAD) = "master" ]
}
@test "update_command should checkout the latest tag" {
run update_command
[ "$status" -eq 0 ]
cd $ASDF_DIR
local tag=$(git describe --tag)
echo $(git tag) | grep $tag
[ "$status" -eq 0 ]
}
@test "update_command should not remove plugin versions" {
run install_command dummy 1.1
[ "$status" -eq 0 ]
[ $(cat $ASDF_DIR/installs/dummy/1.1/version) = "1.1" ]
run update_command
[ "$status" -eq 0 ]
[ -f $ASDF_DIR/installs/dummy/1.1/version ]
run update_command --head
[ "$status" -eq 0 ]
[ -f $ASDF_DIR/installs/dummy/1.1/version ]
}
@test "update_command should not remove plugins" {
# dummy plugin is already installed
run update_command
[ "$status" -eq 0 ]
[ -d $ASDF_DIR/plugins/dummy ]
run update_command --head
[ "$status" -eq 0 ]
[ -d $ASDF_DIR/plugins/dummy ]
}
@test "update_command should not remove shims" {
run install_command dummy 1.1
[ -f $ASDF_DIR/shims/dummy ]
run update_command
[ "$status" -eq 0 ]
[ -f $ASDF_DIR/shims/dummy ]
run update_command --head
[ "$status" -eq 0 ]
[ -f $ASDF_DIR/shims/dummy ]
}