From 2ac8b8df1bff7c38b1a4008d3ef528e93a4bbec9 Mon Sep 17 00:00:00 2001 From: Chun-Hsu Lai Date: Sun, 5 May 2024 21:50:13 +0800 Subject: [PATCH 1/3] fix use command will use unavailable flavor --- scripts/init | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) 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 From 1e70d32d35f0429a72ae4bb8e6bc8e76bd745ee5 Mon Sep 17 00:00:00 2001 From: Chun-Hsu Lai Date: Sun, 5 May 2024 22:11:19 +0800 Subject: [PATCH 2/3] add unit test to test use cmd --- tests/runner.sh | 1 + tests/test_init.sh | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100755 tests/test_init.sh 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..d6ead47 --- /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 + assertNotNull ${DEVENVFLAVOR} + devenv off + devenv del foo + devenv use foo + assertNull "${DEVENVFLAVOR}" +} + +# Load and run shUnit2. +. ./shunit2/shunit2 From 9ca221e21533b7f6f2b109f4596fee1f814e1c73 Mon Sep 17 00:00:00 2001 From: Chun-Hsu Lai Date: Mon, 6 May 2024 21:31:35 +0800 Subject: [PATCH 3/3] refine test_init test case --- tests/test_init.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_init.sh b/tests/test_init.sh index d6ead47..bc80c1f 100755 --- a/tests/test_init.sh +++ b/tests/test_init.sh @@ -6,11 +6,11 @@ echo "*** test file: $(basename ${BASH_SOURCE[0]})" test_use_cmd() { devenv add foo devenv use foo - assertNotNull ${DEVENVFLAVOR} + assertEquals ${DEVENVFLAVOR} "foo" devenv off devenv del foo devenv use foo - assertNull "${DEVENVFLAVOR}" + assertNotContains "${DEVENVFLAVOR}" "foo" } # Load and run shUnit2.