Debian Codegraph @

testsuite/config/unix.exp

raw
1 ##############################################################################
2 # Modules Revision 3.0
3 # Providing a flexible user environment
4 #
5 # File: config/%M%
6 # Revision: %I%
7 # First Edition: 1995/12/06
8 # Last Mod.: %U%, %G%
9 #
10 # Authors: Jens Hamisch, [email protected]
11 #
12 # Description: Testuite initialization
13 # Command:
14 # Sub-Command:
15 #
16 # Comment: %C{
17 # Initialization of the testsuite. Definition of
18 # globally used start procedures for the test
19 # target.
20 # }C%
21 #
22 ##############################################################################
23
24 #
25 # modulecmd_xxx_ -- run modulecmd
26 #
27
28 # alternative method to collect stdout and stderr from command execution (on
29 # Tcl>=8.6): use channel pipe instead of saving these outputs in file
30 if {[lindex [lsort -dictionary [list 8.6 [info tclversion]]] 1] eq [info tclversion]} {
31
32 proc readpipe {p1 p2 varname {exit_varname {}}} {
33 append ::$varname [read $p1]
34 if {[eof $p1]} {
35 fconfigure $p1 -blocking 1
36 try {
37 close $p1
38 } on ok {output} {
39 if {[string length $exit_varname]} {
40 set ::$exit_varname 0
41 }
42 } trap {CHILDSTATUS} {output options} {
43 if {[string length $exit_varname]} {
44 set ::$exit_varname [lindex [dict get $options -errorcode] end]
45 }
46 }
47 if {$p2 ni [chan names]} {
48 set ::endpipe ok
49 }
50 }
51 }
52
53 proc modulecmd_xxx_ {command {input noinput}} {
54 global MODULECMD
55 global TCLSH
56 global verbose
57 global shell
58 global comp_output
59 global comp_error
60 global comp_exit
61 global errorCode
62
63 if {[info exists ::endpipe]} {
64 unset ::endpipe
65 }
66
67 if ![info exists command] then {
68 unresolved "internal testsuite error: no module command specified"
69 }
70
71 set cmdlist [list $TCLSH $MODULECMD $shell]
72 # check if asked not to split passed command line
73 if {[string first "NOCMDSPLIT" $command] == 0} {
74 lappend cmdlist [string range $command 10 end]
75 } else {
76 # preserve argument including space character
77 foreach cmdelt [split [string map {{\ } {<SPACE>}} $command] { }] {
78 lappend cmdlist [string map {<SPACE> { }} $cmdelt]
79 }
80 }
81 if {$input ne {noinput}} {
82 lappend cmdlist << $input
83 }
84
85 if { $verbose > 1 } {
86 send_user "starting [lrange $cmdlist 1 end]\n"
87 }
88
89 # create pipes
90 lassign [chan pipe] rdstderr wrstderr
91
92 # run command in separate thread
93 lappend cmdlist 2>@ $wrstderr
94 set rdstdout [open "|$cmdlist"]
95
96 # fetch output asynchronously
97 fileevent $rdstdout readable [list readpipe $rdstdout $rdstderr comp_output comp_exit]
98 fconfigure $rdstdout -blocking 0
99 fileevent $rdstderr readable [list readpipe $rdstderr $rdstdout comp_error]
100 fconfigure $rdstderr -blocking 0
101
102 close $wrstderr
103
104 vwait endpipe
105 }
106
107 } else {
108
109 proc modulecmd_xxx_ {command {input noinput}} {
110 global MODULECMD
111 global TCLSH
112 global verbose
113 global shell
114 global comp_output
115 global comp_error
116 global comp_exit
117 global errorCode
118
119 if ![info exists command] then {
120 unresolved "internal testsuite error: no module command specified"
121 }
122
123 set cmdlist [list exec $TCLSH $MODULECMD $shell]
124 # check if asked not to split passed command line
125 if {[string first "NOCMDSPLIT" $command] == 0} {
126 lappend cmdlist [string range $command 10 end]
127 } else {
128 # preserve argument including space character
129 foreach cmdelt [split [string map {{\ } {<SPACE>}} $command] { }] {
130 lappend cmdlist [string map {<SPACE> { }} $cmdelt]
131 }
132 }
133 lappend cmdlist 2> test321.err > test321.out
134 if {$input ne {noinput}} {
135 lappend cmdlist << $input
136 }
137
138 if { $verbose > 1 } {
139 send_user "starting [lrange $cmdlist 1 end]\n"
140 }
141
142 if [catch {
143 set comp_output [{*}$cmdlist]
144 } ] {
145 set comp_exit [lindex $errorCode 2]
146 } else {
147 set comp_exit 0
148 }
149
150 catch {
151 set errfile [ open test321.err ]
152 read $errfile
153 } comp_error
154 catch { close $errfile }
155 catch { file delete test321.err }
156
157 catch {
158 set outfile [ open test321.out ]
159 read $outfile
160 } comp_output
161 catch { close $outfile }
162 catch { file delete test321.out }
163 }
164
165 }
166
167
168 #
169 # Test procedure to check a module installation
170 #
171
172 # alternative method to collect stdout and stderr from command execution (on
173 # Tcl>=8.6): use channel pipe instead of saving these outputs in file
174 if {[lindex [lsort -dictionary [list 8.6 [info tclversion]]] 1] eq [info tclversion]} {
175
176 proc install_test_xxx_ {command} {
177 global verbose
178 global autoinit_script
179 global shell
180 global autoinit_mode
181 global shell_list
182 global shell_test
183 global shell_path
184 global shell_opts
185 global shell_init
186 global shell_level
187 global subshell
188
189 global comp_output
190 global comp_error
191 global comp_exit
192 global errorCode
193
194 if {[info exists ::endpipe]} {
195 unset ::endpipe
196 }
197
198 if {![info exists command]} {
199 unresolved "internal testsuite error: no command specified"
200 }
201 if {![info exists shell_path($shell)]} {
202 unresolved "internal testsuite error: no shell path found for '$shell' shell"
203 }
204 if {![info exists shell_test($shell)]} {
205 unresolved "internal testsuite error: no install test script set for '$shell' shell"
206 }
207 if {![info exists shell_init($shell)]} {
208 unresolved "internal testsuite error: no init script set for '$shell' shell"
209 }
210 if {![info exists autoinit_script]} {
211 unresolved "internal testsuite error: no autoinit script set"
212 }
213 if {![info exists shell_level]} {
214 set level "top"
215 } else {
216 set level $shell_level
217 }
218 if {![info exists subshell]} {
219 set sub "$shell"
220 } else {
221 set sub $subshell
222 }
223
224 set cmd_to_exec [list $shell_path($shell)]
225 if {[info exists shell_opts($shell)]} {
226 lappend cmd_to_exec $shell_opts($shell)
227 }
228
229 if {$shell eq "cmake"} {
230 lappend cmd_to_exec "-Dinitfile='$shell_init($shell)'"
231 lappend cmd_to_exec "-Dcmdlist='$command'"
232 lappend cmd_to_exec "-P"
233 lappend cmd_to_exec $shell_test($shell)
234 if {$verbose} {
235 send_user " ... Testing '$cmd_to_exec'\n"
236 }
237 } else {
238 lappend cmd_to_exec $shell_test($shell)
239 if {$autoinit_mode} {
240 set autoinit_verb "autoinit "
241 lappend cmd_to_exec $autoinit_script
242 } else {
243 set autoinit_verb ""
244 lappend cmd_to_exec $shell_init($shell)
245 }
246
247 if {[lsearch -exact $shell_list $shell] != -1} {
248 lappend cmd_to_exec $level $shell_path($sub) $command
249 if {$verbose} {
250 send_user " ... Testing '$shell [file tail $shell_test($shell)]\
251 $autoinit_verb$level $sub $command'\n"
252 }
253 } else {
254 lappend cmd_to_exec $command
255 if {$verbose} {
256 send_user " ... Testing '$shell [file tail $shell_test($shell)]\
257 $autoinit_verb$command'\n"
258 }
259 }
260 }
261 if { $verbose > 1 } {
262 send_user "starting $cmd_to_exec\n"
263 }
264
265 # create pipes
266 lassign [chan pipe] rdstderr wrstderr
267
268 # run command in separate thread
269 lappend cmd_to_exec 2>@ $wrstderr
270 set rdstdout [open "|$cmd_to_exec"]
271
272 # fetch output asynchronously
273 fileevent $rdstdout readable [list readpipe $rdstdout $rdstderr comp_output comp_exit]
274 fconfigure $rdstdout -blocking 0
275 fileevent $rdstderr readable [list readpipe $rdstderr $rdstdout comp_error]
276 fconfigure $rdstderr -blocking 0
277
278 close $wrstderr
279
280 vwait endpipe
281
282 if {$shell eq {ruby}} {
283 set comp_error [regsub -all -line {^.* warning: Insecure world writable dir .*(\n|$)} $comp_error {}]
284 set comp_error [regsub -all -line {^`RubyGems' were not loaded\.(\n|$)} $comp_error {}]
285 }
286 }
287
288 } else {
289
290 proc install_test_xxx_ {command} {
291 global verbose
292 global autoinit_script
293 global shell
294 global autoinit_mode
295 global shell_list
296 global shell_test
297 global shell_path
298 global shell_opts
299 global shell_init
300 global shell_level
301 global subshell
302
303 global comp_output
304 global comp_error
305 global comp_exit
306 global errorCode
307
308 if {![info exists command]} {
309 unresolved "internal testsuite error: no command specified"
310 }
311 if {![info exists shell_path($shell)]} {
312 unresolved "internal testsuite error: no shell path found for '$shell' shell"
313 }
314 if {![info exists shell_test($shell)]} {
315 unresolved "internal testsuite error: no install test script set for '$shell' shell"
316 }
317 if {![info exists shell_init($shell)]} {
318 unresolved "internal testsuite error: no init script set for '$shell' shell"
319 }
320 if {![info exists autoinit_script]} {
321 unresolved "internal testsuite error: no autoinit script set"
322 }
323 if {![info exists shell_level]} {
324 set level "top"
325 } else {
326 set level $shell_level
327 }
328 if {![info exists subshell]} {
329 set sub "$shell"
330 } else {
331 set sub $subshell
332 }
333
334 set cmd_to_exec [list $shell_path($shell)]
335 if {[info exists shell_opts($shell)]} {
336 lappend cmd_to_exec $shell_opts($shell)
337 }
338
339 if {$shell eq "cmake"} {
340 lappend cmd_to_exec "-Dinitfile='$shell_init($shell)'"
341 lappend cmd_to_exec "-Dcmdlist='$command'"
342 lappend cmd_to_exec "-P"
343 lappend cmd_to_exec $shell_test($shell)
344 if {$verbose} {
345 send_user " ... Testing '$cmd_to_exec'\n"
346 }
347 } else {
348 lappend cmd_to_exec $shell_test($shell)
349 if {$autoinit_mode} {
350 set autoinit_verb "autoinit "
351 lappend cmd_to_exec $autoinit_script
352 } else {
353 set autoinit_verb ""
354 lappend cmd_to_exec $shell_init($shell)
355 }
356
357 if {[lsearch -exact $shell_list $shell] != -1} {
358 lappend cmd_to_exec $level $shell_path($sub) $command
359 if {$verbose} {
360 send_user " ... Testing '$shell [file tail $shell_test($shell)]\
361 $autoinit_verb$level $sub $command'\n"
362 }
363 } else {
364 lappend cmd_to_exec $command
365 if {$verbose} {
366 send_user " ... Testing '$shell [file tail $shell_test($shell)]\
367 $autoinit_verb$command'\n"
368 }
369 }
370 }
371 if { $verbose > 1 } {
372 send_user "starting $cmd_to_exec\n"
373 }
374
375 # now need to capture the exit return code.
376 if [catch {
377 set comp_output [exec {*}$cmd_to_exec 2> test321.err > test321.out ]
378 } ] {
379 set comp_exit [lindex $errorCode 2]
380 } else {
381 set comp_exit 0
382 }
383
384 catch {
385 set errfile [ open test321.err ]
386 read $errfile
387 } comp_error
388 catch { close $errfile }
389 catch { file delete test321.err }
390
391 if {$shell eq {ruby}} {
392 set comp_error [regsub -all -line {^.* warning: Insecure world writable dir .*(\n|$)} $comp_error {}]
393 }
394
395 catch {
396 set outfile [ open test321.out ]
397 read $outfile
398 } comp_output
399 catch { close $outfile }
400 catch { file delete test321.out }
401 }
402
403 }
404
405 #
406 # Test procedure to lint script files
407 #
408
409 # alternative method to collect stdout and stderr from command execution (on
410 # Tcl>=8.6): use channel pipe instead of saving these outputs in file
411 if {[lindex [lsort -dictionary [list 8.6 [info tclversion]]] 1] eq [info tclversion]} {
412
413 proc lint_test_xxx_ {filepath} {
414 if {[info exists ::endpipe]} {
415 unset ::endpipe
416 }
417
418 # global variable ::shell corresponds to linter command to use
419 if {[auto_execok $::shell] eq {}} {
420 untested "linter command '$::shell' not found"
421 return
422 }
423
424 # prepare command to execute
425 set cmd_to_exec [list $::shell]
426 if {[info exists ::linter_opts]} {
427 lappend cmd_to_exec {*}$::linter_opts
428 }
429 lappend cmd_to_exec $filepath
430
431 if {$::verbose} {
432 send_user " ... Testing '$::shell $filepath\n"
433 }
434 if {$::verbose > 1} {
435 send_user "starting $cmd_to_exec\n"
436 }
437
438 # create pipes
439 lassign [chan pipe] rdstdout wrstdout
440 lassign [chan pipe] rdstderr wrstderr
441
442 # fetch output asynchronously
443 fileevent $rdstdout readable [list readpipe $rdstdout $rdstderr comp_output]
444 fconfigure $rdstdout -blocking 0
445 fileevent $rdstderr readable [list readpipe $rdstderr $rdstdout comp_error]
446 fconfigure $rdstderr -blocking 0
447
448 # run command in separate thread
449 lappend cmd_to_exec >@ $wrstdout 2>@ $wrstderr
450 if [catch {
451 exec {*}$cmd_to_exec
452 } ] {
453 set ::comp_exit [lindex $::errorCode 2]
454 } else {
455 set ::comp_exit 0
456 }
457 close $wrstdout
458 close $wrstderr
459
460 vwait endpipe
461 }
462
463 } else {
464
465 # expect 'lint' testsuite to be run only on Tcl>=8.6
466 proc lint_test_xxx_ {filepath} {
467 unsupported {lint testsuite not supported on Tcl<8.5}
468 }
469
470 }