From 52862d4aeb45df2aad6c9d0b2ef00fcb89790be8 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 19 Feb 2016 10:49:57 +0000 Subject: Proposed fix for [9b47029467631832]: testing existence of env(some_thing) destroys traces. Was the comment [http://core.tcl.tk/tcl/artifact/f93c0675115b73ce?ln=554|here] not correct after all?. --- generic/tclEnv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/generic/tclEnv.c b/generic/tclEnv.c index 2cb240d..66ddb57 100644 --- a/generic/tclEnv.c +++ b/generic/tclEnv.c @@ -551,7 +551,8 @@ TclGetEnv( * array. * * Results: - * Always returns NULL to indicate success. + * Returns NULL to indicate success, or an error-message if the array + * element being handled doesn't exist. * * Side effects: * Environment variable changes get propagated. If the whole "env" array @@ -609,8 +610,7 @@ EnvTraceProc( const char *value = TclGetEnv(name2, &valueString); if (value == NULL) { - Tcl_UnsetVar2(interp, name1, name2, 0); - return NULL; + return (char *) "no such variable"; } Tcl_SetVar2(interp, name1, name2, value, 0); Tcl_DStringFree(&valueString); -- cgit v0.12 From 3a234ba343433d741a7a0c873702da6cb7987ae5 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 19 Feb 2016 14:42:53 +0000 Subject: Add test-case which demonstrates the problem. This test-case fails in trunk (but passes in core-8-5-branch, as expected). --- tests/env.test | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/env.test b/tests/env.test index 83d99e0..f9df4d6 100644 --- a/tests/env.test +++ b/tests/env.test @@ -314,6 +314,19 @@ test env-7.2 {[219226]: links to env elements should not be removed by read} { }} } ok +test env-7.3 {[9b4702]: testing existence of env(some_thing) should not destroy trace} { + apply {{} { + catch {unset ::env(test7_3)} + proc foo args { + set ::env(test7_3) ok + } + trace add variable ::env(not_yet_existent) write foo + info exists ::env(not_yet_existent) + set ::env(not_yet_existent) "Now I'm here"; + info exists ::env(test7_3) + }} +} 1 + # Restore the environment variables at the end of the test. foreach name [array names env] { -- cgit v0.12 From 96f8fc81311574307013ca7a6f4abc589600d848 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 22 Feb 2016 12:39:10 +0000 Subject: Convert remaining env.test test-cases to tcltest-2 format --- tests/env.test | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/tests/env.test b/tests/env.test index f9df4d6..9f59fbc 100644 --- a/tests/env.test +++ b/tests/env.test @@ -278,20 +278,20 @@ test env-5.4 {corner cases - unset the env array} -setup { } -cleanup { interp delete i } -result {1 a 1} -test env-5.5 {corner cases - cannot have null entries on Windows} {win} { +test env-5.5 {corner cases - cannot have null entries on Windows} -constraints win -body { set env() a catch {set env()} -} {1} +} -result 1 -test env-6.1 {corner cases - add lots of env variables} {} { +test env-6.1 {corner cases - add lots of env variables} -body { set size [array size env] for {set i 0} {$i < 100} {incr i} { set env(BOGUS$i) $i } expr {[array size env] - $size} -} 100 +} -result 100 -test env-7.1 {[219226]: whole env array should not be unset by read} { +test env-7.1 {[219226]: whole env array should not be unset by read} -body { set n [array size env] set s [array startsearch env] while {[array anymore env $s]} { @@ -300,21 +300,18 @@ test env-7.1 {[219226]: whole env array should not be unset by read} { } array donesearch env $s return $n -} 0 -test env-7.2 {[219226]: links to env elements should not be removed by read} { +} -result 0 + +test env-7.2 {[219226]: links to env elements should not be removed by read} -body { apply {{} { set ::env(test7_2) ok upvar env(test7_2) elem set ::env(PATH) - try { - return $elem - } finally { - unset ::env(test7_2) - } + return $elem }} -} ok +} -result ok -test env-7.3 {[9b4702]: testing existence of env(some_thing) should not destroy trace} { +test env-7.3 {[9b4702]: testing existence of env(some_thing) should not destroy trace} -body { apply {{} { catch {unset ::env(test7_3)} proc foo args { @@ -323,9 +320,9 @@ test env-7.3 {[9b4702]: testing existence of env(some_thing) should not destroy trace add variable ::env(not_yet_existent) write foo info exists ::env(not_yet_existent) set ::env(not_yet_existent) "Now I'm here"; - info exists ::env(test7_3) + return [info exists ::env(test7_3)] }} -} 1 +} -result 1 # Restore the environment variables at the end of the test. -- cgit v0.12