| 1 |
############################################################################## |
| 2 |
# Modules Revision 3.0 |
| 3 |
# Providing a flexible user environment |
| 4 |
# |
| 5 |
# File: cookbook.00-init/%M% |
| 6 |
# Revision: %I% |
| 7 |
# First Edition: 2026/08/13 |
| 8 |
# Last Mod.: %U%, %G% |
| 9 |
# |
| 10 |
# Authors: Xavier Delaruelle, [email protected] |
| 11 |
# |
| 12 |
# Description: Testuite testsequence |
| 13 |
# Command: avail, load, list, unload |
| 14 |
# Modulefiles: sandboxed copy of doc/example/sync-remote-appdir |
| 15 |
# Sub-Command: |
| 16 |
# |
| 17 |
# Comment: %C{ |
| 18 |
# Exercise the 'Sync remote application directories on |
| 19 |
# first load' cookbook recipe |
| 20 |
# (doc/source/cookbook/sync-remote-appdir.rst) against |
| 21 |
# the exact files shipped in |
| 22 |
# doc/example/sync-remote-appdir/: the remote-share |
| 23 |
# application directory gets synced locally on first |
| 24 |
# load only, the 'remote' tag shows up on avail until |
| 25 |
# then and is dropped once loaded, and the commands |
| 26 |
# driven here are the ones the recipe doc's 'Usage |
| 27 |
# example' section demonstrates (see |
| 28 |
# cookbook_parse_transcript, defined in 005-init_ts.exp) |
| 29 |
# }C% |
| 30 |
# |
| 31 |
############################################################################## |
| 32 |
|
| 33 |
set recipe sync-remote-appdir |
| 34 |
set reciperst "$cookbookdocdir/$recipe.rst" |
| 35 |
set recipeexampledir "$cookbookexampledir/$recipe" |
| 36 |
|
| 37 |
if {![file readable $reciperst] || ![file isdirectory $recipeexampledir]} { |
| 38 |
unsupported "cookbook recipe files not found for '$recipe' (this\ |
| 39 |
testsuite requires a full source checkout, not a release tarball)" |
| 40 |
return |
| 41 |
} |
| 42 |
|
| 43 |
set rsyncbin [find_bin rsync] |
| 44 |
if {$rsyncbin eq {}} { |
| 45 |
unsupported {no rsync binary found to drive the sync-remote-appdir cookbook recipe} |
| 46 |
return |
| 47 |
} |
| 48 |
|
| 49 |
# |
| 50 |
# build the sandbox fixture from the exact files shipped with the recipe |
| 51 |
# |
| 52 |
|
| 53 |
set recipedir "$cookbooksandbox/$recipe" |
| 54 |
file delete -force $recipedir |
| 55 |
|
| 56 |
set remoteapps "$recipedir/remote_apps" |
| 57 |
set localapps "$recipedir/local_apps" |
| 58 |
set recipemodpath "$recipedir/modulefiles" |
| 59 |
set recipeetc "$recipedir/etc" |
| 60 |
file mkdir $remoteapps $localapps $recipemodpath $recipeetc |
| 61 |
|
| 62 |
# .module_appdir_map: copied verbatim, no hardcoded path to rewrite, at the |
| 63 |
# root of the sandboxed remote share |
| 64 |
set mapfile [file join $recipeexampledir .module_appdir_map] |
| 65 |
file copy $mapfile "$remoteapps/.module_appdir_map" |
| 66 |
|
| 67 |
# fake application directory payload on the sandboxed remote share, synced |
| 68 |
# locally on first load -- the recipe doc does not ship one since its |
| 69 |
# content is site-specific, only its mapped basename |
| 70 |
regexp {\S+\s+(\S+)} [cookbook_read_example_file $mapfile {}] -> appdir |
| 71 |
file mkdir "$remoteapps/$appdir/bin" "$remoteapps/$appdir/lib" |
| 72 |
cookbook_write_file "$remoteapps/$appdir/bin/foo" "#!/bin/sh\necho foo\n" |
| 73 |
cookbook_write_file "$remoteapps/$appdir/lib/libfoo.so" "fake shared object\n" |
| 74 |
|
| 75 |
# every other recipe file hardcodes '/remote_apps'/'/local_apps' as the |
| 76 |
# real-system absolute paths it gets installed under: rewrite just those to |
| 77 |
# this test's own sandbox paths, everything else is used byte for byte -- |
| 78 |
# the same kind of surgical rewrite completion.00-init/005-init_ts.exp |
| 79 |
# applies to the tcsh completion script under test. This sandbox is also |
| 80 |
# not tied to any particular Modules release, so also drop the recipe's |
| 81 |
# '#%Module5.7' minimum-version requirement, which would otherwise reject |
| 82 |
# these files on a pre-5.7 development checkout of the very release that |
| 83 |
# ships the hook API they exercise |
| 84 |
set submap [list /remote_apps $remoteapps /local_apps $localapps\ |
| 85 |
#%Module5.7 #%Module] |
| 86 |
|
| 87 |
cookbook_write_file "$recipemodpath/.modulerc" [cookbook_read_example_file\ |
| 88 |
[file join $recipeexampledir modulefiles/.modulerc] $submap] |
| 89 |
cookbook_write_file "$recipemodpath/foo/2.1" [cookbook_read_example_file\ |
| 90 |
[file join $recipeexampledir modulefiles/foo/2.1] $submap] |
| 91 |
cookbook_write_file "$recipeetc/siteconfig.tcl" [cookbook_read_example_file\ |
| 92 |
[file join $recipeexampledir siteconfig.tcl] $submap] |
| 93 |
|
| 94 |
# |
| 95 |
# point the test environment at the sandbox |
| 96 |
# |
| 97 |
|
| 98 |
setenv_path_var MODULEPATH $recipemodpath |
| 99 |
setenv_var MODULES_SITECONFIG "$recipeetc/siteconfig.tcl" |
| 100 |
# give the 'remote' tag its abbreviation and drop it once a module is |
| 101 |
# loaded, exactly as documented for the initrc installed alongside |
| 102 |
# siteconfig.tcl -- 'module config' from an actual initrc file only runs |
| 103 |
# through shell autoinit (see doc/example/sync-remote-appdir/initrc), |
| 104 |
# which this testsuite does not drive; setting the equivalent |
| 105 |
# configuration through its environment variable override has the same |
| 106 |
# effect on modulecmd.tcl itself |
| 107 |
setenv_var MODULES_TAG_ABBREV remote=R |
| 108 |
setenv_var MODULES_NON_EXPORTABLE_TAGS remote |
| 109 |
|
| 110 |
# |
| 111 |
# drive the exact command sequence the recipe doc's 'Usage example' section |
| 112 |
# demonstrates, in the order it demonstrates it, checking the real stderr |
| 113 |
# each command produces is similar to the output illustrated there (with |
| 114 |
# its placeholder modulepath and unpredictable separator width widened |
| 115 |
# into a regexp, see cookbook_output_re) |
| 116 |
# |
| 117 |
|
| 118 |
set transcript [cookbook_parse_transcript $reciperst {Usage example}] |
| 119 |
|
| 120 |
set modpathre [cookbook_re_escape $recipemodpath] |
| 121 |
set appdirbin "$localapps/$appdir/bin" |
| 122 |
set appdirlib "$localapps/$appdir/lib" |
| 123 |
set altname {foo/2.1&as|foo/default&as|foo/latest} |
| 124 |
set origpath $env(PATH) |
| 125 |
set outputsubs [list /path/to/modulefiles $modpathre] |
| 126 |
|
| 127 |
set loadans [list] |
| 128 |
lappend loadans [list set LD_LIBRARY_PATH $appdirlib] |
| 129 |
lappend loadans [list set __MODULES_LMALTNAME $altname] |
| 130 |
lappend loadans [list set PATH "$appdirbin:$origpath"] |
| 131 |
lappend loadans [list set _LMFILES_ $recipemodpath/foo/2.1] |
| 132 |
lappend loadans [list set LOADEDMODULES foo/2.1] |
| 133 |
|
| 134 |
set unloadans [list] |
| 135 |
lappend unloadans [list unset LD_LIBRARY_PATH] |
| 136 |
lappend unloadans [list unset __MODULES_LMALTNAME] |
| 137 |
lappend unloadans [list set PATH $origpath] |
| 138 |
lappend unloadans [list unset _LMFILES_] |
| 139 |
lappend unloadans [list unset LOADEDMODULES] |
| 140 |
|
| 141 |
# expected stdout (the env-var-assignment syntax a real shell would eval |
| 142 |
# silently, so not part of what the doc transcript illustrates) for each |
| 143 |
# step, in the same order 'module avail foo'/'load foo/2.1'/'list'/ |
| 144 |
# 'unload foo/2.1'/'avail foo'/'load foo/2.1' appears in the doc |
| 145 |
set stdoutexpected [list OK $loadans OK $unloadans OK $loadans] |
| 146 |
|
| 147 |
if {[llength $transcript] != [llength $stdoutexpected]} { |
| 148 |
unresolved "sync-remote-appdir.rst 'Usage example' transcript now has\ |
| 149 |
[llength $transcript] steps ([llength $stdoutexpected] expected) --\ |
| 150 |
this test needs updating to match" |
| 151 |
return |
| 152 |
} |
| 153 |
|
| 154 |
set idx 0 |
| 155 |
foreach step $transcript { |
| 156 |
lassign $step cmd docoutput |
| 157 |
if {![regexp {^module\s+(.*)$} $cmd -> modargs]} { |
| 158 |
unresolved "unexpected non-'module' command in sync-remote-appdir.rst\ |
| 159 |
'Usage example' transcript: '$cmd'" |
| 160 |
return |
| 161 |
} |
| 162 |
|
| 163 |
testouterr_cmd_re sh $modargs [lindex $stdoutexpected $idx]\ |
| 164 |
[cookbook_output_re $docoutput $outputsubs] |
| 165 |
|
| 166 |
# step 1 (0-indexed) is the first 'load foo/2.1': check the sync |
| 167 |
# actually happened on disk, then simulate that it took hold in this |
| 168 |
# shell, as steps 2 and 3 ('list'/'unload') need to see it |
| 169 |
if {$idx == 1} { |
| 170 |
if {[file exists "$localapps/.$appdir.synced"]} { |
| 171 |
pass "sync-remote-appdir: local sync marker created" |
| 172 |
} else { |
| 173 |
fail "sync-remote-appdir: local sync marker created" |
| 174 |
} |
| 175 |
if {[file exists "$appdirbin/foo"]} { |
| 176 |
pass "sync-remote-appdir: application directory synced locally" |
| 177 |
} else { |
| 178 |
fail "sync-remote-appdir: application directory synced locally" |
| 179 |
} |
| 180 |
|
| 181 |
setenv_loaded_module foo/2.1 $recipemodpath/foo/2.1 |
| 182 |
setenv_var __MODULES_LMALTNAME $altname |
| 183 |
setenv_path_var PATH $appdirbin $origpath |
| 184 |
setenv_var LD_LIBRARY_PATH $appdirlib |
| 185 |
} |
| 186 |
|
| 187 |
# step 3 is 'unload foo/2.1': drop the simulated loaded state so steps |
| 188 |
# 4 and 5 ('avail'/'load' again) see a clean environment, exactly as a |
| 189 |
# real shell would once the unload's env changes above got eval'd |
| 190 |
if {$idx == 3} { |
| 191 |
unsetenv_loaded_module |
| 192 |
unsetenv_var __MODULES_LMALTNAME |
| 193 |
unsetenv_var LD_LIBRARY_PATH |
| 194 |
setenv_var PATH $origpath |
| 195 |
} |
| 196 |
|
| 197 |
incr idx |
| 198 |
} |
| 199 |
|
| 200 |
# |
| 201 |
# Cleanup |
| 202 |
# |
| 203 |
|
| 204 |
file delete -force $recipedir |
| 205 |
reset_test_env |
| 206 |
|
| 207 |
# vim:set tabstop=3 shiftwidth=3 expandtab autoindent: |