Mercurial > vim
comparison src/testdir/test_profile.vim @ 23725:f98692ae09a0 v8.2.2404
patch 8.2.2404: Vim9: profiling try/catch not correct
Commit: https://github.com/vim/vim/commit/107e9cecf72928b4aaaf08b73bf2d191924ab695
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 24 20:52:00 2021 +0100
patch 8.2.2404: Vim9: profiling try/catch not correct
Problem: Vim9: profiling try/catch not correct.
Solution: Add profile instructions. Fix that "entry" did not rethrow an
excpetion.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 24 Jan 2021 21:00:04 +0100 |
parents | 14e92f4c98c9 |
children | 7caffd835aa1 |
comparison
equal
deleted
inserted
replaced
23724:85e6fa8b86f7 | 23725:f98692ae09a0 |
---|---|
98 call delete('Xprofile_func.vim') | 98 call delete('Xprofile_func.vim') |
99 call delete('Xprofile_func.log') | 99 call delete('Xprofile_func.log') |
100 endfunc | 100 endfunc |
101 | 101 |
102 func Test_profile_func_with_ifelse() | 102 func Test_profile_func_with_ifelse() |
103 call Run_profile_func_with_ifelse('func', 'let', 'let') | 103 call Run_profile_func_with_ifelse('func', 'let') |
104 call Run_profile_func_with_ifelse('def', 'var', '') | 104 call Run_profile_func_with_ifelse('def', 'var') |
105 endfunc | 105 endfunc |
106 | 106 |
107 func Run_profile_func_with_ifelse(command, declare, assign) | 107 func Run_profile_func_with_ifelse(command, declare) |
108 let lines =<< trim [CODE] | 108 let lines =<< trim [CODE] |
109 XXX Foo1() | 109 XXX Foo1() |
110 if 1 | 110 if 1 |
111 DDD x = 0 | 111 DDD x = 0 |
112 elseif 1 | 112 elseif 1 |
138 call Foo3() | 138 call Foo3() |
139 [CODE] | 139 [CODE] |
140 | 140 |
141 call map(lines, {k, v -> substitute(v, 'XXX', a:command, '') }) | 141 call map(lines, {k, v -> substitute(v, 'XXX', a:command, '') }) |
142 call map(lines, {k, v -> substitute(v, 'DDD', a:declare, '') }) | 142 call map(lines, {k, v -> substitute(v, 'DDD', a:declare, '') }) |
143 call map(lines, {k, v -> substitute(v, 'AAA', a:assign, '') }) | |
144 | 143 |
145 call writefile(lines, 'Xprofile_func.vim') | 144 call writefile(lines, 'Xprofile_func.vim') |
146 call system(GetVimCommand() | 145 call system(GetVimCommand() |
147 \ . ' -es -i NONE --noplugin' | 146 \ . ' -es -i NONE --noplugin' |
148 \ . ' -c "profile start Xprofile_func.log"' | 147 \ . ' -c "profile start Xprofile_func.log"' |
217 call delete('Xprofile_func.vim') | 216 call delete('Xprofile_func.vim') |
218 call delete('Xprofile_func.log') | 217 call delete('Xprofile_func.log') |
219 endfunc | 218 endfunc |
220 | 219 |
221 func Test_profile_func_with_trycatch() | 220 func Test_profile_func_with_trycatch() |
221 call Run_profile_func_with_trycatch('func', 'let') | |
222 call Run_profile_func_with_trycatch('def', 'var') | |
223 endfunc | |
224 | |
225 func Run_profile_func_with_trycatch(command, declare) | |
222 let lines =<< trim [CODE] | 226 let lines =<< trim [CODE] |
223 func! Foo1() | 227 XXX Foo1() |
224 try | 228 try |
225 let x = 0 | 229 DDD x = 0 |
226 catch | 230 catch |
227 let x = 1 | 231 DDD x = 1 |
228 finally | 232 finally |
229 let x = 2 | 233 DDD x = 2 |
230 endtry | 234 endtry |
231 endfunc | 235 endXXX |
232 func! Foo2() | 236 XXX Foo2() |
233 try | 237 try |
234 throw 0 | 238 throw 0 |
235 catch | 239 catch |
236 let x = 1 | 240 DDD x = 1 |
237 finally | 241 finally |
238 let x = 2 | 242 DDD x = 2 |
239 endtry | 243 endtry |
240 endfunc | 244 endXXX |
241 func! Foo3() | 245 XXX Foo3() |
242 try | 246 try |
243 throw 0 | 247 throw 0 |
244 catch | 248 catch |
245 throw 1 | 249 throw 1 |
246 finally | 250 finally |
247 let x = 2 | 251 DDD x = 2 |
248 endtry | 252 endtry |
249 endfunc | 253 endXXX |
250 call Foo1() | 254 call Foo1() |
251 call Foo2() | 255 call Foo2() |
256 let rethrown = 0 | |
252 try | 257 try |
253 call Foo3() | 258 call Foo3() |
254 catch | 259 catch |
260 let rethrown = 1 | |
255 endtry | 261 endtry |
262 if rethrown != 1 | |
263 " call Foo1 again so that the test fails | |
264 call Foo1() | |
265 endif | |
256 [CODE] | 266 [CODE] |
267 | |
268 call map(lines, {k, v -> substitute(v, 'XXX', a:command, '') }) | |
269 call map(lines, {k, v -> substitute(v, 'DDD', a:declare, '') }) | |
257 | 270 |
258 call writefile(lines, 'Xprofile_func.vim') | 271 call writefile(lines, 'Xprofile_func.vim') |
259 call system(GetVimCommand() | 272 call system(GetVimCommand() |
260 \ . ' -es -i NONE --noplugin' | 273 \ . ' -es -i NONE --noplugin' |
261 \ . ' -c "profile start Xprofile_func.log"' | 274 \ . ' -c "profile start Xprofile_func.log"' |
277 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[3]) | 290 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[3]) |
278 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[4]) | 291 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[4]) |
279 call assert_equal('', lines[5]) | 292 call assert_equal('', lines[5]) |
280 call assert_equal('count total (s) self (s)', lines[6]) | 293 call assert_equal('count total (s) self (s)', lines[6]) |
281 call assert_match('^\s*1\s\+.*\stry$', lines[7]) | 294 call assert_match('^\s*1\s\+.*\stry$', lines[7]) |
282 call assert_match('^\s*1\s\+.*\s let x = 0$', lines[8]) | 295 call assert_match('^\s*1\s\+.*\s \(let\|var\) x = 0$', lines[8]) |
283 call assert_match( '^\s\+catch$', lines[9]) | 296 call assert_match( '^\s\+catch$', lines[9]) |
284 call assert_match( '^\s\+let x = 1$', lines[10]) | 297 call assert_match( '^\s\+\(let\|var\) x = 1$', lines[10]) |
285 call assert_match('^\s*1\s\+.*\sfinally$', lines[11]) | 298 call assert_match('^\s*1\s\+.*\sfinally$', lines[11]) |
286 call assert_match('^\s*1\s\+.*\s let x = 2$', lines[12]) | 299 call assert_match('^\s*1\s\+.*\s \(let\|var\) x = 2$', lines[12]) |
287 call assert_match('^\s*1\s\+.*\sendtry$', lines[13]) | 300 call assert_match('^\s*1\s\+.*\sendtry$', lines[13]) |
288 call assert_equal('', lines[14]) | 301 call assert_equal('', lines[14]) |
289 call assert_equal('FUNCTION Foo2()', lines[15]) | 302 call assert_equal('FUNCTION Foo2()', lines[15]) |
290 call assert_equal('Called 1 time', lines[17]) | 303 call assert_equal('Called 1 time', lines[17]) |
291 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[18]) | 304 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[18]) |
293 call assert_equal('', lines[20]) | 306 call assert_equal('', lines[20]) |
294 call assert_equal('count total (s) self (s)', lines[21]) | 307 call assert_equal('count total (s) self (s)', lines[21]) |
295 call assert_match('^\s*1\s\+.*\stry$', lines[22]) | 308 call assert_match('^\s*1\s\+.*\stry$', lines[22]) |
296 call assert_match('^\s*1\s\+.*\s throw 0$', lines[23]) | 309 call assert_match('^\s*1\s\+.*\s throw 0$', lines[23]) |
297 call assert_match('^\s*1\s\+.*\scatch$', lines[24]) | 310 call assert_match('^\s*1\s\+.*\scatch$', lines[24]) |
298 call assert_match('^\s*1\s\+.*\s let x = 1$', lines[25]) | 311 call assert_match('^\s*1\s\+.*\s \(let\|var\) x = 1$', lines[25]) |
299 call assert_match('^\s*1\s\+.*\sfinally$', lines[26]) | 312 call assert_match('^\s*1\s\+.*\sfinally$', lines[26]) |
300 call assert_match('^\s*1\s\+.*\s let x = 2$', lines[27]) | 313 call assert_match('^\s*1\s\+.*\s \(let\|var\) x = 2$', lines[27]) |
301 call assert_match('^\s*1\s\+.*\sendtry$', lines[28]) | 314 call assert_match('^\s*1\s\+.*\sendtry$', lines[28]) |
302 call assert_equal('', lines[29]) | 315 call assert_equal('', lines[29]) |
303 call assert_equal('FUNCTION Foo3()', lines[30]) | 316 call assert_equal('FUNCTION Foo3()', lines[30]) |
304 call assert_equal('Called 1 time', lines[32]) | 317 call assert_equal('Called 1 time', lines[32]) |
305 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[33]) | 318 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[33]) |
309 call assert_match('^\s*1\s\+.*\stry$', lines[37]) | 322 call assert_match('^\s*1\s\+.*\stry$', lines[37]) |
310 call assert_match('^\s*1\s\+.*\s throw 0$', lines[38]) | 323 call assert_match('^\s*1\s\+.*\s throw 0$', lines[38]) |
311 call assert_match('^\s*1\s\+.*\scatch$', lines[39]) | 324 call assert_match('^\s*1\s\+.*\scatch$', lines[39]) |
312 call assert_match('^\s*1\s\+.*\s throw 1$', lines[40]) | 325 call assert_match('^\s*1\s\+.*\s throw 1$', lines[40]) |
313 call assert_match('^\s*1\s\+.*\sfinally$', lines[41]) | 326 call assert_match('^\s*1\s\+.*\sfinally$', lines[41]) |
314 call assert_match('^\s*1\s\+.*\s let x = 2$', lines[42]) | 327 call assert_match('^\s*1\s\+.*\s \(let\|var\) x = 2$', lines[42]) |
315 call assert_match( '^\s\+endtry$', lines[43]) | 328 call assert_match( '^\s\+endtry$', lines[43]) |
316 call assert_equal('', lines[44]) | 329 call assert_equal('', lines[44]) |
317 call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[45]) | 330 call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[45]) |
318 call assert_equal('count total (s) self (s) function', lines[46]) | 331 call assert_equal('count total (s) self (s) function', lines[46]) |
319 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[47]) | 332 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[47]) |