tcltest: do a better job of cleanup up after tests
[jimtcl.git] / tests / stacktrace.test
blob847297bed83fa4eb31d9b61081ff91d35d89190f
1 source [file dirname [info script]]/testing.tcl
2 needs constraint jim; needs cmd package
3 package require errors
4 # Make this a proc so that the line numbers don't have to change
5 proc main {} {
6         set id1 0
7         foreach type {badcmd badvar badproc error interpbadvar interpbadcmd package source badpackage returncode} {
8                 set id2 0
9                 incr id1
10                 foreach method {call uplevel eval evalstr} {
11                         incr id2
12                         set exp ""
13                         if {[info exists ::expected(err-$id1.$id2)]} {
14                                 set exp $::expected(err-$id1.$id2)
15                         }
16                         test err-$id1.$id2 "Stacktrace on error type $type, method $method" {
17                                 set rc [catch {error_caller $type $method} msg]
18                                 #puts "\n-----------------\n$type, $method\n[errorInfo $msg]\n\n"
19                                 if {$::SHOW_EXPECTED} { puts stderr "\terr-$id1.$id2 {[list $rc $msg [info stacktrace]]}" }
21                                 list $rc $msg [info stacktrace]
22                         } $exp
23                 }
24         }
25         proc unknown {args} {
26                 error "from unknown"
27         }
29         test err-10.1 "Stacktrace on error from unknown (badcmd, call)" {
30                 set rc [catch {error_caller badcmd call} msg]
31                 #puts stderr "err-10.1\n[errorInfo $msg]\n"
32                 #puts stderr "\terr-10.1 {[list $rc $msg [info stacktrace]]}"
34                 list $rc $msg [info stacktrace]
35         } {1 {from unknown} {{} stacktrace.test 26 {} errors.tcl 6 error_generator errors.tcl 44 error_caller stacktrace.test 30}}
37         rename unknown ""
39         set a {one}
40         set b [list 1 \
41                 2 \
42                 3]
43         set c {two}
44         set d "list 1 
45                 2 
46                 3"
47         set e {three}
48         set f "list 1  \
49                 2  \
50                 3"
51         set g {four}
53         test source-1.1 "Basic line numbers" {
54                 info source $a
55         } {stacktrace.test 39}
57         test source-1.2 "Line numbers after command with escaped newlines" {
58                 info source $c
59         } {stacktrace.test 43}
60         test source-1.3 "Line numbers after string with newlines" {
61                 info source $e
62         } {stacktrace.test 47}
63         test source-1.4 "Line numbers after string with escaped newlines" {
64                 info source $g
65         } {stacktrace.test 51}
68 set expected {
69         err-1.1 {1 {invalid command name "bogus"} {{} errors.tcl 6 error_generator errors.tcl 44 error_caller stacktrace.test 17}}
70         err-1.2 {1 {invalid command name "bogus"} {{} errors.tcl 6 error_generator errors.tcl 47 error_caller stacktrace.test 17}}
71         err-1.3 {1 {invalid command name "bogus"} {{} errors.tcl 6 error_generator errors.tcl 50 error_caller stacktrace.test 17}}
72         err-1.4 {1 {invalid command name "bogus"} {{} errors.tcl 6 error_generator errors.tcl 53 error_caller stacktrace.test 17}}
73         err-2.1 {1 {can't read "bogus": no such variable} {{} errors.tcl 9 error_generator errors.tcl 44 error_caller stacktrace.test 17}}
74         err-2.2 {1 {can't read "bogus": no such variable} {{} errors.tcl 9 error_generator errors.tcl 47 error_caller stacktrace.test 17}}
75         err-2.3 {1 {can't read "bogus": no such variable} {{} errors.tcl 9 error_generator errors.tcl 50 error_caller stacktrace.test 17}}
76         err-2.4 {1 {can't read "bogus": no such variable} {{} errors.tcl 9 error_generator errors.tcl 53 error_caller stacktrace.test 17}}
77         err-3.1 {1 {unmatched "["} {{} errors.tcl 62 error_badproc errors.tcl 33 error_generator errors.tcl 44 error_caller stacktrace.test 17}}
78         err-3.2 {1 {unmatched "["} {{} errors.tcl 62 error_badproc errors.tcl 33 error_generator errors.tcl 47 error_caller stacktrace.test 17}}
79         err-3.3 {1 {unmatched "["} {{} errors.tcl 62 error_badproc errors.tcl 33 error_generator errors.tcl 50 error_caller stacktrace.test 17}}
80         err-3.4 {1 {unmatched "["} {{} errors.tcl 62 error_badproc errors.tcl 33 error_generator errors.tcl 53 error_caller stacktrace.test 17}}
81         err-4.1 {1 bogus {{} errors.tcl 12 error_generator errors.tcl 44 error_caller stacktrace.test 17}}
82         err-4.2 {1 bogus {{} errors.tcl 12 error_generator errors.tcl 47 error_caller stacktrace.test 17}}
83         err-4.3 {1 bogus {{} errors.tcl 12 error_generator errors.tcl 50 error_caller stacktrace.test 17}}
84         err-4.4 {1 bogus {{} errors.tcl 12 error_generator errors.tcl 53 error_caller stacktrace.test 17}}
85         err-5.1 {1 {can't read "bogus": no such variable} {{} errors.tcl 15 error_generator errors.tcl 44 error_caller stacktrace.test 17}}
86         err-5.2 {1 {can't read "bogus": no such variable} {{} errors.tcl 15 error_generator errors.tcl 47 error_caller stacktrace.test 17}}
87         err-5.3 {1 {can't read "bogus": no such variable} {{} errors.tcl 15 error_generator errors.tcl 50 error_caller stacktrace.test 17}}
88         err-5.4 {1 {can't read "bogus": no such variable} {{} errors.tcl 15 error_generator errors.tcl 53 error_caller stacktrace.test 17}}
89         err-6.1 {1 {can't read "bogus": no such variable} {{} errors.tcl 18 error_generator errors.tcl 44 error_caller stacktrace.test 17}}
90         err-6.2 {1 {can't read "bogus": no such variable} {{} errors.tcl 18 error_generator errors.tcl 47 error_caller stacktrace.test 17}}
91         err-6.3 {1 {can't read "bogus": no such variable} {{} errors.tcl 18 error_generator errors.tcl 50 error_caller stacktrace.test 17}}
92         err-6.4 {1 {can't read "bogus": no such variable} {{} errors.tcl 18 error_generator errors.tcl 53 error_caller stacktrace.test 17}}
93         err-7.1 {1 {from dummyproc
94 Can't load package dummy} {{} dummy.tcl 3 dummyproc dummy.tcl 6 {} errors.tcl 21 error_generator errors.tcl 44 error_caller stacktrace.test 17}}
95         err-7.2 {1 {from dummyproc
96 Can't load package dummy} {{} dummy.tcl 3 dummyproc dummy.tcl 6 {} errors.tcl 21 error_generator errors.tcl 47 error_caller stacktrace.test 17}}
97         err-7.3 {1 {from dummyproc
98 Can't load package dummy} {{} dummy.tcl 3 dummyproc dummy.tcl 6 {} errors.tcl 21 error_generator errors.tcl 50 error_caller stacktrace.test 17}}
99         err-7.4 {1 {from dummyproc
100 Can't load package dummy} {{} dummy.tcl 3 dummyproc dummy.tcl 6 {} errors.tcl 21 error_generator errors.tcl 53 error_caller stacktrace.test 17}}
101         err-8.1 {1 {from dummyproc} {{} dummy.tcl 3 dummyproc dummy.tcl 6 {} errors.tcl 24 error_generator errors.tcl 44 error_caller stacktrace.test 17}}
102         err-8.2 {1 {from dummyproc} {{} dummy.tcl 3 dummyproc dummy.tcl 6 {} errors.tcl 24 error_generator errors.tcl 47 error_caller stacktrace.test 17}}
103         err-8.3 {1 {from dummyproc} {{} dummy.tcl 3 dummyproc dummy.tcl 6 {} errors.tcl 24 error_generator errors.tcl 50 error_caller stacktrace.test 17}}
104         err-8.4 {1 {from dummyproc} {{} dummy.tcl 3 dummyproc dummy.tcl 6 {} errors.tcl 24 error_generator errors.tcl 53 error_caller stacktrace.test 17}}
105         err-9.1 {1 {Can't load package bogus} {{} errors.tcl 27 error_generator errors.tcl 44 error_caller stacktrace.test 17}}
106         err-9.2 {1 {Can't load package bogus} {{} errors.tcl 27 error_generator errors.tcl 47 error_caller stacktrace.test 17}}
107         err-9.3 {1 {Can't load package bogus} {{} errors.tcl 27 error_generator errors.tcl 50 error_caller stacktrace.test 17}}
108         err-9.4 {1 {Can't load package bogus} {{} errors.tcl 27 error_generator errors.tcl 53 error_caller stacktrace.test 17}}
109         err-10.1 {1 failure {{} errors.tcl 44 error_caller stacktrace.test 17}}
110         err-10.2 {1 failure {{} errors.tcl 47 error_caller stacktrace.test 17}}
111         err-10.3 {1 failure {{} errors.tcl 50 error_caller stacktrace.test 17}}
112         err-10.4 {1 failure {{} errors.tcl 53 error_caller stacktrace.test 17}}
115 # Set this to output expected results to stderr
116 # in a form which can be pasted into 'expected' below
117 set SHOW_EXPECTED 0
119 main
121 testreport