File: unix.exp

package info (click to toggle)
modules 5.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 20,572 kB
  • sloc: exp: 46,525; sh: 5,261; tcl: 3,182; makefile: 1,355; ansic: 466; python: 251; csh: 201; perl: 47; ruby: 44
file content (615 lines) | stat: -rw-r--r-- 15,607 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		config/%M%
#   Revision:		%I%
#   First Edition:	1995/12/06
#   Last Mod.:		%U%, %G%
#
#   Authors:		Jens Hamisch, Jens.Hamisch@Strawberry.COM
#
#   Description:	Testuite initialization
#   Command:
#   Sub-Command:
#
#   Comment:	%C{
#			Initialization of the testsuite. Definition of
#			globally used start procedures for the test
#			target.
#		}C%
#
##############################################################################

#
# default shell is the bourne shell
#

proc default_shell {} {
    global shell

    if ![info exists shell] then {
	set shell "sh"
    }
}

#
# the default for the modulecmd binary is the one in the upper directory
# if it doesn't exist, look up the search path in order to locate one.
#

proc default_modulecmd {} {
    global MODULECMD
    global verbose
    global env

    if ![info exists MODULECMD] then {
    if [info exists env(MODULECMD)] {
        set MODULECMD $env(MODULECMD)
	} elseif [file exists ../modulecmd] then {
	    set MODULECMD "../modulecmd"
	} elseif [file exists ./modulecmd] then {
	    set MODULECMD "./modulecmd"
	# use test-specific modulecmd.tcl script if it exists
	} elseif [file exists "./modulecmd-test.tcl"] then {
	  set MODULECMD "./modulecmd-test.tcl"
	# check for modulecmd.tcl before guessing from path
	# to give this flavor a chance to be found when modulecmd
	# binary is also installed in system default paths
	} elseif [file exists "../modulecmd.tcl"] then {
	  set MODULECMD "../modulecmd.tcl"
	} elseif [file exists "./modulecmd.tcl"] then {
	  set MODULECMD "./modulecmd.tcl"
	} else {
	    set MODULECMD [which modulecmd]
	    if ![file exists $MODULECMD] then {
		fail "No 'modulecmd' found"
		exit -1
	    } elseif { $verbose > 1 } {
		send_user "using 'modulecmd' from search path"
	    }
	}
    }

}

proc default_tclsh {} {
   global TCLSH
   global verbose
   global env

   if ![info exists TCLSH] then {
      if [info exists env(TCLSH)] {
         set TCLSH $env(TCLSH)
      } else {
	     set TCLSH [which modulecmd]
	     if ![file exists $TCLSH] then {
		    fail "No 'tclsh' found"
		    exit -1
	     } elseif { $verbose > 1 } {
		    send_user "using 'tclsh' from search path"
	     }
      }
   }
}


#
# modulecmd_exit -- cleanup
#

proc modulecmd_exit {} {
#not applicable
}

#
# modulecmd_start -- start modulecmd running
# Since modulecmd writes to both streams, stdout and stderr, a catcher
# has to be installed in order to scan both 
#

