Debian Codegraph @

testsuite/example/siteconfig.tcl-1

raw
1 # enable siteconfig content only if following environment variable is set
2 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG)]} {
3
4 # force stderr terminal attachment state
5 proc initStateIsStderrTty {} {
6 return 1
7 }
8
9 # enable debug mode if following environment variable is set
10 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_DEBUG)]} {
11 set asked_verbosity debug
12 }
13
14 # call a non-existent procedure to raise error if following environment variable is set
15 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_BROKEN)]} {
16 unk_foo
17 }
18
19 # redefine existing modulecmd.tcl procedure to make it broken
20 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_BROKEN2)]} {
21 proc reportVersion {} {
22 unk_foo
23 }
24 }
25
26 # unset existing modulecmd.tcl procedure
27 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_BROKEN3)]} {
28 rename ::reportVersion {}
29 }
30
31 # generate error with parseAccessIssue generic msg if following environment variable is set
32 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_ACCESSERR)]} {
33 set errorCode "Custom error code"
34 error [parseAccessIssue "foo"]
35 }
36
37 # try element list display in terse+numbered mode if following environment variable is set
38 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_TERSENUM)]} {
39 displayElementList test {} terse 1 1 1 [list elt1 elt2 elt3]
40 }
41
42 # try element list display with a tricky list that triggers unusual condition in displayElementList proc
43 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_TRICKYLISTDISP)]} {
44 # set a specific terminal column number to fall in tricky condition
45 set orig_term_columns [getState term_columns]
46 setState term_columns 80
47 foreach elt [list abc/def abcdefgh/ijklmnop abc/defg abcd/ef abc/defg-hijkl.mn.op abcdefgh/ijklm.nopqrst abcdefg/hijklmnop-qr.st.uvw abcdefgh/ijklmnopqrst-u-vwxy.zA-BCD-E abcdef/ghijklm-nopq.r_st.uv abcdefgh/ijklmnop-q-rstu.vw-xyz-A abcdefg/hijklmn-op.qr.stu abcdefg/hijkl-mn.op.qrs abcd/efgh-ij.k abcdefg/hijk-lmnop_qr.st.uvw abcdef/ghijklmno-p.q.r abcdefgh/ijklmn-o-pqrs.tu abcdefgh/ijklmnop-q-rstu.vw-xyz abcdefg/hij-klm.nopq abcdefg/hij-kl.mn.opq abcdefgh/ijklmnopq_rstuv-w-xyzA.BC-DEF abcdefgh/ijklmnopqrstuv-w-xyzA.BC abcdefgh/ij-k-lmno.pq abcdefgh/ijk-l-mnop.qr-stu abcdefgh/ijklmnop-qr.st abcdef/ghijklmno-pq.rs abcdef/ghi-jklm_no_pqrstuv abcdefgh/ijk-lm-n-opqr.st abcdefgh/ijklm-n-opqr.st-uvw abcdef/ghijklm-nopq_r abcdefg/hijkl-mn.op.qzs abcdefg/hijklmn-op.qr.stz abcdefgh/ijklmn] {
48 lappend display_list $elt
49 lappend len_list [string length $elt]
50 }
51 displayElementList test {} terse 0 1 1 $display_list $len_list
52 setState term_columns $orig_term_columns
53 }
54
55
56 # use loaded module accessor on non-loaded module if following environment variable is set
57 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_LMACCESSOR)]} {
58 report [getModulefileFromLoadedModule "foo"]
59 report [getModuleFromLoadedModulefile "/path/to/foo"]
60 report [getModuleFromLoadingModulefile "/path/to/foo"]
61 }
62
63 # fake Solaris stty if following environment variable is set
64 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_SOLARIS_STTY)]} {
65 set tcl_platform(os) "SunOS"
66 set env(PATH) "$env(TESTSUITEDIR):$env(PATH)"
67 }
68
69 # fake Windows mode if following environment variable is set
70 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_WINDOWS_MODE)]} {
71 set tcl_platform(os) "Windows NT"
72 set env(PATH) "$env(TESTSUITEDIR):$env(PATH)"
73 }
74
75 # fake Windows platform if following environment variable is set
76 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_WINDOWS_PLATFORM)]} {
77 set tcl_platform(platform) "windows"
78 }
79
80 # test getDiffBetweenList procedure with element of second list arg not in first list arg
81 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_GETDIFFBETWEENLIST)]} {
82 report [getDiffBetweenList [list same foo foo2] [list same bar bar2]]
83 }
84
85 # test getDiffBetweenArray procedure with element of first list arg with empty value
86 # not in second list arg (notset_equals_empty option enabled)
87 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_GETDIFFBETWEENARRAY)]} {
88 array set arr1 [list same {} foo val]
89 array set arr2 [list foo val]
90 report [getDiffBetweenArray arr1 arr2 1]
91 }
92
93 # test twice calls to getConf term_background and getConf colors procedures
94 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_TWICEINITCOLORS)]} {
95 getConf term_background
96 getConf term_background
97 getConf colors
98 getConf colors
99 }
100
101 # test clear sub-command confirmation message without waiting indefinitely
102 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_EXITONGETSSTDIN)]} {
103 rename ::gets ::__gets
104 proc gets {fid} {
105 if {$fid eq {stdin}} {
106 exit 0
107 } else {
108 return [__gets $fid]
109 }
110 }
111 }
112
113 # test extra siteconfig disablement
114 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_NOEXTRASITECONFIG)]} {
115 lappendConf locked_configs extra_siteconfig
116 }
117
118 # test Tcl ext lib load by a Tcl interpreter < 8.5
119 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_TCLEXTLIBLOAD83)]} {
120 # call an external Tcl shell to just attempt to load lib in it (as
121 # modulecmd.tcl is not compatible with Tcl<8.5)
122 exec ./tclsh83 << "load [getConf tcl_ext_lib] Envmodules"
123 }
124
125 # test tcl ext lib procedures against erroneous calls
126 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_TCLEXTLIBBADCALL)]} {
127 set badcalllist [list readFile {readFile foo bar} {readFile foo 0 bar}\
128 {readFile foo 0 0 0} getFilesInDirectory {getFilesInDirectory foo bar}]
129 foreach badcall $badcalllist {
130 if {[catch {eval $badcall} errMsg]} {
131 reportError $errMsg
132 }
133 }
134 }
135
136 # test tcl ext lib procedures against a failed closedir call
137 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_TCLEXTLIBFAILEDCLOSEDIR)]} {
138 if {[catch {getFilesInDirectory $env(TESTSUITEDIR)/modulefiles 0} errMsg]} {
139 reportError $errMsg
140 }
141 }
142
143 # test tcl ext lib procedures against a failed getpwduid call
144 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_TCLEXTLIBFAILEDGETPWUID)]} {
145 if {[catch {initStateUsername} errMsg]} {
146 reportError $errMsg
147 }
148 if {$tcl_platform(os) eq "Darwin"} {
149 if {[catch {[initStateUsergroups]} errMsg]} {
150 reportError $errMsg
151 }
152 }
153 }
154
155 # test tcl ext lib procedures against a failed getgroups call
156 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_TCLEXTLIBFAILEDGETGROUPS)]} {
157 if {[catch {initStateUsergroups} errMsg]} {
158 reportError $errMsg
159 }
160 }
161
162 # test tcl ext lib procedures against a zero result getgroups call
163 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_TCLEXTLIB0GETGROUPS)]} {
164 report [initStateUsergroups]
165 }
166
167 # test tcl ext lib procedures against a duplicate entries in result getgroups call
168 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_TCLEXTLIBDUPGETGROUPS)]} {
169 report [initStateUsergroups]
170 }
171
172 # test tcl ext lib procedures against a failed time call
173 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_TCLEXTLIBFAILEDTIME)]} {
174 if {[catch {initStateClockSeconds} errMsg]} {
175 reportError $errMsg
176 }
177 }
178
179 # test tcl ext lib procedures called without argument
180 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_PARSEDATETIMEARG_NOARG)]} {
181 if {[catch {parseDateTimeArg} errMsg]} {
182 reportError $errMsg
183 }
184 }
185
186 # test tcl ext lib procedures against a failed mktime call
187 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_TCLEXTLIBFAILEDMKTIME)]} {
188 if {[catch {parseDateTimeArg --before 2020-09-18} errMsg]} {
189 reportError $errMsg
190 }
191 }
192
193 # test tcl ext lib procedures called with badly formatted date
194 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_PARSEDATETIMEARG_BADDATE)]} {
195 if {[catch {parseDateTimeArg --before 2020-09-19U20:00} errMsg]} {
196 reportError $errMsg
197 }
198 }
199
200 # specific tests to improve modEq procs coverage
201 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_MODEQ)]} {
202 # psuf tests
203 report [modEqProc foo foo/bar eqstart 1 0 0 0 /*]
204 report [modEqProc bar foo/bar eqstart 1 0 0 0 /*]
205 report [modEqProc foo foo/bar match 1 0 0 0 /*]
206 report [modEqProc bar foo/bar match 1 0 0 0 /*]
207 report [modEqProc foo/ foo/bar match 1 0 0 0 /*]
208 report [modEqProcIcase Foo foo/bar eqstart 1 0 0 0 /*]
209 report [modEqProcIcase Bar foo/bar eqstart 1 0 0 0 /*]
210 report [modEqProcIcase Foo foo/bar match 1 0 0 0 /*]
211 report [modEqProcIcase Bar foo/bar match 1 0 0 0 /*]
212 report [modEqProcIcase Foo/ foo/bar match 1 0 0 0 /*]
213 report [modEqProcExtdfl foo foo/bar eqstart 1 0 0 0 /*]
214 report [modEqProcExtdfl bar foo/bar eqstart 1 0 0 0 /*]
215 report [modEqProcExtdfl foo foo/bar match 1 0 0 0 /*]
216 report [modEqProcExtdfl bar foo/bar match 1 0 0 0 /*]
217 report [modEqProcExtdfl foo/ foo/bar match 1 0 0 0 /*]
218 report [modEqProcIcaseExtdfl Foo foo/bar eqstart 1 0 0 0 /*]
219 report [modEqProcIcaseExtdfl Bar foo/bar eqstart 1 0 0 0 /*]
220 report [modEqProcIcaseExtdfl Foo foo/bar match 1 0 0 0 /*]
221 report [modEqProcIcaseExtdfl Bar foo/bar match 1 0 0 0 /*]
222 report [modEqProcIcaseExtdfl Foo/ foo/bar match 1 0 0 0 /*]
223 # matchin tests
224 report [modEqProc oo/bar foo/bar matchin 1]
225 report [modEqProc aa foo/bar matchin 1]
226 report [modEqProc oo foo/bar matchin 1 0 0 0 /*]
227 report [modEqProcIcase Oo/bar foo/bar matchin 1]
228 report [modEqProcIcase Aa foo/bar matchin 1]
229 report [modEqProcIcase Oo foo/bar matchin 1 0 0 0 /*]
230 report [modEqProcExtdfl oo/bar foo/bar matchin 1]
231 report [modEqProcExtdfl aa foo/bar matchin 1]
232 report [modEqProcExtdfl oo foo/bar matchin 1 0 0 0 /*]
233 report [modEqProcIcaseExtdfl Oo/bar foo/bar matchin 1]
234 report [modEqProcIcaseExtdfl Aa foo/bar matchin 1]
235 report [modEqProcIcaseExtdfl Oo foo/bar matchin 1 0 0 0 /*]
236 defineParseModuleSpecificationProc [getConf advanced_version_spec]
237 parseModuleSpecification 0 0 0 0 [email protected]:1.3
238 parseModuleSpecification 0 0 0 0 [email protected]:1.3
239 parseModuleSpecification 0 0 0 0 [email protected]:1.3
240 parseModuleSpecification 0 0 0 0 [email protected]:1.3
241 defineModVersCmpProc 0 0
242 report [modEqProc [email protected]:1.3 foo/1.2 matchin]
243 report [modEqProc [email protected]:1.3 foo/1.4 matchin]
244 report [modEqProc [email protected]:1.3 fooo/1.3 matchin]
245 defineModVersCmpProc 1 0
246 report [modEqProcIcase [email protected]:1.3 foo/1.2 matchin]
247 report [modEqProcIcase [email protected]:1.3 foo/1.4 matchin]
248 report [modEqProcIcase [email protected]:1.3 fooo/1.3 matchin]
249 defineModVersCmpProc 0 1
250 report [modEqProcExtdfl [email protected]:1.3 foo/1.2.2 matchin]
251 report [modEqProcExtdfl [email protected]:1.3 foo/1.4.5 matchin]
252 report [modEqProcExtdfl [email protected]:1.3 fooo/1.3.1 matchin]
253 defineModVersCmpProc 1 1
254 report [modEqProcIcaseExtdfl [email protected]:1.3 foo/1.2.2 matchin]
255 report [modEqProcIcaseExtdfl [email protected]:1.3 foo/1.4.5 matchin]
256 report [modEqProcIcaseExtdfl [email protected]:1.3 fooo/1.3.1 matchin]
257 parseModuleSpecification 0 0 0 0 [email protected]:1.3
258 parseModuleSpecification 0 0 0 0 [email protected]:1.3
259 parseModuleSpecification 0 0 0 0 [email protected]:1.3
260 parseModuleSpecification 0 0 0 0 [email protected]:1.3
261 defineModVersCmpProc 0 0
262 report [modEqProc [email protected]:1.3 foo?bar/1.2 matchin]
263 report [modEqProc [email protected]:1.3 foo?bar/1.4 matchin]
264 report [modEqProc [email protected]:1.3 foo?bar/1.3 matchin]
265 defineModVersCmpProc 1 0
266 report [modEqProcIcase [email protected]:1.3 foo?bar/1.2 matchin]
267 report [modEqProcIcase [email protected]:1.3 foo?bar/1.4 matchin]
268 report [modEqProcIcase [email protected]:1.3 foo?bar/1.3 matchin]
269 defineModVersCmpProc 0 1
270 report [modEqProcExtdfl [email protected]:1.3 foo?bar/1.2.2 matchin]
271 report [modEqProcExtdfl [email protected]:1.3 foo?bar/1.4.5 matchin]
272 report [modEqProcExtdfl [email protected]:1.3 foo?bar/1.3.1 matchin]
273 defineModVersCmpProc 1 1
274 report [modEqProcIcaseExtdfl [email protected]:1.3 foo?bar/1.2.2 matchin]
275 report [modEqProcIcaseExtdfl [email protected]:1.3 foo?bar/1.4.5 matchin]
276 report [modEqProcIcaseExtdfl [email protected]:1.3 foo?bar/1.3.1 matchin]
277 }
278
279 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_REDEFONTHEFLYPROCS)]} {
280 defineModStartNbProc 0
281 defineModEqProc 0 0
282 report [modStartNb foo bar]
283 report [modStartNb foo foo]
284 report [modStartNb foo fOo]
285 defineModStartNbProc 0
286 defineModEqProc 0 0
287 report [modStartNb foo bar]
288 report [modStartNb foo foo]
289 report [modStartNb foo fOo]
290 defineModStartNbProc 1
291 defineModEqProc 1 1
292 report [modStartNb foo bar]
293 report [modStartNb foo foo]
294 report [modStartNb foo fOo]
295 defineModStartNbProc 1
296 defineModEqProc 1 1
297 report [modStartNb foo bar]
298 report [modStartNb foo foo]
299 report [modStartNb foo fOo]
300 defineModVersCmpProc 0 0
301 report [modVersCmp in {{eq foo}} foo eqstart]
302 report [modVersCmp in {{eq foo}} bar eqstart]
303 report [modVersCmp in {{eq foo}} fOo eqstart]
304 defineModVersCmpProc 0 0
305 report [modVersCmp in {{eq foo}} foo eqstart]
306 report [modVersCmp in {{eq foo}} bar eqstart]
307 report [modVersCmp in {{eq foo}} fOo eqstart]
308 defineModVersCmpProc 1 1
309 report [modVersCmp in {{eq foo}} foo eqstart]
310 report [modVersCmp in {{eq foo}} bar eqstart]
311 report [modVersCmp in {{eq foo}} fOo eqstart]
312 defineModVersCmpProc 1 1
313 report [modVersCmp in {{eq foo}} foo eqstart]
314 report [modVersCmp in {{eq foo}} bar eqstart]
315 report [modVersCmp in {{eq foo}} fOo eqstart]
316 defineModEqProc 0 0
317 report [modEq foo foo equal]
318 report [modEq foo bar equal]
319 report [modEq foo fOo equal]
320 defineModEqProc 0 0
321 report [modEq foo foo equal]
322 report [modEq foo bar equal]
323 report [modEq foo fOo equal]
324 defineModEqProc 1 1
325 report [modEq foo foo equal]
326 report [modEq foo bar equal]
327 report [modEq foo fOo equal]
328 defineModEqProc 1 1
329 report [modEq foo foo equal]
330 report [modEq foo bar equal]
331 report [modEq foo fOo equal]
332 }
333
334 # defineGetEqArrayKeyProc redefinition coverage test: the first two calls
335 # use the same implicit_default value in a row to exercise the no-op path
336 # where the currently active variant already matches what is being asked
337 # for; the following two calls switch value each time, to exercise the
338 # rename-the-previous-variant-back path in both directions
339 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_REDEFGETEQARRAYKEYPROC)]} {
340 array set arr {foo/1.0 {version foo/1.0}}
341 defineGetEqArrayKeyProc 0
342 report [getEqArrayKey arr foo/1.0]
343 defineGetEqArrayKeyProc 0
344 report [getEqArrayKey arr foo/1.0]
345 defineGetEqArrayKeyProc 1
346 report [getEqArrayKey arr foo/1.0]
347 defineGetEqArrayKeyProc 0
348 report [getEqArrayKey arr foo/1.0]
349 }
350
351 # getMatchingTagList coverage test: force a duplicate tag entry directly in
352 # the global tag structures (setModspecTag itself always dedupes by tag
353 # name, so this shape cannot occur through module-tag/module-hide/
354 # module-forbid) to exercise the "tag already seen earlier in this same
355 # call" skip path, which normal usage never reaches
356 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_DUPTAGROOT)]} {
357 defineModEqProc 0 0
358 set ::g_moduleTagRoot(duptagtest) [list sometag sometag]
359 set ::g_moduleTagRootSpec(duptagtest) [list [list duptagtest/1.0 {}]\
360 [list duptagtest/1.0 {}]]
361 report [getMatchingTagList duptagtest/1.0]
362 }
363
364 # getAvailListFromVersSpec coverage test: its only caller (the extra-match
365 # search dispatch in modscan.tcl) always passes a modarg already registered
366 # through parseModuleSpecification, so the unregistered-modarg path is
367 # exercised directly here instead
368 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_AVAILLISTUNREG)]} {
369 report [string length [getAvailListFromVersSpec neverregisteredmodarg]]
370 }
371
372 # specific tests to improve formatErrStackTrace proc coverage
373 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_FORMATERRSTACKTRACE)]} {
374 set errmsg {error message
375 while executing
376 foo call
377 invoked from within
378 foo
379 (file "foo")}
380
381 report [formatErrStackTrace $errmsg foo]
382 }
383
384 # specific test to improve formatErrStackTrace proc coverage: the topmost
385 # stack frame is itself an 'eval [...]' wrapper (as modulefile content is
386 # evaluated via 'eval [getModuleContent $::ModulesCurrentModulefile]'), which
387 # requires extracting the inner command from the second word of that frame
388 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_FORMATERRSTACKTRACE_EVAL)]} {
389 set errmsg {error message
390 while executing
391 "eval [getModuleContent $::ModulesCurrentModulefile]"
392 invoked from within
393 "eval [getModuleContent $::ModulesCurrentModulefile]"
394 (file "foo")}
395
396 report [formatErrStackTrace $errmsg foo]
397 }
398
399 # produce an unknown error in a modulecmd.tcl procedure during a modulefile evaluation
400 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_UNKINTERRDURINGMODEVAL)]} {
401 proc getModshareVarName {var} {
402 foo
403 }
404 }
405
406 # set a bad value for tag_abbrev default value
407 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_BADTAGABBREVDFLVALUE)]} {
408 set g_config_defs(tag_abbrev) {MODULES_TAG_ABBREV {loaded} 0 l {} {} initConfTagAbbrev}
409 }
410
411 # set a bad value for variant_shortcut default value
412 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_BADVARIANTSHORTCUTDFLVALUE)]} {
413 set g_config_defs(variant_shortcut) {MODULES_VARIANT_SHORTCUT {foo} 0 l {} {} initConfVariantShortcut}
414 }
415
416 # exercise the single-element validvallist "string is" class check path in
417 # getConf, not used by any current config option, by superseding an existing
418 # lockable option's definition with that shape
419 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_VALIDVALLISTSTRINGIS)]} {
420 set ::g_config_defs(run_quarantine) {MODULES_RUN_QUARANTINE default 0 s\
421 integer}
422 set env(MODULES_RUN_QUARANTINE) 42
423 report [getConf run_quarantine]
424 }
425
426 # exercise the generic intvallist conversion path in getConf when no initproc
427 # is set, not used by any current config option (the only option using
428 # intvallist, color, has an initproc superseding this path)
429 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_INTVALLISTCONV)]} {
430 set ::g_config_defs(csh_limit) {{} val2 0 s {val1 val2} {10 20}}
431 report [getConf csh_limit]
432 }
433
434 # specific tests to improve getModuleDesignation procs coverage
435 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_GETMODULEDESIGNATION)]} {
436 # test disabled sgr mode
437 cacheCurrentModules
438 report [getModuleDesignation loaded variant/1.0 0]
439 }
440
441 # unsetModuleTag/unsetModuleExtraTag coverage test
442 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_UNSETMODULETAG)]} {
443 unsetModuleTag unk foo
444 unsetModuleExtraTag unk foo
445 }
446
447 # readCollectionContent coverage test
448 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_READCOLLCONTENT)]} {
449 readCollectionContent /path/to/unk unk
450 }
451
452 # test removal of alias, function and completion from a source-sh bash script
453 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_SOURCESHBASHUNSET)]} {
454 # update the list of commands run by execShAndGetEnv procedure
455 # to predefine alias, function and completion prior source-sh evaluation
456 proc traceCommandVarOfSourceSh {name1 name2 op} {
457 set defalias {alias alfoo='echo foo'}
458 set deffunc {funcfoo() { echo foo; }}
459 set defcomp {complete -o default -F _cmd cmd}
460 uplevel 1 [list set $name1 "$defalias; $deffunc; $defcomp; [uplevel 1 set $name1]"]
461 }
462 # update start of execShAndGetEnv proc to set up trace on command variable
463 set tracevarcall "trace add variable command write traceCommandVarOfSourceSh"
464 proc execShAndGetEnv [info args execShAndGetEnv] "$tracevarcall ; [info body execShAndGetEnv]"
465 }
466
467 # test removal of alias, function and completion from a source-sh tcsh script
468 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_SOURCESHTCSHUNSET)]} {
469 # update the list of commands run by execShAndGetEnv procedure
470 # to predefine alias, function and completion prior source-sh evaluation
471 proc traceCommandVarOfSourceSh {name1 name2 op} {
472 # no function definition: not supported on tcsh shell
473 set defalias {alias alfoo 'echo foo'}
474 set defcomp {complete cmd 'n/--help/n/'}
475 uplevel 1 [list set $name1 "$defalias; $defcomp; [uplevel 1 set $name1]"]
476 }
477 # update start of execShAndGetEnv proc to set up trace on command variable
478 set tracevarcall "trace add variable command write traceCommandVarOfSourceSh"
479 proc execShAndGetEnv [info args execShAndGetEnv] "$tracevarcall ; [info body execShAndGetEnv]"
480 }
481
482 # test removal of alias, function and completion from a source-sh fish script
483 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_SOURCESHFISHUNSET)]} {
484 # update the list of commands run by execShAndGetEnv procedure
485 # to predefine alias, function and completion prior source-sh evaluation
486 proc traceCommandVarOfSourceSh {name1 name2 op} {
487 set defalias {alias alfoo='echo foo'}
488 set deffunc {function funcfoo; echo foo; end}
489 set defcomp {complete -c cmd -s V -l version --description 'Command version'}
490 uplevel 1 [list set $name1 "$defalias; $deffunc; $defcomp; [uplevel 1 set $name1]"]
491 }
492 # update start of execShAndGetEnv proc to set up trace on command variable
493 set tracevarcall "trace add variable command write traceCommandVarOfSourceSh"
494 proc execShAndGetEnv [info args execShAndGetEnv] "$tracevarcall ; [info body execShAndGetEnv]"
495 }
496
497 # supersede pwd procedure to raise an error
498 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_PWDERROR)]} {
499 proc pwd {} {
500 error {Custom error message}
501 }
502 }
503
504 # extra modulefile/modulerc command and variable tests
505 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_EXTRA_ODD)]} {
506 switch -- $env(TESTSUITE_ENABLE_SITECONFIG_EXTRA_ODD) {
507 cmd {set modulefile_extra_cmds [list mycmd]}
508 rc_cmd {set modulerc_extra_cmds [list mycmd]}
509 var {set modulefile_extra_vars [list myvar]}
510 rc_var {set modulerc_extra_vars [list myvar]}
511 }
512 }
513
514 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_EXTRA_EMPTYDEF)]} {
515 switch -- $env(TESTSUITE_ENABLE_SITECONFIG_EXTRA_EMPTYDEF) {
516 cmd {set modulefile_extra_cmds [list]}
517 rc_cmd {set modulerc_extra_cmds {}}
518 var {set modulefile_extra_vars {}}
519 rc_var {set modulerc_extra_vars [list]}
520 }
521 }
522
523 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_EXTRA_EMPTYVAL)]} {
524 switch -- $env(TESTSUITE_ENABLE_SITECONFIG_EXTRA_EMPTYVAL) {
525 cmd {set modulefile_extra_cmds [list mycmd {}]}
526 rc_cmd {set modulerc_extra_cmds [list mycmd {}]}
527 var {set modulefile_extra_vars [list myvar {}]}
528 rc_var {set modulerc_extra_vars [list myvar {}]}
529 }
530 }
531
532 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_EXTRA_UNK)]} {
533 switch -- $env(TESTSUITE_ENABLE_SITECONFIG_EXTRA_UNK) {
534 cmd {set modulefile_extra_cmds [list mycmd unkproc]}
535 rc_cmd {set modulerc_extra_cmds [list mycmd unkproc]}
536 }
537 }
538
539 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_EXTRA_SUPERSEDE)]} {
540 proc myproc1 {args} {
541 return myproc1
542 }
543 proc myproc2 {args} {
544 return myproc2
545 }
546 switch -- $env(TESTSUITE_ENABLE_SITECONFIG_EXTRA_SUPERSEDE) {
547 cmd {set modulefile_extra_cmds [list uname myproc1 pid myproc2]}
548 rc_cmd {set modulerc_extra_cmds [list uname myproc1 pid myproc2]}
549 var {set modulefile_extra_vars [list ModuleTool super ModulesCurrentModulefile myfile]}
550 rc_var {set modulerc_extra_vars [list ModuleTool super ModulesCurrentModulefile myfile]}
551 }
552 }
553
554 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_EXTRA_SPACEINVAL)]} {
555 proc {my proc1} {args} {
556 return myproc1
557 }
558 switch -- $env(TESTSUITE_ENABLE_SITECONFIG_EXTRA_SPACEINVAL) {
559 cmd {set modulefile_extra_cmds [list mycmd {my proc1}]}
560 rc_cmd {set modulerc_extra_cmds [list mycmd {my proc1}]}
561 }
562 }
563
564 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_EXTRA_SPACEINNAME)]} {
565 proc myproc1 {args} {
566 return myproc1
567 }
568 switch -- $env(TESTSUITE_ENABLE_SITECONFIG_EXTRA_SPACEINNAME) {
569 cmd {set modulefile_extra_cmds [list {my cmd} myproc1]}
570 rc_cmd {set modulerc_extra_cmds [list {my cmd} myproc1]}
571 var {set modulefile_extra_vars [list {my var} value]}
572 rc_var {set modulerc_extra_vars [list {my var} value]}
573 }
574 }
575
576 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_EXTRA_REGULAR)]} {
577 proc mycmd {args} {
578 return myproc1
579 }
580 proc mycmd2 {args} {
581 return myproc2
582 }
583 switch -- $env(TESTSUITE_ENABLE_SITECONFIG_EXTRA_REGULAR) {
584 cmd {set modulefile_extra_cmds [list mycmd mycmd othercmd mycmd2]}
585 rc_cmd {set modulerc_extra_cmds [list mycmd mycmd othercmd mycmd2]}
586 var {set modulefile_extra_vars [list myvar {my value} othervar value]}
587 rc_var {set modulerc_extra_vars [list myvar {my value} othervar value]}
588 mix - override {
589 set modulefile_extra_cmds [list mycmd mycmd othercmd mycmd2]
590 set modulerc_extra_cmds [list mycmd mycmd othercmd mycmd2]
591 set modulefile_extra_vars [list myvar value]
592 set modulerc_extra_vars [list myvar value]
593 }
594 }
595 }
596
597 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_CACHECLEAR_DELETE)]\
598 || [info exists env(TESTSUITE_ENABLE_SITECONFIG_CACHEBUILD_CREATE)]\
599 || [info exists env(TESTSUITE_ENABLE_SITECONFIG_CACHE_READ)]} {
600 rename file __file
601 proc file {args} {
602 switch -- [lindex $args 0] {
603 readable - writable {
604 return 1
605 }
606 default {
607 return [__file {*}$args]
608 }
609 }
610 }
611 }
612
613 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_CACHEBUILD_READ1)]} {
614 proc readFile {filename {firstline 0} {must_have_cookie 0}} {
615 if {[string first bar/1.0 $filename] > -1} {
616 set filename unk
617 }
618 return [__readFile $filename $firstline $must_have_cookie]
619 }
620 }
621
622 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_CACHEBUILD_READ2)]} {
623 proc readFile {filename {firstline 0} {must_have_cookie 0}} {
624 if {[string first foo/.modulerc $filename] > -1} {
625 set filename unk
626 }
627 return [__readFile $filename $firstline $must_have_cookie]
628 }
629 }
630
631 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_MKDIR_COLLDIR)]} {
632 rename file __file
633 proc file {args} {
634 switch -- [lindex $args 0] {
635 mkdir {
636 error {Custom error message}
637 }
638 default {
639 return [__file {*}$args]
640 }
641 }
642 }
643 }
644
645 # specific test to improve getInterpVar proc coverage
646 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_GETINTERPVAR)]} {
647 interp create foo
648 report [getInterpVar foo bar undef]
649 foo eval {set bar value}
650 report [getInterpVar foo bar undef]
651 interp delete foo
652 }
653
654 # specific test to improve getLoadingModulefileList proc coverage
655 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_GETLOADINGMODULEFILELIST)]} {
656 lappendState modulefile /path/to/foo/1.0
657 lappendState mode load
658 lappendState modulefile /path/to/bar/1.0
659 lappendState mode unload
660 lappendState modulefile /path/to/qux/1.0
661 lappendState mode load
662 report [getLoadingModuleFileList]
663 }
664
665 # specific test to improve getModuleFromLoadingModulefile proc coverage
666 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_GETMODULEFROMLOADINGMODULEFILE)]} {
667 lappendState modulefile /path/to/foo/1.0
668 lappendState modulename qux/1.0
669 lappendState mode load
670 lappendState modulefile /path/to/bar/1.0
671 lappendState modulename bar/1.0
672 lappendState mode load
673 lappendState modulefile /path/to/foo/1.0
674 lappendState modulename foo/1.0
675 lappendState mode load
676 report [getModuleFromLoadingModulefile /path/to/foo/1.0 0]
677 }
678
679 # specific tests for reportFinalError procedure
680 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_EXTERNALERRORTCLCOMPAT)]} {
681 proc reportVersion {} {
682 error {interpreter uses an incompatible stubs mechanism}
683 }
684 }
685 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_EXTERNALERRORLIBCOMPAT)]} {
686 proc reportVersion {} {
687 error {dlopen(/usr/local/Modules/lib/libtclenvmodules.dylib, 0x000A): tried: '/usr/local/Modules/lib/libtclenvmodules.dylib' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e)))}
688 }
689 }
690 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_EXTERNALERRORTCLINSTALL)]} {
691 proc reportVersion {} {
692 error {Can't find a usable init.tcl in the following directories:
693 /root/lib/tcl8.6 /usr/lib/tcl8.6 /lib/tcl8.6 /usr/library /library /tcl8.6.14/library /tcl8.6.14/library
694
695 This probably means that Tcl wasn't installed properly.}
696 }
697 }
698 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_EXTERNALERRORTCLINIT)]} {
699 rename tcl::mathfunc::max {}
700 }
701 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_EXTERNALERRORRESSOURCEUNAVAIL)]} {
702 proc reportVersion {} {
703 error {couldn't fork child process: resource temporarily unavailable}
704 }
705 }
706
707 # specific tests to improve getModuleFromEvalId procs coverage
708 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_GETMODULEFROMEVALID)]} {
709 report [string length [getModuleFromEvalId unknown_eval_id]]
710 }
711
712 # specific tests to improve changeContextOfModuleEval procs coverage
713 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_CHANGECONTEXTOFMODULEEVAL)]} {
714 switch -- $env(TESTSUITE_ENABLE_SITECONFIG_CHANGECONTEXTOFMODULEEVAL) {
715 1 {
716 set evalid [topState evalid]
717 set ::g_moduleEval($evalid) [list depun]
718 report [string length [changeContextOfModuleEval foo depre urequn]]
719 }
720 2 {
721 set evalid [topState evalid]
722 set ::g_moduleEval($evalid) [list depre]
723 report [string length [changeContextOfModuleEval foo depre urequn]]
724 }
725 }
726 }
727
728 # specific tests to improve getLoadedPrereqPath coverage
729 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_GETLOADEDPREREQPATH)]} {
730 set ::g_loadedModulePrereqPath(foo) {bar mp}
731 report [string length [getLoadedPrereqPath foo qux]]
732 }
733
734 # specific tests to improve getModulefileFromLoadingModule coverage
735 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_GETMODULEFILEFROMLOADINGMODULE)]} {
736 report [string length [getModulefileFromLoadingModule foo]]
737 }
738
739 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_EXTRA_VALNOTALIST)]} {
740 switch -- $env(TESTSUITE_ENABLE_SITECONFIG_EXTRA_VALNOTALIST) {
741 var {set modulefile_extra_vars [list myvar {"foo"; "bar"}]}
742 rc_var {set modulerc_extra_vars [list myvar {"foo"; "bar"}]}
743 }
744 }
745
746 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_UNKNOWNSTATE)]} {
747 report [string length [getState unknown_state]]
748 }
749
750 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_RELEASESTATE)]} {
751 report [getState modules_release]
752 }
753
754 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_GETHELPLINES)]} {
755 report [string length [getModuleHelpLines]]
756 }
757
758 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_GETCMPSPECFROMVERSSPEC)]} {
759 report [getCmpSpecFromVersSpec unk]
760 }
761
762 # fake id command if following environment variable is set
763 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_ID)]} {
764 set env(PATH) "$env(TESTSUITEDIR):$env(PATH)"
765 report [__initStateUsergroups]
766 }
767
768 # fake id command if following environment variable is set
769 if {[info exists env(TESTSUITE_ENABLE_RUNENVCOMMAND_UNSET)]} {
770 runEnvCommand {UNK_VAR val} echo
771 if {![info exists ::env(UNK_VAR)]} {
772 report ok
773 }
774 }
775
776 # specific tests to improve compute_output_grid coverage
777 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_COMPUTEOUTPUTGRID)]} {
778 report [compute_output_grid 80 {} 3]
779 }
780
781 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_GETVIAMODULEMODULEPATH)]} {
782 report [string length [getViaModuleModulepath unk]]
783 }
784
785 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_REPLACEFIRSTINSTR)]} {
786 report [replaceFirstInStr string unk foo]
787 }
788
789 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_INITCONFINITENVVARS)]} {
790 set ::g_config_defs(init_envvars) {MODULES_INIT_ENVVARS FOO 0 l {} {} initConfInitEnvvars}
791 report [string length [getConf init_envvars]]
792 }
793
794 # add-hook command and hook event tests
795 if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_HOOK)]} {
796 switch -- $env(TESTSUITE_ENABLE_SITECONFIG_HOOK) {
797 unknownevent {
798 add-hook not-an-event testsuite_hook_unknown
799 }
800 modulefile {
801 proc testsuite_hook_before_modulefile {modfile modname\
802 modnamevr modspec mode requested} {
803 report "HOOK before-modulefile-eval $modfile $modname\
804 $modnamevr $modspec $mode $requested"
805 }
806 proc testsuite_hook_after_modulefile {modfile modname modnamevr\
807 modspec mode requested status} {
808 report "HOOK after-modulefile-eval $modfile $modname\
809 $modnamevr $modspec $mode $requested $status"
810 }
811 add-hook before-modulefile-eval testsuite_hook_before_modulefile
812 add-hook after-modulefile-eval testsuite_hook_after_modulefile
813 }
814 modulerc {
815 proc testsuite_hook_before_modulerc {modfile modname} {
816 report "HOOK before-modulerc-eval $modfile $modname"
817 }
818 proc testsuite_hook_after_modulerc {modfile modname status} {
819 report "HOOK after-modulerc-eval $modfile $modname $status"
820 }
821 add-hook before-modulerc-eval testsuite_hook_before_modulerc
822 add-hook after-modulerc-eval testsuite_hook_after_modulerc
823 }
824 multiple {
825 proc testsuite_hook_multi1 {modfile modname modnamevr modspec\
826 mode requested} {
827 report "HOOK1 $modname"
828 }
829 proc testsuite_hook_multi2 {modfile modname modnamevr modspec\
830 mode requested} {
831 report "HOOK2 $modname"
832 }
833 add-hook before-modulefile-eval testsuite_hook_multi1
834 add-hook before-modulefile-eval testsuite_hook_multi2
835 }
836 error {
837 proc testsuite_hook_error {modfile modname modnamevr modspec\
838 mode requested} {
839 error "hook failure for $modname"
840 }
841 proc testsuite_hook_after_error {modfile modname modnamevr\
842 modspec mode requested} {
843 report "HOOK survived after error for $modname"
844 }
845 add-hook before-modulefile-eval testsuite_hook_error
846 add-hook before-modulefile-eval testsuite_hook_after_error
847 }
848 arity_missing {
849 proc testsuite_hook_arity_missing {modfile modname} {
850 report "HOOK should not be reached for $modname"
851 }
852 add-hook before-modulefile-eval testsuite_hook_arity_missing
853 }
854 arity_extra {
855 proc testsuite_hook_arity_extra {modfile modname modnamevr\
856 modspec mode requested extra} {
857 report "HOOK should not be reached for $modname"
858 }
859 add-hook before-modulefile-eval testsuite_hook_arity_extra
860 }
861 codeerror {
862 proc testsuite_hook_codeerror {modfile modname modnamevr modspec\
863 mode requested} {
864 testsuite_hook_undefined_command $modname
865 }
866 add-hook before-modulefile-eval testsuite_hook_codeerror
867 }
868 error_second {
869 proc testsuite_hook_first_ok {modfile modname modnamevr modspec\
870 mode requested} {
871 report "HOOK1 ok for $modname"
872 }
873 proc testsuite_hook_second_error {modfile modname modnamevr\
874 modspec mode requested} {
875 error "second hook failure for $modname"
876 }
877 add-hook before-modulefile-eval testsuite_hook_first_ok
878 add-hook before-modulefile-eval testsuite_hook_second_error
879 }
880 docexamples {
881 # replicates the auditRequestedLoad example from module.rst
882 # (using report instead of writing to a real file, for test
883 # purposes)
884 proc testsuite_hook_audit_requested {modfile modname modnamevr\
885 modspec mode requested} {
886 if {$requested && $mode eq {load}} {
887 report "would audit: $modnamevr"
888 }
889 }
890 add-hook before-modulefile-eval testsuite_hook_audit_requested
891
892 # replicates the hook_procedure example from module.rst
893 proc testsuite_hook_setenv {modfile modname modnamevr modspec\
894 mode requested} {
895 set modfile_interp [getCurrentModfileInterpName]
896 interp eval $modfile_interp setenv MYVAR value
897 }
898 add-hook before-modulefile-eval testsuite_hook_setenv
899 }
900 blockmodule {
901 # replicates the blockModule example from module.rst (Advanced
902 # hooks): a low-level trace-based hook that can reject a
903 # modulefile evaluation outright, unlike add-hook
904 proc testsuite_hook_block_module {cmdstring op} {
905 if {[lindex $cmdstring 2] eq {foo/1.0}} {
906 error "foo/1.0 is blocked by site policy"
907 }
908 }
909 trace add execution execute-modulefile enter\
910 testsuite_hook_block_module
911 }
912 }
913 }
914
915 }