| 1 |
############################################################################## |
| 2 |
# Modules Revision 3.0 |
| 3 |
# Providing a flexible user environment |
| 4 |
# |
| 5 |
# File: modules.00-init/%M% |
| 6 |
# Revision: %I% |
| 7 |
# First Edition: 2018/02/22 |
| 8 |
# Last Mod.: %U%, %G% |
| 9 |
# |
| 10 |
# Authors: Xavier Delaruelle, [email protected] |
| 11 |
# |
| 12 |
# Description: Testuite testsequence |
| 13 |
# Command: |
| 14 |
# Sub-Command: |
| 15 |
# |
| 16 |
# Comment: %C{ |
| 17 |
# Checks commands when stderr is attached to a TTY |
| 18 |
# }C% |
| 19 |
# |
| 20 |
############################################################################## |
| 21 |
|
| 22 |
# activate potential siteconfig extension |
| 23 |
if {$verbose} { |
| 24 |
send_user "\tSetup TESTSUITE_ENABLE_SITECONFIG = '1'\n" |
| 25 |
} |
| 26 |
set env(TESTSUITE_ENABLE_SITECONFIG) 1 |
| 27 |
|
| 28 |
# check if stderr terminal attachment state is forced |
| 29 |
set is_stderr_tty [siteconfig_isStderrTty] |
| 30 |
if {$verbose} { |
| 31 |
send_user "\tIs STDERR a TTY? = '$is_stderr_tty'\n" |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
# test only if stderr is attached to TTY |
| 36 |
if {$is_stderr_tty} { |
| 37 |
|
| 38 |
if {$verbose} { |
| 39 |
send_user "\tChecking basic set of commands when STDERR is attached to TTY\n" |
| 40 |
} |
| 41 |
|
| 42 |
set bad_cmd "$error_msgs: Invalid command 'foo'" |
| 43 |
set bad_cmd_re "(envmodule: )?$bad_cmd" |
| 44 |
|
| 45 |
foreach shell $shell_list { |
| 46 |
switch -- $shell { |
| 47 |
{csh} - {tcsh} { |
| 48 |
testall_cmd_re "$shell" "module --version" "" "Modules Release \\S+ (\\S+)" 0 |
| 49 |
testall_cmd "$shell" "module foo" "" "$bad_cmd\n$type_help" 1 |
| 50 |
testall_cmd "$shell" "module use $share_modpath\; module purge\; module load null\; module list -t" "" "$cur_loaded\nnull" 0 |
| 51 |
testall_cmd "$shell" "module use $share_modpath\; module purge\; module load null\; module unload null\; module list -t" "" "$no_loaded" 0 |
| 52 |
testall_cmd "$shell" "module is-loaded unk" "" "" 1 |
| 53 |
testall_cmd "$shell" "module use $share_modpath\; module load null\; module is-loaded null" "" "" 0 |
| 54 |
testall_cmd "$shell" "module info-loaded unk" "" "" 0 |
| 55 |
testall_cmd "$shell" "module use $share_modpath\; module load null\; module info-loaded null" "null" "" 0 |
| 56 |
} |
| 57 |
default { |
| 58 |
testall_cmd_re "$shell" "module --version" "Modules Release \\S+ (\\S+)" "" 0 |
| 59 |
testall_cmd "$shell" "module foo" "$bad_cmd\n$type_help" "" 1 |
| 60 |
testall_cmd "$shell" "module use $share_modpath\; module purge\; module load null\; module list -t" "$cur_loaded\nnull" "" 0 |
| 61 |
testall_cmd "$shell" "module use $share_modpath\; module purge\; module load null\; module unload null\; module list -t" "$no_loaded" "" 0 |
| 62 |
testall_cmd "$shell" "module is-loaded unk" "" "" 1 |
| 63 |
testall_cmd "$shell" "module use $share_modpath\; module load null\; module is-loaded null" "" "" 0 |
| 64 |
testall_cmd "$shell" "module info-loaded unk" "" "" 0 |
| 65 |
testall_cmd "$shell" "module use $share_modpath\; module load null\; module info-loaded null" "null" "" 0 |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
foreach shell $othlang_list { |
| 71 |
switch -- $shell { |
| 72 |
pwsh { |
| 73 |
testall_cmd_re "$shell" "--version" "Modules Release \\S+ (\\S+)" "" 0 |
| 74 |
testall_cmd "$shell" "use,$share_modpath:purge:load,null:list,-t" "$cur_loaded\nnull" "" 0 |
| 75 |
testall_cmd "$shell" "use,$share_modpath:purge:load,null:unload,null:list,-t" "$no_loaded" "" 0 |
| 76 |
} |
| 77 |
default { |
| 78 |
testall_cmd_re "$shell" "--version" "" "Modules Release \\S+ (\\S+)" 0 |
| 79 |
testall_cmd "$shell" "use,$share_modpath:purge:load,null:list,-t" "" "$cur_loaded\nnull" 0 |
| 80 |
testall_cmd "$shell" "use,$share_modpath:purge:load,null:unload,null:list,-t" "" "$no_loaded" 0 |
| 81 |
} |
| 82 |
} |
| 83 |
testall_cmd_re "$shell" "foo" "" "$bad_cmd_re\n$type_help.*" 1 |
| 84 |
switch -- $shell { |
| 85 |
cmake - r { |
| 86 |
testall_cmd_re "$shell" "is-loaded,unk" "" ".*" 1 |
| 87 |
} |
| 88 |
default { |
| 89 |
testall_cmd_re "$shell" "is-loaded,unk" "" "" 1 |
| 90 |
} |
| 91 |
} |
| 92 |
testall_cmd "$shell" "use,$share_modpath:load,null:is-loaded,null" "" "" 0 |
| 93 |
switch -- $shell { |
| 94 |
r { |
| 95 |
testall_cmd "$shell" "info-loaded,unk" "\[1\] \"\"" {} 0 |
| 96 |
} |
| 97 |
python - ruby { |
| 98 |
testall_cmd "$shell" "info-loaded,unk" "\n" "" 0 |
| 99 |
} |
| 100 |
default { |
| 101 |
testall_cmd "$shell" "info-loaded,unk" "" "" 0 |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
switch -- $shell { |
| 106 |
{cmake} { |
| 107 |
set anstxt "-- null" |
| 108 |
} |
| 109 |
{r} { |
| 110 |
set anstxt "\[1\] \"null\"" |
| 111 |
} |
| 112 |
default { |
| 113 |
set anstxt "null" |
| 114 |
} |
| 115 |
} |
| 116 |
testall_cmd "$shell" "use,$share_modpath:load,null:info-loaded,null" $anstxt "" 0 |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
# set a directory with name starting by '$' to check if shell arguments are correctly escaped |
| 121 |
set disruptive_dir1 "[pwd]/\$RE.BIN" |
| 122 |
set disruptive_dir2 "[pwd]/something (test)" |
| 123 |
if {$verbose} { |
| 124 |
send_user "\tCreate disruptive directory $disruptive_dir1\n" |
| 125 |
send_user "\tCreate disruptive directory $disruptive_dir2\n" |
| 126 |
} |
| 127 |
file mkdir $disruptive_dir1 |
| 128 |
file mkdir $disruptive_dir2 |
| 129 |
|
| 130 |
foreach shell $shell_list { |
| 131 |
switch -- $shell { |
| 132 |
{csh} - {tcsh} { |
| 133 |
testall_cmd_re "$shell" "module --version" "" "Modules Release \\S+ (\\S+)" 0 |
| 134 |
} |
| 135 |
default { |
| 136 |
testall_cmd_re "$shell" "module --version" "Modules Release \\S+ (\\S+)" "" 0 |
| 137 |
} |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
foreach shell $othlang_list { |
| 142 |
switch -- $shell { |
| 143 |
pwsh { |
| 144 |
testall_cmd_re "$shell" "--version" "Modules Release \\S+ (\\S+)" "" 0 |
| 145 |
} |
| 146 |
default { |
| 147 |
testall_cmd_re "$shell" "--version" "" "Modules Release \\S+ (\\S+)" 0 |
| 148 |
} |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
if {$verbose} { |
| 154 |
send_user "\tDelete disruptive directory $disruptive_dir1\n" |
| 155 |
send_user "\tDelete disruptive directory $disruptive_dir2\n" |
| 156 |
} |
| 157 |
file delete $disruptive_dir1 |
| 158 |
file delete $disruptive_dir2 |
| 159 |
|
| 160 |
|
| 161 |
} elseif {$verbose} { |
| 162 |
send_user "\tSkip most tests as STDERR is not attached to a TTY\n" |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
# test output redirection when shell is found or not attached to tty |
| 167 |
set tserr "Modules Release \\S+ (\\S+)" |
| 168 |
if {$is_stderr_tty} { |
| 169 |
set dflout $tserr |
| 170 |
set dflerr {} |
| 171 |
} else { |
| 172 |
set dflout {} |
| 173 |
set dflerr $tserr |
| 174 |
} |
| 175 |
|
| 176 |
foreach shell $shell_redir_list { |
| 177 |
set modcmd "module" |
| 178 |
if {$shell eq "pwsh"} { |
| 179 |
set modcmd "envmodule" |
| 180 |
} |
| 181 |
|
| 182 |
testall_cmd_re $shell "$modcmd --version" $dflout $dflerr 0 |
| 183 |
testall_cmd_re $shell "$modcmd --version --redirect" $tserr {} 0 |
| 184 |
testall_cmd_re $shell "$modcmd --version --no-redirect" {} $tserr 0 |
| 185 |
if {$shell ne "pwsh"} { |
| 186 |
testall_cmd_re autoinit:$shell "$modcmd --version" $dflout $dflerr 0 |
| 187 |
testall_cmd_re autoinit:$shell "$modcmd --version --redirect" $tserr {} 0 |
| 188 |
testall_cmd_re autoinit:$shell "$modcmd --version --no-redirect" {} $tserr 0 |
| 189 |
} |
| 190 |
# if --no-redirect is part of arg list it wins even if --redirect is set after |
| 191 |
testall_cmd_re $shell "$modcmd --version --redirect --no-redirect" {} $tserr 0 |
| 192 |
testall_cmd_re $shell "$modcmd --version --no-redirect --redirect" {} $tserr 0 |
| 193 |
|
| 194 |
setenv_var MODULES_REDIRECT_OUTPUT 0 |
| 195 |
testall_cmd_re $shell "$modcmd --version" {} $tserr 0 |
| 196 |
testall_cmd_re $shell "$modcmd --version --redirect" $tserr {} 0 |
| 197 |
testall_cmd_re $shell "$modcmd --version --no-redirect" {} $tserr 0 |
| 198 |
testall_cmd_re $shell "$modcmd --version --redirect --no-redirect" {} $tserr 0 |
| 199 |
testall_cmd_re $shell "$modcmd --version --no-redirect --redirect" {} $tserr 0 |
| 200 |
|
| 201 |
setenv_var MODULES_REDIRECT_OUTPUT 1 |
| 202 |
testall_cmd_re $shell "$modcmd --version" $tserr {} 0 |
| 203 |
testall_cmd_re $shell "$modcmd --version --redirect" $tserr {} 0 |
| 204 |
testall_cmd_re $shell "$modcmd --version --no-redirect" {} $tserr 0 |
| 205 |
testall_cmd_re $shell "$modcmd --version --redirect --no-redirect" {} $tserr 0 |
| 206 |
testall_cmd_re $shell "$modcmd --version --no-redirect --redirect" {} $tserr 0 |
| 207 |
|
| 208 |
# bad value set on MODULES_REDIRECT_OUTPUT env var |
| 209 |
# any value different than 0 or 1 is ignored |
| 210 |
setenv_var MODULES_REDIRECT_OUTPUT foo |
| 211 |
testall_cmd_re $shell "$modcmd --version" $dflout $dflerr 0 |
| 212 |
testall_cmd_re $shell "$modcmd --version --redirect" $tserr {} 0 |
| 213 |
testall_cmd_re $shell "$modcmd --version --no-redirect" {} $tserr 0 |
| 214 |
setenv_var MODULES_REDIRECT_OUTPUT {} |
| 215 |
testall_cmd_re $shell "$modcmd --version" $dflout $dflerr 0 |
| 216 |
testall_cmd_re $shell "$modcmd --version --redirect" $tserr {} 0 |
| 217 |
testall_cmd_re $shell "$modcmd --version --no-redirect" {} $tserr 0 |
| 218 |
|
| 219 |
unsetenv_var MODULES_REDIRECT_OUTPUT |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
# |
| 224 |
# Clean up variables used in this test case |
| 225 |
# |
| 226 |
|
| 227 |
reset_test_env |