11" Test for getstacktrace() and v:stacktrace
22
3+ import ' ./vim9.vim' as v9
4+
35let s: thisfile = expand (' %:p' )
46let s: testdir = s: thisfile- >fnamemodify (' :h' )
57
@@ -34,7 +36,7 @@ func Test_getstacktrace()
3436 source Xscript1
3537 call Xfunc1 ()
3638 call AssertStacktrace ([
37- \ #{funcref : funcref (' Test_getstacktrace' ), lnum: 35 , filepath: s: thisfile },
39+ \ #{funcref : funcref (' Test_getstacktrace' ), lnum: 37 , filepath: s: thisfile },
3840 \ #{funcref : funcref (' Xfunc1' ), lnum: 5 , filepath: Filepath (' Xscript1' )},
3941 \ #{funcref : funcref (' Xfunc2' ), lnum: 4 , filepath: Filepath (' Xscript2' )},
4042 \ ], g: stacktrace )
@@ -61,7 +63,7 @@ func Test_getstacktrace_event()
6163 source Xscript1
6264 source Xscript2
6365 call AssertStacktrace ([
64- \ #{funcref : funcref (' Test_getstacktrace_event' ), lnum: 62 , filepath: s: thisfile },
66+ \ #{funcref : funcref (' Test_getstacktrace_event' ), lnum: 64 , filepath: s: thisfile },
6567 \ #{event : ' SourcePre Autocommands for "*"' , lnum: 7 , filepath: Filepath (' Xscript1' )},
6668 \ #{funcref : funcref (' Xfunc' ), lnum: 4 , filepath: Filepath (' Xscript1' )},
6769 \ ], g: stacktrace )
@@ -98,10 +100,33 @@ func Test_vstacktrace()
98100 endtry
99101 call assert_equal ([], v: stacktrace )
100102 call AssertStacktrace ([
101- \ #{funcref : funcref (' Test_vstacktrace' ), lnum: 95 , filepath: s: thisfile },
103+ \ #{funcref : funcref (' Test_vstacktrace' ), lnum: 97 , filepath: s: thisfile },
102104 \ #{funcref : funcref (' Xfunc1' ), lnum: 5 , filepath: Filepath (' Xscript1' )},
103105 \ #{funcref : funcref (' Xfunc2' ), lnum: 4 , filepath: Filepath (' Xscript2' )},
104106 \ ], stacktrace)
105107endfunc
106108
109+ func Test_zzz_stacktrace_vim9 ()
110+ let lines = << trim [SCRIPT]
111+ var stacktrace = getstacktrace ()
112+ assert_notequal ([], stacktrace)
113+ for d in stacktrace
114+ assert_true (has_key (d , ' lnum' ))
115+ endfor
116+ try
117+ throw ' Exception from s:Func'
118+ catch
119+ assert_notequal ([], v: stacktrace )
120+ assert_equal (len (stacktrace), len (v: stacktrace ))
121+ for d in v: stacktrace
122+ assert_true (has_key (d , ' lnum' ))
123+ endfor
124+ endtry
125+ [SCRIPT]
126+ call v9.CheckDefSuccess (lines )
127+ " FIXME: v:stacktrace is not cleared after the exception handling, and this
128+ " test has to be run as the last one because of this.
129+ " call assert_equal([], v:stacktrace)
130+ endfunc
131+
107132" vim: shiftwidth = 2 sts = 2 expandtab
0 commit comments