From dd28a7aab9895df2d5cff2b7d9bad5b580dd76e1 Mon Sep 17 00:00:00 2001 From: Elias Dorneles Date: Wed, 19 Jun 2013 22:28:52 -0300 Subject: [PATCH] added tests for shortcuts, and removed candidates in place of commands --- src/main/bash/gvm-main.sh | 52 ++++++++++--------------- src/test/cucumber/gvm/shortcuts.feature | 52 +++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 31 deletions(-) create mode 100644 src/test/cucumber/gvm/shortcuts.feature diff --git a/src/main/bash/gvm-main.sh b/src/main/bash/gvm-main.sh index 86bd5c37..43dddd13 100644 --- a/src/main/bash/gvm-main.sh +++ b/src/main/bash/gvm-main.sh @@ -59,83 +59,73 @@ function gvm { source "${GVM_DIR}/etc/config" fi - command="$1" - candidate="$2" + COMMAND="$1" + CANDIDATE="$2" shift; shift # no command provided - if [[ -z "$command" ]]; then + if [[ -z "$COMMAND" ]]; then __gvmtool_help return 1 fi - case "$command" in + case "$COMMAND" in ls) - command="list";; + COMMAND="list";; h) - command="help";; + COMMAND="help";; v) - command="version";; + COMMAND="version";; u) - command="use";; + COMMAND="use";; remove) - command="uninstall";; + COMMAND="uninstall";; cur) - command="current";; + COMMAND="current";; def) - command="default";; - groovy) # assumes the command use, if ommitted - command="use"; candidate="groovy";; - grails) - command="use"; candidate="grails";; - gradle) - command="use"; candidate="gradle";; - lazybones) - command="use"; candidate="lazybones";; - vertx) - command="use"; candidate="vertx";; + COMMAND="default";; esac # Check if it is a valid command CMD_FOUND="" - CMD_TARGET="${GVM_DIR}/src/gvm-$command.sh" + CMD_TARGET="${GVM_DIR}/src/gvm-${COMMAND}.sh" if [[ -f "${CMD_TARGET}" ]]; then CMD_FOUND="${CMD_TARGET}" fi # Check if it is a sourced function - CMD_TARGET="${GVM_DIR}/ext/gvm-$command.sh" + CMD_TARGET="${GVM_DIR}/ext/gvm-${COMMAND}" if [[ -f "${CMD_TARGET}" ]]; then CMD_FOUND="${CMD_TARGET}" fi # couldn't find the command if [[ -z "${CMD_FOUND}" ]]; then - echo "Invalid command: $command" + echo "Invalid command: ${COMMAND}" __gvmtool_help fi # Check whether the candidate exists - if [[ -n "$candidate" && "$command" != "offline" && -z $(echo ${GVM_CANDIDATES[@]} | grep -w "$candidate") ]]; then - echo -e "\nStop! $candidate is not a valid candidate." + if [[ -n "${CANDIDATE}" && "${COMMAND}" != "offline" && -z $(echo ${GVM_CANDIDATES[@]} | grep -w "${CANDIDATE}") ]]; then + echo -e "\nStop! ${CANDIDATE} is not a valid candidate." return 1 fi - if [[ "$command" == "offline" && -z "$candidate" ]]; then + if [[ "${COMMAND}" == "offline" && -z "${CANDIDATE}" ]]; then echo -e "\nStop! Specify a valid offline mode." - elif [[ "$command" == "offline" && ( -z $(echo "enable disable" | grep -w "$candidate")) ]]; then - echo -e "\nStop! $candidate is not a valid offline mode." + elif [[ "${COMMAND}" == "offline" && ( -z $(echo "enable disable" | grep -w "${CANDIDATE}")) ]]; then + echo -e "\nStop! ${CANDIDATE} is not a valid offline mode." fi # Check whether the command exists as an internal function... # # NOTE Internal commands use underscores rather than hyphens, # hence the name conversion as the first step here. - CONVERTED_CMD_NAME=$(echo "$command" | tr '-' '_') + CONVERTED_CMD_NAME=$(echo "${COMMAND}" | tr '-' '_') # Execute the requested command if [ -n "${CMD_FOUND}" ]; then # It's available as a shell function - __gvmtool_"${CONVERTED_CMD_NAME}" "$candidate" $@ + __gvmtool_"${CONVERTED_CMD_NAME}" "${CANDIDATE}" $@ fi } diff --git a/src/test/cucumber/gvm/shortcuts.feature b/src/test/cucumber/gvm/shortcuts.feature new file mode 100644 index 00000000..268cd2d1 --- /dev/null +++ b/src/test/cucumber/gvm/shortcuts.feature @@ -0,0 +1,52 @@ +Feature: Shortcuts + + Background: + Given the internet is reachable + + Scenario: Shortcut - List an uninstalled available Version + Given I do not have a "grails" candidate installed + When I enter "gvm ls grails" + Then I see "Available Grails Versions" + And I see " 2.1.0" + + Scenario: Shortcut - Ask for help + When I enter "gvm h" + Then I see "Usage: gvm [version]" + + Scenario: Shortcut - Display current candidate version in use + Given the candidate "grails" version "1.3.9" is already installed and default + When I enter "gvm cur grails" + Then I see "Using grails version 1.3.9" + + Scenario: Shortcut - Display current candidate versions + Given the candidate "groovy" version "2.0.5" is already installed and default + And the candidate "grails" version "2.1.0" is already installed and default + When I enter "gvm cur" + Then I see "Using:" + And I see "grails: 2.1.0" + And I see "groovy: 2.0.5" + + Scenario: Shortcut - Uninstall a local development version + Given the candidate "groovy" version "2.1-SNAPSHOT" is already linked to "/tmp/groovy-core" + When I enter "gvm remove groovy 2.1-SNAPSHOT" + Then I see "Uninstalling groovy 2.1-SNAPSHOT" + And the candidate "groovy" version "2.1-SNAPSHOT" is not installed + + Scenario: Shortcut - Show the current version of gvm + When I enter "gvm version" + Then I see "Groovy enVironment Manager x.y.z" + + Scenario: Shortcut - Use a candidate version that is installed + Given the candidate "grails" version "2.1.0" is already installed and default + And the candidate "grails" version "1.3.9" is already installed but not default + When I enter "gvm u grails 1.3.9" + Then I see "Using grails version 1.3.9 in this shell." + Then the candidate "grails" version "1.3.9" should be in use + And the candidate "grails" version "2.1.0" should be the default + + Scenario: Shortcut - Default a candidate version that is installed and not default + And the candidate "groovy" version "2.0.5" is already installed but not default + When I enter "gvm def groovy 2.0.5" + Then I see "Default groovy version set to 2.0.5" + And the candidate "groovy" version "2.0.5" should be the default +