# alternative method to collect stdout and stderr from command execution (on
# Tcl>=8.6): use channel pipe instead of saving these outputs in file
if {[lindex [lsort -dictionary [list 8.6 [info tclversion]]] 1] eq [info tclversion]} {

proc readpipe {p1 p2 varname} {
    append ::$varname [read $p1]
    if {[eof $p1]} {
        close $p1
        if {$p2 ni [chan names]} {
            set ::endpipe ok
        }
    }
}

proc modulecmd_xxx_ {command {input noinput}} {
	global MODULECMD
	global TCLSH
	global verbose
	global shell
	global comp_output
	global comp_error
	global comp_exit
	global errorCode
	global no_verbose

    if {[info exists ::endpipe]} {
        unset ::endpipe
    }

	if ![info exists command] then {
	  unresolved "internal testsuite error: no module command specified"
	}

	default_shell
	default_modulecmd
	default_tclsh

    set cmdlist [list exec $TCLSH $MODULECMD $shell]
    # check if asked not to split passed command line
    if {[string first "NOCMDSPLIT" $command] == 0} {
        lappend cmdlist [string range $command 10 end]
    } else {
        # preserve argument including space character
        foreach cmdelt [split [string map {{\ } {<SPACE>}} $command] { }] {
            lappend cmdlist [string map {<SPACE> { }} $cmdelt]
        }
    }
    if {$input ne {noinput}} {
        lappend cmdlist << $input
    }

	if { ! $no_verbose && $verbose > 1 } {
        send_user "starting [lrange $cmdlist 1 end]\n"
	}

    # create pipes
    lassign [chan pipe] rdstdout wrstdout
    lassign [chan pipe] rdstderr wrstderr

    # fetch output asynchronously
    fileevent $rdstdout readable [list readpipe $rdstdout $rdstderr comp_output]
    fconfigure $rdstdout -blocking 0
    fileevent $rdstderr readable [list readpipe $rdstderr $rdstdout comp_error]
    fconfigure $rdstderr -blocking 0

    # run command in separate thread
    lappend cmdlist >@ $wrstdout 2>@ $wrstderr &
    if [catch {
        {*}$cmdlist
    } ] {
        set comp_exit [lindex $::errorCode 2]
    } else {
        set comp_exit 0
    }
    close $wrstdout
    close $wrstderr

    vwait endpipe
}

} else {

proc modulecmd_xxx_ {command {input noinput}} {
	global MODULECMD
	global TCLSH
	global verbose
	global shell
	global comp_output
	global comp_error
	global comp_exit
	global errorCode
	global no_verbose

	if ![info exists command] then {
	  unresolved "internal testsuite error: no module command specified"
	}

	default_shell
	default_modulecmd
	default_tclsh

    set cmdlist [list exec $TCLSH $MODULECMD $shell]
    # check if asked not to split passed command line
    if {[string first "NOCMDSPLIT" $command] == 0} {
        lappend cmdlist [string range $command 10 end]
    } else {
        # preserve argument including space character
        foreach cmdelt [split [string map {{\ } {<SPACE>}} $command] { }] {
            lappend cmdlist [string map {<SPACE> { }} $cmdelt]
        }
    }
    lappend cmdlist 2> test321.err > test321.out
    if {$input ne {noinput}} {
        lappend cmdlist << $input
    }

	if { ! $no_verbose && $verbose > 1 } {
        send_user "starting [lrange $cmdlist 1 end]\n"
	}

	if [catch {
        set comp_output [{*}$cmdlist]
	} ] {
		set comp_exit [lindex $errorCode 2]
	} else {
		set comp_exit 0
	}
                                                                                
	catch {
		set errfile [ open test321.err ]
		read $errfile
	} comp_error
	catch { close $errfile }
	catch { file delete test321.err }

	catch {
		set outfile [ open test321.out ]
		read $outfile
	} comp_output
	catch { close $outfile }
	catch { file delete test321.out }
}

}

proc modulecmd_start {command {input noinput}} {
	global no_verbose

	set no_verbose 0
	modulecmd_xxx_ "$command" $input
	unset no_verbose
}

#
# modulecmd__ -- start modulecmd running
#   (same as above but no verbose output)

proc modulecmd__ {command} {
	global shell
	global no_verbose

	set shell "sh"
	set no_verbose 1
	modulecmd_xxx_ "$command"
	unset no_verbose
}

#
# modulecmd_version -- extract and print the version number of modulecmd
#

proc modulecmd_version {} {
    global MODULECMD
    global shell
    global comp_output
    global comp_error

    set shell "sh"
    default_modulecmd

    modulecmd_start help
    regexp {Modules Release (Tcl [0-9a-zA-Z\.]+)(.*)} \
	$comp_error version rest

    set comp_output "$version"
}

#
# modulecmd_load -- loads the program
#

proc modulecmd_load { arg } {
#   not applicable
}


#
# Test procedure to check a module installation
#

