os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/unixInit.test
First public contribution.
1 # The file tests the functions in the tclUnixInit.c file.
3 # This file contains a collection of tests for one or more of the Tcl
4 # built-in commands. Sourcing this file into Tcl runs the tests and
5 # generates output for errors. No output means no errors were found.
7 # Copyright (c) 1997 by Sun Microsystems, Inc.
8 # Copyright (c) 1998-1999 by Scriptics Corporation.
10 # See the file "license.terms" for information on usage and redistribution
11 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13 # RCS: @(#) $Id: unixInit.test,v 1.30.2.12 2005/04/27 21:07:52 dgp Exp $
15 package require tcltest 2
16 namespace import -force ::tcltest::*
17 unset -nocomplain path
18 if {[info exists env(TCL_LIBRARY)]} {
19 set oldlibrary $env(TCL_LIBRARY)
20 unset env(TCL_LIBRARY)
22 catch {set oldlang $env(LANG)}
25 test unixInit-1.1 {TclpInitPlatform: ignore SIGPIPE} {unixOnly stdio} {
28 # Watch out for a race condition here. If tcltest is too slow to start
29 # then we'll kill it before it has a chance to set up its signal handler.
31 set f [open "|[list [interpreter]]" w+]
35 exec kill -PIPE [pid $f]
36 lappend x [catch {close $f}]
38 set f [open "|[list [interpreter]]" w+]
43 lappend x [catch {close $f}]
48 # This test is really a test of code in tclUnixChan.c, but the
49 # channels are set up as part of initialisation of the interpreter so
50 # the test seems to me to fit here as well as anywhere else.
51 test unixInit-1.2 {initialisation: standard channel type deduction} {unixOnly stdio} {
52 # pipe1 is a connection to a server that reports what port it
53 # starts on, and delivers a constant string to the first client to
54 # connect to that port before exiting.
55 set pipe1 [open "|[list [interpreter]]" r+]
57 proc accept {channel host port} {
58 puts $channel {puts [fconfigure stdin -peername]; exit}
62 puts [fconfigure [socket -server accept 0] -sockname]
65 # Note the backslash above; this is important to make sure that the
66 # whole string is read before an [exit] can happen...
68 set port [lindex [gets $pipe1] 2]
69 set sock [socket localhost $port]
70 # pipe2 is a connection to a Tcl interpreter that takes its orders
71 # from the socket we hand it (i.e. the server we create above.)
72 # These orders will tell it to print out the details about the
73 # socket it is taking instructions from, hopefully identifying it
74 # as a socket. Which is what this test is all about.
75 set pipe2 [open "|[list [interpreter] <@$sock]" r]
76 set result [gets $pipe2]
78 # Clear any pending data; stops certain kinds of (non-important) errors
79 fconfigure $pipe1 -blocking 0; gets $pipe1
80 fconfigure $pipe2 -blocking 0; gets $pipe2
82 # Close the pipes and the socket.
87 # Can't use normal comparison, as hostname varies due to some
88 # installations having a messed up /etc/hosts file.
90 [string equal 127.0.0.1 [lindex $result 0]] &&
91 [string equal $port [lindex $result 2]]
95 subst "Expected: `[list 127.0.0.1 localhost $port]', Got `$result'"
99 proc getlibpath [list [list program [interpreter]]] {
100 set f [open "|[list $program]" w+]
101 fconfigure $f -buffering none
102 puts $f {puts $tcl_libPath; exit}
108 # Some tests require the testgetdefenc command
110 testConstraint testgetdefenc [llength [info commands testgetdefenc]]
112 test unixInit-2.0 {TclpInitLibraryPath: setting tclDefaultEncodingDir} \
113 {unixOnly testgetdefenc} {
114 set origDir [testgetdefenc]
116 set path [testgetdefenc]
117 testsetdefenc $origDir
120 test unixInit-2.1 {TclpInitLibraryPath: value of installLib, developLib} \
122 set path [getlibpath]
124 set installLib lib/tcl[info tclversion]
125 set developLib tcl[info patchlevel]/library
126 set prefix [file dirname [file dirname [interpreter]]]
129 lappend x [string compare [lindex $path 0] $prefix/$installLib]
130 lappend x [string compare [lindex $path 4] [file dirname $prefix]/$developLib]
133 test unixInit-2.2 {TclpInitLibraryPath: TCL_LIBRARY} {unixOnly stdio} {
134 # ((str != NULL) && (str[0] != '\0'))
136 set env(TCL_LIBRARY) sparkly
137 set path [getlibpath]
138 unset env(TCL_LIBRARY)
142 test unixInit-2.3 {TclpInitLibraryPath: TCL_LIBRARY wrong version} \
144 # ((pathc > 0) && (strcasecmp(installLib + 4, pathv[pathc - 1]) != 0))
146 set env(TCL_LIBRARY) /a/b/tcl1.7
147 set path [getlibpath]
148 unset env(TCL_LIBRARY)
151 } [list /a/b/tcl1.7 /a/b/tcl[info tclversion]]
152 test unixInit-2.4 {TclpInitLibraryPath: TCL_LIBRARY: INTL} \
154 # Child process translates env variable from native encoding.
156 set env(TCL_LIBRARY) "\xa7"
157 set x [lindex [getlibpath] 0]
158 unset env(TCL_LIBRARY)
163 test unixInit-2.5 {TclpInitLibraryPath: compiled-in library path} \
164 {emptyTest unixOnly} {
167 test unixInit-2.6 {TclpInitLibraryPath: executable relative} \
170 makeDirectory [file join tmp sparkly]
171 makeDirectory [file join tmp sparkly bin]
172 file copy [interpreter] [file join [temporaryDirectory] tmp sparkly \
174 makeDirectory [file join tmp sparkly lib]
175 makeDirectory [file join tmp sparkly lib tcl[info tclversion]]
176 makeFile {} [file join tmp sparkly lib tcl[info tclversion] init.tcl]
178 set x [lrange [getlibpath [file join [temporaryDirectory] tmp sparkly \
180 removeFile [file join tmp sparkly lib tcl[info tclversion] init.tcl]
181 removeDirectory [file join tmp sparkly lib tcl[info tclversion]]
182 removeDirectory [file join tmp sparkly lib]
183 removeDirectory [file join tmp sparkly bin]
184 removeDirectory [file join tmp sparkly]
187 } [list [temporaryDirectory]/tmp/sparkly/lib/tcl[info tclversion] [temporaryDirectory]/tmp/lib/tcl[info tclversion]]
188 test unixInit-2.7 {TclpInitLibraryPath: compiled-in library path} \
189 {emptyTest unixOnly} {
190 # would need test command to get defaultLibDir and compare it to
191 # [lindex $auto_path end]
194 # The following two tests write to the directory /tmp/sparkly instead
195 # of to [temporaryDirectory]. This is because the failures tested by
196 # these tests need paths near the "root" of the file system to present
199 testConstraint noSparkly [expr {![file exists [file join /tmp sparkly]]}]
200 testConstraint noTmpInstall [expr {![file exists \
201 [file join /tmp lib tcl[info tclversion]]]}]
202 test unixInit-2.8 {TclpInitLibraryPath: all absolute pathtype} {unix noSparkly noTmpInstall} {
203 # Checking for Bug 219416
204 # When a program that embeds the Tcl library, like tcltest, is
205 # installed near the "root" of the file system, there was a problem
206 # constructing directories relative to the executable. When a
207 # relative ".." went past the root, relative path names were created
208 # rather than absolute pathnames. In some cases, accessing past the
209 # root caused memory access violations too.
211 # The bug is now fixed, but here we check for it by making sure that
212 # the directories constructed relative to the executable are all
213 # absolute pathnames, even when the executable is installed near
214 # the root of the filesystem.
216 # The only directory near the root we are likely to have write access
218 file delete -force /tmp/sparkly
219 file delete -force /tmp/lib/tcl[info tclversion]
220 file mkdir /tmp/sparkly
221 file copy [interpreter] /tmp/sparkly/tcltest
223 # Keep any existing /tmp/lib directory
225 if {[file exists /tmp/lib]} {
226 if {[file isdirectory /tmp/lib]} {
229 file delete -force /tmp/lib
233 # For a successful Tcl_Init, we need a [source]-able init.tcl in
234 # ../lib/tcl$version relative to the executable.
235 file mkdir /tmp/lib/tcl[info tclversion]
236 close [open /tmp/lib/tcl[info tclversion]/init.tcl w]
238 # Check that all directories in the library path are absolute pathnames
240 foreach dir [getlibpath /tmp/sparkly/tcltest] {
241 set allAbsolute [expr {$allAbsolute \
242 && [string equal absolute [file pathtype $dir]]}]
245 # Clean up temporary installation
246 file delete -force /tmp/sparkly
247 file delete -force /tmp/lib/tcl[info tclversion]
248 if {$deletelib} {file delete -force /tmp/lib}
251 testConstraint noTmpBuild [expr {![file exists [file join /tmp library]]}]
252 test unixInit-2.9 {TclpInitLibraryPath: paths relative to executable} {unix noSparkly noTmpBuild} {
253 # Checking for Bug 438014
254 file delete -force /tmp/sparkly
255 file delete -force /tmp/library
256 file mkdir /tmp/sparkly
257 file copy [interpreter] /tmp/sparkly/tcltest
259 file mkdir /tmp/library/
260 close [open /tmp/library/init.tcl w]
262 set x [lrange [getlibpath /tmp/sparkly/tcltest] 0 4]
264 file delete -force /tmp/sparkly
265 file delete -force /tmp/library
267 } [list /tmp/lib/tcl[info tclversion] /lib/tcl[info tclversion] \
268 /tmp/library /library /tcl[info patchlevel]/library]
270 test unixInit-2.10 {TclpInitLibraryPath: executable relative} -constraints {
273 set tmpDir [makeDirectory tmp]
274 set sparklyDir [makeDirectory sparkly $tmpDir]
275 set execPath [file join [makeDirectory bin $sparklyDir] tcltest]
276 file copy [interpreter] $execPath
277 set libDir [makeDirectory lib $sparklyDir]
278 set scriptDir [makeDirectory tcl[info tclversion] $libDir]
279 makeFile {} init.tcl $scriptDir
283 # Checking for Bug 832657
284 set x [lrange [getlibpath [file join .. bin tcltest]] 2 3]
286 lappend y [file normalize $p]
292 removeFile init.tcl $scriptDir
294 removeDirectory tcl[info tclversion] $libDir
296 file delete $execPath
298 removeDirectory bin $sparklyDir
299 removeDirectory lib $sparklyDir
301 removeDirectory sparkly $tmpDir
305 } -result [list [file join [temporaryDirectory] tmp sparkly library] \
306 [file join [temporaryDirectory] tmp library] ]
308 test unixInit-3.1 {TclpSetInitialEncodings} -constraints {
313 set f [open "|[list [interpreter]]" w+]
314 fconfigure $f -buffering none
315 puts $f {puts [encoding system]; exit}
321 } -match regexp -result [expr {
322 ($tcl_platform(os) eq "Darwin") ? "^utf-8$" : "^iso8859-15?$"}]
324 test unixInit-3.2 {TclpSetInitialEncodings} {unixOnly stdio} {
325 set env(LANG) japanese
326 catch {set oldlc_all $env(LC_ALL)}
327 set env(LC_ALL) japanese
329 set f [open "|[list [interpreter]]" w+]
330 fconfigure $f -buffering none
331 puts $f {puts [encoding system]; exit}
336 catch {set env(LC_ALL) $oldlc_all}
338 set validEncodings [list euc-jp]
339 if {[string match HP-UX $tcl_platform(os)]} {
340 # Some older HP-UX systems need us to accept this as valid
341 # Bug 453883 reports that newer HP-UX systems report euc-jp
342 # like everybody else.
343 lappend validEncodings shiftjis
345 expr {[lsearch -exact $validEncodings $enc] < 0}
348 test unixInit-4.1 {TclpSetVariables} {unixOnly} {
349 # just make sure they exist
351 set a [list $tcl_library $tcl_pkgPath $tcl_platform(os)]
352 set a [list $tcl_platform(osVersion) $tcl_platform(machine)]
353 set tcl_platform(platform)
356 test unixInit-5.1 {Tcl_Init} {emptyTest unixOnly} {
360 test unixInit-6.1 {Tcl_SourceRCFile} {emptyTest unixOnly} {
363 test unixInit-7.1 {closed standard channel: Bug 772288} -constraints {
366 set tclsh [interpreter]
367 set crash [makeFile {puts [open /dev/null]} crash.tcl]
368 set crashtest [makeFile "
370 [list exec $tclsh $crash]
372 exec $tclsh $crashtest
375 removeFile crashtest.tcl
379 if {[info exists oldlibrary]} {
380 set env(TCL_LIBRARY) $oldlibrary
382 catch {unset env(LANG)}
383 catch {set env(LANG) $oldlang}
384 unset -nocomplain path
385 ::tcltest::cleanupTests