| 1 |
############################################################################## |
| 2 |
# Modules Revision 3.0 |
| 3 |
# Providing a flexible user environment |
| 4 |
# |
| 5 |
# File: modules.50-cmds/%M% |
| 6 |
# Revision: %I% |
| 7 |
# First Edition: 2018/04/01 |
| 8 |
# Last Mod.: %U%, %G% |
| 9 |
# |
| 10 |
# Authors: Xavier Delaruelle, [email protected] |
| 11 |
# |
| 12 |
# Description: Testuite testsequence |
| 13 |
# Command: load, unload, display, test, switch, whatis, |
| 14 |
# apropos, purge, reload, aliases, savelist, save, |
| 15 |
# restore, saveshow, saverm, use, unuse, avail |
| 16 |
# Modulefiles: |
| 17 |
# Sub-Command: |
| 18 |
# |
| 19 |
# Comment: %C{ |
| 20 |
# Test module commands called from modulefile with an empty string |
| 21 |
# argument called |
| 22 |
# }C% |
| 23 |
# |
| 24 |
############################################################################## |
| 25 |
|
| 26 |
skip_if_quick_mode |
| 27 |
|
| 28 |
# ensure auto symbolic versions are not set for these tests |
| 29 |
setenv_var MODULES_ADVANCED_VERSION_SPEC 0 |
| 30 |
|
| 31 |
set module "modemptyarg" |
| 32 |
set modulepath "$modpath.2" |
| 33 |
set modulepathre "$modpathre.2" |
| 34 |
|
| 35 |
# setup specific environment |
| 36 |
setenv_path_var MODULEPATH $modulepath |
| 37 |
|
| 38 |
# no test of module commands that can only be called from the top level |
| 39 |
# (command-line). these commands are already checked in 151-module-onlytop.exp |
| 40 |
|
| 41 |
# |
| 42 |
# test load mode |
| 43 |
# |
| 44 |
|
| 45 |
# wrong arg number if command does not accept any argument |
| 46 |
foreach cmd [list purge reload aliases] { |
| 47 |
testouterr_cmd "sh" "load $module/$cmd" "ERR" [msg_load $module/$cmd [msg_moderr "Unexpected number of args for '$cmd' command" "module $cmd {}" $modulepath/$module/$cmd 27]] |
| 48 |
} |
| 49 |
|
| 50 |
# on most module commands, empty arg leads to error |
| 51 |
# test both empty names {} and "" on same module command |
| 52 |
testouterr_cmd "sh" "load $module/load" "ERR" [msg_load $module/load $err_emptymodname [err_reqlo {}]] |
| 53 |
if {[is_conf_enabled autohandling conflictunload]} { |
| 54 |
set ans [list] |
| 55 |
lappend ans [list set __MODULES_LMCONFLICT "$module/unload&"] |
| 56 |
lappend ans [list set _LMFILES_ "$modulepath/$module/unload"] |
| 57 |
lappend ans [list set LOADEDMODULES "$module/unload"] |
| 58 |
set tserr {} |
| 59 |
} else { |
| 60 |
set ans ERR |
| 61 |
set tserr [msg_load $module/unload $err_emptymodname $err_emptymodname] |
| 62 |
} |
| 63 |
testouterr_cmd "sh" "load $module/unload" $ans $tserr |
| 64 |
|
| 65 |
testouterr_cmd "sh" "load $module/load-any" "ERR" [msg_load $module/load-any [err_reqlo {} {}]] |
| 66 |
|
| 67 |
set ans [list] |
| 68 |
lappend ans [list set __MODULES_LMPREREQ "$module/try-load&$module/try-load|"] |
| 69 |
lappend ans [list set _LMFILES_ "$modulepath/$module/try-load"] |
| 70 |
lappend ans [list set LOADEDMODULES "$module/try-load"] |
| 71 |
testouterr_cmd "sh" "load $module/try-load" $ans {} |
| 72 |
|
| 73 |
# for some module commands, error is not fatal and modulefile is loaded |
| 74 |
foreach cmd [list display test whatis] { |
| 75 |
set ans [list] |
| 76 |
lappend ans [list set _LMFILES_ "$modulepath/$module/$cmd"] |
| 77 |
lappend ans [list set LOADEDMODULES "$module/$cmd"] |
| 78 |
lappend ans [list ERR] |
| 79 |
testouterr_cmd "sh" "load $module/$cmd" $ans [msg_load $module/$cmd $err_emptymodname] |
| 80 |
} |
| 81 |
testouterr_cmd "sh" "load $module/swap" ERR [msg_load $module/swap $err_emptymodname] |
| 82 |
# switch: an empty second arg leads to one name rule |
| 83 |
testouterr_cmd_re "sh" "load $module/swap2" ERR [msg_load $module/swap2 $err_path'barunk' [err_reqlo barunk]] |
| 84 |
testouterr_cmd "sh" "load $module/swap3" ERR [msg_load $module/swap3 $err_emptymodname] |
| 85 |
foreach cmd [list use unuse] { |
| 86 |
set ans [list] |
| 87 |
lappend ans [list set _LMFILES_ "$modulepath/$module/$cmd"] |
| 88 |
lappend ans [list set LOADEDMODULES "$module/$cmd"] |
| 89 |
lappend ans [list ERR] |
| 90 |
testouterr_cmd "sh" "load $module/$cmd" $ans [msg_load $module/$cmd $err_emptydirname] |
| 91 |
} |
| 92 |
|
| 93 |
# or error is reported as modulefile error rather global error |
| 94 |
foreach cmd [list save restore saveshow saverm] { |
| 95 |
testouterr_cmd "sh" "load $module/$cmd" "ERR" [msg_load $module/$cmd [msg_moderr $msg_collnameempty "module $cmd {}" $modulepath/$module/$cmd 27]] |
| 96 |
} |
| 97 |
|
| 98 |
set ans [list] |
| 99 |
lappend ans [list set _LMFILES_ "$modulepath/$module/apropos"] |
| 100 |
lappend ans [list set LOADEDMODULES "$module/apropos"] |
| 101 |
# other evaluated modulefiles lead to an error result on stdout |
| 102 |
lappend ans [list ERR] |
| 103 |
testouterr_cmd_re "sh" "load $module/apropos" $ans {.+} |
| 104 |
set ans [list] |
| 105 |
lappend ans [list set _LMFILES_ "$modulepath/$module/avail"] |
| 106 |
lappend ans [list set LOADEDMODULES "$module/avail"] |
| 107 |
testouterr_cmd_re "sh" "load $module/avail" $ans ".+" |
| 108 |
set ans [list] |
| 109 |
lappend ans [list set _LMFILES_ $modulepath/$module/list] |
| 110 |
lappend ans [list set LOADEDMODULES $module/list] |
| 111 |
testouterr_cmd sh "load $module/list" $ans $no_loaded |
| 112 |
set ans [list] |
| 113 |
lappend ans [list set _LMFILES_ $modulepath/$module/savelist] |
| 114 |
lappend ans [list set LOADEDMODULES $module/savelist] |
| 115 |
testouterr_cmd sh "load $module/savelist" $ans [msg_no_named_coll] |
| 116 |
|
| 117 |
|
| 118 |
# |
| 119 |
# test unload mode |
| 120 |
# |
| 121 |
|
| 122 |
# wrong arg number if command does not accept any argument |
| 123 |
foreach cmd [list purge reload aliases] { |
| 124 |
setenv_loaded_module "$module/$cmd" "$modulepath/$module/$cmd" |
| 125 |
testouterr_cmd "sh" "unload $module/$cmd" "ERR" [msg_unload $module/$cmd [msg_moderr "Unexpected number of args for '$cmd' command" "module $cmd {}" $modulepath/$module/$cmd 27]] |
| 126 |
} |
| 127 |
|
| 128 |
# on most module commands, empty arg leads to error |
| 129 |
foreach cmd [list load load-any try-load unload] { |
| 130 |
setenv_loaded_module "$module/$cmd" "$modulepath/$module/$cmd" |
| 131 |
set ans [list] |
| 132 |
lappend ans [list unset _LMFILES_] |
| 133 |
lappend ans [list unset LOADEDMODULES] |
| 134 |
testouterr_cmd "sh" "unload $module/$cmd" $ans "" |
| 135 |
} |
| 136 |
|
| 137 |
# for some module commands, error is not fatal and modulefile is unloaded |
| 138 |
foreach cmd [list display test whatis] { |
| 139 |
setenv_loaded_module "$module/$cmd" "$modulepath/$module/$cmd" |
| 140 |
set ans [list] |
| 141 |
lappend ans [list unset _LMFILES_] |
| 142 |
lappend ans [list unset LOADEDMODULES] |
| 143 |
lappend ans [list ERR] |
| 144 |
testouterr_cmd "sh" "unload $module/$cmd" $ans [msg_unload $module/$cmd $err_emptymodname] |
| 145 |
} |
| 146 |
setenv_loaded_module "$module/swap" "$modulepath/$module/swap" |
| 147 |
set ans [list] |
| 148 |
lappend ans [list unset _LMFILES_] |
| 149 |
lappend ans [list unset LOADEDMODULES] |
| 150 |
testouterr_cmd "sh" "unload $module/swap" $ans {} |
| 151 |
# switch: an empty second arg leads to one name rule |
| 152 |
setenv_loaded_module "$module/swap2" "$modulepath/$module/swap2" |
| 153 |
testouterr_cmd_re "sh" "unload $module/swap2" $ans {} |
| 154 |
setenv_loaded_module "$module/swap3" "$modulepath/$module/swap3" |
| 155 |
testouterr_cmd_re "sh" "unload $module/swap3" $ans {} |
| 156 |
lappend ans [list ERR] |
| 157 |
foreach cmd [list use unuse] { |
| 158 |
setenv_loaded_module "$module/$cmd" "$modulepath/$module/$cmd" |
| 159 |
testouterr_cmd "sh" "unload $module/$cmd" $ans [msg_unload $module/$cmd $err_emptydirname] |
| 160 |
} |
| 161 |
|
| 162 |
# or error is reported as modulefile error rather global error |
| 163 |
foreach cmd [list save restore saveshow saverm] { |
| 164 |
setenv_loaded_module "$module/$cmd" "$modulepath/$module/$cmd" |
| 165 |
testouterr_cmd "sh" "unload $module/$cmd" "ERR" [msg_unload $module/$cmd [msg_moderr $msg_collnameempty "module $cmd {}" $modulepath/$module/$cmd 27]] |
| 166 |
} |
| 167 |
|
| 168 |
setenv_loaded_module "$module/apropos" "$modulepath/$module/apropos" |
| 169 |
set ans [list] |
| 170 |
lappend ans [list unset _LMFILES_] |
| 171 |
lappend ans [list unset LOADEDMODULES] |
| 172 |
# other evaluated modulefiles lead to an error result on stdout |
| 173 |
lappend ans [list ERR] |
| 174 |
testouterr_cmd_re "sh" "unload $module/apropos" $ans {.+} |
| 175 |
setenv_loaded_module "$module/avail" "$modulepath/$module/avail" |
| 176 |
set ans [list] |
| 177 |
lappend ans [list unset _LMFILES_] |
| 178 |
lappend ans [list unset LOADEDMODULES] |
| 179 |
testouterr_cmd_re "sh" "unload $module/avail" $ans ".+" |
| 180 |
setenv_loaded_module $module/list $modulepath/$module/list |
| 181 |
set ans [list] |
| 182 |
lappend ans [list unset _LMFILES_] |
| 183 |
lappend ans [list unset LOADEDMODULES] |
| 184 |
testouterr_cmd sh "unload $module/list" $ans "$cur_matchingloaded\n 1) $module/list " |
| 185 |
setenv_loaded_module $module/savelist $modulepath/$module/savelist |
| 186 |
set ans [list] |
| 187 |
lappend ans [list unset _LMFILES_] |
| 188 |
lappend ans [list unset LOADEDMODULES] |
| 189 |
testouterr_cmd sh "unload $module/savelist" $ans [msg_no_named_coll] |
| 190 |
|
| 191 |
# restore environment |
| 192 |
unsetenv_loaded_module |
| 193 |
|
| 194 |
|
| 195 |
# |
| 196 |
# test display mode |
| 197 |
# |
| 198 |
|
| 199 |
proc display_stderr_content {modfile content} { |
| 200 |
if {$content ne ""} { |
| 201 |
append content "\n" |
| 202 |
} |
| 203 |
|
| 204 |
return "$::modlin\n$modfile:\n\n$content$::modlin" |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
# on all module commands, command line with empty arg is printed |
| 209 |
foreach cmd [list load load-any try-load unload] { |
| 210 |
# test both empty names {} and "" on same module command |
| 211 |
testouterr_cmd_re "sh" "display $module/$cmd" "OK" [display_stderr_content "$modulepathre/$module/$cmd" "module\t\t$cmd {} {}"] |
| 212 |
} |
| 213 |
foreach cmd [list use unuse list purge reload aliases savelist display test save restore saveshow saverm whatis apropos avail] { |
| 214 |
testouterr_cmd_re "sh" "display $module/$cmd" "OK" [display_stderr_content "$modulepathre/$module/$cmd" "module\t\t$cmd {}"] |
| 215 |
} |
| 216 |
testouterr_cmd_re "sh" "display $module/swap" "OK" [display_stderr_content "$modulepathre/$module/swap" "module\t\tswap {} barunk"] |
| 217 |
testouterr_cmd_re "sh" "display $module/swap2" "OK" [display_stderr_content "$modulepathre/$module/swap2" "module\t\tswap barunk {}"] |
| 218 |
|
| 219 |
|
| 220 |
# |
| 221 |
# test help mode |
| 222 |
# |
| 223 |
|
| 224 |
proc help_stderr_content {modfile content {procwarn 0}} { |
| 225 |
if {$content ne ""} { |
| 226 |
append content "\n" |
| 227 |
} |
| 228 |
|
| 229 |
if {$procwarn} { |
| 230 |
append content "WARNING: Unable to find ModulesHelp in $modfile.\n" |
| 231 |
} |
| 232 |
|
| 233 |
return "$::modlin\nModule Specific Help for $modfile:\n\n$content$::modlin" |
| 234 |
} |
| 235 |
|
| 236 |
# on all module commands, command line is ignored |
| 237 |
foreach cmd [list load load-any try-load unload use unuse list purge reload aliases savelist display test swap swap2 save restore saveshow saverm whatis apropos avail] { |
| 238 |
testouterr_cmd_re "sh" "help $module/$cmd" "OK" [help_stderr_content "$modulepathre/$module/$cmd" "" 1] |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
# |
| 243 |
# test test mode |
| 244 |
# |
| 245 |
|
| 246 |
proc test_stderr_content {modfile content {procwarn 0}} { |
| 247 |
if {$content ne ""} { |
| 248 |
append content "\n" |
| 249 |
} |
| 250 |
|
| 251 |
if {$procwarn} { |
| 252 |
append content "WARNING: Unable to find ModulesTest in $modfile.\n" |
| 253 |
} |
| 254 |
|
| 255 |
return "$::modlin\nModule Specific Test for $modfile:\n\n$content$::modlin" |
| 256 |
} |
| 257 |
|
| 258 |
# on all module commands, command line is ignored |
| 259 |
foreach cmd [list load load-any try-load unload use unuse list purge reload aliases savelist display test swap swap2 save restore saveshow saverm whatis apropos avail] { |
| 260 |
testouterr_cmd_re "sh" "test $module/$cmd" "OK" [test_stderr_content "$modulepathre/$module/$cmd" "" 1] |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
# |
| 265 |
# test whatis mode |
| 266 |
# |
| 267 |
|
| 268 |
testouterr_cmd "sh" "whatis $module" "OK" "" |
| 269 |
|
| 270 |
|
| 271 |
# |
| 272 |
# Cleanup |
| 273 |
# |
| 274 |
|
| 275 |
reset_test_env |
| 276 |
|
| 277 |
# remove procs |
| 278 |
rename display_stderr_content {} |
| 279 |
rename help_stderr_content {} |
| 280 |
rename test_stderr_content {} |