os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/env.test
Update contrib.
1 # Commands covered: none (tests environment variable implementation)
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) 1991-1993 The Regents of the University of California.
8 # Copyright (c) 1994 Sun Microsystems, Inc.
9 # Copyright (c) 1998-1999 by Scriptics Corporation.
11 # See the file "license.terms" for information on usage and redistribution
12 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 # RCS: @(#) $Id: env.test,v 1.17.2.5 2007/01/19 01:05:50 das Exp $
16 package require tcltest 2
17 namespace import -force ::tcltest::*
20 # These tests will run on any platform (and indeed crashed
21 # on the Mac). So put them before you test for the existance
24 test env-1.1 {propagation of env values to child interpreters} {
25 catch {interp delete child}
26 catch {unset env(test)}
29 set return [child eval {set env(test)}]
35 # This one crashed on Solaris under Tcl8.0, so we only
36 # want to make sure it runs.
38 test env-1.2 {lappend to env value} {
39 catch {unset env(test)}
40 set env(test) aaaaaaaaaaaaaaaa
41 append env(test) bbbbbbbbbbbbbb
44 test env-1.3 {reflection of env by "array names"} {
45 catch {interp delete child}
46 catch {unset env(test)}
48 child eval {set env(test) garbage}
49 set names [array names env]
51 set ix [lsearch $names test]
52 catch {unset env(test)}
57 # Some tests require the "exec" command.
58 # Skip them if exec is not defined.
59 testConstraint exec [llength [info commands exec]]
61 set printenvScript [makeFile {
62 proc lrem {listname name} {
64 set i [lsearch $list $name]
66 set list [lreplace $list $i $i]
71 set names [lsort [array names env]]
72 if {$tcl_platform(platform) == "windows"} {
79 TCL_LIBRARY PATH LD_LIBRARY_PATH LIBPATH PURE_PROG_NAME DISPLAY
80 SHLIB_PATH SYSTEMDRIVE SYSTEMROOT DYLD_LIBRARY_PATH DYLD_FRAMEWORK_PATH
81 DYLD_NEW_LOCAL_SHARED_REGIONS DYLD_NO_FIX_PREBINDING
82 __CF_USER_TEXT_ENCODING SECURITYSESSIONID
92 # [exec] is required here to see the actual environment received
95 global printenvScript tcltest
96 catch {exec [interpreter] $printenvScript} out
97 if {$out == "child process exited abnormally"} {
103 # Save the current environment variables at the start of the test.
105 foreach name [array names env] {
106 set env2([string toupper $name]) $env($name)
110 # Added the following lines so that child tcltest can actually find its
111 # library if the initial tcltest is run from a non-standard place.
114 TCL_LIBRARY PATH LD_LIBRARY_PATH LIBPATH DISPLAY SHLIB_PATH
115 SYSTEMDRIVE SYSTEMROOT DYLD_LIBRARY_PATH DYLD_FRAMEWORK_PATH
116 DYLD_NEW_LOCAL_SHARED_REGIONS DYLD_NO_FIX_PREBINDING
118 if {[info exists env2($name)]} {
119 set env($name) $env2($name);
123 test env-2.1 {adding environment variables} {exec} {
127 set env(NAME1) "test string"
128 test env-2.2 {adding environment variables} {exec} {
130 } {NAME1=test string}
132 set env(NAME2) "more"
133 test env-2.3 {adding environment variables} {exec} {
138 set env(XYZZY) "garbage"
139 test env-2.4 {adding environment variables} {exec} {
145 set env(NAME2) "new value"
146 test env-3.1 {changing environment variables} {exec} {
154 test env-4.1 {unsetting environment variables} {exec} {
161 test env-4.2 {unsetting environment variables} {exec} {
167 test env-4.3 {setting international environment variables} {exec} {
171 test env-4.4 {changing international environment variables} {exec} {
175 test env-4.5 {unsetting international environment variables} {exec} {
183 test env-5.0 {corner cases - set a value, it should exist} {} {
185 set result [set env(temp)]
189 test env-5.1 {corner cases - remove one elem at a time} {} {
190 # When no environment variables exist, the env var will
191 # contain no entries. The "array names" call synchs up
192 # the C-level environ array with the Tcl level env array.
193 # Make sure an empty Tcl array is created.
195 set x [array get env]
196 foreach e [array names env] {
199 set result [catch {array names env}]
203 test env-5.2 {corner cases - unset the env array} {} {
204 # Unsetting a variable in an interp detaches the C-level
205 # traces from the Tcl "env" variable.
209 i eval { set env(THIS_SHOULDNT_EXIST) a}
210 set result [info exists env(THIS_SHOULDNT_EXIST)]
214 test env-5.3 {corner cases - unset the env in master should unset child} {} {
215 # Variables deleted in a master interp should be deleted in
219 i eval { set env(THIS_SHOULD_EXIST) a}
220 set result [set env(THIS_SHOULD_EXIST)]
221 unset env(THIS_SHOULD_EXIST)
222 lappend result [i eval {catch {set env(THIS_SHOULD_EXIST)}}]
226 test env-5.4 {corner cases - unset the env array} {} {
227 # The info exists command should be in synch with the env array.
231 i eval { set env(THIS_SHOULD_EXIST) a}
232 set result [info exists env(THIS_SHOULD_EXIST)]
233 lappend result [set env(THIS_SHOULD_EXIST)]
234 lappend result [info exists env(THIS_SHOULD_EXIST)]
238 test env-5.5 {corner cases - cannot have null entries on Windows} {pcOnly} {
243 test env-6.1 {corner cases - add lots of env variables} {} {
244 set size [array size env]
245 for {set i 0} {$i < 100} {incr i} {
248 expr {[array size env] - $size}
251 # Restore the environment variables at the end of the test.
253 foreach name [array names env] {
256 foreach name [array names env2] {
257 set env($name) $env2($name)
261 removeFile $printenvScript
262 ::tcltest::cleanupTests