blob: ddabe3a953623e135e3233d1481ed9ec750d0a36 [file] [log] [blame]
Bram Moolenaar296b1f22017-01-15 15:22:33 +01001" Test Vim profiler
Bram Moolenaarb0f94c12019-06-13 22:19:53 +02002
Bram Moolenaar296b1f22017-01-15 15:22:33 +01003if !has('profile')
Bram Moolenaarb0f94c12019-06-13 22:19:53 +02004 throw 'Skipped, profile feature missing'
Bram Moolenaar296b1f22017-01-15 15:22:33 +01005endif
6
7func Test_profile_func()
Bram Moolenaarc79745a2019-05-20 22:12:34 +02008 let lines =<< trim [CODE]
9 profile start Xprofile_func.log
10 profile func Foo*
11 func! Foo1()
12 endfunc
13 func! Foo2()
14 let l:count = 100
15 while l:count > 0
16 let l:count = l:count - 1
17 endwhile
18 endfunc
19 func! Foo3()
20 endfunc
21 func! Bar()
22 endfunc
23 call Foo1()
24 call Foo1()
25 profile pause
26 call Foo1()
27 profile continue
28 call Foo2()
29 call Foo3()
30 call Bar()
31 if !v:profiling
32 delfunc Foo2
33 endif
34 delfunc Foo3
35 [CODE]
Bram Moolenaar296b1f22017-01-15 15:22:33 +010036
37 call writefile(lines, 'Xprofile_func.vim')
Bram Moolenaarc011a3d2017-01-16 22:37:42 +010038 call system(v:progpath
Bram Moolenaar1fbfe7c2018-06-30 21:18:13 +020039 \ . ' -es --clean'
Bram Moolenaarc011a3d2017-01-16 22:37:42 +010040 \ . ' -c "so Xprofile_func.vim"'
41 \ . ' -c "qall!"')
42 call assert_equal(0, v:shell_error)
43
Bram Moolenaar296b1f22017-01-15 15:22:33 +010044 let lines = readfile('Xprofile_func.log')
45
Bram Moolenaar296b1f22017-01-15 15:22:33 +010046 " - Foo1() is called 3 times but should be reported as called twice
47 " since one call is in between "profile pause" .. "profile continue".
Bram Moolenaarc011a3d2017-01-16 22:37:42 +010048 " - Foo2() should come before Foo1() since Foo1() does much more work.
Bram Moolenaar296b1f22017-01-15 15:22:33 +010049 " - Foo3() is not reported because function is deleted.
50 " - Unlike Foo3(), Foo2() should not be deleted since there is a check
51 " for v:profiling.
52 " - Bar() is not reported since it does not match "profile func Foo*".
Bram Moolenaar4c7b08f2018-09-10 22:03:40 +020053 call assert_equal(30, len(lines))
Bram Moolenaarc011a3d2017-01-16 22:37:42 +010054
55 call assert_equal('FUNCTION Foo1()', lines[0])
Bram Moolenaar4c7b08f2018-09-10 22:03:40 +020056 call assert_match('Defined:.*Xprofile_func.vim', lines[1])
57 call assert_equal('Called 2 times', lines[2])
58 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[3])
59 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[4])
60 call assert_equal('', lines[5])
61 call assert_equal('count total (s) self (s)', lines[6])
62 call assert_equal('', lines[7])
63 call assert_equal('FUNCTION Foo2()', lines[8])
64 call assert_equal('Called 1 time', lines[10])
65 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[11])
66 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[12])
67 call assert_equal('', lines[13])
68 call assert_equal('count total (s) self (s)', lines[14])
69 call assert_match('^\s*1\s\+.*\slet l:count = 100$', lines[15])
70 call assert_match('^\s*101\s\+.*\swhile l:count > 0$', lines[16])
71 call assert_match('^\s*100\s\+.*\s let l:count = l:count - 1$', lines[17])
72 call assert_match('^\s*101\s\+.*\sendwhile$', lines[18])
73 call assert_equal('', lines[19])
74 call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[20])
75 call assert_equal('count total (s) self (s) function', lines[21])
76 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo2()$', lines[22])
77 call assert_match('^\s*2\s\+\d\+\.\d\+\s\+Foo1()$', lines[23])
78 call assert_equal('', lines[24])
79 call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[25])
80 call assert_equal('count total (s) self (s) function', lines[26])
81 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo2()$', lines[27])
82 call assert_match('^\s*2\s\+\d\+\.\d\+\s\+Foo1()$', lines[28])
83 call assert_equal('', lines[29])
Bram Moolenaar296b1f22017-01-15 15:22:33 +010084
85 call delete('Xprofile_func.vim')
86 call delete('Xprofile_func.log')
87endfunc
88
Bram Moolenaar7feb35e2018-08-21 17:49:54 +020089func Test_profile_func_with_ifelse()
Bram Moolenaarc79745a2019-05-20 22:12:34 +020090 let lines =<< trim [CODE]
91 func! Foo1()
92 if 1
93 let x = 0
94 elseif 1
95 let x = 1
96 else
97 let x = 2
98 endif
99 endfunc
100 func! Foo2()
101 if 0
102 let x = 0
103 elseif 1
104 let x = 1
105 else
106 let x = 2
107 endif
108 endfunc
109 func! Foo3()
110 if 0
111 let x = 0
112 elseif 0
113 let x = 1
114 else
115 let x = 2
116 endif
117 endfunc
118 call Foo1()
119 call Foo2()
120 call Foo3()
121 [CODE]
Bram Moolenaar7feb35e2018-08-21 17:49:54 +0200122
123 call writefile(lines, 'Xprofile_func.vim')
124 call system(v:progpath
125 \ . ' -es -u NONE -U NONE -i NONE --noplugin'
126 \ . ' -c "profile start Xprofile_func.log"'
127 \ . ' -c "profile func Foo*"'
128 \ . ' -c "so Xprofile_func.vim"'
129 \ . ' -c "qall!"')
130 call assert_equal(0, v:shell_error)
131
132 let lines = readfile('Xprofile_func.log')
133
134 " - Foo1() should pass 'if' block.
135 " - Foo2() should pass 'elseif' block.
136 " - Foo3() should pass 'else' block.
Bram Moolenaar4c7b08f2018-09-10 22:03:40 +0200137 call assert_equal(57, len(lines))
Bram Moolenaar7feb35e2018-08-21 17:49:54 +0200138
139 call assert_equal('FUNCTION Foo1()', lines[0])
Bram Moolenaar4c7b08f2018-09-10 22:03:40 +0200140 call assert_match('Defined:.*Xprofile_func.vim', lines[1])
141 call assert_equal('Called 1 time', lines[2])
142 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[3])
143 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[4])
144 call assert_equal('', lines[5])
145 call assert_equal('count total (s) self (s)', lines[6])
146 call assert_match('^\s*1\s\+.*\sif 1$', lines[7])
147 call assert_match('^\s*1\s\+.*\s let x = 0$', lines[8])
148 call assert_match( '^\s\+elseif 1$', lines[9])
149 call assert_match( '^\s\+let x = 1$', lines[10])
150 call assert_match( '^\s\+else$', lines[11])
151 call assert_match( '^\s\+let x = 2$', lines[12])
152 call assert_match('^\s*1\s\+.*\sendif$', lines[13])
153 call assert_equal('', lines[14])
154 call assert_equal('FUNCTION Foo2()', lines[15])
155 call assert_equal('Called 1 time', lines[17])
156 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[18])
157 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[19])
158 call assert_equal('', lines[20])
159 call assert_equal('count total (s) self (s)', lines[21])
160 call assert_match('^\s*1\s\+.*\sif 0$', lines[22])
161 call assert_match( '^\s\+let x = 0$', lines[23])
162 call assert_match('^\s*1\s\+.*\selseif 1$', lines[24])
163 call assert_match('^\s*1\s\+.*\s let x = 1$', lines[25])
164 call assert_match( '^\s\+else$', lines[26])
165 call assert_match( '^\s\+let x = 2$', lines[27])
166 call assert_match('^\s*1\s\+.*\sendif$', lines[28])
167 call assert_equal('', lines[29])
168 call assert_equal('FUNCTION Foo3()', lines[30])
169 call assert_equal('Called 1 time', lines[32])
170 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[33])
171 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[34])
172 call assert_equal('', lines[35])
173 call assert_equal('count total (s) self (s)', lines[36])
174 call assert_match('^\s*1\s\+.*\sif 0$', lines[37])
175 call assert_match( '^\s\+let x = 0$', lines[38])
176 call assert_match('^\s*1\s\+.*\selseif 0$', lines[39])
177 call assert_match( '^\s\+let x = 1$', lines[40])
178 call assert_match('^\s*1\s\+.*\selse$', lines[41])
179 call assert_match('^\s*1\s\+.*\s let x = 2$', lines[42])
180 call assert_match('^\s*1\s\+.*\sendif$', lines[43])
181 call assert_equal('', lines[44])
182 call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[45])
183 call assert_equal('count total (s) self (s) function', lines[46])
184 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[47])
185 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[48])
186 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[49])
187 call assert_equal('', lines[50])
188 call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[51])
189 call assert_equal('count total (s) self (s) function', lines[52])
190 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[53])
191 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[54])
192 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[55])
193 call assert_equal('', lines[56])
Bram Moolenaar7feb35e2018-08-21 17:49:54 +0200194
195 call delete('Xprofile_func.vim')
196 call delete('Xprofile_func.log')
197endfunc
198
199func Test_profile_func_with_trycatch()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200200 let lines =<< trim [CODE]
201 func! Foo1()
202 try
203 let x = 0
204 catch
205 let x = 1
206 finally
207 let x = 2
208 endtry
209 endfunc
210 func! Foo2()
211 try
212 throw 0
213 catch
214 let x = 1
215 finally
216 let x = 2
217 endtry
218 endfunc
219 func! Foo3()
220 try
221 throw 0
222 catch
223 throw 1
224 finally
225 let x = 2
226 endtry
227 endfunc
228 call Foo1()
229 call Foo2()
230 try
231 call Foo3()
232 catch
233 endtry
234 [CODE]
Bram Moolenaar7feb35e2018-08-21 17:49:54 +0200235
236 call writefile(lines, 'Xprofile_func.vim')
237 call system(v:progpath
238 \ . ' -es -u NONE -U NONE -i NONE --noplugin'
239 \ . ' -c "profile start Xprofile_func.log"'
240 \ . ' -c "profile func Foo*"'
241 \ . ' -c "so Xprofile_func.vim"'
242 \ . ' -c "qall!"')
243 call assert_equal(0, v:shell_error)
244
245 let lines = readfile('Xprofile_func.log')
246
247 " - Foo1() should pass 'try' 'finally' blocks.
248 " - Foo2() should pass 'catch' 'finally' blocks.
249 " - Foo3() should not pass 'endtry'.
Bram Moolenaar4c7b08f2018-09-10 22:03:40 +0200250 call assert_equal(57, len(lines))
Bram Moolenaar7feb35e2018-08-21 17:49:54 +0200251
252 call assert_equal('FUNCTION Foo1()', lines[0])
Bram Moolenaar4c7b08f2018-09-10 22:03:40 +0200253 call assert_match('Defined:.*Xprofile_func.vim', lines[1])
254 call assert_equal('Called 1 time', lines[2])
255 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[3])
256 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[4])
257 call assert_equal('', lines[5])
258 call assert_equal('count total (s) self (s)', lines[6])
259 call assert_match('^\s*1\s\+.*\stry$', lines[7])
260 call assert_match('^\s*1\s\+.*\s let x = 0$', lines[8])
261 call assert_match( '^\s\+catch$', lines[9])
262 call assert_match( '^\s\+let x = 1$', lines[10])
263 call assert_match('^\s*1\s\+.*\sfinally$', lines[11])
264 call assert_match('^\s*1\s\+.*\s let x = 2$', lines[12])
265 call assert_match('^\s*1\s\+.*\sendtry$', lines[13])
266 call assert_equal('', lines[14])
267 call assert_equal('FUNCTION Foo2()', lines[15])
268 call assert_equal('Called 1 time', lines[17])
269 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[18])
270 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[19])
271 call assert_equal('', lines[20])
272 call assert_equal('count total (s) self (s)', lines[21])
273 call assert_match('^\s*1\s\+.*\stry$', lines[22])
274 call assert_match('^\s*1\s\+.*\s throw 0$', lines[23])
275 call assert_match('^\s*1\s\+.*\scatch$', lines[24])
276 call assert_match('^\s*1\s\+.*\s let x = 1$', lines[25])
277 call assert_match('^\s*1\s\+.*\sfinally$', lines[26])
278 call assert_match('^\s*1\s\+.*\s let x = 2$', lines[27])
279 call assert_match('^\s*1\s\+.*\sendtry$', lines[28])
280 call assert_equal('', lines[29])
281 call assert_equal('FUNCTION Foo3()', lines[30])
282 call assert_equal('Called 1 time', lines[32])
283 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[33])
284 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[34])
285 call assert_equal('', lines[35])
286 call assert_equal('count total (s) self (s)', lines[36])
287 call assert_match('^\s*1\s\+.*\stry$', lines[37])
288 call assert_match('^\s*1\s\+.*\s throw 0$', lines[38])
289 call assert_match('^\s*1\s\+.*\scatch$', lines[39])
290 call assert_match('^\s*1\s\+.*\s throw 1$', lines[40])
291 call assert_match('^\s*1\s\+.*\sfinally$', lines[41])
292 call assert_match('^\s*1\s\+.*\s let x = 2$', lines[42])
293 call assert_match( '^\s\+endtry$', lines[43])
294 call assert_equal('', lines[44])
295 call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[45])
296 call assert_equal('count total (s) self (s) function', lines[46])
297 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[47])
298 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[48])
299 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[49])
300 call assert_equal('', lines[50])
301 call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[51])
302 call assert_equal('count total (s) self (s) function', lines[52])
303 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[53])
304 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[54])
305 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[55])
306 call assert_equal('', lines[56])
Bram Moolenaar7feb35e2018-08-21 17:49:54 +0200307
308 call delete('Xprofile_func.vim')
309 call delete('Xprofile_func.log')
310endfunc
311
Bram Moolenaar296b1f22017-01-15 15:22:33 +0100312func Test_profile_file()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200313 let lines =<< trim [CODE]
314 func! Foo()
315 endfunc
316 for i in range(10)
317 " a comment
318 call Foo()
319 endfor
320 call Foo()
321 [CODE]
Bram Moolenaar296b1f22017-01-15 15:22:33 +0100322
323 call writefile(lines, 'Xprofile_file.vim')
Bram Moolenaarc011a3d2017-01-16 22:37:42 +0100324 call system(v:progpath
Bram Moolenaar1fbfe7c2018-06-30 21:18:13 +0200325 \ . ' -es --clean'
Bram Moolenaarc011a3d2017-01-16 22:37:42 +0100326 \ . ' -c "profile start Xprofile_file.log"'
327 \ . ' -c "profile file Xprofile_file.vim"'
328 \ . ' -c "so Xprofile_file.vim"'
329 \ . ' -c "so Xprofile_file.vim"'
330 \ . ' -c "qall!"')
331 call assert_equal(0, v:shell_error)
Bram Moolenaar296b1f22017-01-15 15:22:33 +0100332
333 let lines = readfile('Xprofile_file.log')
334
335 call assert_equal(14, len(lines))
336
337 call assert_match('^SCRIPT .*Xprofile_file.vim$', lines[0])
338 call assert_equal('Sourced 2 times', lines[1])
339 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[2])
340 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[3])
341 call assert_equal('', lines[4])
342 call assert_equal('count total (s) self (s)', lines[5])
Bram Moolenaar67435d92017-10-19 21:04:37 +0200343 call assert_match(' 2 0.\d\+ func! Foo()', lines[6])
Bram Moolenaar296b1f22017-01-15 15:22:33 +0100344 call assert_equal(' endfunc', lines[7])
345 " Loop iterates 10 times. Since script runs twice, body executes 20 times.
346 " First line of loop executes one more time than body to detect end of loop.
347 call assert_match('^\s*22\s\+\d\+\.\d\+\s\+for i in range(10)$', lines[8])
348 call assert_equal(' " a comment', lines[9])
Bram Moolenaard21b16f2017-08-14 23:13:30 +0200349 " if self and total are equal we only get one number
350 call assert_match('^\s*20\s\+\(\d\+\.\d\+\s\+\)\=\d\+\.\d\+\s\+call Foo()$', lines[10])
Bram Moolenaar7feb35e2018-08-21 17:49:54 +0200351 call assert_match('^\s*22\s\+\d\+\.\d\+\s\+endfor$', lines[11])
Bram Moolenaare32bbde2017-01-15 21:12:48 +0100352 " if self and total are equal we only get one number
353 call assert_match('^\s*2\s\+\(\d\+\.\d\+\s\+\)\=\d\+\.\d\+\s\+call Foo()$', lines[12])
Bram Moolenaar296b1f22017-01-15 15:22:33 +0100354 call assert_equal('', lines[13])
355
356 call delete('Xprofile_file.vim')
357 call delete('Xprofile_file.log')
358endfunc
359
Bram Moolenaar67435d92017-10-19 21:04:37 +0200360func Test_profile_file_with_cont()
361 let lines = [
362 \ 'echo "hello',
363 \ ' \ world"',
364 \ 'echo "foo ',
365 \ ' \bar"',
366 \ ]
367
368 call writefile(lines, 'Xprofile_file.vim')
369 call system(v:progpath
370 \ . ' -es --clean'
371 \ . ' -c "profile start Xprofile_file.log"'
372 \ . ' -c "profile file Xprofile_file.vim"'
373 \ . ' -c "so Xprofile_file.vim"'
374 \ . ' -c "qall!"')
375 call assert_equal(0, v:shell_error)
376
377 let lines = readfile('Xprofile_file.log')
378 call assert_equal(11, len(lines))
379
Bram Moolenaar1fbfe7c2018-06-30 21:18:13 +0200380 call assert_match('^SCRIPT .*Xprofile_file.vim$', lines[0])
381 call assert_equal('Sourced 1 time', lines[1])
382 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[2])
383 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[3])
384 call assert_equal('', lines[4])
385 call assert_equal('count total (s) self (s)', lines[5])
386 call assert_match(' 1 0.\d\+ echo "hello', lines[6])
387 call assert_equal(' \ world"', lines[7])
388 call assert_match(' 1 0.\d\+ echo "foo ', lines[8])
389 call assert_equal(' \bar"', lines[9])
390 call assert_equal('', lines[10])
Bram Moolenaar67435d92017-10-19 21:04:37 +0200391
392 call delete('Xprofile_file.vim')
393 call delete('Xprofile_file.log')
394endfunc
395
Bram Moolenaar296b1f22017-01-15 15:22:33 +0100396func Test_profile_completion()
397 call feedkeys(":profile \<C-A>\<C-B>\"\<CR>", 'tx')
398 call assert_equal('"profile continue file func pause start', @:)
399
400 call feedkeys(":profile start test_prof\<C-A>\<C-B>\"\<CR>", 'tx')
401 call assert_match('^"profile start.* test_profile\.vim', @:)
402endfunc
403
404func Test_profile_errors()
405 call assert_fails("profile func Foo", 'E750:')
406 call assert_fails("profile pause", 'E750:')
407 call assert_fails("profile continue", 'E750:')
408endfunc
Bram Moolenaarac112f02017-12-05 16:46:28 +0100409
410func Test_profile_truncate_mbyte()
Bram Moolenaar30276f22019-01-24 17:59:39 +0100411 if &enc !=# 'utf-8'
Bram Moolenaarac112f02017-12-05 16:46:28 +0100412 return
413 endif
414
415 let lines = [
416 \ 'scriptencoding utf-8',
417 \ 'func! Foo()',
418 \ ' return [',
419 \ ' \ "' . join(map(range(0x4E00, 0x4E00 + 340), 'nr2char(v:val)'), '') . '",',
420 \ ' \ "' . join(map(range(0x4F00, 0x4F00 + 340), 'nr2char(v:val)'), '') . '",',
421 \ ' \ ]',
422 \ 'endfunc',
423 \ 'call Foo()',
424 \ ]
425
426 call writefile(lines, 'Xprofile_file.vim')
427 call system(v:progpath
428 \ . ' -es --clean --cmd "set enc=utf-8"'
429 \ . ' -c "profile start Xprofile_file.log"'
430 \ . ' -c "profile file Xprofile_file.vim"'
431 \ . ' -c "so Xprofile_file.vim"'
432 \ . ' -c "qall!"')
433 call assert_equal(0, v:shell_error)
434
435 split Xprofile_file.log
436 if &fenc != ''
437 call assert_equal('utf-8', &fenc)
438 endif
439 /func! Foo()
440 let lnum = line('.')
441 call assert_match('^\s*return \[$', getline(lnum + 1))
442 call assert_match("\u4F52$", getline(lnum + 2))
443 call assert_match("\u5052$", getline(lnum + 3))
444 call assert_match('^\s*\\ \]$', getline(lnum + 4))
445 bwipe!
446
447 call delete('Xprofile_file.vim')
448 call delete('Xprofile_file.log')
449endfunc
Bram Moolenaar1fbfe7c2018-06-30 21:18:13 +0200450
451func Test_profdel_func()
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200452 let lines =<< trim [CODE]
453 profile start Xprofile_file.log
454 func! Foo1()
455 endfunc
456 func! Foo2()
457 endfunc
458 func! Foo3()
459 endfunc
460
461 profile func Foo1
462 profile func Foo2
463 call Foo1()
464 call Foo2()
465
466 profile func Foo3
467 profdel func Foo2
468 profdel func Foo3
469 call Foo1()
470 call Foo2()
471 call Foo3()
472 [CODE]
Bram Moolenaar1fbfe7c2018-06-30 21:18:13 +0200473 call writefile(lines, 'Xprofile_file.vim')
474 call system(v:progpath . ' -es --clean -c "so Xprofile_file.vim" -c q')
475 call assert_equal(0, v:shell_error)
476
477 let lines = readfile('Xprofile_file.log')
Bram Moolenaar4c7b08f2018-09-10 22:03:40 +0200478 call assert_equal(26, len(lines))
Bram Moolenaar1fbfe7c2018-06-30 21:18:13 +0200479
480 " Check that:
481 " - Foo1() is called twice (profdel not invoked)
482 " - Foo2() is called once (profdel invoked after it was called)
483 " - Foo3() is not called (profdel invoked before it was called)
484 call assert_equal('FUNCTION Foo1()', lines[0])
Bram Moolenaar4c7b08f2018-09-10 22:03:40 +0200485 call assert_match('Defined:.*Xprofile_file.vim', lines[1])
486 call assert_equal('Called 2 times', lines[2])
487 call assert_equal('FUNCTION Foo2()', lines[8])
488 call assert_equal('Called 1 time', lines[10])
489 call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[16])
490 call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[21])
Bram Moolenaar1fbfe7c2018-06-30 21:18:13 +0200491
492 call delete('Xprofile_file.vim')
493 call delete('Xprofile_file.log')
494endfunc
495
496func Test_profdel_star()
497 " Foo() is invoked once before and once after 'profdel *'.
498 " So profiling should report it only once.
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200499 let lines =<< trim [CODE]
500 profile start Xprofile_file.log
501 func! Foo()
502 endfunc
503 profile func Foo
504 call Foo()
505 profdel *
506 call Foo()
507 [CODE]
Bram Moolenaar1fbfe7c2018-06-30 21:18:13 +0200508 call writefile(lines, 'Xprofile_file.vim')
509 call system(v:progpath . ' -es --clean -c "so Xprofile_file.vim" -c q')
510 call assert_equal(0, v:shell_error)
511
512 let lines = readfile('Xprofile_file.log')
Bram Moolenaar4c7b08f2018-09-10 22:03:40 +0200513 call assert_equal(16, len(lines))
Bram Moolenaar1fbfe7c2018-06-30 21:18:13 +0200514
515 call assert_equal('FUNCTION Foo()', lines[0])
Bram Moolenaar4c7b08f2018-09-10 22:03:40 +0200516 call assert_match('Defined:.*Xprofile_file.vim', lines[1])
517 call assert_equal('Called 1 time', lines[2])
518 call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[8])
519 call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[12])
Bram Moolenaar1fbfe7c2018-06-30 21:18:13 +0200520
521 call delete('Xprofile_file.vim')
522 call delete('Xprofile_file.log')
523endfunc