summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorHarmen Stoppels <harmenstoppels@gmail.com>2021-10-29 10:10:22 +0200
committerGitHub <noreply@github.com>2021-10-29 08:10:22 +0000
commit49034abd769af00ed85ca6583b83f1f36e42ce11 (patch)
tree1db3bce306a786d90a1b717827d3b013e7d971a9 /share
parentf610b506cdad8b8717bcecc3d9138136a26fa6b8 (diff)
downloadspack-49034abd769af00ed85ca6583b83f1f36e42ce11.tar.gz
spack-49034abd769af00ed85ca6583b83f1f36e42ce11.tar.bz2
spack-49034abd769af00ed85ca6583b83f1f36e42ce11.tar.xz
spack-49034abd769af00ed85ca6583b83f1f36e42ce11.zip
Fix exit codes posix shell wrapper (#27012)
* Correct exit code in sh wrapper * Fix tests * SC2069
Diffstat (limited to 'share')
-rwxr-xr-xshare/spack/qa/setup-env-test.sh14
-rwxr-xr-xshare/spack/setup-env.sh13
2 files changed, 21 insertions, 6 deletions
diff --git a/share/spack/qa/setup-env-test.sh b/share/spack/qa/setup-env-test.sh
index bddf7ca1af..b93ac6c0e6 100755
--- a/share/spack/qa/setup-env-test.sh
+++ b/share/spack/qa/setup-env-test.sh
@@ -75,7 +75,7 @@ spack env create spack_test_2_env
# Ensure that we uninstall b on exit
cleanup() {
echo "Removing test environment before exiting."
- spack env deactivate 2>&1 > /dev/null
+ spack env deactivate > /dev/null 2>&1
spack env rm -y spack_test_env spack_test_2_env
title "Cleanup"
@@ -149,14 +149,17 @@ contains "usage: spack env deactivate " spack env deactivate --help
title 'Testing activate and deactivate together'
echo "Testing 'spack env activate spack_test_env'"
+succeeds spack env activate spack_test_env
spack env activate spack_test_env
is_set SPACK_ENV
echo "Testing 'spack env deactivate'"
+succeeds spack env deactivate
spack env deactivate
is_not_set SPACK_ENV
echo "Testing 'spack env activate spack_test_env'"
+succeeds spack env activate spack_test_env
spack env activate spack_test_env
is_set SPACK_ENV
@@ -165,6 +168,7 @@ despacktivate
is_not_set SPACK_ENV
echo "Testing 'spack env activate --prompt spack_test_env'"
+succeeds spack env activate --prompt spack_test_env
spack env activate --prompt spack_test_env
is_set SPACK_ENV
is_set SPACK_OLD_PS1
@@ -175,13 +179,21 @@ is_not_set SPACK_ENV
is_not_set SPACK_OLD_PS1
echo "Testing 'spack env activate --temp'"
+succeeds spack env activate --temp
spack env activate --temp
is_set SPACK_ENV
+succeeds spack env deactivate
spack env deactivate
is_not_set SPACK_ENV
echo "Testing spack env activate repeatedly"
spack env activate spack_test_env
+succeeds spack env activate spack_test_2_env
spack env activate spack_test_2_env
contains "spack_test_2_env" sh -c 'echo $PATH'
does_not_contain "spack_test_env" sh -c 'echo $PATH'
+despacktivate
+
+echo "Correct error exit codes for activate and deactivate"
+fails spack env activate nonexisiting_environment
+fails spack env deactivate
diff --git a/share/spack/setup-env.sh b/share/spack/setup-env.sh
index 21bd696386..eb364a3809 100755
--- a/share/spack/setup-env.sh
+++ b/share/spack/setup-env.sh
@@ -136,7 +136,8 @@ _spack_shell_wrapper() {
command spack env activate "$@"
else
# Actual call to activate: source the output.
- eval $(command spack $_sp_flags env activate --sh "$@")
+ stdout="$(command spack $_sp_flags env activate --sh "$@")" || return
+ eval "$stdout"
fi
;;
deactivate)
@@ -157,7 +158,8 @@ _spack_shell_wrapper() {
command spack env deactivate -h
else
# No args: source the output of the command.
- eval $(command spack $_sp_flags env deactivate --sh)
+ stdout="$(command spack $_sp_flags env deactivate --sh)" || return
+ eval "$stdout"
fi
;;
*)
@@ -183,8 +185,8 @@ _spack_shell_wrapper() {
# Args contain --sh, --csh, or -h/--help: just execute.
command spack $_sp_flags $_sp_subcommand "$@"
else
- eval $(command spack $_sp_flags $_sp_subcommand --sh "$@" || \
- echo "return 1") # return 1 if spack command fails
+ stdout="$(command spack $_sp_flags $_sp_subcommand --sh "$@")" || return
+ eval "$stdout"
fi
;;
*)
@@ -363,7 +365,8 @@ if [ -z "${SPACK_SKIP_MODULES+x}" ]; then
_spack_pathadd PATH "${_sp_module_bin}"
fi;
else
- eval `spack --print-shell-vars sh`
+ stdout="$(command spack --print-shell-vars sh)" || return
+ eval "$stdout"
fi;