Fix exit codes in fish (#27028)

This commit is contained in:
Harmen Stoppels 2021-10-29 03:10:31 +02:00 committed by GitHub
parent c04b2fa26a
commit 574395af93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 13 deletions

View File

@ -289,13 +289,13 @@ spack -m install --fake a
# create a test environment for testing environment commands # create a test environment for testing environment commands
echo "Creating a mock environment" echo "Creating a mock environment"
spack env create spack_test_env spt_succeeds spack env create spack_test_env
spack env create spack_test_2_env spt_succeeds spack env create spack_test_2_env
# ensure that we uninstall b on exit # ensure that we uninstall b on exit
function spt_cleanup -p %self function spt_cleanup -p %self
echo "Removing test environment before exiting." 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 spack env rm -y spack_test_env spack_test_2_env
title "Cleanup" title "Cleanup"
@ -381,14 +381,17 @@ spt_contains "usage: spack env deactivate " spack env deactivate --help
title 'Testing activate and deactivate together' title 'Testing activate and deactivate together'
echo "Testing 'spack env activate spack_test_env'" echo "Testing 'spack env activate spack_test_env'"
spt_succeeds spack env activate spack_test_env
spack env activate spack_test_env spack env activate spack_test_env
is_set SPACK_ENV is_set SPACK_ENV
echo "Testing 'spack env deactivate'" echo "Testing 'spack env deactivate'"
spt_succeeds spack env deactivate
spack env deactivate spack env deactivate
is_not_set SPACK_ENV is_not_set SPACK_ENV
echo "Testing 'spack env activate spack_test_env'" echo "Testing 'spack env activate spack_test_env'"
spt_succeeds spack env activate spack_test_env
spack env activate spack_test_env spack env activate spack_test_env
is_set SPACK_ENV is_set SPACK_ENV
@ -397,6 +400,7 @@ despacktivate
is_not_set SPACK_ENV is_not_set SPACK_ENV
echo "Testing 'spack env activate --temp'" echo "Testing 'spack env activate --temp'"
spt_succeeds spack env activate --temp
spack env activate --temp spack env activate --temp
is_set SPACK_ENV is_set SPACK_ENV
spack env deactivate spack env deactivate
@ -407,6 +411,12 @@ spack env activate spack_test_env
spack env activate spack_test_2_env spack env activate spack_test_2_env
spt_contains 'spack_test_2_env' 'fish' '-c' 'echo $PATH' spt_contains 'spack_test_2_env' 'fish' '-c' 'echo $PATH'
spt_does_not_contain 'spack_test_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. # NOTE: `--prompt` on fish does nothing => currently not implemented.

View File

@ -383,7 +383,7 @@ function spack_runner -d "Runner function for the `spack` wrapper"
if check_sp_flags $sp_flags if check_sp_flags $sp_flags
command spack $sp_flags $__sp_remaining_args command spack $sp_flags $__sp_remaining_args
return 0 return
end 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" if test "x$sp_arg" = "x-h"; or test "x$sp_arg" = "x--help"
# nothing more needs to be done for `-h` or `--help` # nothing more needs to be done for `-h` or `--help`
command spack cd -h command spack cd -h
return
else else
# extract location using the subcommand (fish `(...)`) # extract location using the subcommand (fish `(...)`)
set -l LOC (command spack location $sp_arg $__sp_remaining_args) 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: # test location and cd if exists:
if test -d "$LOC" if test -d "$LOC"
cd $LOC cd $LOC
return
else else
return 1 return 1
end end
end end
return 0
# CASE: spack subcommand is `env`. Here we get the spack runtime to # CASE: spack subcommand is `env`. Here we get the spack runtime to
# supply the appropriate shell commands for setting the environment # 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" if test "x$sp_arg" = "x-h"; or test "x$sp_arg" = "x--help"
# nothing more needs to be done for `-h` or `--help` # nothing more needs to be done for `-h` or `--help`
command spack env -h command spack env -h
return
else else
switch $sp_arg switch $sp_arg
case "activate" case "activate"
@ -469,6 +470,7 @@ function spack_runner -d "Runner function for the `spack` wrapper"
if check_env_activate_flags $_a if check_env_activate_flags $_a
# no args or args contain -h/--help, --sh, or --csh: just execute # no args or args contain -h/--help, --sh, or --csh: just execute
command spack env activate $_a command spack env activate $_a
return
else else
# actual call to activate: source the output # actual call to activate: source the output
set -l sp_env_cmd "command spack $sp_flags env activate --fish $__sp_remaining_args" 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" if test -n "$__sp_stderr"
echo -s \n$__sp_stderr 1>&2 # current fish bug: handle stderr manually echo -s \n$__sp_stderr 1>&2 # current fish bug: handle stderr manually
end end
return $__sp_stat
end end
case "deactivate" case "deactivate"
@ -485,6 +488,7 @@ function spack_runner -d "Runner function for the `spack` wrapper"
if check_env_deactivate_flags $_a if check_env_deactivate_flags $_a
# just execute the command if --sh, --csh, or --fish are provided # just execute the command if --sh, --csh, or --fish are provided
command spack env deactivate $_a command spack env deactivate $_a
return
# Test of further (unparsed arguments). Any other # Test of further (unparsed arguments). Any other
# arguments are an error or help, so just run help # 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). # -> Notes: [1] (cf. EOF).
else if test -n "$__sp_remaining_args" else if test -n "$__sp_remaining_args"
command spack env deactivate -h command spack env deactivate -h
return
else else
# no args: source the output of the command # no args: source the output of the command
set -l sp_env_cmd "command spack $sp_flags env deactivate --fish" set -l sp_env_cmd "command spack $sp_flags env deactivate --fish"
capture_all $sp_env_cmd __sp_stat __sp_stdout __sp_stderr capture_all $sp_env_cmd __sp_stat __sp_stdout __sp_stderr
eval $__sp_stdout
if test $__sp_stat -ne 0 if test $__sp_stat -ne 0
if test -n "$__sp_stderr" if test -n "$__sp_stderr"
echo -s \n$__sp_stderr 1>&2 # current fish bug: handle stderr manually echo -s \n$__sp_stderr 1>&2 # current fish bug: handle stderr manually
end end
return 1 return $__sp_stat
end end
eval $__sp_stdout
end end
case "*" case "*"
@ -512,8 +517,10 @@ function spack_runner -d "Runner function for the `spack` wrapper"
# string input!) # string input!)
if test -n "$__sp_remaining_args" if test -n "$__sp_remaining_args"
command spack env $sp_arg $__sp_remaining_args command spack env $sp_arg $__sp_remaining_args
return
else else
command spack env $sp_arg command spack env $sp_arg
return
end end
end end
end end
@ -531,17 +538,18 @@ function spack_runner -d "Runner function for the `spack` wrapper"
if check_env_activate_flags $_a if check_env_activate_flags $_a
# no args or args contain -h/--help, --sh, or --csh: just execute # no args or args contain -h/--help, --sh, or --csh: just execute
command spack $sp_flags $sp_subcommand $__sp_remaining_args command spack $sp_flags $sp_subcommand $__sp_remaining_args
return
else else
# actual call to activate: source the output # actual call to activate: source the output
set -l sp_env_cmd "command spack $sp_flags $sp_subcommand --fish $__sp_remaining_args" 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 capture_all $sp_env_cmd __sp_stat __sp_stdout __sp_stderr
eval $__sp_stdout
if test $__sp_stat -ne 0 if test $__sp_stat -ne 0
if test -n "$__sp_stderr" if test -n "$__sp_stderr"
echo -s \n$__sp_stderr 1>&2 # current fish bug: handle stderr manually echo -s \n$__sp_stderr 1>&2 # current fish bug: handle stderr manually
end end
return 1 return $__sp_stat
end end
eval $__sp_stdout
end end
@ -549,10 +557,8 @@ function spack_runner -d "Runner function for the `spack` wrapper"
case "*" case "*"
command spack $argv command spack $argv
return
end end
return 0
end end