| 1 |
############################################################################## |
| 2 |
# Modules Revision 3.0 |
| 3 |
# Providing a flexible user environment |
| 4 |
# |
| 5 |
# File: completion.00-init/%M% |
| 6 |
# Revision: %I% |
| 7 |
# First Edition: 2026/08/12 |
| 8 |
# Last Mod.: %U%, %G% |
| 9 |
# |
| 10 |
# Authors: Xavier Delaruelle, [email protected] |
| 11 |
# |
| 12 |
# Description: Testuite testsequence |
| 13 |
# Command: avail, load, unload, ml, use, unuse, restore |
| 14 |
# Sub-Command: |
| 15 |
# |
| 16 |
# Comment: %C{ |
| 17 |
# Check tcsh Tab completion: mirrors 021-bash.exp (see |
| 18 |
# that file for the full rationale of each check) as |
| 19 |
# closely as tcsh's own completion script allows -- every |
| 20 |
# completion_bash_* call replaced by its completion_tcsh_* |
| 21 |
# counterpart -- since init/tcsh_completion.in gates its |
| 22 |
# option flags per sub-command via the same shared |
| 23 |
# @comp_*_opts@ token lists bash's own script is built |
| 24 |
# from (see init/Makefile), every per-sub-command |
| 25 |
# ground-truth section bash has is kept here too, unlike |
| 26 |
# 031-zsh.exp/041-fish.exp. The few genuine deviations |
| 27 |
# from bash, all driven by init/tcsh_completion.in itself |
| 28 |
# or by tcsh's own line editor (see 050-tcsh-procs.exp's |
| 29 |
# header for the latter), are noted where they occur: |
| 30 |
# - "bar" uniquely matching the "bar/" module category |
| 31 |
# still rings a bell on completion: tcsh has no |
| 32 |
# equivalent of bash's 'compopt -o nospace' exception |
| 33 |
# that stays silent right at a directory-style '/' |
| 34 |
# boundary even though the match remains ambiguous |
| 35 |
# beyond it (see 050-tcsh-procs.exp's header) |
| 36 |
# - unlike bash/zsh's own completion scripts, the |
| 37 |
# aliases in init/tcsh_completion.in (_module_avail, |
| 38 |
# ...) never collapse every module sharing a name into |
| 39 |
# one directory-style "name/" candidate of their own: |
| 40 |
# Ctrl-D's listing always shows the flat 'name/version' |
| 41 |
# strings modulecmd.tcl produced, so every listing |
| 42 |
# check in this file looks for those instead of the |
| 43 |
# "name/" category entries 021-bash.exp checks for. A |
| 44 |
# single Tab's own common-prefix computation can still |
| 45 |
# land exactly on a "/" boundary and insert it (eg the |
| 46 |
# "bar" case above) -- that is a computed common |
| 47 |
# prefix, not a distinct listed candidate, so it is |
| 48 |
# unaffected by this |
| 49 |
# - 'ml' has a far sparser 'complete' registration of its |
| 50 |
# own than 'module' does: no global switches at all for |
| 51 |
# a bare 'ml' (no '-h'/'--help'/'-D', unlike bash), and |
| 52 |
# 'ml -<Tab>' offers only the loaded-module unload |
| 53 |
# shortcuts ('-name', via a dedicated 'c/-/.../' rule) |
| 54 |
# -- not also 'load's own option flags the way bash |
| 55 |
# mixes in there. This file's 'ml' section is pared |
| 56 |
# down to just the checks that still apply |
| 57 |
# - 'unuse' is only usable from a bare, empty word: every |
| 58 |
# modulepath in this fixture is an absolute path, and |
| 59 |
# the moment the word being completed starts with '/' |
| 60 |
# it matches init/tcsh_completion.in's own unconditional |
| 61 |
# 'C,/*,f,' rule (plain filename completion for any |
| 62 |
# word starting with '/'), which is declared ahead of |
| 63 |
# the 'unuse'-specific 'n/unuse/`_module_modulepath`/' |
| 64 |
# rule and wins over it -- so, unlike bash, this file |
| 65 |
# cannot narrow the listing by prefix or check the |
| 66 |
# single-remaining-modulepath inline-completion case |
| 67 |
# - 'use' and 'source' each document an option flag or |
| 68 |
# two in their usage synopsis ('-a'/'-p'; |
| 69 |
# '--auto'/'--no-auto'/'-f'), but init/tcsh_completion.in |
| 70 |
# never wires any @comp_*_opts@ macro into their own |
| 71 |
# rule the way every other option-bearing sub-command's |
| 72 |
# rule does -- so, like 'ml'/'unuse' above, the |
| 73 |
# per-sub-command option ground-truth section below |
| 74 |
# treats these two as if they took no option at all |
| 75 |
# ('help' had the same gap -- no '@comp_mfile_opts@' in |
| 76 |
# its own rule despite documenting '-i' -- fixed |
| 77 |
# directly in init/tcsh_completion.in rather than |
| 78 |
# worked around here, since 'help' otherwise dispatches |
| 79 |
# exactly like 'show'/'display'/'test'/... which all |
| 80 |
# already carry that macro) |
| 81 |
# |
| 82 |
# Also checks, like 021-bash.exp/031-zsh.exp, that a |
| 83 |
# candidate word built from untrusted text (a module |
| 84 |
# name, LOADEDMODULES, MODULEPATH) cannot reach a shell |
| 85 |
# expansion step: init/tcsh_completion.in only ever hands |
| 86 |
# such text to a plain 'n/.../`...`/' backtick rule, where |
| 87 |
# each output line becomes a literal candidate string, so |
| 88 |
# this is expected to already be safe -- these cases guard |
| 89 |
# against a regression, not a known vulnerability. The |
| 90 |
# MODULEPATH case uses a bare 'module unuse ' (no typed |
| 91 |
# prefix), same restriction as this file's own 'unuse' |
| 92 |
# section above |
| 93 |
# }C% |
| 94 |
# |
| 95 |
############################################################################## |
| 96 |
|
| 97 |
|
| 98 |
# |
| 99 |
# module names and option flags both get listed on Tab completion |
| 100 |
# |
| 101 |
|
| 102 |
setenv_path_var MODULEPATH $modpath |
| 103 |
|
| 104 |
completion_tcsh_start |
| 105 |
|
| 106 |
## unlike bash/zsh's own completion scripts, init/tcsh_completion.in's |
| 107 |
## aliases (_module_avail, ...) do not collapse every module sharing a name |
| 108 |
## into one directory-style "name/" candidate -- Ctrl-D's listing shows |
| 109 |
## exactly the flat 'name/version' strings modulecmd.tcl produced, so this |
| 110 |
## file checks for those instead of the "name/" category entries |
| 111 |
## 021-bash.exp looks for (a single Tab's own common-prefix computation can |
| 112 |
## still land exactly on a "/" boundary, see the "bar" case further below -- |
| 113 |
## that is a computed common prefix, not a distinct listed candidate) |
| 114 |
set got [completion_tcsh_list {module avail }] |
| 115 |
completion_assert_contains $got {advvers/1.0 bar/1.0 baz/1.0 foo/1.0} |
| 116 |
completion_assert_contains $got {--all --icase --terse} |
| 117 |
|
| 118 |
set got [completion_tcsh_list {module load }] |
| 119 |
completion_assert_contains $got {advvers/1.0 bar/1.0 baz/1.0 foo/1.0} |
| 120 |
completion_assert_contains $got {--force -f --icase} |
| 121 |
|
| 122 |
## "ba" is the common prefix of bar/ and baz/: a single Tab from "b" must |
| 123 |
## auto-insert the "a" inline, with a bell right before it since bar/baz |
| 124 |
## still leave the completion ambiguous beyond it |
| 125 |
set got [completion_tcsh_inline {module load b}] |
| 126 |
completion_assert_eq $got "\aa" |
| 127 |
|
| 128 |
## from "ba", nothing more can be auto-inserted (bar/baz diverge right |
| 129 |
## there): Ctrl-D must list every flat module matching that prefix (see |
| 130 |
## this section's opening comment on why these are not "bar/"/"baz/" |
| 131 |
## category entries) |
| 132 |
set got [completion_tcsh_list {module load ba}] |
| 133 |
completion_assert_contains $got {bar/1.0 bar/2.0 baz/1.0 baz/2.0} |
| 134 |
completion_assert_not_contains $got {foo/1.0 advvers/1.0} |
| 135 |
|
| 136 |
## "bar" uniquely matches the "bar/" module category: a single Tab must |
| 137 |
## complete it inline with a trailing '/' and no trailing space (so typing |
| 138 |
## can continue straight into a version) -- but, unlike bash, still with a |
| 139 |
## leading bell, since tcsh has no exception for a directory-style boundary |
| 140 |
## that remains ambiguous beyond it (see this file's header) |
| 141 |
set got [completion_tcsh_inline {module load bar}] |
| 142 |
completion_assert_eq $got "\a/" |
| 143 |
|
| 144 |
## from "bar/", Ctrl-D must list the versions available under it |
| 145 |
set got [completion_tcsh_list {module load bar/}] |
| 146 |
completion_assert_contains $got {bar/1.0 bar/2.0} |
| 147 |
|
| 148 |
## "flatlcompat" is a single, versionless module (no further completion |
| 149 |
## possible beneath it, so unlike "bar" above it does not end in '/'): a |
| 150 |
## single Tab must complete it inline, with a trailing space since it is |
| 151 |
## not a directory-style entry, and no bell since it is genuinely unique |
| 152 |
set got [completion_tcsh_inline {module load fl}] |
| 153 |
completion_assert_eq $got {atlcompat } |
| 154 |
|
| 155 |
completion_tcsh_close |
| 156 |
|
| 157 |
|
| 158 |
# |
| 159 |
# 'unload' lists the currently loaded modules alongside the option flags, |
| 160 |
# and lists/completes them on the typed prefix like any other candidate list |
| 161 |
# |
| 162 |
|
| 163 |
setenv_loaded_module [list bar/1.0 baz/1.0 foo/1.0]\ |
| 164 |
[list $modpath/bar/1.0 $modpath/baz/1.0 $modpath/foo/1.0] |
| 165 |
|
| 166 |
completion_tcsh_start |
| 167 |
|
| 168 |
set got [completion_tcsh_list {module unload }] |
| 169 |
completion_assert_contains $got {bar/1.0 baz/1.0 foo/1.0 --force -f --icase} |
| 170 |
|
| 171 |
## "ba" is the common prefix of bar/1.0 and baz/1.0: a single Tab from "b" |
| 172 |
## must auto-insert the "a" inline, with a bell right before it since |
| 173 |
## bar/1.0 and baz/1.0 still leave the completion ambiguous beyond it |
| 174 |
set got [completion_tcsh_inline {module unload b}] |
| 175 |
completion_assert_eq $got "\aa" |
| 176 |
|
| 177 |
## from "ba", nothing more can be auto-inserted (bar/1.0 and baz/1.0 |
| 178 |
## diverge right there), so Ctrl-D must list just the two matching loaded |
| 179 |
## modules, not foo/1.0 |
| 180 |
set got [completion_tcsh_list {module unload ba}] |
| 181 |
completion_assert_contains $got {bar/1.0 baz/1.0} |
| 182 |
completion_assert_not_contains $got {foo/1.0} |
| 183 |
|
| 184 |
## "foo/1.0" is the only loaded module starting with "f", and no option |
| 185 |
## flag does either: a single Tab must complete the rest of it inline, |
| 186 |
## with a trailing space since a loaded-module candidate is not a |
| 187 |
## directory-style entry, and no bell since it is genuinely unique |
| 188 |
set got [completion_tcsh_inline {module unload f}] |
| 189 |
completion_assert_eq $got {oo/1.0 } |
| 190 |
|
| 191 |
completion_tcsh_close |
| 192 |
unsetenv_loaded_module |
| 193 |
|
| 194 |
|
| 195 |
# |
| 196 |
# 'ml' mirrors 'module load' completion for the bare sub-command case, but |
| 197 |
# (unlike bash) proposes no global switches at all alongside the module |
| 198 |
# names, and (once an option flag is being typed) offers only the "-<name>" |
| 199 |
# unload shortcut for each currently loaded module -- not also 'load's own |
| 200 |
# option flags (see this file's header) |
| 201 |
# |
| 202 |
|
| 203 |
setenv_path_var MODULEPATH $modpath |
| 204 |
|
| 205 |
completion_tcsh_start |
| 206 |
|
| 207 |
set got [completion_tcsh_list {ml }] |
| 208 |
completion_assert_contains $got {advvers/1.0 bar/1.0 baz/1.0 foo/1.0} |
| 209 |
completion_assert_not_contains $got {-h --help -D} |
| 210 |
|
| 211 |
completion_tcsh_raw {module load bar} |
| 212 |
|
| 213 |
## with bar/2.0 loaded (the default version, no .version file pins it), a |
| 214 |
## "bar/2.0" candidate must appear -- and, unlike bash, nothing else. The |
| 215 |
## listing itself drops the leading "-" the 'c/-/.../' rule matched on (it |
| 216 |
## is only the single-Tab *insertion* below that appends the suffix right |
| 217 |
## after the "-" already typed on the line, making the result look like |
| 218 |
## "-bar/2.0" there) |
| 219 |
set got [completion_tcsh_list {ml -}] |
| 220 |
completion_assert_contains $got {bar/2.0} |
| 221 |
completion_assert_not_contains $got {--force -f --icase} |
| 222 |
|
| 223 |
## "-bar/2.0" is the only candidate starting with "-ba": a single Tab must |
| 224 |
## complete the rest of it inline, with a trailing space since it is not a |
| 225 |
## directory-style entry, and no bell since it is genuinely unique |
| 226 |
set got [completion_tcsh_inline {ml -ba}] |
| 227 |
completion_assert_eq $got {r/2.0 } |
| 228 |
|
| 229 |
completion_tcsh_close |
| 230 |
|
| 231 |
|
| 232 |
# |
| 233 |
# 'use' completes a filesystem directory path: init/tcsh_completion.in |
| 234 |
# registers it as directory-only completion ('n/use/d/'), and the |
| 235 |
# unconditional 'C,/*,f,' rule (see this file's header) reaches the same |
| 236 |
# filesystem entry regardless for this fixture's absolute path, so either |
| 237 |
# way this behaves like plain directory completion |
| 238 |
# |
| 239 |
|
| 240 |
set usedir "$env(TESTSUITEDIR)/completion-use-fixture" |
| 241 |
file delete -force $usedir |
| 242 |
file mkdir $usedir |
| 243 |
|
| 244 |
completion_tcsh_start |
| 245 |
|
| 246 |
## drop the last 3 characters of the fixture dir name ("ure"): a single Tab |
| 247 |
## must complete them back plus a trailing '/', with no trailing space and |
| 248 |
## no bell, exactly like the "flatlcompat" case above -- the match is |
| 249 |
## genuinely unique, so unlike the "bar" -> "bar/" case earlier there is no |
| 250 |
## further ambiguity beyond the boundary for tcsh to bell about |
| 251 |
set got [completion_tcsh_inline "module use [string range $usedir 0 end-3]"] |
| 252 |
completion_assert_eq $got {ure/} |
| 253 |
|
| 254 |
completion_tcsh_close |
| 255 |
file delete -force $usedir |
| 256 |
|
| 257 |
|
| 258 |
# |
| 259 |
# 'unuse' lists the currently enabled modulepaths, but (unlike bash) only |
| 260 |
# from a bare, empty word -- typing any prefix at all trips the '/' |
| 261 |
# filename-completion catch-all before it ever reaches the modulepath list |
| 262 |
# (see this file's header), so this section, unlike 031-zsh.exp's own |
| 263 |
# 'unuse' checks, cannot narrow by prefix or exercise the single-remaining- |
| 264 |
# modulepath inline-completion case |
| 265 |
# |
| 266 |
|
| 267 |
setenv_path_var MODULEPATH $modpath "$env(TESTSUITEDIR)/modulefiles.4" /tmp |
| 268 |
|
| 269 |
completion_tcsh_start |
| 270 |
|
| 271 |
set got [completion_tcsh_list {module unuse }] |
| 272 |
completion_assert_contains $got [list $modpath "$env(TESTSUITEDIR)/modulefiles.4" /tmp] |
| 273 |
|
| 274 |
completion_tcsh_close |
| 275 |
|
| 276 |
|
| 277 |
# |
| 278 |
# 'restore' lists the saved collections, and filters them on the typed |
| 279 |
# prefix like any other candidate list |
| 280 |
# |
| 281 |
|
| 282 |
setenv_path_var MODULEPATH $modpath |
| 283 |
|
| 284 |
completion_tcsh_start |
| 285 |
|
| 286 |
completion_tcsh_raw {module save foo} |
| 287 |
completion_tcsh_raw {module save fox} |
| 288 |
completion_tcsh_raw {module save bar1} |
| 289 |
|
| 290 |
set got [completion_tcsh_list {module restore }] |
| 291 |
completion_assert_contains $got {foo fox bar1} |
| 292 |
|
| 293 |
## "fo" is the common prefix of foo/fox: a single Tab from "f" must |
| 294 |
## auto-insert the "o" inline, with a bell right before it since foo/fox |
| 295 |
## still leave the completion ambiguous beyond it |
| 296 |
set got [completion_tcsh_inline {module restore f}] |
| 297 |
completion_assert_eq $got "\ao" |
| 298 |
|
| 299 |
## from "fo", nothing more can be auto-inserted (foo/fox diverge right |
| 300 |
## there), so Ctrl-D must list just the two matching collections |
| 301 |
set got [completion_tcsh_list {module restore fo}] |
| 302 |
completion_assert_contains $got {foo fox} |
| 303 |
completion_assert_not_contains $got {bar1} |
| 304 |
|
| 305 |
## "bar1" is the only collection starting with "ba": a single Tab must |
| 306 |
## complete the rest of it inline, with a trailing space since a |
| 307 |
## collection candidate is not a directory-style entry, and no bell since |
| 308 |
## it is genuinely unique |
| 309 |
set got [completion_tcsh_inline {module restore ba}] |
| 310 |
completion_assert_eq $got {r1 } |
| 311 |
|
| 312 |
completion_tcsh_close |
| 313 |
|
| 314 |
|
| 315 |
# |
| 316 |
# ground-truth check against 'module help' (see completion.00-init/ |
| 317 |
# 007-module_help.exp): a bare 'module <Tab>' must propose exactly the |
| 318 |
# documented sub-commands plus the global switches, and 'module -<Tab>' |
| 319 |
# (isolating the switches from the sub-command names) must propose exactly |
| 320 |
# the documented switches |
| 321 |
# |
| 322 |
|
| 323 |
setenv_path_var MODULEPATH $modpath |
| 324 |
|
| 325 |
completion_tcsh_start |
| 326 |
|
| 327 |
set got [completion_tcsh_list {module }] |
| 328 |
set got_subcmds [lsearch -all -inline -not -regexp $got {^-}] |
| 329 |
completion_assert_contains $got_subcmds $help_subcmds |
| 330 |
completion_assert_only_known $got_subcmds {*} $help_subcmds |
| 331 |
|
| 332 |
set got [completion_tcsh_list {module -}] |
| 333 |
completion_assert_contains $got $help_switches |
| 334 |
completion_assert_only_known $got {-*} $help_switches |
| 335 |
|
| 336 |
completion_tcsh_close |
| 337 |
|
| 338 |
|
| 339 |
# |
| 340 |
# ground-truth check, per sub-command: 'module <sub-command> -<Tab>' must |
| 341 |
# propose exactly the option flags 'module help' documents for that |
| 342 |
# sub-command -- including none at all, for a sub-command that takes no |
| 343 |
# option |
| 344 |
# |
| 345 |
|
| 346 |
## typing '-' first, rather than a bare trailing space, matters for the |
| 347 |
## same reason it does in 021-bash.exp: every option-bearing sub-command's |
| 348 |
## own completion helper skips looking up real module/collection/modulepath |
| 349 |
## candidates once the word being completed starts with '-', isolating the |
| 350 |
## option flags on their own -- unlike bash/zsh, though, this needs no |
| 351 |
## special-casing for 'config's own further '-' -> '--' auto-extension, |
| 352 |
## since completion_tcsh_list's Ctrl-D never extends the typed word at all |
| 353 |
## (see 050-tcsh-procs.exp's header) |
| 354 |
## |
| 355 |
## two further sub-commands, beyond 'ml'/'unuse' already noted in this |
| 356 |
## file's header, turn out to have a gap of their own here: 'use' |
| 357 |
## ('n/use/d/'/'N/use/d/') and 'source' ('n/source/f/') each document an |
| 358 |
## option flag or two in their usage synopsis ('-a'/'-p'; |
| 359 |
## '--auto'/'--no-auto'/'-f'), but their init/tcsh_completion.in rule never |
| 360 |
## concatenates any @comp_*_opts@ macro the way every other option-bearing |
| 361 |
## sub-command's rule does -- so these two are treated the same as a |
| 362 |
## genuinely option-less sub-command below, overriding whatever |
| 363 |
## 'module help' itself documents for them ('help' had the same gap, fixed |
| 364 |
## directly in init/tcsh_completion.in instead, see this file's header) |
| 365 |
set tcsh_no_opt_subcmds {use source} |
| 366 |
setenv_path_var MODULEPATH $modpath |
| 367 |
|
| 368 |
completion_tcsh_start |
| 369 |
|
| 370 |
foreach subcmd $help_subcmds { |
| 371 |
set expected {} |
| 372 |
if {[info exists help_subcmd_opts($subcmd)] && $subcmd ni $tcsh_no_opt_subcmds} { |
| 373 |
set expected $help_subcmd_opts($subcmd) |
| 374 |
} |
| 375 |
if {[llength $expected] == 0} { |
| 376 |
## nothing is expected to complete at all: a single Tab must insert |
| 377 |
## nothing but a bell (not even a directory-style default-completion |
| 378 |
## fallback match, since no file in the test run's working directory |
| 379 |
## starts with '-') -- tcsh rings the bell on any Tab that finds zero |
| 380 |
## completions, not just an ambiguous one |
| 381 |
set got [completion_tcsh_inline "module $subcmd -"] |
| 382 |
completion_assert_eq $got "\a" |
| 383 |
} else { |
| 384 |
set got [completion_tcsh_list "module $subcmd -"] |
| 385 |
completion_assert_contains $got $expected |
| 386 |
completion_assert_only_known $got {-*} $expected |
| 387 |
} |
| 388 |
} |
| 389 |
|
| 390 |
completion_tcsh_close |
| 391 |
|
| 392 |
|
| 393 |
# |
| 394 |
# same ground truth, this time against 'ml': unlike 021-bash.exp, its |
| 395 |
# per-sub-command dispatch does not apply here at all -- 'ml's own |
| 396 |
# 'complete' registration in init/tcsh_completion.in only ever completes a |
| 397 |
# bare module name or an unload shortcut (see this file's header), it has |
| 398 |
# no sub-command dispatch of its own to check |
| 399 |
# |
| 400 |
|
| 401 |
|
| 402 |
# |
| 403 |
# ground-truth check, per sub-command: 'module <sub-command> <Tab>' must |
| 404 |
# propose a candidate of the kind 'module help' documents as that |
| 405 |
# sub-command's positional argument, for the two kinds with fixture data |
| 406 |
# predictable enough to check for by name -- an available/loaded module |
| 407 |
# ('modulefile'/'modfile'/'mod1'/'mod2'/'mod' in the usage synopsis) or a |
| 408 |
# saved collection ('collection'/'coll'). The remaining kinds |
| 409 |
# (a filesystem directory, an arbitrary file, or nothing completable at |
| 410 |
# all -- a search string, a shell name, a stash collection name generated |
| 411 |
# with an unpredictable timestamp, ...) are not asserted on here: 'use' and |
| 412 |
# 'unuse' already get a dedicated, fixture-appropriate check of their own |
| 413 |
# earlier in this file, and the rest fall back to plain filename completion |
| 414 |
# of the working directory, which is not fixture data this testsuite |
| 415 |
# controls |
| 416 |
# |
| 417 |
|
| 418 |
setenv_path_var MODULEPATH $modpath |
| 419 |
setenv_loaded_module [list bar/1.0] [list $modpath/bar/1.0] |
| 420 |
|
| 421 |
completion_tcsh_start |
| 422 |
|
| 423 |
completion_tcsh_raw {module save foo} |
| 424 |
completion_tcsh_raw {module save fox} |
| 425 |
completion_tcsh_raw {module save bar1} |
| 426 |
|
| 427 |
foreach subcmd $help_subcmds { |
| 428 |
## 'list'/'savelist' take a search string filtering already-known state |
| 429 |
## (loaded modules / saved collections), not a name completion target: |
| 430 |
## their own completion only ever proposes their option flags, despite |
| 431 |
## their usage synopsis documenting a module/collection-shaped argument |
| 432 |
if {$subcmd in {list savelist}} { |
| 433 |
continue |
| 434 |
} |
| 435 |
if {$subcmd eq {config}} { |
| 436 |
## 'config' takes a configuration option name, not a module or |
| 437 |
## collection: check it against the ground truth fetched from |
| 438 |
## 'module config' (see 008-module_config.exp), plus the two real |
| 439 |
## flags mixed into the same candidate list -- neither less nor more |
| 440 |
set got [completion_tcsh_list "module $subcmd "] |
| 441 |
completion_assert_contains $got $config_opts |
| 442 |
completion_assert_only_known $got {*} [concat $config_opts\ |
| 443 |
$help_subcmd_opts(config)] |
| 444 |
continue |
| 445 |
} |
| 446 |
if {![info exists help_subcmd_argtype($subcmd)]} { |
| 447 |
continue |
| 448 |
} |
| 449 |
set argtype $help_subcmd_argtype($subcmd) |
| 450 |
if {$argtype ni {module collection}} { |
| 451 |
continue |
| 452 |
} |
| 453 |
set got [completion_tcsh_list "module $subcmd "] |
| 454 |
if {$argtype eq {module}} { |
| 455 |
## covers every module-completion mechanism this fixture set can |
| 456 |
## produce: available modules not yet loaded (directory-style, |
| 457 |
## trailing '/'), available modules regardless of load state |
| 458 |
## (whatis/display/... style), and the one loaded module (flat |
| 459 |
## 'name/version', switch/unload style) |
| 460 |
completion_assert_any $got {bar/ baz/ foo/ advvers/ flatlcompat bar/1.0} |
| 461 |
} else { |
| 462 |
completion_assert_any $got {foo fox bar1} |
| 463 |
} |
| 464 |
} |
| 465 |
|
| 466 |
completion_tcsh_close |
| 467 |
unsetenv_loaded_module |
| 468 |
|
| 469 |
|
| 470 |
# |
| 471 |
# candidate words built from untrusted text cannot reach a shell expansion |
| 472 |
# step (see this file's header, and the security fix for the bash-completion |
| 473 |
# command injection this guards against a regression of) |
| 474 |
# |
| 475 |
|
| 476 |
# each case below spawns a fresh tcsh session and, unlike every other |
| 477 |
# section in this file, its Ctrl-D listing goes through _module_loaded/ |
| 478 |
# _module_avail/_module_modulepath cold (no completion call already primed |
| 479 |
# the pty/subprocess pipeline): comfortably inside the default 10s |
| 480 |
# 'timeout' most of the time, but occasionally not under a loaded machine, |
| 481 |
# so it is raised for just this section rather than risking a false |
| 482 |
# UNRESOLVED |
| 483 |
set old_timeout $timeout |
| 484 |
set timeout 30 |
| 485 |
|
| 486 |
set marker "$env(TESTSUITEDIR)/completion-injection-marker" |
| 487 |
file delete -force $marker |
| 488 |
|
| 489 |
# module avail: malicious module name read off disk |
| 490 |
|
| 491 |
# the marker path is passed through as an env var rather than embedded |
| 492 |
# directly in the filename, since a filename cannot itself contain '/' |
| 493 |
setenv_var INJMARKER $marker |
| 494 |
set evilname {evil$(touch>$INJMARKER)} |
| 495 |
file mkdir $injectdir |
| 496 |
set fd [open "$injectdir/$evilname" w] |
| 497 |
puts $fd {#%Module1.0} |
| 498 |
close $fd |
| 499 |
|
| 500 |
setenv_path_var MODULEPATH $injectdir |
| 501 |
|
| 502 |
completion_tcsh_start |
| 503 |
|
| 504 |
set got [completion_tcsh_list {module load }] |
| 505 |
completion_assert_no_exec $marker |
| 506 |
completion_assert_contains $got [list $evilname] |
| 507 |
|
| 508 |
completion_tcsh_close |
| 509 |
unsetenv_path_var MODULEPATH |
| 510 |
unsetenv_var INJMARKER |
| 511 |
file delete -force $injectdir |
| 512 |
|
| 513 |
# LOADEDMODULES: malicious already-loaded module name |
| 514 |
|
| 515 |
set evilmod [string map [list MARKERPATH $marker] {python$(touch>MARKERPATH)}] |
| 516 |
setenv_loaded_module [list gcc $evilmod] [list /fake/gcc /fake/evilmod] |
| 517 |
|
| 518 |
completion_tcsh_start |
| 519 |
|
| 520 |
set got [completion_tcsh_list {module unload }] |
| 521 |
completion_assert_no_exec $marker |
| 522 |
completion_assert_contains $got [list $evilmod] |
| 523 |
|
| 524 |
completion_tcsh_close |
| 525 |
unsetenv_loaded_module |
| 526 |
|
| 527 |
# MODULEPATH: malicious path entry (module unuse); like this file's own |
| 528 |
# 'unuse' section above, only a bare, empty word reaches the modulepath |
| 529 |
# listing at all (see this file's header) |
| 530 |
|
| 531 |
set evilpath [string map [list MARKERPATH $marker] {/opt$(touch>MARKERPATH)}] |
| 532 |
setenv_path_var MODULEPATH /tmp $evilpath |
| 533 |
|
| 534 |
completion_tcsh_start |
| 535 |
|
| 536 |
set got [completion_tcsh_list {module unuse }] |
| 537 |
completion_assert_no_exec $marker |
| 538 |
completion_assert_contains $got [list $evilpath] |
| 539 |
|
| 540 |
completion_tcsh_close |
| 541 |
unsetenv_path_var MODULEPATH |
| 542 |
|
| 543 |
set timeout $old_timeout |
| 544 |
file delete -force $marker |
| 545 |
|
| 546 |
|
| 547 |
# |
| 548 |
# Cleanup |
| 549 |
# |
| 550 |
|
| 551 |
reset_test_env |
| 552 |
|
| 553 |
# vim:set tabstop=3 shiftwidth=3 expandtab autoindent: |