aboutsummaryrefslogtreecommitdiff
path: root/tests/infoframe.test
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2023-05-18 15:34:26 +1000
committerSteve Bennett <steveb@workware.net.au>2023-06-21 09:17:47 +1000
commit0b08e74e656c6bfb65c6f38657be05bb463f54e6 (patch)
treefaa80db8a2cd6f24cf890ad6730c00f4d7dd2738 /tests/infoframe.test
parentf07c53e38d55f0c7c648b7818798138d91053527 (diff)
downloadjimtcl-0b08e74e656c6bfb65c6f38657be05bb463f54e6.zip
jimtcl-0b08e74e656c6bfb65c6f38657be05bb463f54e6.tar.gz
jimtcl-0b08e74e656c6bfb65c6f38657be05bb463f54e6.tar.bz2
core: Display errors in a more "pythonesque" way
A typical error message now looks like this: t4.tcl:2: Error: syntax error in expression: "blah" Traceback (most recent call last): File "t4.tcl", line 14 c 1 2 3 File "t4.tcl", line 10, in c b a c File "t4.tcl", line 6, in b a A14 File "t4.tcl", line 2, in a expr blah This is produced by stackdump (that can be replaced), called by errorInfo. Note that now stacktraces (stacktrace, info stacktrace, $opts(-errorinfo)) include the running command at each level in addition to proc, file, line. In order for scripts to detect this new format, a new entry tcl_platform entry has been added: tcl_platform(stackFormat) = 4 (to signify 4 elements per frame) In addition, instead of building the error stack frame as the stack is unwound in response to an error, instead the entire current stack trace is captured by stacktrace. This means that the trace extends beyond the try/catch right back to the initial interpreter command. The 'stacktrace' command is now implemented in C based on the same code that generates the error stacktrace. Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'tests/infoframe.test')
-rw-r--r--tests/infoframe.test30
1 files changed, 18 insertions, 12 deletions
diff --git a/tests/infoframe.test b/tests/infoframe.test
index e8544b1..ef827bc 100644
--- a/tests/infoframe.test
+++ b/tests/infoframe.test
@@ -1,44 +1,50 @@
source [file dirname [info script]]/testing.tcl
-proc a {n} {
+proc a {n args} {
if {$n eq "trace"} {
- return [basename-stacktrace [stacktrace]]
+ return [basename-stacktrace [stacktrace {*}$args]]
}
set frame [info frame $n]
if {![dict exists $frame proc]} {
dict set frame proc {}
}
- basename-stacktrace [list [dict get $frame proc] [file tail [dict get $frame file]] [dict get $frame line]]
+ basename-stacktrace [list [dict get $frame proc] [file tail [dict get $frame file]] [dict get $frame line] [dict get $frame cmd]]
}
-proc b {n} {
- a $n
+proc b {args} {
+ a {*}$args
}
-proc c {n} {
- b $n
+proc c {args} {
+ b {*}$args
}
# --- Don't change line numbers above
test info-frame-1.1 {Current command} -body {
c 0
-} -result {a infoframe.test 7}
+} -result {a infoframe.test 7 {info frame 0}}
test info-frame-1.2 {Current Proc} -body {
c -1
-} -result {b infoframe.test 15}
+} -result {b infoframe.test 15 {a -1}}
test info-frame-1.3 Caller -body {
c -2
-} -result {c infoframe.test 19}
+} -result {c infoframe.test 19 {b -2}}
test info-frame-1.4 {Caller of Caller} -body {
c -3
-} -result {test infoframe.test 37}
+} -result {test infoframe.test 37 {c -3}}
test stacktrace-1.1 {Full stack trace} -body {
c trace
-} -result {a infoframe.test 5 b infoframe.test 15 c infoframe.test 19 test infoframe.test 41}
+} -result {a infoframe.test 5 stacktrace b infoframe.test 15 {a trace} c infoframe.test 19 {b trace} test infoframe.test 41 {c trace} {} infoframe.test 40 test\ stacktrace-1.1\ \{...}
+
+test stacktrace-1.2 {Stack trace with limited depth} -body {
+ # This will limit the stack trace to omit "this" level and below
+ c trace 0 [info frame]
+} -result {a infoframe.test 5 {stacktrace 0 2} b infoframe.test 15 {a trace 0 2} c infoframe.test 19 {b trace 0 2}}
+
testreport