From 367a0718bdcc9bdbcebf5f23a1c2e4de0474d44e Mon Sep 17 00:00:00 2001 From: Pol Bassiner Date: Wed, 11 Jan 2017 22:30:24 +0100 Subject: [PATCH] Make upgrade command handle properly multi-upgrade in bash (#524) --- src/main/bash/sdkman-upgrade.sh | 9 +++++++-- src/test/cucumber/upgrade_candidate.feature | 7 +++++++ src/test/resources/__files/groovy-2.4.1.zip | Bin 0 -> 541 bytes 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 src/test/resources/__files/groovy-2.4.1.zip diff --git a/src/main/bash/sdkman-upgrade.sh b/src/main/bash/sdkman-upgrade.sh index 3a86f50f..b7a571b7 100644 --- a/src/main/bash/sdkman-upgrade.sh +++ b/src/main/bash/sdkman-upgrade.sh @@ -65,8 +65,13 @@ function __sdk_upgrade { read UPGRADE_ALL export auto_answer_upgrade='true' if [[ -z "$UPGRADE_ALL" || "$UPGRADE_ALL" == "y" || "$UPGRADE_ALL" == "Y" ]]; then - for upgradable_candidate in ${upgradable_candidates}; do - __sdk_install $upgradable_candidate + # Using array for bash & zsh compatibility + for (( i=0; i <= ${#upgradable_candidates[*]}; i++ )); do + upgradable_candidate="${upgradable_candidates[${i}]}" + # Filter empty elements (in bash arrays are zero index based, in zsh they are 1 based) + if [[ -n "$upgradable_candidate" ]]; then + __sdk_install $upgradable_candidate + fi done fi unset auto_answer_upgrade diff --git a/src/test/cucumber/upgrade_candidate.feature b/src/test/cucumber/upgrade_candidate.feature index aa3398f0..1d85bfc5 100644 --- a/src/test/cucumber/upgrade_candidate.feature +++ b/src/test/cucumber/upgrade_candidate.feature @@ -63,14 +63,21 @@ Feature: Upgrade Candidate Given the candidate "grails" version "1.3.9" is already installed and default And the default "grails" version is "2.1.0" And the candidate "grails" version "2.1.0" is available for download + And the candidate "groovy" version "2.0.5" is already installed and default + And the default "groovy" version is "2.4.1" + And the candidate "groovy" version "2.4.1" is available for download And the system is bootstrapped When I enter "sdk upgrade" and answer "Y" Then I see "Upgrade:" And I see "grails (1.3.9 < 2.1.0)" + And I see "groovy (2.0.5 < 2.4.1)" And I see "Upgrade candidate(s) and set latest version(s) as default? (Y/n)" And I do not see "Do you want grails 2.1.0 to be set as default? (Y/n)" And I see "Setting grails 2.1.0 as default." + And I do not see "Do you want groovy 2.4.1 to be set as default? (Y/n)" + And I see "Setting groovy 2.4.1 as default." Then the candidate "grails" version "2.1.0" should be the default + And the candidate "groovy" version "2.4.1" should be the default Scenario: Don't update all upgradable candidates versions and set them as default Given the candidate "grails" version "1.3.9" is already installed and default diff --git a/src/test/resources/__files/groovy-2.4.1.zip b/src/test/resources/__files/groovy-2.4.1.zip new file mode 100644 index 0000000000000000000000000000000000000000..1b302efd3ba19229efc186fc9e0e0a6d2fac0517 GIT binary patch literal 541 zcmWIWW@h1H0D_a;bdU$TOJZ9HmfY6w1S&~ zk>v$50|S@{fE&ZSPTLFF7(sMnk}~rkMzI2oVJBo%!pFO;vOx1dSR9*C5GR7&1~L$Y z(cG4roRP1f*pLN?ZZnj7)OOxI#bz>JtHmw~intT6nNR!UN4d zWFs*{1KCJ-bR!{Q12h(kH_(km4H<~Bj6egIG)}^1EG(RG8P3WE)WyIIgzO+wK$rml D520p0 literal 0 HcmV?d00001