comparison src/testdir/test_timers.vim @ 17716:50b3b9c13ab8 v8.1.1855

patch 8.1.1855: another failing timer test commit https://github.com/vim/vim/commit/9a2fddcf04192a643dc97601d689c27f5bc5184f Author: Bram Moolenaar <Bram@vim.org> Date: Fri Aug 16 11:26:06 2019 +0200 patch 8.1.1855: another failing timer test Problem: Another failing timer test. Solution: Assert that timers are finished by the end of the test. Rename test functions to make them easier to find.
author Bram Moolenaar <Bram@vim.org>
date Fri, 16 Aug 2019 11:30:03 +0200
parents 7d56da1c98f0
children 76fba68d1c67
comparison
equal deleted inserted replaced
17715:4c7b01e6b932 17716:50b3b9c13ab8
12 12
13 func MyHandlerWithLists(lists, timer) 13 func MyHandlerWithLists(lists, timer)
14 let x = string(a:lists) 14 let x = string(a:lists)
15 endfunc 15 endfunc
16 16
17 func Test_oneshot() 17 func Test_timer_oneshot()
18 let g:val = 0 18 let g:val = 0
19 let timer = timer_start(50, 'MyHandler') 19 let timer = timer_start(50, 'MyHandler')
20 let slept = WaitFor('g:val == 1') 20 let slept = WaitFor('g:val == 1')
21 call assert_equal(1, g:val) 21 call assert_equal(1, g:val)
22 if has('reltime') 22 if has('reltime')
24 else 24 else
25 call assert_inrange(20, 100, slept) 25 call assert_inrange(20, 100, slept)
26 endif 26 endif
27 endfunc 27 endfunc
28 28
29 func Test_repeat_three() 29 func Test_timer_repeat_three()
30 let g:val = 0 30 let g:val = 0
31 let timer = timer_start(50, 'MyHandler', {'repeat': 3}) 31 let timer = timer_start(50, 'MyHandler', {'repeat': 3})
32 let slept = WaitFor('g:val == 3') 32 let slept = WaitFor('g:val == 3')
33 call assert_equal(3, g:val) 33 call assert_equal(3, g:val)
34 if has('reltime') 34 if has('reltime')
36 else 36 else
37 call assert_inrange(80, 200, slept) 37 call assert_inrange(80, 200, slept)
38 endif 38 endif
39 endfunc 39 endfunc
40 40
41 func Test_repeat_many() 41 func Test_timer_repeat_many()
42 let g:val = 0 42 let g:val = 0
43 let timer = timer_start(50, 'MyHandler', {'repeat': -1}) 43 let timer = timer_start(50, 'MyHandler', {'repeat': -1})
44 sleep 200m 44 sleep 200m
45 call timer_stop(timer) 45 call timer_stop(timer)
46 call assert_inrange(2, 5, g:val) 46 call assert_inrange(2, 5, g:val)
47 endfunc 47 endfunc
48 48
49 func Test_with_partial_callback() 49 func Test_timer_with_partial_callback()
50 let g:val = 0 50 let g:val = 0
51 let meow = {'one': 1} 51 let meow = {'one': 1}
52 function meow.bite(...) 52 function meow.bite(...)
53 let g:val += self.one 53 let g:val += self.one
54 endfunction 54 endfunction
61 else 61 else
62 call assert_inrange(20, 100, slept) 62 call assert_inrange(20, 100, slept)
63 endif 63 endif
64 endfunc 64 endfunc
65 65
66 func Test_retain_partial() 66 func Test_timer_retain_partial()
67 call timer_start(50, function('MyHandlerWithLists', [['a']])) 67 call timer_start(50, function('MyHandlerWithLists', [['a']]))
68 call test_garbagecollect_now() 68 call test_garbagecollect_now()
69 sleep 100m 69 sleep 100m
70 endfunc 70 endfunc
71 71
72 func Test_info() 72 func Test_timer_info()
73 let id = timer_start(1000, 'MyHandler') 73 let id = timer_start(1000, 'MyHandler')
74 let info = timer_info(id) 74 let info = timer_info(id)
75 call assert_equal(id, info[0]['id']) 75 call assert_equal(id, info[0]['id'])
76 call assert_equal(1000, info[0]['time']) 76 call assert_equal(1000, info[0]['time'])
77 call assert_true(info[0]['remaining'] > 500) 77 call assert_true(info[0]['remaining'] > 500)
89 89
90 call timer_stop(id) 90 call timer_stop(id)
91 call assert_equal([], timer_info(id)) 91 call assert_equal([], timer_info(id))
92 endfunc 92 endfunc
93 93
94 func Test_stopall() 94 func Test_timer_stopall()
95 let id1 = timer_start(1000, 'MyHandler') 95 let id1 = timer_start(1000, 'MyHandler')
96 let id2 = timer_start(2000, 'MyHandler') 96 let id2 = timer_start(2000, 'MyHandler')
97 let info = timer_info() 97 let info = timer_info()
98 call assert_equal(2, len(info)) 98 call assert_equal(2, len(info))
99 99
100 call timer_stopall() 100 call timer_stopall()
101 let info = timer_info() 101 let info = timer_info()
102 call assert_equal(0, len(info)) 102 call assert_equal(0, len(info))
103 endfunc 103 endfunc
104 104
105 func Test_paused() 105 func Test_timer_paused()
106 let g:val = 0 106 let g:val = 0
107 107
108 let id = timer_start(50, 'MyHandler') 108 let id = timer_start(50, 'MyHandler')
109 let info = timer_info(id) 109 let info = timer_info(id)
110 call assert_equal(0, info[0]['paused']) 110 call assert_equal(0, info[0]['paused'])
138 if g:called == 2 138 if g:called == 2
139 call timer_stop(a:timer) 139 call timer_stop(a:timer)
140 endif 140 endif
141 endfunc 141 endfunc
142 142
143 func Test_delete_myself() 143 func Test_timer_delete_myself()
144 let g:called = 0 144 let g:called = 0
145 let t = timer_start(10, 'StopMyself', {'repeat': -1}) 145 let t = timer_start(10, 'StopMyself', {'repeat': -1})
146 call WaitForAssert({-> assert_equal(2, g:called)}) 146 call WaitForAssert({-> assert_equal(2, g:called)})
147 call assert_equal(2, g:called) 147 call assert_equal(2, g:called)
148 call assert_equal([], timer_info(t)) 148 call assert_equal([], timer_info(t))
157 157
158 func StopTimer2(timer) 158 func StopTimer2(timer)
159 call timer_stop(g:timer1) 159 call timer_stop(g:timer1)
160 endfunc 160 endfunc
161 161
162 func Test_stop_in_callback() 162 func Test_timer_stop_in_callback()
163 let g:timer1 = timer_start(10, 'StopTimer1') 163 let g:timer1 = timer_start(10, 'StopTimer1')
164 sleep 40m 164 sleep 40m
165 call assert_equal(0, len(timer_info()))
165 endfunc 166 endfunc
166 167
167 func StopTimerAll(timer) 168 func StopTimerAll(timer)
168 call timer_stopall() 169 call timer_stopall()
169 endfunc 170 endfunc
170 171
171 func Test_stop_all_in_callback() 172 func Test_timer_stop_all_in_callback()
172 let g:timer1 = timer_start(10, 'StopTimerAll') 173 let g:timer1 = timer_start(10, 'StopTimerAll')
173 let info = timer_info() 174 let info = timer_info()
174 call assert_equal(1, len(info)) 175 call assert_equal(1, len(info))
175 sleep 40m 176 sleep 40m
176 let info = timer_info() 177 let info = timer_info()
185 call timer_start(10, 'FeedkeysCb') 186 call timer_start(10, 'FeedkeysCb')
186 let g:val = input('?') 187 let g:val = input('?')
187 call Resume() 188 call Resume()
188 endfunc 189 endfunc
189 190
190 func Test_input_in_timer() 191 func Test_timer_input_in_timer()
191 let g:val = '' 192 let g:val = ''
192 call timer_start(10, 'InputCb') 193 call timer_start(10, 'InputCb')
193 call Standby(1000) 194 call Standby(1000)
194 call assert_equal('hello', g:val) 195 call assert_equal('hello', g:val)
195 endfunc 196 endfunc
236 237
237 func Interrupt(timer) 238 func Interrupt(timer)
238 call test_feedinput("\<C-C>") 239 call test_feedinput("\<C-C>")
239 endfunc 240 endfunc
240 241
241 func Test_peek_and_get_char() 242 func Test_timer_peek_and_get_char()
242 CheckUnix 243 CheckUnix
243 CheckGui 244 CheckGui
244 245
245 call timer_start(0, 'FeedAndPeek') 246 call timer_start(0, 'FeedAndPeek')
246 let intr = timer_start(100, 'Interrupt') 247 let intr = timer_start(100, 'Interrupt')
247 let c = getchar() 248 let c = getchar()
248 call assert_equal(char2nr('a'), c) 249 call assert_equal(char2nr('a'), c)
249 call timer_stop(intr) 250 call timer_stop(intr)
250 endfunc 251 endfunc
251 252
252 func Test_getchar_zero() 253 func Test_timer_getchar_zero()
253 if has('win32') && !has('gui_running') 254 if has('win32') && !has('gui_running')
254 throw 'Skipped: cannot get low-level input' 255 throw 'Skipped: cannot get low-level input'
255 endif 256 endif
256 257
257 " Measure the elapsed time to avoid a hang when it fails. 258 " Measure the elapsed time to avoid a hang when it fails.
264 endwhile 265 endwhile
265 call assert_equal('x', nr2char(c)) 266 call assert_equal('x', nr2char(c))
266 call timer_stop(id) 267 call timer_stop(id)
267 endfunc 268 endfunc
268 269
269 func Test_ex_mode() 270 func Test_timer_ex_mode()
270 " Function with an empty line. 271 " Function with an empty line.
271 func Foo(...) 272 func Foo(...)
272 273
273 endfunc 274 endfunc
274 let timer = timer_start(40, function('g:Foo'), {'repeat':-1}) 275 let timer = timer_start(40, function('g:Foo'), {'repeat':-1})
275 " This used to throw error E749. 276 " This used to throw error E749.
276 exe "normal Qsleep 100m\rvi\r" 277 exe "normal Qsleep 100m\rvi\r"
277 call timer_stop(timer) 278 call timer_stop(timer)
278 endfunc 279 endfunc
279 280
280 func Test_restore_count() 281 func Test_timer_restore_count()
281 if !CanRunVimInTerminal() 282 if !CanRunVimInTerminal()
282 throw 'Skipped: cannot run Vim in a terminal window' 283 throw 'Skipped: cannot run Vim in a terminal window'
283 endif 284 endif
284 " Check that v:count is saved and restored, not changed by a timer. 285 " Check that v:count is saved and restored, not changed by a timer.
285 call writefile([ 286 call writefile([
308 call delete('Xtrctext') 309 call delete('Xtrctext')
309 endfunc 310 endfunc
310 311
311 " Test that the garbage collector isn't triggered if a timer callback invokes 312 " Test that the garbage collector isn't triggered if a timer callback invokes
312 " vgetc(). 313 " vgetc().
313 func Test_nocatch_garbage_collect() 314 func Test_timer_nocatch_garbage_collect()
314 " 'uptimetime. must be bigger than the timer timeout 315 " 'uptimetime. must be bigger than the timer timeout
315 set ut=200 316 set ut=200
316 call test_garbagecollect_soon() 317 call test_garbagecollect_soon()
317 call test_override('no_wait_return', 0) 318 call test_override('no_wait_return', 0)
318 func CauseAnError(id) 319 func CauseAnError(id)
330 call test_override('no_wait_return', 1) 331 call test_override('no_wait_return', 1)
331 delfunc CauseAnError 332 delfunc CauseAnError
332 delfunc FeedChar 333 delfunc FeedChar
333 endfunc 334 endfunc
334 335
335 func Test_error_in_timer_callback() 336 func Test_timer_error_in_timer_callback()
336 if !has('terminal') || (has('win32') && has('gui_running')) 337 if !has('terminal') || (has('win32') && has('gui_running'))
337 throw 'Skipped: cannot run Vim in a terminal window' 338 throw 'Skipped: cannot run Vim in a terminal window'
338 endif 339 endif
339 340
340 let lines =<< trim [CODE] 341 let lines =<< trim [CODE]