# alternative method to collect stdout and stderr from command execution (on
# Tcl>=8.6): use channel pipe instead of saving these outputs in file
if {[lindex [lsort -dictionary [list 8.6 [info tclversion]]] 1] eq [info tclversion]} {

proc install_test_xxx_ {command} {
   global verbose
   global autoinit_script
   global shell
   global autoinit_mode
   global shell_list
   global shell_test
   global shell_path
   global shell_opts
   global shell_init
   global shell_level
   global subshell

   global comp_output
   global comp_error
   global comp_exit
   global errorCode

   if {[info exists ::endpipe]} {
      unset ::endpipe
   }

   if {![info exists command]} {
      unresolved "internal testsuite error: no command specified"
   }
   if {![info exists shell_path($shell)]} {
      unresolved "internal testsuite error: no shell path found for '$shell' shell"
   }
   if {![info exists shell_test($shell)]} {
      unresolved "internal testsuite error: no install test script set for '$shell' shell"
   }
   if {![info exists shell_init($shell)]} {
      unresolved "internal testsuite error: no init script set for '$shell' shell"
   }
   if {![info exists autoinit_script]} {
      unresolved "internal testsuite error: no autoinit script set"
   }
   if {![info exists shell_level]} {
      set level "top"
   } else {
      set level $shell_level
   }
   if {![info exists subshell]} {
      set sub "$shell"
   } else {
      set sub $subshell
   }

   set cmd_to_exec [list $shell_path($shell)]
   if {[info exists shell_opts($shell)]} {
      lappend cmd_to_exec $shell_opts($shell)
   }

   if {$shell eq "cmake"} {
      lappend cmd_to_exec "-Dinitfile='$shell_init($shell)'"
      lappend cmd_to_exec "-Dcmdlist='$command'"
      lappend cmd_to_exec "-P"
      lappend cmd_to_exec $shell_test($shell)
      if { $verbose > 0 } {
         send_user "   ...  Testing '$cmd_to_exec'\n"
      }
   } else {
      lappend cmd_to_exec $shell_test($shell)
      if {$autoinit_mode} {
         set autoinit_verb "autoinit "
         lappend cmd_to_exec $autoinit_script
      } else {
         set autoinit_verb ""
         lappend cmd_to_exec $shell_init($shell)
      }

      if {[lsearch -exact $shell_list $shell] != -1} {
         lappend cmd_to_exec $level $shell_path($sub) $command
         if { $verbose > 0 } {
            send_user "   ...  Testing '$shell [file tail $shell_test($shell)]\
               $autoinit_verb$level $sub $command'\n"
         }
      } else {
         lappend cmd_to_exec $command
         if { $verbose > 0 } {
            send_user "   ...  Testing '$shell [file tail $shell_test($shell)]\
               $autoinit_verb$command'\n"
         }
      }
   }
   if { $verbose > 1 } {
      send_user "starting $cmd_to_exec\n"
   }

   # create pipes
   lassign [chan pipe] rdstdout wrstdout
   lassign [chan pipe] rdstderr wrstderr

   # fetch output asynchronously
   fileevent $rdstdout readable [list readpipe $rdstdout $rdstderr comp_output]
   fconfigure $rdstdout -blocking 0
   fileevent $rdstderr readable [list readpipe $rdstderr $rdstdout comp_error]
   fconfigure $rdstderr -blocking 0

   # run command in separate thread
   lappend cmd_to_exec >@ $wrstdout 2>@ $wrstderr
   if [catch {
       exec {*}$cmd_to_exec
   } ] {
       set comp_exit [lindex $errorCode 2]
   } else {
       set comp_exit 0
   }
   close $wrstdout
   close $wrstderr

   vwait endpipe

   if {$shell eq {ruby}} {
      set comp_error [regsub -all -line {^.* warning: Insecure world writable dir .*(\n|$)} $comp_error {}]
   }
}

} else {

proc install_test_xxx_ {command} {
   global verbose
   global autoinit_script
   global shell
   global autoinit_mode
   global shell_list
   global shell_test
   global shell_path
   global shell_opts
   global shell_init
   global shell_level
   global subshell

   global comp_output
   global comp_error
   global comp_exit
   global errorCode

   if {![info exists command]} {
      unresolved "internal testsuite error: no command specified"
   }
   if {![info exists shell_path($shell)]} {
      unresolved "internal testsuite error: no shell path found for '$shell' shell"
   }
   if {![info exists shell_test($shell)]} {
      unresolved "internal testsuite error: no install test script set for '$shell' shell"
   }
   if {![info exists shell_init($shell)]} {
      unresolved "internal testsuite error: no init script set for '$shell' shell"
   }
   if {![info exists autoinit_script]} {
      unresolved "internal testsuite error: no autoinit script set"
   }
   if {![info exists shell_level]} {
      set level "top"
   } else {
      set level $shell_level
   }
   if {![info exists subshell]} {
      set sub "$shell"
   } else {
      set sub $subshell
   }

   set cmd_to_exec [list $shell_path($shell)]
   if {[info exists shell_opts($shell)]} {
      lappend cmd_to_exec $shell_opts($shell)
   }

   if {$shell eq "cmake"} {
      lappend cmd_to_exec "-Dinitfile='$shell_init($shell)'"
      lappend cmd_to_exec "-Dcmdlist='$command'"
      lappend cmd_to_exec "-P"
      lappend cmd_to_exec $shell_test($shell)
      if { $verbose > 0 } {
         send_user "   ...  Testing '$cmd_to_exec'\n"
      }
   } else {
      lappend cmd_to_exec $shell_test($shell)
      if {$autoinit_mode} {
         set autoinit_verb "autoinit "
         lappend cmd_to_exec $autoinit_script
      } else {
         set autoinit_verb ""
         lappend cmd_to_exec $shell_init($shell)
      }

      if {[lsearch -exact $shell_list $shell] != -1} {
         lappend cmd_to_exec $level $shell_path($sub) $command
         if { $verbose > 0 } {
            send_user "   ...  Testing '$shell [file tail $shell_test($shell)]\
               $autoinit_verb$level $sub $command'\n"
         }
      } else {
         lappend cmd_to_exec $command
         if { $verbose > 0 } {
            send_user "   ...  Testing '$shell [file tail $shell_test($shell)]\
               $autoinit_verb$command'\n"
         }
      }
   }
   if { $verbose > 1 } {
      send_user "starting $cmd_to_exec\n"
   }

   # now need to capture the exit return code.
   if [catch {
      set comp_output [exec {*}$cmd_to_exec 2> test321.err > test321.out ]
   } ] {
      set comp_exit [lindex $errorCode 2]
   } else {
      set comp_exit 0
   }

   catch {
      set errfile [ open test321.err ]
      read $errfile
   } comp_error
   catch { close $errfile }
   catch { file delete test321.err }

   if {$shell eq {ruby}} {
      set comp_error [regsub -all -line {^.* warning: Insecure world writable dir .*(\n|$)} $comp_error {}]
   }

   catch {
      set outfile [ open test321.out ]
      read $outfile
   } comp_output
   catch { close $outfile }
   catch { file delete test321.out }
}

}

