Skip to content

Commit

Permalink
setup-env.sh: make setup scripts work with set -u
Browse files Browse the repository at this point in the history
- Add set -u to the setup-env.sh test script

- Refactor lines in setup-env.sh that tested potentially undefined
  variables to use the `[ -z ${var+x} ]` construct
  • Loading branch information
tgamblin committed Jul 3, 2019
1 parent 52c936e commit 035efed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions share/spack/qa/setup-env-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ unuse() {
# Make sure no environment is active
unset SPACK_ENV

# fail with undefined variables
set -u

# Source setup-env.sh before tests
. share/spack/setup-env.sh

Expand Down
7 changes: 4 additions & 3 deletions share/spack/setup-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ spack() {
fi

# accumulate initial flags for main spack command
# trnaslation for humans: "while $1 is set and $1 starts with -"
_sp_flags=""
while [ "${1#-}" != "${1}" ]; do
while [ ! -z ${1+x} ] && [ "${1#-}" != "${1}" ]; do
_sp_flags="$_sp_flags $1"
shift
done
Expand All @@ -63,7 +64,7 @@ spack() {
fi

_sp_subcommand=""
if [ -n "$1" ]; then
if [ ! -z ${1+x} ]; then
_sp_subcommand="$1"
shift
fi
Expand Down Expand Up @@ -102,7 +103,7 @@ spack() {
case $_sp_arg in
activate)
_a="$@"
if [ -z "$1" ] || \
if [ -z ${1+x} ] || \
[ "${_a#*--sh}" != "$_a" ] || \
[ "${_a#*--csh}" != "$_a" ] || \
[ "${_a#*-h}" != "$_a" ];
Expand Down

0 comments on commit 035efed

Please sign in to comment.