--- Begin Message ---
Subject: |
[PATCH] Propagate return value of auto-loaded command |
Date: |
Wed, 17 Jun 2020 13:40:40 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 |
Hi,
I think I found a bug in proc unknown in lib/framework.exp.
Patch describing the problem and fixing it attached below.
Thanks,
- Tom
Propagate return value of auto-loaded command
Consider a library file foo.tcl:
...
$ cat lib/foo.tcl
proc foo { } {
return "foo-return"
}
...
and a test-case test.tcl:
...
$ cat test.tcl
\#!/usr/bin/tclsh
auto_mkindex lib *.tcl
lappend auto_path [pwd]/lib
set res [foo]
puts "RES: $res"
...
which gives us:
...
$ ./test.tcl
RES: foo-return
...
When overriding the ::unknown command using:
...
rename ::unknown ::tcl_unknown
proc unknown args {
if {[catch {uplevel 1 ::tcl_unknown $args} msg]} {
puts "ERROR: proc \"$args\" does not exist."
exit
}
}
...
we have instead:
...
$ ./test.tcl
RES:
...
What is missing, is the propagation of the return value of foo, like this:
...
puts "ERROR: proc \"$args\" does not exist."
exit
}
-}
+} else {
+ return $msg
+}
...
Fix unknown in lib/framework.exp accordingly.
ChangeLog:
2020-06-17 Tom de Vries <tdevries@suse.de>
* lib/framework.exp (unknown): Propagate return value of auto-loaded
command.
---
lib/framework.exp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lib/framework.exp b/lib/framework.exp
index e6ce197..c9875d2 100644
--- a/lib/framework.exp
+++ b/lib/framework.exp
@@ -272,6 +272,9 @@ proc unknown args {
}
set exit_status 2
log_and_exit
+ } else {
+ # Propagate return value.
+ return $msg
}
}
--- End Message ---
--- Begin Message ---
Subject: |
Re: bug#41914: [PATCH] Propagate return value of auto-loaded command |
Date: |
Wed, 17 Jun 2020 18:19:03 -0500 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.22) Gecko/20090807 MultiZilla/1.8.3.4e SeaMonkey/1.1.17 Mnenhy/0.7.6.0 |
Tom de Vries wrote:
I think I found a bug in proc unknown in lib/framework.exp.
Patch describing the problem and fixing it attached below.
I found and fixed the same bug while working on the patch for bug #41824.
-- Jacob
--- End Message ---