diff --git a/scripts/init b/scripts/init index a6b9fed..25502ff 100644 --- a/scripts/init +++ b/scripts/init @@ -20,23 +20,22 @@ devenv() { ;; use) shift - # create subshell to isolate name space - ( - . ${DEVENVROOT}/scripts/func.d/bash_utils - if [ ! -d "${DEVENVFLAVORROOT}/$1" ]; then - devenv_display "flavor $1 is not available" - return + if [ ! -d "${DEVENVFLAVORROOT}/$1" ]; then + # create subshell to isolate name space + ( + . ${DEVENVROOT}/scripts/func.d/bash_utils + devenv_display -e "flavor $1 is not available" + ) + else + # cmd use need to manipulate current session's env variables + # therefore subshell is not working here + if [ ! -z "${DEVENVFLAVOR}" ] ; then + devenv_act devenv_nameremove ${DEVENVFLAVOR} fi - ) - # cmd use need to manipulate current session's env variables - # therefore subshell is not working here - if [ ! -z "${DEVENVFLAVOR}" ] ; then - devenv_act devenv_nameremove ${DEVENVFLAVOR} + devenv_act devenv_namemunge $1 + export DEVENVCURRENTROOT=${DEVENVFLAVORROOT}/${DEVENVFLAVOR} + echo "now using '${DEVENVFLAVOR}'" fi - - devenv_act devenv_namemunge $1 - export DEVENVCURRENTROOT=${DEVENVFLAVORROOT}/${DEVENVFLAVOR} - echo "now using '${DEVENVFLAVOR}'" ;; off) # create subshell to isolate name space diff --git a/tests/runner.sh b/tests/runner.sh index 12baa6d..7aeaa48 100755 --- a/tests/runner.sh +++ b/tests/runner.sh @@ -5,5 +5,6 @@ final_ret=0 ./test_init_var.sh ; if [ $? != 0 ] ; then final_ret=1 ; fi ./test_bash_utils.sh ; if [ $? != 0 ] ; then final_ret=1 ; fi ./test_devenv_impl.sh ; if [ $? != 0 ] ; then final_ret=1 ; fi +./test_init.sh ; if [ $? != 0 ] ; then final_ret=1 ; fi exit $final_ret diff --git a/tests/test_init.sh b/tests/test_init.sh new file mode 100755 index 0000000..bc80c1f --- /dev/null +++ b/tests/test_init.sh @@ -0,0 +1,17 @@ +#!/bin/bash +. ../scripts/init + +echo "*** test file: $(basename ${BASH_SOURCE[0]})" + +test_use_cmd() { + devenv add foo + devenv use foo + assertEquals ${DEVENVFLAVOR} "foo" + devenv off + devenv del foo + devenv use foo + assertNotContains "${DEVENVFLAVOR}" "foo" +} + +# Load and run shUnit2. +. ./shunit2/shunit2