Skip to content

Commit

Permalink
ts: protect sh alias and function unset code
Browse files Browse the repository at this point in the history
  • Loading branch information
xdelaruelle committed Jan 19, 2024
1 parent d8bbcdd commit 4fc85a5
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 67 deletions.
5 changes: 4 additions & 1 deletion testsuite/config/base-config.exp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,10 @@ proc shell_unalias {test_shell var {re_mode 0}} {
}

switch -- $test_shell {
{sh} - {bash} - {ksh} - {zsh} - {csh} - {tcsh} {
{sh} - {bash} - {ksh} - {zsh} {
set answer "unalias $var 2>/dev/null || true;"
}
{csh} - {tcsh} {
set answer "unalias $var;"
}
{fish} {
Expand Down
10 changes: 5 additions & 5 deletions testsuite/modules.50-cmds/391-function-undo.exp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ set ans_sh [list]
lappend ans_sh [list unset _LMFILES_]
lappend ans_sh [list unset LOADEDMODULES]
lappend ans_sh [list unset __MODULES_LMREFRESH]
lappend ans_sh [list "unset -f testsuite2;"]
lappend ans_sh [list "unset -f testsuite3;"]
lappend ans_sh [list "unset -f testsuite4;"]
lappend ans_sh [list "unset -f testsuite;"]
lappend ans_sh [list "unset -f testsuite5;"]
lappend ans_sh [list "unset -f testsuite2 2>/dev/null || true;"]
lappend ans_sh [list "unset -f testsuite3 2>/dev/null || true;"]
lappend ans_sh [list "unset -f testsuite4 2>/dev/null || true;"]
lappend ans_sh [list "unset -f testsuite 2>/dev/null || true;"]
lappend ans_sh [list "unset -f testsuite5 2>/dev/null || true;"]

set ans_empty [list]
lappend ans_empty [list unset _LMFILES_]
Expand Down
68 changes: 34 additions & 34 deletions testsuite/modules.50-cmds/400-source-sh.exp
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ lappend ans [list unalias alsp]
lappend ans [list unalias alfoo]
lappend ans [list unalias alcb]
lappend ans [list unalias alem]
lappend ans [list "unset -f funcfoo;"]
lappend ans [list "unset -f funccb;"]
lappend ans [list "unset -f funcwc;"]
lappend ans [list "unset -f funcnl;"]
lappend ans [list "unset -f funcsp;"]
lappend ans [list "unset -f funcfoo 2>/dev/null || true;"]
lappend ans [list "unset -f funccb 2>/dev/null || true;"]
lappend ans [list "unset -f funcwc 2>/dev/null || true;"]
lappend ans [list "unset -f funcnl 2>/dev/null || true;"]
lappend ans [list "unset -f funcsp 2>/dev/null || true;"]
testouterr_cmd sh {unload source-sh/1} $ans {}

skip_if_quick_mode
Expand Down Expand Up @@ -189,11 +189,11 @@ lappend ans [list unalias alsp]
lappend ans [list unalias alfoo]
lappend ans [list unalias alcb]
lappend ans [list unalias alem]
lappend ans [list "unset -f funcfoo;"]
lappend ans [list "unset -f funccb;"]
lappend ans [list "unset -f funcwc;"]
lappend ans [list "unset -f funcnl;"]
lappend ans [list "unset -f funcsp;"]
lappend ans [list "unset -f funcfoo 2>/dev/null || true;"]
lappend ans [list "unset -f funccb 2>/dev/null || true;"]
lappend ans [list "unset -f funcwc 2>/dev/null || true;"]
lappend ans [list "unset -f funcnl 2>/dev/null || true;"]
lappend ans [list "unset -f funcsp 2>/dev/null || true;"]
testouterr_cmd sh {unload source-sh/1} $ans {}

# load a third modulefile, using same script than firstly loaded module
Expand Down Expand Up @@ -262,11 +262,11 @@ lappend ans [list unalias alsp]
lappend ans [list unalias alfoo]
lappend ans [list unalias alcb]
lappend ans [list unalias alem]
lappend ans [list "unset -f funcfoo;"]
lappend ans [list "unset -f funccb;"]
lappend ans [list "unset -f funcwc;"]
lappend ans [list "unset -f funcnl;"]
lappend ans [list "unset -f funcsp;"]
lappend ans [list "unset -f funcfoo 2>/dev/null || true;"]
lappend ans [list "unset -f funccb 2>/dev/null || true;"]
lappend ans [list "unset -f funcwc 2>/dev/null || true;"]
lappend ans [list "unset -f funcnl 2>/dev/null || true;"]
lappend ans [list "unset -f funcsp 2>/dev/null || true;"]
testouterr_cmd_re sh {unload source-sh/1} $ans {}


Expand Down Expand Up @@ -891,10 +891,10 @@ lappend ans [list unset FOOPATHSPEM]
lappend ans [list unalias alsp]
lappend ans [list unalias alcb]
lappend ans [list unalias alem]
lappend ans [list "unset -f funccb;"]
lappend ans [list "unset -f funcwc;"]
lappend ans [list "unset -f funcnl;"]
lappend ans [list "unset -f funcsp;"]
lappend ans [list "unset -f funccb 2>/dev/null || true;"]
lappend ans [list "unset -f funcwc 2>/dev/null || true;"]
lappend ans [list "unset -f funcnl 2>/dev/null || true;"]
lappend ans [list "unset -f funcsp 2>/dev/null || true;"]
testouterr_cmd sh {unload source-sh/1} $ans {}

unsetenv_var __MODULES_LMREFRESH
Expand Down Expand Up @@ -1320,11 +1320,11 @@ lappend ans [list unalias alsp]
lappend ans [list unalias alfoo]
lappend ans [list unalias alcb]
lappend ans [list unalias alem]
lappend ans [list out {unset -f funcfoo;}]
lappend ans [list out {unset -f funccb;}]
lappend ans [list out {unset -f funcwc;}]
lappend ans [list out {unset -f funcnl;}]
lappend ans [list out {unset -f funcsp;}]
lappend ans [list out {unset -f funcfoo 2>/dev/null || true;}]
lappend ans [list out {unset -f funccb 2>/dev/null || true;}]
lappend ans [list out {unset -f funcwc 2>/dev/null || true;}]
lappend ans [list out {unset -f funcnl 2>/dev/null || true;}]
lappend ans [list out {unset -f funcsp 2>/dev/null || true;}]
lappend ans [list out {complete -r cmd;}]
lappend ans [list out {complete -r othercmd;}]
lappend ans [list out {complete -r mycmd;}]
Expand Down Expand Up @@ -1681,9 +1681,9 @@ if {$install_versioning eq {y}} {
lappend ans [list set MODULE_VERSION $install_version]
}
if {$is_modules_defined} {
lappend ans [list {unset -f ml;}]
lappend ans [list {unset -f module;}]
lappend ans [list {unset -f _module_raw;}]
lappend ans [list {unset -f ml 2>/dev/null || true;}]
lappend ans [list {unset -f module 2>/dev/null || true;}]
lappend ans [list {unset -f _module_raw 2>/dev/null || true;}]
}
testouterr_cmd sh {load source-sh/1} $ans {}

Expand Down Expand Up @@ -1771,9 +1771,9 @@ if {$install_versioning eq {y}} {
lappend ans [list set MODULE_VERSION $install_version]
}
if {$is_modules_defined} {
lappend ans [list {unset -f ml;}]
lappend ans [list {unset -f module;}]
lappend ans [list {unset -f _module_raw;}]
lappend ans [list {unset -f ml 2>/dev/null || true;}]
lappend ans [list {unset -f module 2>/dev/null || true;}]
lappend ans [list {unset -f _module_raw 2>/dev/null || true;}]
}
testouterr_cmd sh {load source-sh/1} $ans {}

Expand Down Expand Up @@ -1806,9 +1806,9 @@ if {$install_versioning eq {y}} {
lappend ans [list set MODULE_VERSION $install_version]
}
if {$is_modules_defined} {
lappend ans [list {unset -f ml;}]
lappend ans [list {unset -f module;}]
lappend ans [list {unset -f _module_raw;}]
lappend ans [list {unset -f ml 2>/dev/null || true;}]
lappend ans [list {unset -f module 2>/dev/null || true;}]
lappend ans [list {unset -f _module_raw 2>/dev/null || true;}]
}
testouterr_cmd sh {load source-sh/1} $ans {}

Expand Down Expand Up @@ -1862,7 +1862,7 @@ lappend ans [list set _LMFILES_ $mp/source-sh/1]
lappend ans [list set LOADEDMODULES source-sh/1]
lappend ans [list set __MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|uncomplete\ cmd\|unset-alias\ alfoo\|unset-function\ funcfoo]
lappend ans [list unalias alfoo]
lappend ans [list out {unset -f funcfoo;}]
lappend ans [list out {unset -f funcfoo 2>/dev/null || true;}]
lappend ans [list out {complete -r cmd;}]
testouterr_cmd bash {load source-sh/1} $ans {}
unsetenv_var TESTSUITE_ENABLE_SITECONFIG_SOURCESHBASHUNSET
Expand Down
20 changes: 10 additions & 10 deletions testsuite/modules.50-cmds/610-abort_on_error-unload.exp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ lappend ans_continue [list set LOADEDMODULES err/1.0]
lappend ans_continue [list set _LMFILES_ $mp/err/1.0]
lappend ans_continue [list unset TS]
lappend ans_continue [list unalias alall]
lappend ans_continue [list out {unset -f funcall;}]
lappend ans_continue [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_continue [list out {complete -r compall;}]
lappend ans_continue [list out all-out]
lappend ans_continue [list ERR]
Expand All @@ -48,7 +48,7 @@ lappend ans_forced [list unset _LMFILES_]
lappend ans_forced [list unset LOADEDMODULES]
lappend ans_forced [list unset TS]
lappend ans_forced [list unalias alall]
lappend ans_forced [list out {unset -f funcall;}]
lappend ans_forced [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_forced [list out {complete -r compall;}]
lappend ans_forced [list out all-out]

Expand All @@ -60,7 +60,7 @@ lappend ans_forced_tag [list unset LOADEDMODULES]
lappend ans_forced_tag [list unset __MODULES_LMTAG]
lappend ans_forced_tag [list unset TS]
lappend ans_forced_tag [list unalias alall]
lappend ans_forced_tag [list out {unset -f funcall;}]
lappend ans_forced_tag [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_forced_tag [list out {complete -r compall;}]
lappend ans_forced_tag [list out all-out]

Expand All @@ -73,7 +73,7 @@ lappend ans_depre_error [list set LOADEDMODULES foo/1.0:err/1.0]
lappend ans_depre_error [list set _LMFILES_ $mp/foo/1.0:$mp/err/1.0]
lappend ans_depre_error [list unset TS]
lappend ans_depre_error [list unalias alall]
lappend ans_depre_error [list out {unset -f funcall;}]
lappend ans_depre_error [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_depre_error [list out {complete -r compall;}]
lappend ans_depre_error [list out all-out]
lappend ans_depre_error [list ERR]
Expand All @@ -88,7 +88,7 @@ lappend ans_depre_error_force [list unset _LMFILES_]
lappend ans_depre_error_force [list unset __MODULES_LMPREREQ]
lappend ans_depre_error_force [list unset TS]
lappend ans_depre_error_force [list unalias alall]
lappend ans_depre_error_force [list out {unset -f funcall;}]
lappend ans_depre_error_force [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_depre_error_force [list out {complete -r compall;}]
lappend ans_depre_error_force [list out all-out]
lappend ans_depre_error_force [list ERR]
Expand All @@ -100,7 +100,7 @@ lappend ans_depre_exit [list set _LMFILES_ $mp/setenv/1.0:$mp/foo/1.0:$mp/err/1.
lappend ans_depre_exit [list set LOADEDMODULES setenv/1.0:foo/1.0:err/1.0]
lappend ans_depre_exit [list unset TS]
lappend ans_depre_exit [list unalias alall]
lappend ans_depre_exit [list out {unset -f funcall;}]
lappend ans_depre_exit [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_depre_exit [list out {complete -r compall;}]
lappend ans_depre_exit [list out all-out]
lappend ans_depre_exit [list ERR]
Expand All @@ -113,7 +113,7 @@ lappend ans_depre_exit_force [list set _LMFILES_ $mp/setenv/1.0]
lappend ans_depre_exit_force [list set LOADEDMODULES setenv/1.0]
lappend ans_depre_exit_force [list unset TS]
lappend ans_depre_exit_force [list unalias alall]
lappend ans_depre_exit_force [list out {unset -f funcall;}]
lappend ans_depre_exit_force [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_depre_exit_force [list out {complete -r compall;}]
lappend ans_depre_exit_force [list out all-out]
lappend ans_depre_exit_force [list ERR]
Expand All @@ -128,7 +128,7 @@ lappend ans_depre_unload_error_force [list set _LMFILES_ $mp/err/1.0]
lappend ans_depre_unload_error_force [list set LOADEDMODULES err/1.0]
lappend ans_depre_unload_error_force [list unset TS]
lappend ans_depre_unload_error_force [list unalias alall]
lappend ans_depre_unload_error_force [list out {unset -f funcall;}]
lappend ans_depre_unload_error_force [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_depre_unload_error_force [list out {complete -r compall;}]
lappend ans_depre_unload_error_force [list out all-out]

Expand All @@ -144,7 +144,7 @@ lappend ans_depun_error_force [list unset _LMFILES_]
lappend ans_depun_error_force [list unset LOADEDMODULES]
lappend ans_depun_error_force [list unset TS]
lappend ans_depun_error_force [list unalias alall]
lappend ans_depun_error_force [list out {unset -f funcall;}]
lappend ans_depun_error_force [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_depun_error_force [list out {complete -r compall;}]
lappend ans_depun_error_force [list out all-out]

Expand All @@ -155,7 +155,7 @@ lappend ans_not_loaded [list set _LMFILES_ $mp/err/1.0]
lappend ans_not_loaded [list set LOADEDMODULES err/1.0]
lappend ans_not_loaded [list unset TS]
lappend ans_not_loaded [list unalias alall]
lappend ans_not_loaded [list out {unset -f funcall;}]
lappend ans_not_loaded [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_not_loaded [list out {complete -r compall;}]
lappend ans_not_loaded [list out all-out]

Expand Down
16 changes: 8 additions & 8 deletions testsuite/modules.50-cmds/611-abort_on_error-ml_unload.exp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ lappend ans_forced [list unset _LMFILES_]
lappend ans_forced [list unset LOADEDMODULES]
lappend ans_forced [list unset TS]
lappend ans_forced [list unalias alall]
lappend ans_forced [list out {unset -f funcall;}]
lappend ans_forced [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_forced [list out {complete -r compall;}]
lappend ans_forced [list out all-out]

Expand All @@ -48,7 +48,7 @@ lappend ans_forced_tag [list unset LOADEDMODULES]
lappend ans_forced_tag [list unset __MODULES_LMTAG]
lappend ans_forced_tag [list unset TS]
lappend ans_forced_tag [list unalias alall]
lappend ans_forced_tag [list out {unset -f funcall;}]
lappend ans_forced_tag [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_forced_tag [list out {complete -r compall;}]
lappend ans_forced_tag [list out all-out]

Expand All @@ -62,7 +62,7 @@ lappend ans_depre_error_force [list unset _LMFILES_]
lappend ans_depre_error_force [list unset __MODULES_LMPREREQ]
lappend ans_depre_error_force [list unset TS]
lappend ans_depre_error_force [list unalias alall]
lappend ans_depre_error_force [list out {unset -f funcall;}]
lappend ans_depre_error_force [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_depre_error_force [list out {complete -r compall;}]
lappend ans_depre_error_force [list out all-out]
lappend ans_depre_error_force [list ERR]
Expand All @@ -77,7 +77,7 @@ lappend ans_depre_unload_error_force [list set _LMFILES_ $mp/err/1.0]
lappend ans_depre_unload_error_force [list set LOADEDMODULES err/1.0]
lappend ans_depre_unload_error_force [list unset TS]
lappend ans_depre_unload_error_force [list unalias alall]
lappend ans_depre_unload_error_force [list out {unset -f funcall;}]
lappend ans_depre_unload_error_force [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_depre_unload_error_force [list out {complete -r compall;}]
lappend ans_depre_unload_error_force [list out all-out]

Expand All @@ -91,7 +91,7 @@ lappend ans_depun_error_force [list unset _LMFILES_]
lappend ans_depun_error_force [list unset LOADEDMODULES]
lappend ans_depun_error_force [list unset TS]
lappend ans_depun_error_force [list unalias alall]
lappend ans_depun_error_force [list out {unset -f funcall;}]
lappend ans_depun_error_force [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_depun_error_force [list out {complete -r compall;}]
lappend ans_depun_error_force [list out all-out]

Expand All @@ -102,7 +102,7 @@ lappend ans_not_loaded [list set _LMFILES_ $mp/err/1.0]
lappend ans_not_loaded [list set LOADEDMODULES err/1.0]
lappend ans_not_loaded [list unset TS]
lappend ans_not_loaded [list unalias alall]
lappend ans_not_loaded [list out {unset -f funcall;}]
lappend ans_not_loaded [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_not_loaded [list out {complete -r compall;}]
lappend ans_not_loaded [list out all-out]

Expand All @@ -128,7 +128,7 @@ lappend ans_exit_forced [list set _LMFILES_ $mp/setenv/1.0]
lappend ans_exit_forced [list set LOADEDMODULES setenv/1.0]
lappend ans_exit_forced [list unset TS]
lappend ans_exit_forced [list unalias alall]
lappend ans_exit_forced [list out {unset -f funcall;}]
lappend ans_exit_forced [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_exit_forced [list out {complete -r compall;}]
lappend ans_exit_forced [list out all-out]
lappend ans_exit_forced [list ERR]
Expand All @@ -140,7 +140,7 @@ lappend ans_supersticky_forced [list set LOADEDMODULES err/1.0]
lappend ans_supersticky_forced [list set _LMFILES_ $mp/err/1.0]
lappend ans_supersticky_forced [list unset TS]
lappend ans_supersticky_forced [list unalias alall]
lappend ans_supersticky_forced [list out {unset -f funcall;}]
lappend ans_supersticky_forced [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_supersticky_forced [list out {complete -r compall;}]
lappend ans_supersticky_forced [list out all-out]
lappend ans_supersticky_forced [list ERR]
Expand Down
14 changes: 7 additions & 7 deletions testsuite/modules.50-cmds/613-abort_on_error-purge.exp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ lappend ans_forced [list unset _LMFILES_]
lappend ans_forced [list unset LOADEDMODULES]
lappend ans_forced [list unset TS]
lappend ans_forced [list unalias alall]
lappend ans_forced [list out {unset -f funcall;}]
lappend ans_forced [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_forced [list out {complete -r compall;}]
lappend ans_forced [list out all-out]

Expand All @@ -48,7 +48,7 @@ lappend ans_forced_tag [list unset LOADEDMODULES]
lappend ans_forced_tag [list unset __MODULES_LMTAG]
lappend ans_forced_tag [list unset TS]
lappend ans_forced_tag [list unalias alall]
lappend ans_forced_tag [list out {unset -f funcall;}]
lappend ans_forced_tag [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_forced_tag [list out {complete -r compall;}]
lappend ans_forced_tag [list out all-out]

Expand All @@ -62,7 +62,7 @@ lappend ans_depre [list unset _LMFILES_]
lappend ans_depre [list unset LOADEDMODULES]
lappend ans_depre [list unset TS]
lappend ans_depre [list unalias alall]
lappend ans_depre [list out {unset -f funcall;}]
lappend ans_depre [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_depre [list out {complete -r compall;}]
lappend ans_depre [list out all-out]

Expand All @@ -75,7 +75,7 @@ lappend ans_continue [list set LOADEDMODULES err/1.0]
lappend ans_continue [list set _LMFILES_ $mp/err/1.0]
lappend ans_continue [list unset TS]
lappend ans_continue [list unalias alall]
lappend ans_continue [list out {unset -f funcall;}]
lappend ans_continue [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_continue [list out {complete -r compall;}]
lappend ans_continue [list out all-out]
lappend ans_continue [list ERR]
Expand All @@ -89,7 +89,7 @@ lappend ans_depre_continue [list set LOADEDMODULES err/1.0]
lappend ans_depre_continue [list set _LMFILES_ $mp/err/1.0]
lappend ans_depre_continue [list unset TS]
lappend ans_depre_continue [list unalias alall]
lappend ans_depre_continue [list out {unset -f funcall;}]
lappend ans_depre_continue [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_depre_continue [list out {complete -r compall;}]
lappend ans_depre_continue [list out all-out]
lappend ans_depre_continue [list ERR]
Expand All @@ -103,7 +103,7 @@ lappend ans_depun_continue [list set LOADEDMODULES foo/1.0:err/1.0]
lappend ans_depun_continue [list set _LMFILES_ $mp/foo/1.0:$mp/err/1.0]
lappend ans_depun_continue [list unset TS]
lappend ans_depun_continue [list unalias alall]
lappend ans_depun_continue [list out {unset -f funcall;}]
lappend ans_depun_continue [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_depun_continue [list out {complete -r compall;}]
lappend ans_depun_continue [list out all-out]
lappend ans_depun_continue [list ERR]
Expand All @@ -119,7 +119,7 @@ lappend ans_supersticky_forced [list set LOADEDMODULES err/1.0]
lappend ans_supersticky_forced [list set _LMFILES_ $mp/err/1.0]
lappend ans_supersticky_forced [list unset TS]
lappend ans_supersticky_forced [list unalias alall]
lappend ans_supersticky_forced [list out {unset -f funcall;}]
lappend ans_supersticky_forced [list out {unset -f funcall 2>/dev/null || true;}]
lappend ans_supersticky_forced [list out {complete -r compall;}]
lappend ans_supersticky_forced [list out all-out]
lappend ans_supersticky_forced [list ERR]
Expand Down
Loading

0 comments on commit 4fc85a5

Please sign in to comment.