############################################################################## # 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% # ############################################################################## # # modulecmd_xxx_ -- run modulecmd # # 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]} { # catch background errors, like a modulecmd process killed by a signal that # makes readpipe raise an uncaught CHILDKILLED error from its event handler. # without this catching procedure defined, such an error leaves the endpipe # variable unset and the vwait call in modulecmd_xxx_ hangs forever proc bgerror {msg} { send_user "ERROR: background error caught: $msg\n" # release ongoing command wait to make related test fail right away set ::endpipe error } proc readpipe {p1 p2 varname {exit_varname {}}} { append ::$varname [read $p1] if {[eof $p1]} { fconfigure $p1 -blocking 1 try { close $p1 } on ok {output} { if {[string length $exit_varname]} { set ::$exit_varname 0 } } trap {CHILDSTATUS} {output options} { if {[string length $exit_varname]} { set ::$exit_varname [lindex [dict get $options -errorcode] end] } } if {$p2 ni [chan names]} { set ::endpipe ok } } } proc modulecmd_xxx_ {command {input noinput} {launcher {}}} { global MODULECMD global TCLSH global verbose global shell global comp_output global comp_error global comp_exit global errorCode if {[info exists ::endpipe]} { unset ::endpipe } if ![info exists command] then { unresolved "internal testsuite error: no module command specified" } set cmdlist [list] if {[llength $launcher]} { lappend cmdlist {*}$launcher } lappend cmdlist $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 {{\ } {}} $command] { }] { lappend cmdlist [string map { { }} $cmdelt] } } if {$input ne {noinput}} { lappend cmdlist << $input } if { $verbose > 1 } { send_user "starting [lrange $cmdlist 1 end]\n" } # create pipes lassign [chan pipe] rdstderr wrstderr # run command in separate thread lappend cmdlist 2>@ $wrstderr set rdstdout [open "|$cmdlist"] # fetch output asynchronously fileevent $rdstdout readable [list readpipe $rdstdout $rdstderr comp_output comp_exit] fconfigure $rdstdout -blocking 0 fileevent $rdstderr readable [list readpipe $rdstderr $rdstdout comp_error] fconfigure $rdstderr -blocking 0 close $wrstderr vwait endpipe } } else { proc modulecmd_xxx_ {command {input noinput} {launcher {}}} { global MODULECMD global TCLSH global verbose global shell global comp_output global comp_error global comp_exit global errorCode if ![info exists command] then { unresolved "internal testsuite error: no module command specified" } set cmdlist [list] if {[llength $launcher]} { lappend cmdlist {*}$launcher } lappend cmdlist $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 {{\ } {}} $command] { }] { lappend cmdlist [string map { { }} $cmdelt] } } lappend cmdlist 2> test321.err > test321.out if {$input ne {noinput}} { lappend cmdlist << $input } if { $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 } } } # # 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} { 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} { send_user " ... Testing '$shell [file tail $shell_test($shell)]\ $autoinit_verb$level $sub $command'\n" } } else { lappend cmd_to_exec $command if {$verbose} { 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] rdstderr wrstderr # run command in separate thread lappend cmd_to_exec 2>@ $wrstderr set rdstdout [open "|$cmd_to_exec"] # fetch output asynchronously fileevent $rdstdout readable [list readpipe $rdstdout $rdstderr comp_output comp_exit] fconfigure $rdstdout -blocking 0 fileevent $rdstderr readable [list readpipe $rdstderr $rdstdout comp_error] fconfigure $rdstderr -blocking 0 close $wrstderr vwait endpipe if {$shell eq {ruby}} { set comp_error [regsub -all -line {^.* warning: Insecure world writable dir .*(\n|$)} $comp_error {}] set comp_error [regsub -all -line {^`RubyGems' were not loaded\.(\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} { 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} { send_user " ... Testing '$shell [file tail $shell_test($shell)]\ $autoinit_verb$level $sub $command'\n" } } else { lappend cmd_to_exec $command if {$verbose} { 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} { 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} } }