summaryrefslogtreecommitdiffstats
path: root/tests/env.test
diff options
context:
space:
mode:
Diffstat (limited to 'tests/env.test')
-rw-r--r--tests/env.test209
1 files changed, 124 insertions, 85 deletions
diff --git a/tests/env.test b/tests/env.test
index c42e49d..9010f52 100644
--- a/tests/env.test
+++ b/tests/env.test
@@ -24,39 +24,42 @@ testConstraint exec [llength [info commands exec]]
# These tests will run on any platform (and indeed crashed on the Mac). So put
# them before you test for the existance of exec.
#
-test env-1.1 {propagation of env values to child interpreters} {
+test env-1.1 {propagation of env values to child interpreters} -setup {
catch {interp delete child}
catch {unset env(test)}
+} -body {
interp create child
set env(test) garbage
- set return [child eval {set env(test)}]
+ child eval {set env(test)}
+} -cleanup {
interp delete child
unset env(test)
- set return
-} {garbage}
+} -result {garbage}
#
# This one crashed on Solaris under Tcl8.0, so we only want to make sure it
# runs.
#
-test env-1.2 {lappend to env value} {
+test env-1.2 {lappend to env value} -setup {
catch {unset env(test)}
+} -body {
set env(test) aaaaaaaaaaaaaaaa
append env(test) bbbbbbbbbbbbbb
unset env(test)
-} {}
-test env-1.3 {reflection of env by "array names"} {
+}
+test env-1.3 {reflection of env by "array names"} -setup {
catch {interp delete child}
catch {unset env(test)}
+} -body {
interp create child
child eval {set env(test) garbage}
- set names [array names env]
+ expr {"test" in [array names env]}
+} -cleanup {
interp delete child
- set ix [lsearch $names test]
catch {unset env(test)}
- expr {$ix >= 0}
-} {1}
+} -result {1}
set printenvScript [makeFile {
+ encoding system iso8859-1
proc lrem {listname name} {
upvar $listname list
set i [lsearch -nocase $list $name]
@@ -75,7 +78,7 @@ set printenvScript [makeFile {
}
set names [lsort [array names env]]
- if {$tcl_platform(platform) == "windows"} {
+ if {$tcl_platform(platform) eq "windows"} {
lrem names HOME
lrem names COMSPEC
lrem names ComSpec
@@ -96,12 +99,12 @@ set printenvScript [makeFile {
exit
} printenv]
-# [exec] is required here to see the actual environment received
-# by child processes.
+# [exec] is required here to see the actual environment received by child
+# processes.
proc getenv {} {
global printenvScript tcltest
catch {exec [interpreter] $printenvScript} out
- if {$out == "child process exited abnormally"} {
+ if {$out eq "child process exited abnormally"} {
set out {}
}
return $out
@@ -124,121 +127,157 @@ foreach name [array names env] {
}
}
-test env-2.1 {adding environment variables} {exec} {
- getenv
-} {}
+# Need to run 'getenv' in known encoding, so save the current one here...
+set sysenc [encoding system]
-set env(NAME1) "test string"
-test env-2.2 {adding environment variables} {exec} {
+test env-2.1 {adding environment variables} -setup {
+ encoding system iso8859-1
+} -constraints {exec} -body {
getenv
-} {NAME1=test string}
-
-set env(NAME2) "more"
-test env-2.3 {adding environment variables} {exec} {
+} -cleanup {
+ encoding system $sysenc
+} -result {}
+test env-2.2 {adding environment variables} -setup {
+ encoding system iso8859-1
+} -constraints {exec} -body {
+ set env(NAME1) "test string"
getenv
-} {NAME1=test string
+} -cleanup {
+ encoding system $sysenc
+} -result {NAME1=test string}
+test env-2.3 {adding environment variables} -setup {
+ encoding system iso8859-1
+} -constraints {exec} -body {
+ set env(NAME2) "more"
+ getenv
+} -cleanup {
+ encoding system $sysenc
+} -result {NAME1=test string
NAME2=more}
-
-set env(XYZZY) "garbage"
-test env-2.4 {adding environment variables} {exec} {
+test env-2.4 {adding environment variables} -setup {
+ encoding system iso8859-1
+} -constraints {exec} -body {
+ set env(XYZZY) "garbage"
getenv
-} {NAME1=test string
+} -cleanup {
+ encoding system $sysenc
+} -result {NAME1=test string
NAME2=more
XYZZY=garbage}
set env(NAME2) "new value"
-test env-3.1 {changing environment variables} {exec} {
+test env-3.1 {changing environment variables} -setup {
+ encoding system iso8859-1
+} -constraints {exec} -body {
set result [getenv]
unset env(NAME2)
set result
-} {NAME1=test string
+} -cleanup {
+ encoding system $sysenc
+} -result {NAME1=test string
NAME2=new value
XYZZY=garbage}
-test env-4.1 {unsetting environment variables} {exec} {
- set result [getenv]
- unset env(NAME1)
- set result
-} {NAME1=test string
+test env-4.1 {unsetting environment variables: default} -setup {
+ encoding system iso8859-1
+} -constraints {exec} -body {
+ getenv
+} -cleanup {
+ encoding system $sysenc
+} -result {NAME1=test string
XYZZY=garbage}
-
-test env-4.2 {unsetting environment variables} {exec} {
- set result [getenv]
+test env-4.2 {unsetting environment variables} -setup {
+ encoding system iso8859-1
+} -constraints {exec} -body {
+ unset env(NAME1)
+ getenv
+} -cleanup {
unset env(XYZZY)
- set result
-} {XYZZY=garbage}
-
-test env-4.3 {setting international environment variables} {exec} {
+ encoding system $sysenc
+} -result {XYZZY=garbage}
+test env-4.3 {setting international environment variables} -setup {
+ encoding system iso8859-1
+} -constraints {exec} -body {
set env(\ua7) \ub6
getenv
-} {\u00a7=\u00b6}
-test env-4.4 {changing international environment variables} {exec} {
+} -cleanup {
+ encoding system $sysenc
+} -result {\u00a7=\u00b6}
+test env-4.4 {changing international environment variables} -setup {
+ encoding system iso8859-1
+} -constraints {exec} -body {
set env(\ua7) \ua7
getenv
-} {\u00a7=\u00a7}
-test env-4.5 {unsetting international environment variables} {exec} {
+} -cleanup {
+ encoding system $sysenc
+} -result {\u00a7=\u00a7}
+test env-4.5 {unsetting international environment variables} -setup {
+ encoding system iso8859-1
+} -body {
set env(\ub6) \ua7
unset env(\ua7)
- set result [getenv]
+ getenv
+} -constraints {exec} -cleanup {
+ encoding system $sysenc
unset env(\ub6)
- set result
-} {\u00b6=\u00a7}
+} -result {\u00b6=\u00a7}
-test env-5.0 {corner cases - set a value, it should exist} {} {
+test env-5.0 {corner cases - set a value, it should exist} -body {
set env(temp) a
- set result [set env(temp)]
+ set env(temp)
+} -cleanup {
unset env(temp)
- set result
-} {a}
-test env-5.1 {corner cases - remove one elem at a time} {} {
- # When no environment variables exist, the env var will
- # contain no entries. The "array names" call synchs up
- # the C-level environ array with the Tcl level env array.
- # Make sure an empty Tcl array is created.
-
+} -result {a}
+test env-5.1 {corner cases - remove one elem at a time} -setup {
set x [array get env]
+} -body {
+ # When no environment variables exist, the env var will contain no
+ # entries. The "array names" call synchs up the C-level environ array with
+ # the Tcl level env array. Make sure an empty Tcl array is created.
foreach e [array names env] {
unset env($e)
}
- set result [catch {array names env}]
+ array size env
+} -cleanup {
array set env $x
- set result
-} {0}
-test env-5.2 {corner cases - unset the env array} {} {
- # Unsetting a variable in an interp detaches the C-level
- # traces from the Tcl "env" variable.
-
- interp create i
- i eval { unset env }
- i eval { set env(THIS_SHOULDNT_EXIST) a}
- set result [info exists env(THIS_SHOULDNT_EXIST)]
+} -result {0}
+test env-5.2 {corner cases - unset the env array} -setup {
+ interp create i
+} -body {
+ # Unsetting a variable in an interp detaches the C-level traces from the
+ # Tcl "env" variable.
+ i eval {
+ unset env
+ set env(THIS_SHOULDNT_EXIST) a
+ }
+ info exists env(THIS_SHOULDNT_EXIST)
+} -cleanup {
interp delete i
- set result
-} {0}
-test env-5.3 {corner cases - unset the env in master should unset child} {} {
- # Variables deleted in a master interp should be deleted in
- # child interp too.
-
- interp create i
+} -result {0}
+test env-5.3 {corner cases: unset the env in master should unset child} -setup {
+ interp create i
+} -body {
+ # Variables deleted in a master interp should be deleted in child interp
+ # too.
i eval { set env(THIS_SHOULD_EXIST) a}
set result [set env(THIS_SHOULD_EXIST)]
unset env(THIS_SHOULD_EXIST)
lappend result [i eval {catch {set env(THIS_SHOULD_EXIST)}}]
+} -cleanup {
interp delete i
- set result
-} {a 1}
-test env-5.4 {corner cases - unset the env array} {} {
+} -result {a 1}
+test env-5.4 {corner cases - unset the env array} -setup {
+ interp create i
+} -body {
# The info exists command should be in synch with the env array.
# Know Bug: 1737
-
- interp create i
i eval { set env(THIS_SHOULD_EXIST) a}
set result [info exists env(THIS_SHOULD_EXIST)]
lappend result [set env(THIS_SHOULD_EXIST)]
lappend result [info exists env(THIS_SHOULD_EXIST)]
+} -cleanup {
interp delete i
- set result
-} {1 a 1}
+} -result {1 a 1}
test env-5.5 {corner cases - cannot have null entries on Windows} {win} {
set env() a
catch {set env()}