Fix exit codes posix shell wrapper (#27012)

* Correct exit code in sh wrapper

* Fix tests

* SC2069
This commit is contained in:
Harmen Stoppels 2021-10-29 10:10:22 +02:00 committed by GitHub
parent f610b506cd
commit 49034abd76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 6 deletions

View File

@ -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

View File

@ -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;