summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarmen Stoppels <harmenstoppels@gmail.com>2021-10-29 03:10:31 +0200
committerGitHub <noreply@github.com>2021-10-29 01:10:31 +0000
commit574395af93578dab4bba31b8b62bd47d846e35e1 (patch)
treeae06d5402065286f6fda7b1f09e8d8825015f836
parentc04b2fa26a9f6c4648f609345693f2063403eec5 (diff)
downloadspack-574395af93578dab4bba31b8b62bd47d846e35e1.tar.gz
spack-574395af93578dab4bba31b8b62bd47d846e35e1.tar.bz2
spack-574395af93578dab4bba31b8b62bd47d846e35e1.tar.xz
spack-574395af93578dab4bba31b8b62bd47d846e35e1.zip
Fix exit codes in fish (#27028)
-rwxr-xr-xshare/spack/qa/setup-env-test.fish16
-rwxr-xr-xshare/spack/setup-env.fish26
2 files changed, 29 insertions, 13 deletions
diff --git a/share/spack/qa/setup-env-test.fish b/share/spack/qa/setup-env-test.fish
index c48ecf4bc4..eaa1e34cee 100755
--- a/share/spack/qa/setup-env-test.fish
+++ b/share/spack/qa/setup-env-test.fish
@@ -289,13 +289,13 @@ spack -m install --fake a
# create a test environment for testing environment commands
echo "Creating a mock environment"
-spack env create spack_test_env
-spack env create spack_test_2_env
+spt_succeeds spack env create spack_test_env
+spt_succeeds spack env create spack_test_2_env
# ensure that we uninstall b on exit
function spt_cleanup -p %self
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"
@@ -381,14 +381,17 @@ spt_contains "usage: spack env deactivate " spack env deactivate --help
title 'Testing activate and deactivate together'
echo "Testing 'spack env activate spack_test_env'"
+spt_succeeds spack env activate spack_test_env
spack env activate spack_test_env
is_set SPACK_ENV
echo "Testing 'spack env deactivate'"
+spt_succeeds spack env deactivate
spack env deactivate
is_not_set SPACK_ENV
echo "Testing 'spack env activate spack_test_env'"
+spt_succeeds spack env activate spack_test_env
spack env activate spack_test_env
is_set SPACK_ENV
@@ -397,6 +400,7 @@ despacktivate
is_not_set SPACK_ENV
echo "Testing 'spack env activate --temp'"
+spt_succeeds spack env activate --temp
spack env activate --temp
is_set SPACK_ENV
spack env deactivate
@@ -407,6 +411,12 @@ spack env activate spack_test_env
spack env activate spack_test_2_env
spt_contains 'spack_test_2_env' 'fish' '-c' 'echo $PATH'
spt_does_not_contain 'spack_test_env' 'fish' '-c' 'echo $PATH'
+despacktivate
+
+echo "Correct error exit codes for activate and deactivate"
+spt_fails spack env activate nonexisiting_environment
+spt_fails spack env deactivate
+
#
# NOTE: `--prompt` on fish does nothing => currently not implemented.
diff --git a/share/spack/setup-env.fish b/share/spack/setup-env.fish
index 5205cff206..85a453d1c4 100755
--- a/share/spack/setup-env.fish
+++ b/share/spack/setup-env.fish
@@ -383,7 +383,7 @@ function spack_runner -d "Runner function for the `spack` wrapper"
if check_sp_flags $sp_flags
command spack $sp_flags $__sp_remaining_args
- return 0
+ return
end
@@ -426,6 +426,7 @@ function spack_runner -d "Runner function for the `spack` wrapper"
if test "x$sp_arg" = "x-h"; or test "x$sp_arg" = "x--help"
# nothing more needs to be done for `-h` or `--help`
command spack cd -h
+ return
else
# extract location using the subcommand (fish `(...)`)
set -l LOC (command spack location $sp_arg $__sp_remaining_args)
@@ -433,14 +434,13 @@ function spack_runner -d "Runner function for the `spack` wrapper"
# test location and cd if exists:
if test -d "$LOC"
cd $LOC
+ return
else
return 1
end
end
- return 0
-
# CASE: spack subcommand is `env`. Here we get the spack runtime to
# supply the appropriate shell commands for setting the environment
@@ -461,6 +461,7 @@ function spack_runner -d "Runner function for the `spack` wrapper"
if test "x$sp_arg" = "x-h"; or test "x$sp_arg" = "x--help"
# nothing more needs to be done for `-h` or `--help`
command spack env -h
+ return
else
switch $sp_arg
case "activate"
@@ -469,6 +470,7 @@ function spack_runner -d "Runner function for the `spack` wrapper"
if check_env_activate_flags $_a
# no args or args contain -h/--help, --sh, or --csh: just execute
command spack env activate $_a
+ return
else
# actual call to activate: source the output
set -l sp_env_cmd "command spack $sp_flags env activate --fish $__sp_remaining_args"
@@ -477,6 +479,7 @@ function spack_runner -d "Runner function for the `spack` wrapper"
if test -n "$__sp_stderr"
echo -s \n$__sp_stderr 1>&2 # current fish bug: handle stderr manually
end
+ return $__sp_stat
end
case "deactivate"
@@ -485,6 +488,7 @@ function spack_runner -d "Runner function for the `spack` wrapper"
if check_env_deactivate_flags $_a
# just execute the command if --sh, --csh, or --fish are provided
command spack env deactivate $_a
+ return
# Test of further (unparsed arguments). Any other
# arguments are an error or help, so just run help
@@ -493,17 +497,18 @@ function spack_runner -d "Runner function for the `spack` wrapper"
# -> Notes: [1] (cf. EOF).
else if test -n "$__sp_remaining_args"
command spack env deactivate -h
+ return
else
# no args: source the output of the command
set -l sp_env_cmd "command spack $sp_flags env deactivate --fish"
capture_all $sp_env_cmd __sp_stat __sp_stdout __sp_stderr
- eval $__sp_stdout
if test $__sp_stat -ne 0
if test -n "$__sp_stderr"
echo -s \n$__sp_stderr 1>&2 # current fish bug: handle stderr manually
end
- return 1
+ return $__sp_stat
end
+ eval $__sp_stdout
end
case "*"
@@ -512,8 +517,10 @@ function spack_runner -d "Runner function for the `spack` wrapper"
# string input!)
if test -n "$__sp_remaining_args"
command spack env $sp_arg $__sp_remaining_args
+ return
else
command spack env $sp_arg
+ return
end
end
end
@@ -531,17 +538,18 @@ function spack_runner -d "Runner function for the `spack` wrapper"
if check_env_activate_flags $_a
# no args or args contain -h/--help, --sh, or --csh: just execute
command spack $sp_flags $sp_subcommand $__sp_remaining_args
+ return
else
# actual call to activate: source the output
set -l sp_env_cmd "command spack $sp_flags $sp_subcommand --fish $__sp_remaining_args"
capture_all $sp_env_cmd __sp_stat __sp_stdout __sp_stderr
- eval $__sp_stdout
if test $__sp_stat -ne 0
if test -n "$__sp_stderr"
echo -s \n$__sp_stderr 1>&2 # current fish bug: handle stderr manually
end
- return 1
+ return $__sp_stat
end
+ eval $__sp_stdout
end
@@ -549,10 +557,8 @@ function spack_runner -d "Runner function for the `spack` wrapper"
case "*"
command spack $argv
-
+ return
end
-
- return 0
end