blob: 5669b7b6a9bb3ace41e999a08f8ca0249bded46a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
source [file dirname [info script]]/testing.tcl
needs constraint jim; needs cmd package
proc a {} {
error "error thrown from a"
}
proc b {} {
set rc [catch {a} msg]
if {$rc} {
error $msg [info stacktrace]
}
}
test error-1.1 {Rethrow caught error} -body {
set rc [catch {b} msg]
#puts stderr "error-1.1\n[errorInfo $msg]\n"
list $rc $msg [basename-stacktrace [info stacktrace]]
} -result {1 {error thrown from a} {a error.test 4 error\ \{error\ thrown\ f... b error.test 8 a test error.test 15 b {} error.test 14 test\ error-1.1\ \{Rethr...}}
proc c {} {
a
}
proc d {} {
c
}
proc e {} {
d
}
test error-1.2 {Modify stacktrace} -body {
set rc [catch {e} msg]
set st [info stacktrace]
# Now elide one entry from the stacktrace
#puts [errorInfo $msg]
set newst {}
foreach {p f l cmd} $st {
if {$p ne "d"} {
lappend newst $p $f $l $cmd
}
}
# Now rethrow with the new stack
set rc [catch {error $msg $newst} msg]
#puts [errorInfo $msg]
basename-stacktrace [info stacktrace]
} -result {a error.test 4 error\ \{error\ thrown\ f... c error.test 22 a e error.test 30 d test error.test 34 e {} error.test 33 test\ error-1.2\ \{Modif...}
# Package should be able to invoke exit, which should exit if not caught
test error-2.1 "Exit from package" {
catch -exit {package require exitpackage} msg
} 6
testreport
|