mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
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:
parent
8534ca2858
commit
2ca517d8c1
@ -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
79
test/update_command.bats
Normal 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 ]
|
||||
}
|
Loading…
Reference in New Issue
Block a user