Debian Codegraph @

testsuite/modules.00-init/140-color.exp

raw
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: 2019/01/08
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 # Check color-related switches and configs.
18 # }C%
19 #
20 ##############################################################################
21
22 # skip tests if implicit_default option could not be overridden
23 if {[is_config_locked implicit_default]} {
24 send_user "\tskipping tests as implicit_default could not be overridden\n"
25 } else {
26
27 # unset test-specific color setup disablement
28 unsetenv_var MODULES_COLOR
29
30 # ensure avail tests are made using in depth mode
31 setenv_var MODULES_AVAIL_INDEPTH 1
32
33 # ensure avail tests have implicit default enabled
34 setenv_var MODULES_IMPLICIT_DEFAULT 1
35
36 # check if stderr terminal attachment state is forced
37 set is_stderr_tty [siteconfig_isStderrTty]
38 if {$verbose} {
39 send_user "\tIs STDERR a TTY? = '$is_stderr_tty'\n"
40 }
41
42 # parse default color sets
43 # no default colors will be set if color set is badly defined
44 if {[catch {array set darkbgcolors [split $install_darkbgcolors {=:}]} errMsg ]} {
45 array set darkbgcolors {}
46 }
47 if {[catch {array set lightbgcolors [split $install_lightbgcolors {=:}]} errMsg ]} {
48 array set lightbgcolors {}
49 }
50
51 # create a specific color set for test purpose
52 foreach sgrkey [list hi db tr se er wa me in mp di al sy de cm] {
53 set customcolors($sgrkey) {37;40}
54 }
55
56 proc colorstr {str sgr {re_mode 0}} {
57 # if render bold or faint just reset that attribute, not all
58 if {$sgr == 1 || $sgr == 2} {
59 set sgrreset 22
60 } else {
61 set sgrreset 0
62 }
63 if {$sgr ne {}} {
64 set str [expr {$re_mode ? "\033\\\[${sgr}m$str\033\\\[${sgrreset}m"\
65 : "\033\[${sgr}m$str\033\[${sgrreset}m"}]
66 }
67 return $str
68 }
69
70 # helper proc to generate color test and expected output
71 proc color_test_case {modarg colorize {sgr {}}} {
72 if {!$::is_stderr_tty && $colorize} {
73 incr colorize -1
74 }
75
76 if {$colorize} {
77 set prefix [colorstr $::error_msgs $sgr]
78 } else {
79 set prefix $::error_msgs
80 }
81
82 if {$modarg ne {}} {
83 append modarg { }
84 }
85
86 testouterr_cmd sh "${modarg}foo" ERR "$prefix: Invalid command 'foo'\n$::err_typehelp"
87 }
88
89 # helper proc to generate background color selection test and expected output
90 proc background_test_case {bg} {
91 if {$bg eq {dark} && [info exists ::darkbgcolors(er)] && $::darkbgcolors(er) ne {}} {
92 set sgr_for_bg $::darkbgcolors(er)
93 } elseif {$bg eq {light} && [info exists ::lightbgcolors(er)] && $::lightbgcolors(er) ne {}} {
94 set sgr_for_bg $::lightbgcolors(er)
95 }
96
97 if {[info exists sgr_for_bg]} {
98 color_test_case {--color} 2 $sgr_for_bg
99 } else {
100 color_test_case {--color} 0
101 }
102 }
103
104 # helper proc to test element color against default and specific color sets
105 proc colorset_test_case {cmd sgrstrlist experr {testifcolorset 0} {testspecifcolor 1}} {
106 # get default color set
107 if {$::install_termbg eq {dark}} {
108 array set defbgcolors [array get ::darkbgcolors]
109 } elseif {$::install_termbg eq {light}} {
110 array set defbgcolors [array get ::lightbgcolors]
111 } else {
112 array set defbgcolors {}
113 }
114 set alldefset 1
115 set sgrmap [list]
116 foreach {sgrkey strtocolor} $sgrstrlist {
117 set sgr [expr {[info exists defbgcolors($sgrkey)] ? $defbgcolors($sgrkey) : {}}]
118 if {$sgr eq {}} {
119 set alldefset 0
120 }
121 lappend sgrmap $strtocolor [colorstr $strtocolor $sgr 1]
122 }
123 if {$alldefset || !$testifcolorset} {
124 testerr_cmd_re sh $cmd [string map $sgrmap $experr]
125 }
126
127 if {$testspecifcolor} {
128 # test against specific color set
129 array set custcolors [array get ::customcolors]
130 foreach {key val} [array get custcolors] {
131 lappend custlist $key=$val
132 }
133 setenv_var MODULES_COLORS [join $custlist :]
134 set sgrmap [list]
135 foreach {sgrkey strtocolor} $sgrstrlist {
136 lappend sgrmap $strtocolor [colorstr $strtocolor $custcolors($sgrkey) 1]
137 }
138 testerr_cmd_re sh $cmd [string map $sgrmap $experr]
139 }
140
141 if {!$testifcolorset} {
142 # empty color definition in specific color set
143 foreach {sgrkey strtocolor} $sgrstrlist {
144 set custcolors($sgrkey) {}
145 }
146 set custlist [list]
147 foreach {key val} [array get custcolors] {
148 lappend custlist $key=$val
149 }
150 setenv_var MODULES_COLORS [join $custlist :]
151 testerr_cmd_re sh $cmd $experr
152
153 # element not referred in specific color set
154 foreach {sgrkey strtocolor} $sgrstrlist {
155 if {[info exists custcolors($sgrkey)]} {
156 unset custcolors($sgrkey)
157 }
158 }
159 set custlist [list]
160 foreach {key val} [array get custcolors] {
161 lappend custlist $key=$val
162 }
163 setenv_var MODULES_COLORS [join $custlist :]
164 testerr_cmd_re sh $cmd $experr
165 }
166
167 unsetenv_var MODULES_COLORS
168 }
169
170
171 #
172 # color enablement checks
173 #
174
175 # ensure a color is set to check enablement
176 set sgr 91
177 setenv_var MODULES_COLORS er=$sgr
178
179 # default configuration test
180 if {$install_color eq {y}} {
181 color_test_case {} 1 $sgr
182 } else {
183 color_test_case {} 0 $sgr
184 }
185
186 #
187 # ensure Modules-specific color config env var override and its internal
188 # representation conversion get exercised regardless of quick test mode
189 #
190 setenv_var MODULES_COLOR always
191 color_test_case {} 2 $sgr
192 unsetenv_var MODULES_COLOR
193
194 # an invalid Modules-specific color config env var override is ignored
195 setenv_var MODULES_COLOR foo
196 if {$install_color eq {y}} {
197 color_test_case {} 1 $sgr
198 } else {
199 color_test_case {} 0 $sgr
200 }
201 unsetenv_var MODULES_COLOR
202
203 skip_if_quick_mode
204
205 # environment variable or/and command-line switch override
206 setenv_var NO_COLOR 0
207 color_test_case {} 0 $sgr
208 setenv_var NO_COLOR 1
209 color_test_case {} 0 $sgr
210 setenv_var NO_COLOR {}
211 color_test_case {} 0 $sgr
212 setenv_var NO_COLOR foo
213 color_test_case {} 0 $sgr
214 unsetenv_var NO_COLOR
215
216 setenv_var CLICOLOR 0
217 color_test_case {} 0 $sgr
218 setenv_var CLICOLOR 1
219 color_test_case {} 1 $sgr
220 setenv_var CLICOLOR_FORCE 0
221 color_test_case {} 1 $sgr
222 setenv_var CLICOLOR_FORCE 1
223 color_test_case {} 1 $sgr
224 unsetenv_var CLICOLOR
225 setenv_var CLICOLOR_FORCE 1
226 color_test_case {} 2 $sgr
227 color_test_case {--color} 2 $sgr
228 color_test_case {--color=always} 2 $sgr
229 color_test_case {--color=auto} 1 $sgr
230 color_test_case {--color=never} 0 $sgr
231 color_test_case {--color=foo} 2 $sgr
232 unsetenv_var CLICOLOR_FORCE
233
234 # NO_COLOR prevails over CLICOLOR and CLICOLOR_FORCE
235 setenv_var NO_COLOR 1
236 setenv_var CLICOLOR 0
237 color_test_case {} 0 $sgr
238 setenv_var CLICOLOR 1
239 color_test_case {} 0 $sgr
240 setenv_var CLICOLOR_FORCE 0
241 color_test_case {} 0 $sgr
242 setenv_var CLICOLOR_FORCE 1
243 color_test_case {} 0 $sgr
244 unsetenv_var CLICOLOR
245 color_test_case {} 0 $sgr
246 unsetenv_var CLICOLOR_FORCE
247 unsetenv_var NO_COLOR
248
249 setenv_var MODULES_COLOR always
250 color_test_case {} 2 $sgr
251 color_test_case {--color} 2 $sgr
252 color_test_case {--color=always} 2 $sgr
253 color_test_case {--color=auto} 1 $sgr
254 color_test_case {--color=never} 0 $sgr
255 color_test_case {--color=foo} 2 $sgr
256
257 setenv_var CLICOLOR 0
258 color_test_case {} 2 $sgr
259 unsetenv_var CLICOLOR
260
261 setenv_var NO_COLOR 1
262 color_test_case {} 2 $sgr
263 unsetenv_var NO_COLOR
264
265 setenv_var MODULES_COLOR auto
266 color_test_case {} 1 $sgr
267 color_test_case {--color} 2 $sgr
268 color_test_case {--color=always} 2 $sgr
269 color_test_case {--color=auto} 1 $sgr
270 color_test_case {--color=never} 0 $sgr
271 color_test_case {--color=foo} 1 $sgr
272
273 setenv_var MODULES_COLOR never
274 color_test_case {} 0 $sgr
275 color_test_case {--color} 2 $sgr
276 color_test_case {--color=always} 2 $sgr
277 color_test_case {--color=auto} 1 $sgr
278 color_test_case {--color=never} 0 $sgr
279 color_test_case {--color=foo} 0 $sgr
280
281 setenv_var CLICOLOR 1
282 color_test_case {} 0 $sgr
283 unsetenv_var CLICOLOR
284
285 setenv_var NO_COLOR 1
286 color_test_case {} 0 $sgr
287 unsetenv_var NO_COLOR
288
289 setenv_var CLICOLOR_FORCE 1
290 color_test_case {} 0 $sgr
291 unsetenv_var CLICOLOR_FORCE
292
293 # no color set, disabled
294 setenv_var MODULES_COLORS {}
295 setenv_var MODULES_COLOR always
296 color_test_case {} 0 $sgr
297 color_test_case {--color} 0 $sgr
298 color_test_case {--color=always} 0 $sgr
299 color_test_case {--color=auto} 0 $sgr
300 color_test_case {--color=never} 0 $sgr
301
302 # color key empty, disabled
303 setenv_var MODULES_COLORS {er=}
304 color_test_case {} 0 $sgr
305 color_test_case {--color} 0 $sgr
306 color_test_case {--color=always} 0 $sgr
307 color_test_case {--color=auto} 0 $sgr
308 color_test_case {--color=never} 0 $sgr
309
310
311 #
312 # defined color set applied
313 #
314
315 # specific bold and faint reset
316 setenv_var MODULES_COLORS er=1
317 color_test_case {--color} 2 1
318 setenv_var MODULES_COLORS er=2
319 color_test_case {--color} 2 2
320
321 # background color dependent selection
322 unsetenv_var MODULES_COLOR
323 unsetenv_var MODULES_COLORS
324 background_test_case $install_termbg
325 setenv_var MODULES_TERM_BACKGROUND dark
326 background_test_case dark
327 setenv_var MODULES_TERM_BACKGROUND foo
328 background_test_case $install_termbg
329 setenv_var MODULES_TERM_BACKGROUND {}
330 background_test_case $install_termbg
331 setenv_var MODULES_TERM_BACKGROUND light
332 background_test_case light
333 # user-specific color set will override all background color selection
334 setenv_var MODULES_COLORS er=1
335 setenv_var MODULES_TERM_BACKGROUND dark
336 color_test_case {--color} 2 1
337 setenv_var MODULES_TERM_BACKGROUND foo
338 color_test_case {--color} 2 1
339 setenv_var MODULES_TERM_BACKGROUND {}
340 color_test_case {--color} 2 1
341 setenv_var MODULES_TERM_BACKGROUND light
342 color_test_case {--color} 2 1
343
344 # badly defined MODULES_COLORS is ignored
345 setenv_var MODULES_COLORS er=1:wa
346 setenv_var MODULES_TERM_BACKGROUND dark
347 background_test_case dark
348 setenv_var MODULES_TERM_BACKGROUND light
349 background_test_case light
350
351 unsetenv_var MODULES_TERM_BACKGROUND
352
353 # also if it happen during first execution steps
354 if {[siteconfig_isStderrTty]} {
355 setenv_var TESTSUITE_ENABLE_SITECONFIG_BROKEN 1
356 set tserr [escre "$error_msgs: Site configuration source failed
357 invalid command name \"unk_foo\"
358 while executing
359 \"unk_foo<EXM>\"
360 (file \"$siteconfig_file\" line 2)<EXM>"]
361 colorset_test_case {--color -V} [list er $error_msgs] $tserr
362 unsetenv_var TESTSUITE_ENABLE_SITECONFIG_BROKEN
363 }
364
365 # test of the various element on all commands that can produce a colored output
366 unsetenv_var MODULES_COLOR
367 unsetenv_var MODULES_COLORS
368
369 # warning (wa)
370 colorset_test_case {--color --create -V} [list wa WARNING] {WARNING: Unsupported option '--create'.*}
371 # ensure command-line switch position has no impact
372 colorset_test_case {--create -V --color} [list wa WARNING] {WARNING: Unsupported option '--create'.*}
373
374 # debug information (db)
375 setenv_var MODULES_COLOR always
376 colorset_test_case {-D -V} [list db "DEBUG setState: cmdline set to '$MODULECMD sh -D -V'"] "DEBUG setState: cmdline set to '$MODULECMD sh -D -V'.*"
377
378 # trace information (tr)
379 colorset_test_case {load -T unk} [list tr "Get modules" tr "{} matching 'unk' in '$modpathre'"] ".*Get modules: {} matching 'unk' in '$modpathre'.*"
380
381 # error (er)
382 colorset_test_case {--foo foo} [list er $error_msgs] "$error_msgs: Invalid option '--foo'\n$err_typehelp"
383 if {[info exists x11_warn]} {
384 colorset_test_case {load x-resource/1} [list er $error_msgs] .*[string map [list "\n" "\n\\s+"] $x11_warn]
385 }
386
387 # module error (me)
388 colorset_test_case {load bad2/body} [list me $moderr_msgs] ".*$moderr_msgs: invalid command.*"
389
390 # info (in)
391 colorset_test_case {load --auto prereq/module} [list in {Loading requirement}] ".*Loading requirement: trace/all_on"
392
393 # highlighted element (hi)
394 colorset_test_case {saveshow testsuite/home/.module/infocmd} [list hi testsuite/home/.module/infocmd] ".*testsuite/home/.module/infocmd:.*"
395 colorset_test_case {display setenv/1.0} [list hi $modpathre/setenv/1.0] ".*$modpathre/setenv/1.0:.*"
396 colorset_test_case {help setenv/1.0} [list hi $modpathre/setenv/1.0] ".*$modpathre/setenv/1.0:.*"
397 colorset_test_case {test setenv/1.0} [list hi $modpathre/setenv/1.0] ".*$modpathre/setenv/1.0:.*"
398 colorset_test_case {avail -l loc_tr} [list hi Package/Alias hi Versions hi {Last mod.}] ".*- Package/Alias -.*- Versions -.*- Last mod. -.*"
399 setenv_var HOME $env(TESTSUITEDIR)/home
400 colorset_test_case {savelist -l} [list hi Collection hi {Last mod.}] "- Collection -.*- Last mod. -.*"
401 setenv_var HOME $env(TESTSUITEDIR)
402 # matched strings
403 colorset_test_case {avail loc_t} [list hi loc_t] ".*loc_tr.*loc_tr.*loc_tr.*loc_tr.*loc_tr.*loc_tr.*loc_tr.*loc_tr.*"
404 colorset_test_case {avail -l loc_t} [list hi loc_t] ".*loc_tr.*loc_tr.*loc_tr.*loc_tr.*loc_tr.*loc_tr.*loc_tr.*loc_tr.*"
405 colorset_test_case {avail -t loc_t} [list hi loc_t] ".*loc_tr.*loc_tr.*loc_tr.*loc_tr.*loc_tr.*loc_tr.*loc_tr.*loc_tr.*"
406 colorset_test_case {avail loc_tr} [list hi loc_tr] ".*loc_tr.*loc_tr.*loc_tr.*loc_tr.*loc_tr.*loc_tr.*loc_tr.*loc_tr.*"
407 colorset_test_case {avail loc_tr/3 loc_tr/1} [list hi loc_tr/1 hi loc_tr/3] ".*loc_tr/1.0.*loc_tr/3.0.*"
408 colorset_test_case {spider loc_tr/3.0 loc_tr/1} [list hi loc_tr/1 hi loc_tr/3.0] ".*loc_tr/1.0.*loc_tr/3.0.*"
409 colorset_test_case {whatis loc_tr} [list hi loc_tr] ".*\\s+loc_tr/1.0: .*\\s+loc_tr/2.0: .*\\s+loc_tr/3.0: .*"
410 colorset_test_case {whatis loc_tr/2.0 loc_tr/1.0} [list hi loc_tr/1.0 hi loc_tr/2.0] ".*\\s+loc_tr/1.0: .*\\s+loc_tr/2.0: .*"
411 colorset_test_case {search loc_tr} [list hi loc_tr] ".*: loc_tr/1.0\n.*: loc_tr/2.0\n.*: loc_tr/3.0"
412 # matched strings expressed with the advanced version specifiers
413 setenv_var MODULES_ADVANCED_VERSION_SPEC 1
414 colorset_test_case {avail loc_tr@1} [list hi loc_tr/1] ".*loc_tr/1.0.*"
415 colorset_test_case {avail loc_tr@1,2} [list hi loc_tr/1 hi loc_tr/2] ".*loc_tr/1.0.*loc_tr/2.0.*"
416 colorset_test_case {avail loc_tr@1:3} [list hi loc_tr/1 hi loc_tr/3] ".*loc_tr/1.0.*loc_tr/3.0.*"
417 colorset_test_case {avail [email protected]:} [list hi loc_tr/1.0] ".*loc_tr/1.0.*"
418 colorset_test_case {avail loc_tr@:2.0} [list hi loc_tr/2.0] ".*loc_tr/2.0.*"
419 colorset_test_case {whatis [email protected]} [list hi loc_tr/1.0] ".*\\s+loc_tr/1.0:.*"
420 colorset_test_case {whatis loc_tr@:2} [list hi loc_tr/2] ".*\\s+loc_tr/1.0: .*\\s+loc_tr/2.0: .*"
421 colorset_test_case {whatis loc_tr@1:3.0} [list hi loc_tr/1 hi loc_tr/3.0] ".*\\s+loc_tr/1.0: .*\\s+loc_tr/3.0: .*"
422 unsetenv_var MODULES_ADVANCED_VERSION_SPEC
423
424 # modulepath (mp)
425 colorset_test_case {use} [list mp $modpathre] "Search path for module files \\(in search order\\):\n $modpathre"
426 colorset_test_case {avail loc_tr} [list mp $modpathre] ".*- $modpathre -.*"
427 colorset_test_case {avail -t --no-indepth loc_tr} [list mp $modpathre] ".*$modpathre:.*"
428 colorset_test_case {avail -l --no-indepth loc_tr} [list mp $modpathre] ".*$modpathre:.*"
429
430 # modulepath (mp) and via
431 setenv_var __MODULES_LMUSE loc_tr/1.0&$modpath
432 setenv_loaded_module [list loc_tr/1.0] [list $modpath/loc_tr/1.0]
433 colorset_test_case {avail -o +via loc_tr} [list mp $modpathre] ".*- $modpathre \\(via loc_tr/1.0\\) -.*"
434 unsetenv_var __MODULES_LMUSE
435 unsetenv_loaded_module
436
437 # tag separator (se) / module symbolic version (sy)
438 colorset_test_case {avail loc_tr} [list se \\( se \\) se : sy reg sy cur sy stable] ".*loc_tr.*/\\(reg\\).*loc_tr.*/1.0\\(cur:stable\\).*"
439 colorset_test_case {avail -t loc_tr} [list se \\( se \\) se : sy reg sy cur sy stable] ".*loc_tr.*/\\(reg\\).*loc_tr.*/1.0\\(cur:stable\\).*"
440 colorset_test_case {avail -l loc_tr} [list se : sy reg sy cur sy stable] ".*loc_tr.*/\\s+reg.*loc_tr.*/1.0\\s+cur:stable.*"
441
442 # directory (di)
443 colorset_test_case {avail --no-indepth} [list di loc_tr] ".*loc_tr/.*"
444 colorset_test_case {avail -t} [list di loc_tr] ".*loc_tr/.*"
445 colorset_test_case {avail -l} [list di loc_tr] ".*loc_tr/.*"
446
447 # module alias (al) / module default version (de)
448 colorset_test_case {avail} [list al loc_rc6/bar de loc_rc6/1.2] ".*loc_rc6/1.2.*loc_rc6/bar.*"
449 colorset_test_case {avail -l} [list al loc_rc6/bar de loc_rc6/1.2] ".*loc_rc6/1.2.*loc_rc6/bar.*"
450 colorset_test_case {avail -t} [list al loc_rc6/bar de loc_rc6/1.2] ".*loc_rc6/1.2.*loc_rc6/bar.*"
451 # check @ and default symbols disappear when color is there
452 if {($::install_termbg eq {dark} && (![info exists darkbgcolors(de)] || $darkbgcolors(de) eq {}))\
453 || ($::install_termbg eq {light} && (![info exists lightbgcolors(de)] || $lightbgcolors(de) eq {}))} {
454 colorset_test_case {avail loc_rc6} [list hi loc_rc6 se \\( se \\) se : sy new sy default] ".*loc_rc6/1.2.*\\(default:new\\).*loc_rc6/bar.* .*" 1 0
455 colorset_test_case {avail -C _rc6} [list hi _rc6 se \\( se \\) se : sy new sy default] ".*loc_rc6/1.2.*\\(default:new\\).*loc_rc6/bar.* .*" 1 0
456 } else {
457 colorset_test_case {avail loc_rc6} [list hi loc_rc6 se \\( se \\) sy new] ".*loc_rc6/1.2.*\\(new\\).*loc_rc6/bar.* .*" 1
458 colorset_test_case {avail -C _rc6} [list hi _rc6 se \\( se \\) sy new] ".*loc_rc6/1.2.*\\(new\\).*loc_rc6/bar.* .*" 1
459 }
460
461 # highlighted element (hi) /module alias (al) / module symbolic version (sy)
462 colorset_test_case {aliases} [list hi Aliases hi Versions al loc_rc6/bar sy loc_rc6/default sy loc_rc6/new] ".*- Aliases -.*\nloc_rc6/bar -> .*- Versions -.*\nloc_rc6/default -> .*\nloc_rc6/new -> .*"
463
464 # tag separator (se) / module symbolic version (sy) / module default version (de)
465 setenv_loaded_module [list loc_tr/1.0 loc_rc6/1.2] [list $modpath/loc_tr/1.0 $modpath/loc_rc6/1.2]
466 setenv_var __MODULES_LMALTNAME loc_tr/1.0&loc_tr/cur&loc_tr/stable:loc_rc6/1.2&loc_rc6/default&loc_rc6&loc_rc6/new&al|loc_rc6/1&al|loc_rc6/bar
467 colorset_test_case {list} [list se : se \\( se \\) sy new sy cur sy stable de loc_rc6/1.2] ".*loc_tr/1.0\\(cur:stable\\).*loc_rc6/1.2\\(new\\).*" 1
468 colorset_test_case {list -l} [list se : sy new sy cur sy stable de loc_rc6/1.2] ".*loc_tr/1.0\\s+cur:stable\\s+.*loc_rc6/1.2\\s+new\\s+.*" 1
469 colorset_test_case {list -l} [list hi Package hi Versions hi {Last mod.}] ".*- Package -.*- Versions -.*- Last mod. -.*"
470 colorset_test_case {list -t} [list] ".*loc_tr/1.0\nloc_rc6/1.2" 0
471
472 # highlighted element (hi) on list
473 setenv_var __MODULES_LMALTNAME loc_tr/1.0&loc_tr/cur:loc_rc6/1.2&al|loc_rc6/1&al|loc_rc6/bar
474 colorset_test_case {list loc} [list hi loc se : se \\( se \\) sy new sy cur sy stable] ".*loc_tr/1.0\\(cur\\).*loc_rc6/1.2.*" 1
475 colorset_test_case {list -C tr} [list hi tr se : se \\( se \\) sy new sy cur sy stable] ".*loc_tr/1.0\\(cur\\).*" 1
476 colorset_test_case {list loc loc_rc} [list hi loc se : se \\( se \\) sy new sy cur sy stable] ".*loc_tr/1.0\\(cur\\).*loc_rc6/1.2.*" 1
477 colorset_test_case {list -C rc tr} [list hi rc hi tr se : se \\( se \\) sy new sy cur sy stable] ".*loc_tr/1.0\\(cur\\).*loc_rc6/1.2.*" 1
478
479 unsetenv_loaded_module
480 unsetenv_var __MODULES_LMALTNAME
481
482 # highlighted element (hi) on savelist
483 setenv_var HOME $env(HOME)/home
484 set tserr ".* 1\\) infocmd 2\\) infocmdexp"
485 colorset_test_case {savelist info} [list hi info] $tserr 1
486 set tserr ".*
487 1\\) coll1 3\\) coll3 5\\) coll6.target 7\\) infocmdexp
488 2\\) coll2 4\\) coll4.target 6\\) infocmd "
489 colorset_test_case {savelist -w 80 coll info} [list hi coll hi info] $tserr 1
490 setenv_var HOME $ORIG_HOME
491
492 # modulefile or collection command report (cm)
493 colorset_test_case {saveshow testsuite/home/.module/infocmd} [list cm module] ".*module use --append .*\nmodule load info/command.*"
494 colorset_test_case {display setenv/1.0} [list cm setenv] ".*setenv\t\ttestsuite yes.*"
495
496 # test cumulated sgr codes
497 setenv_var MODULES_COLORS {hi=1:db=2:tr=2:se=2:er=91:wa=93:me=95:in=94:mp=1;94:di=94:al=96:de=4}
498 testerr_cmd_re sh {avail -t loc_dv7/2} ".*\033\\\[4;94m\033\\\[1mloc_dv7/2\033\\\[22m.0\033\\\[0m/\n\033\\\[1mloc_dv7/2\033\\\[22m.0/1.0"
499 testerr_cmd_re sh {avail -t loc_tr/a} ".*\033\\\[4;96m\033\\\[1mloc_tr/a\033\\\[22ml2\033\\\[0m.*"
500 unsetenv_var MODULES_COLORS
501
502
503 #
504 # block output rendering
505 #
506
507 set test_cols 61
508 if {![info exists term_cols]} {
509 # skip tests if current terminal width is unknown
510 send_user "\tskipping terminal width-specific tests\n"
511 # set a specific terminal width
512 } elseif {[catch {exec stty cols $test_cols}] || [getTtyCols] ne $test_cols} {
513 send_user "\tskipping terminal width-specific tests, cannot set width\n"
514 } else {
515
516 setenv_var MODULES_COLORS er=31
517 set tserr "[colorstr $error_msgs 31]: Module cannot be loaded due to missing prereq.
518 HINT: the following module must be loaded first:
519 trace/all_on"
520 testerr_cmd sh {load --color --no-auto prereq/full} [msg_load prereq/full $tserr]
521 unsetenv_var MODULES_COLORS
522
523 # restore terminal width
524 exec stty cols $term_cols
525 }
526
527 # test twice calls to getConf term_background and getConf colors procedures
528 if {[siteconfig_isStderrTty]} {
529 setenv_var TESTSUITE_ENABLE_SITECONFIG_TWICEINITCOLORS 1
530 colorset_test_case {--foo foo} [list er $error_msgs] "$error_msgs: Invalid option '--foo'\n$err_typehelp"
531 unsetenv_var TESTSUITE_ENABLE_SITECONFIG_TWICEINITCOLORS
532 }
533
534
535 #
536 # indesym rendering tests
537 #
538
539 setenv_path_var MODULEPATH $modpath.2
540 setenv_var MODULES_ADVANCED_VERSION_SPEC 0
541 setenv_var MODULES_COLORS {hi=1:db=2:tr=2:se=2:er=91:wa=93:me=95:in=94:mp=1;94:di=94:al=96:de=4:sy=95}
542 set tserr "[sgr 95][sgr 1]hide3/sym[sgr 22][sgr 0]
543
544 Key:
545 [sgr 95]symbolic-version[sgr 0]"
546 testouterr_cmd_re sh {avail --color=always -o key:indesym hide3/sym} OK $tserr
547 set tserr "[sgr 1]hide3/sub2[sgr 22]/4.0
548 [sgr 1]hide3/sub2[sgr 22]/5.0
549 [sgr 95][sgr 1]hide3/sub2[sgr 22]/default[sgr 0]
550 [sgr 95][sgr 1]hide3/sub2[sgr 22]/new[sgr 0]
551 [sgr 95][sgr 1]hide3/sub2[sgr 22]/sym[sgr 0]
552
553 Key:
554 [sgr 95]symbolic-version[sgr 0]"
555 testouterr_cmd_re sh {avail -w 20 --color=always -o key:indesym hide3/sub2} OK $tserr
556 testouterr_cmd_re sh {avail -w 20 --color=always -o key:indesym:dirwsym hide3/sub2} OK $tserr
557 set tserr "[sgr 95][sgr 1]hide3/sub2/default[sgr 22][sgr 0]
558
559 Key:
560 [sgr 95]symbolic-version[sgr 0]"
561 testouterr_cmd_re sh {avail --color=always -o key:indesym hide3/sub2/default} OK $tserr
562 # no color definition for symbolic versions
563 setenv_var MODULES_COLORS {hi=1:db=2:tr=2:se=2:er=91:wa=93:me=95:in=94:mp=1;94:di=94:al=96:de=4}
564 set tserr "[sgr 1]hide3/sym[sgr 22]"
565 testouterr_cmd_re sh {avail --color=always -o key:indesym hide3/sym} OK $tserr
566 unsetenv_var MODULES_COLORS
567 unsetenv_var MODULES_ADVANCED_VERSION_SPEC
568 setenv_path_var MODULEPATH $modpath
569
570
571 #
572 # alias/indesym rendering tests on list
573 #
574
575 setenv_var MODULES_COLORS {hi=1:db=2:tr=2:se=2:er=91:wa=93:me=95:in=94:mp=1;94:di=94:al=96:de=4:sy=95}
576 setenv_loaded_module [list foo/1.0] [list $modpath.3/foo/1.0]
577 setenv_var __MODULES_LMALTNAME foo/1.0&foo/bar&foo&al|alfoo
578
579 #FIXME
580 set tserr " 1\\) [sgr 96]alfoo[sgr 0] 2\\) foo/1.0[sgr 2]\\([sgr 22][sgr 95]bar[sgr 0][sgr 2]\\)[sgr 22]
581
582 Key:
583 [sgr 2]\\([sgr 22][sgr 95]symbolic-version[sgr 0][sgr 2]\\)[sgr 22] [sgr 96]module-alias[sgr 0]"
584 testouterr_cmd_re sh {list --color=always -o alias:idx:sym:key} OK $tserr
585 set tserr " 1\\) [sgr 95]foo/bar[sgr 0]
586 2\\) [sgr 96]alfoo[sgr 0]
587 3\\) foo/1.0
588
589 Key:
590 [sgr 95]symbolic-version[sgr 0] [sgr 96]module-alias[sgr 0]"
591 testouterr_cmd_re sh {list --color=always -t -o alias:idx:indesym:sym:key} OK $tserr
592
593 unsetenv_var __MODULES_LMALTNAME
594 unsetenv_loaded_module
595 unsetenv_var MODULES_COLORS
596
597
598 #
599 # Clean up variables used in this test case
600 #
601
602 reset_test_env
603
604 # remove procs
605 rename colorstr {}
606 rename color_test_case {}
607 rename background_test_case {}
608 rename colorset_test_case {}
609
610 }