Mercurial > vim
comparison src/testdir/test_profile.vim @ 10599:2748b23db6bb v8.0.0189
patch 8.0.0189: profile commands are not tested
commit https://github.com/vim/vim/commit/296b1f28ca9cedeb55872f306808b2214b519ce7
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 15 15:22:33 2017 +0100
patch 8.0.0189: profile commands are not tested
Problem: There are no tests for the :profile command.
Solution: Add tests. (Dominique Pelle, closes https://github.com/vim/vim/issues/1383)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 15 Jan 2017 15:30:04 +0100 |
parents | |
children | 302aedeed8c9 |
comparison
equal
deleted
inserted
replaced
10598:2231f9670ea3 | 10599:2748b23db6bb |
---|---|
1 " Test Vim profiler | |
2 if !has('profile') | |
3 finish | |
4 endif | |
5 | |
6 func Test_profile_func() | |
7 if !has('unix') | |
8 return | |
9 endif | |
10 let lines = [ | |
11 \ "func! Foo1()", | |
12 \ "endfunc", | |
13 \ "func! Foo2()", | |
14 \ " let count = 100", | |
15 \ " while count > 0", | |
16 \ " let count = 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 \ ] | |
36 | |
37 call writefile(lines, 'Xprofile_func.vim') | |
38 let a = system(v:progpath | |
39 \ . " -u NONE -i NONE --noplugin" | |
40 \ . " -c 'profile start Xprofile_func.log'" | |
41 \ . " -c 'profile func Foo*'" | |
42 \ . " -c 'so Xprofile_func.vim'" | |
43 \ . " -c 'qall!'") | |
44 let lines = readfile('Xprofile_func.log') | |
45 | |
46 call assert_equal(28, len(lines)) | |
47 | |
48 call assert_equal('FUNCTION Foo1()', lines[0]) | |
49 call assert_equal('Called 2 times', lines[1]) | |
50 call assert_equal('FUNCTION Foo2()', lines[7]) | |
51 call assert_equal('Called 1 time', lines[8]) | |
52 | |
53 " - Foo1() is called 3 times but should be reported as called twice | |
54 " since one call is in between "profile pause" .. "profile continue". | |
55 " - Foo2() should come before Foo1() since Foo1() does much more work.\ | |
56 " - Foo3() is not reported because function is deleted. | |
57 " - Unlike Foo3(), Foo2() should not be deleted since there is a check | |
58 " for v:profiling. | |
59 " - Bar() is not reported since it does not match "profile func Foo*". | |
60 call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[18]) | |
61 call assert_equal('count total (s) self (s) function', lines[19]) | |
62 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo2()$', lines[20]) | |
63 call assert_match('^\s*2\s\+\d\+\.\d\+\s\+Foo1()$', lines[21]) | |
64 call assert_equal('', lines[22]) | |
65 call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[23]) | |
66 call assert_equal('count total (s) self (s) function', lines[24]) | |
67 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo2()$', lines[25]) | |
68 call assert_match('^\s*2\s\+\d\+\.\d\+\s\+Foo1()$', lines[26]) | |
69 call assert_equal('', lines[27]) | |
70 | |
71 call delete('Xprofile_func.vim') | |
72 call delete('Xprofile_func.log') | |
73 endfunc | |
74 | |
75 func Test_profile_file() | |
76 if !has('unix') | |
77 return | |
78 endif | |
79 let lines = [ | |
80 \ 'func! Foo()', | |
81 \ 'endfunc', | |
82 \ 'for i in range(10)', | |
83 \ ' " a comment', | |
84 \ ' call Foo()', | |
85 \ 'endfor', | |
86 \ 'call Foo()', | |
87 \ ] | |
88 | |
89 call writefile(lines, 'Xprofile_file.vim') | |
90 let a = system(v:progpath | |
91 \ . " -u NONE -i NONE --noplugin" | |
92 \ . " -c 'profile start Xprofile_file.log'" | |
93 \ . " -c 'profile file Xprofile_file.vim'" | |
94 \ . " -c 'so Xprofile_file.vim'" | |
95 \ . " -c 'so Xprofile_file.vim'" | |
96 \ . " -c 'qall!'") | |
97 | |
98 let lines = readfile('Xprofile_file.log') | |
99 | |
100 call assert_equal(14, len(lines)) | |
101 | |
102 call assert_match('^SCRIPT .*Xprofile_file.vim$', lines[0]) | |
103 call assert_equal('Sourced 2 times', lines[1]) | |
104 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[2]) | |
105 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[3]) | |
106 call assert_equal('', lines[4]) | |
107 call assert_equal('count total (s) self (s)', lines[5]) | |
108 call assert_equal(' func! Foo()', lines[6]) | |
109 call assert_equal(' endfunc', lines[7]) | |
110 " Loop iterates 10 times. Since script runs twice, body executes 20 times. | |
111 " First line of loop executes one more time than body to detect end of loop. | |
112 call assert_match('^\s*22\s\+\d\+\.\d\+\s\+for i in range(10)$', lines[8]) | |
113 call assert_equal(' " a comment', lines[9]) | |
114 call assert_match('^\s*20\s\+\d\+\.\d\+\s\+\d\+\.\d\+\s\+call Foo()$', lines[10]) | |
115 call assert_match('^\s*20\s\+\d\+\.\d\+\s\+endfor$', lines[11]) | |
116 call assert_match('^\s*2\s\+\d\+\.\d\+\s\+\d\+\.\d\+\s\+call Foo()$', lines[12]) | |
117 call assert_equal('', lines[13]) | |
118 | |
119 call delete('Xprofile_file.vim') | |
120 call delete('Xprofile_file.log') | |
121 endfunc | |
122 | |
123 func Test_profile_completion() | |
124 call feedkeys(":profile \<C-A>\<C-B>\"\<CR>", 'tx') | |
125 call assert_equal('"profile continue file func pause start', @:) | |
126 | |
127 call feedkeys(":profile start test_prof\<C-A>\<C-B>\"\<CR>", 'tx') | |
128 call assert_match('^"profile start.* test_profile\.vim', @:) | |
129 endfunc | |
130 | |
131 func Test_profile_errors() | |
132 call assert_fails("profile func Foo", 'E750:') | |
133 call assert_fails("profile pause", 'E750:') | |
134 call assert_fails("profile continue", 'E750:') | |
135 endfunc |