aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2023-01-13 10:23:19 +1000
committerSteve Bennett <steveb@workware.net.au>2023-02-13 10:43:00 +1000
commit517d85974c7cf8d4f894f46251462e14b6fc562f (patch)
tree2e4eebd4f75671687827d484803e1a2da1d60d88 /tests
parentdb26fe46ea9a35d403067498f4b85eee82b431b0 (diff)
downloadjimtcl-517d85974c7cf8d4f894f46251462e14b6fc562f.zip
jimtcl-517d85974c7cf8d4f894f46251462e14b6fc562f.tar.gz
jimtcl-517d85974c7cf8d4f894f46251462e14b6fc562f.tar.bz2
Tcl-compatible 'info frame'
Returns a dictionary with file, line, cmd, (possibly) proc and level. And support 'info frame 0' for the current command. Note that now all evaluation frames are captured, not just call frames. Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'tests')
-rw-r--r--tests/apply.test6
-rw-r--r--tests/infoframe.test24
2 files changed, 17 insertions, 13 deletions
diff --git a/tests/apply.test b/tests/apply.test
index 504b4ae..81d3833 100644
--- a/tests/apply.test
+++ b/tests/apply.test
@@ -128,11 +128,11 @@ test apply-8.10 {default values} {
} {{args {}} {x 1} {y 3}}
test apply-9.1 {tailcall within apply} {
- proc p {y frame} {
- list [expr {$y * 2}] [expr {$frame - [info frame]}]
+ proc p {y level} {
+ list [expr {$y * 2}] [expr {$level - [info level]}]
}
apply {{x} {
- tailcall p $x [info frame]
+ tailcall p $x [info level]
notreached
}} {4}
} {8 0}
diff --git a/tests/infoframe.test b/tests/infoframe.test
index 0bfd7a9..9490589 100644
--- a/tests/infoframe.test
+++ b/tests/infoframe.test
@@ -2,10 +2,10 @@ source [file dirname [info script]]/testing.tcl
needs constraint jim
proc a {n} {
if {$n eq "trace"} {
- basename-stacktrace [stacktrace]
- } else {
- basename-stacktrace [info frame $n]
+ # strip the frame levels for test and uplevel
+ return [basename-stacktrace [lrange [stacktrace] 0 end-6]]
}
+ set frame [info frame $n]; list [dict getdef $frame proc {}] [file tail [dict get $frame file]] [dict get $frame line]
}
proc b {n} {
@@ -18,20 +18,24 @@ proc c {n} {
# --- Don't change line numbers above
-test info-frame-1.1 "Current proc" {
+test info-frame-1.1 "Current command" {
c 0
-} {a infoframe.test 12}
+} {a infoframe.test 8}
-test info-frame-1.2 "Caller" {
+test info-frame-1.2 "Current Proc" {
c -1
-} {b infoframe.test 16}
+} {b infoframe.test 12}
-test info-frame-1.3 "Caller of Caller" {
+test info-frame-1.3 "Caller" {
c -2
-} {c infoframe.test 30}
+} {c infoframe.test 16}
+
+test info-frame-1.4 "Caller of Caller" {
+ c -3
+} {test infoframe.test 34}
test stacktrace-1.1 "Full stack trace" {
c trace
-} {a infoframe.test 12 b infoframe.test 16 c infoframe.test 34}
+} {a infoframe.test 12 b infoframe.test 16 c infoframe.test 38}
testreport