#
# Test procedure to lint script files
#

# alternative method to collect stdout and stderr from command execution (on
# Tcl>=8.6): use channel pipe instead of saving these outputs in file
if {[lindex [lsort -dictionary [list 8.6 [info tclversion]]] 1] eq [info tclversion]} {

proc lint_test_xxx_ {filepath} {
   if {[info exists ::endpipe]} {
      unset ::endpipe
   }

   # global variable ::shell corresponds to linter command to use
   if {[auto_execok $::shell] eq {}} {
      untested "linter command '$::shell' not found"
      return
   }

   # prepare command to execute
   set cmd_to_exec [list $::shell]
   if {[info exists ::linter_opts]} {
      lappend cmd_to_exec {*}$::linter_opts
   }
   lappend cmd_to_exec $filepath

   if {$::verbose > 0} {
      send_user "   ...  Testing '$::shell $filepath\n"
   }
   if {$::verbose > 1} {
      send_user "starting $cmd_to_exec\n"
   }

   # create pipes
   lassign [chan pipe] rdstdout wrstdout
   lassign [chan pipe] rdstderr wrstderr

   # fetch output asynchronously
   fileevent $rdstdout readable [list readpipe $rdstdout $rdstderr comp_output]
   fconfigure $rdstdout -blocking 0
   fileevent $rdstderr readable [list readpipe $rdstderr $rdstdout comp_error]
   fconfigure $rdstderr -blocking 0

   # run command in separate thread
   lappend cmd_to_exec >@ $wrstdout 2>@ $wrstderr
   if [catch {
       exec {*}$cmd_to_exec
   } ] {
       set ::comp_exit [lindex $::errorCode 2]
   } else {
       set ::comp_exit 0
   }
   close $wrstdout
   close $wrstderr

   vwait endpipe
}

} else {

# expect 'lint' testsuite to be run only on Tcl>=8.6
proc lint_test_xxx_ {filepath} {
   unsupported {lint testsuite not supported on Tcl<8.5}
}

}