annotate src/testdir/test_timers.vim @ 19176:be81baeb69f8 v8.2.0147

patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set Commit: https://github.com/vim/vim/commit/03c3bd9fd094c1aede2e8fe3ad8fd25b9f033053 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jan 23 20:58:09 2020 +0100 patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set Problem: Block Visual mode operators not correct when 'linebreak' set. Solution: Set w_p_lbr to lbr_saved more often. (Ken Takata, closes https://github.com/vim/vim/issues/5524)
author Bram Moolenaar <Bram@vim.org>
date Thu, 23 Jan 2020 21:00:03 +0100
parents 8696f0ebeb43
children 2a017e9dc6da
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8577
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Test for timers
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
17089
8e9e9124c7a2 patch 8.1.1544: some balloon tests don't run when they can
Bram Moolenaar <Bram@vim.org>
parents: 17049
diff changeset
3 source check.vim
8e9e9124c7a2 patch 8.1.1544: some balloon tests don't run when they can
Bram Moolenaar <Bram@vim.org>
parents: 17049
diff changeset
4 CheckFeature timers
8577
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5
12568
440d934bd616 patch 8.0.1162: shared script for tests cannot be included twice
Christian Brabandt <cb@256bit.org>
parents: 12459
diff changeset
6 source shared.vim
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents: 17159
diff changeset
7 source term_util.vim
12351
4e61b77cd96f patch 8.0.1055: bufline test hangs on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 12347
diff changeset
8
8577
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 func MyHandler(timer)
9810
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
10 let g:val += 1
8577
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 endfunc
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12
9153
c2fe86f2bda1 commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents: 8734
diff changeset
13 func MyHandlerWithLists(lists, timer)
c2fe86f2bda1 commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents: 8734
diff changeset
14 let x = string(a:lists)
c2fe86f2bda1 commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents: 8734
diff changeset
15 endfunc
c2fe86f2bda1 commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents: 8734
diff changeset
16
17716
50b3b9c13ab8 patch 8.1.1855: another failing timer test
Bram Moolenaar <Bram@vim.org>
parents: 17710
diff changeset
17 func Test_timer_oneshot()
9810
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
18 let g:val = 0
8577
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 let timer = timer_start(50, 'MyHandler')
9810
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
20 let slept = WaitFor('g:val == 1')
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
21 call assert_equal(1, g:val)
18920
a76fdc6560c3 patch 8.2.0021: timer test fails too often on Travis with MacOS
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
22 if has('mac')
18964
8295f4061dc2 patch 8.2.0043: timers test is still flaky on Travis for Mac
Bram Moolenaar <Bram@vim.org>
parents: 18920
diff changeset
23 " Mac on Travis can be very slow.
8295f4061dc2 patch 8.2.0043: timers test is still flaky on Travis for Mac
Bram Moolenaar <Bram@vim.org>
parents: 18920
diff changeset
24 let limit = 180
18920
a76fdc6560c3 patch 8.2.0021: timer test fails too often on Travis with MacOS
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
25 else
a76fdc6560c3 patch 8.2.0021: timer test fails too often on Travis with MacOS
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
26 let limit = 100
a76fdc6560c3 patch 8.2.0021: timer test fails too often on Travis with MacOS
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
27 endif
9933
7f38e72a9d65 commit https://github.com/vim/vim/commit/f267f8bdf777073e392ada5b31d837c7b6090eb4
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
28 if has('reltime')
18920
a76fdc6560c3 patch 8.2.0021: timer test fails too often on Travis with MacOS
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
29 call assert_inrange(49, limit, slept)
9933
7f38e72a9d65 commit https://github.com/vim/vim/commit/f267f8bdf777073e392ada5b31d837c7b6090eb4
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
30 else
18920
a76fdc6560c3 patch 8.2.0021: timer test fails too often on Travis with MacOS
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
31 call assert_inrange(20, limit, slept)
9933
7f38e72a9d65 commit https://github.com/vim/vim/commit/f267f8bdf777073e392ada5b31d837c7b6090eb4
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
32 endif
8577
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 endfunc
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34
17716
50b3b9c13ab8 patch 8.1.1855: another failing timer test
Bram Moolenaar <Bram@vim.org>
parents: 17710
diff changeset
35 func Test_timer_repeat_three()
9810
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
36 let g:val = 0
8577
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 let timer = timer_start(50, 'MyHandler', {'repeat': 3})
9810
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
38 let slept = WaitFor('g:val == 3')
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
39 call assert_equal(3, g:val)
9933
7f38e72a9d65 commit https://github.com/vim/vim/commit/f267f8bdf777073e392ada5b31d837c7b6090eb4
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
40 if has('reltime')
18920
a76fdc6560c3 patch 8.2.0021: timer test fails too often on Travis with MacOS
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
41 if has('mac')
a76fdc6560c3 patch 8.2.0021: timer test fails too often on Travis with MacOS
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
42 " Mac on Travis can be slow.
a76fdc6560c3 patch 8.2.0021: timer test fails too often on Travis with MacOS
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
43 call assert_inrange(149, 400, slept)
a76fdc6560c3 patch 8.2.0021: timer test fails too often on Travis with MacOS
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
44 else
a76fdc6560c3 patch 8.2.0021: timer test fails too often on Travis with MacOS
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
45 call assert_inrange(149, 250, slept)
a76fdc6560c3 patch 8.2.0021: timer test fails too often on Travis with MacOS
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
46 endif
9933
7f38e72a9d65 commit https://github.com/vim/vim/commit/f267f8bdf777073e392ada5b31d837c7b6090eb4
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
47 else
7f38e72a9d65 commit https://github.com/vim/vim/commit/f267f8bdf777073e392ada5b31d837c7b6090eb4
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
48 call assert_inrange(80, 200, slept)
7f38e72a9d65 commit https://github.com/vim/vim/commit/f267f8bdf777073e392ada5b31d837c7b6090eb4
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
49 endif
8577
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 endfunc
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51
17716
50b3b9c13ab8 patch 8.1.1855: another failing timer test
Bram Moolenaar <Bram@vim.org>
parents: 17710
diff changeset
52 func Test_timer_repeat_many()
9810
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
53 let g:val = 0
8577
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 let timer = timer_start(50, 'MyHandler', {'repeat': -1})
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 sleep 200m
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 call timer_stop(timer)
18920
a76fdc6560c3 patch 8.2.0021: timer test fails too often on Travis with MacOS
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
57 " Mac on Travis can be slow.
a76fdc6560c3 patch 8.2.0021: timer test fails too often on Travis with MacOS
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
58 if has('mac')
a76fdc6560c3 patch 8.2.0021: timer test fails too often on Travis with MacOS
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
59 call assert_inrange(1, 5, g:val)
a76fdc6560c3 patch 8.2.0021: timer test fails too often on Travis with MacOS
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
60 else
a76fdc6560c3 patch 8.2.0021: timer test fails too often on Travis with MacOS
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
61 call assert_inrange(2, 5, g:val)
a76fdc6560c3 patch 8.2.0021: timer test fails too often on Travis with MacOS
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
62 endif
8577
63dc856bd13d commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 endfunc
8734
986f7c00d43d commit https://github.com/vim/vim/commit/92e35efaf6a3278e4729115648997f09cd4005f5
Christian Brabandt <cb@256bit.org>
parents: 8577
diff changeset
64
17716
50b3b9c13ab8 patch 8.1.1855: another failing timer test
Bram Moolenaar <Bram@vim.org>
parents: 17710
diff changeset
65 func Test_timer_with_partial_callback()
9810
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
66 let g:val = 0
10178
776d0aef1d80 commit https://github.com/vim/vim/commit/26fe0d56912e42c2b16a61b2480e19ba569aee98
Christian Brabandt <cb@256bit.org>
parents: 10122
diff changeset
67 let meow = {'one': 1}
776d0aef1d80 commit https://github.com/vim/vim/commit/26fe0d56912e42c2b16a61b2480e19ba569aee98
Christian Brabandt <cb@256bit.org>
parents: 10122
diff changeset
68 function meow.bite(...)
776d0aef1d80 commit https://github.com/vim/vim/commit/26fe0d56912e42c2b16a61b2480e19ba569aee98
Christian Brabandt <cb@256bit.org>
parents: 10122
diff changeset
69 let g:val += self.one
8734
986f7c00d43d commit https://github.com/vim/vim/commit/92e35efaf6a3278e4729115648997f09cd4005f5
Christian Brabandt <cb@256bit.org>
parents: 8577
diff changeset
70 endfunction
986f7c00d43d commit https://github.com/vim/vim/commit/92e35efaf6a3278e4729115648997f09cd4005f5
Christian Brabandt <cb@256bit.org>
parents: 8577
diff changeset
71
10178
776d0aef1d80 commit https://github.com/vim/vim/commit/26fe0d56912e42c2b16a61b2480e19ba569aee98
Christian Brabandt <cb@256bit.org>
parents: 10122
diff changeset
72 call timer_start(50, meow.bite)
9810
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
73 let slept = WaitFor('g:val == 1')
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
74 call assert_equal(1, g:val)
9933
7f38e72a9d65 commit https://github.com/vim/vim/commit/f267f8bdf777073e392ada5b31d837c7b6090eb4
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
75 if has('reltime')
18975
8696f0ebeb43 patch 8.2.0048: another timers test is flaky on Travis for Mac
Bram Moolenaar <Bram@vim.org>
parents: 18964
diff changeset
76 " Mac on Travis can be slow.
8696f0ebeb43 patch 8.2.0048: another timers test is flaky on Travis for Mac
Bram Moolenaar <Bram@vim.org>
parents: 18964
diff changeset
77 if has('mac')
8696f0ebeb43 patch 8.2.0048: another timers test is flaky on Travis for Mac
Bram Moolenaar <Bram@vim.org>
parents: 18964
diff changeset
78 call assert_inrange(49, 180, slept)
8696f0ebeb43 patch 8.2.0048: another timers test is flaky on Travis for Mac
Bram Moolenaar <Bram@vim.org>
parents: 18964
diff changeset
79 else
8696f0ebeb43 patch 8.2.0048: another timers test is flaky on Travis for Mac
Bram Moolenaar <Bram@vim.org>
parents: 18964
diff changeset
80 call assert_inrange(49, 130, slept)
8696f0ebeb43 patch 8.2.0048: another timers test is flaky on Travis for Mac
Bram Moolenaar <Bram@vim.org>
parents: 18964
diff changeset
81 endif
9933
7f38e72a9d65 commit https://github.com/vim/vim/commit/f267f8bdf777073e392ada5b31d837c7b6090eb4
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
82 else
7f38e72a9d65 commit https://github.com/vim/vim/commit/f267f8bdf777073e392ada5b31d837c7b6090eb4
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
83 call assert_inrange(20, 100, slept)
7f38e72a9d65 commit https://github.com/vim/vim/commit/f267f8bdf777073e392ada5b31d837c7b6090eb4
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
84 endif
8734
986f7c00d43d commit https://github.com/vim/vim/commit/92e35efaf6a3278e4729115648997f09cd4005f5
Christian Brabandt <cb@256bit.org>
parents: 8577
diff changeset
85 endfunc
9153
c2fe86f2bda1 commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents: 8734
diff changeset
86
17716
50b3b9c13ab8 patch 8.1.1855: another failing timer test
Bram Moolenaar <Bram@vim.org>
parents: 17710
diff changeset
87 func Test_timer_retain_partial()
9810
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
88 call timer_start(50, function('MyHandlerWithLists', [['a']]))
9153
c2fe86f2bda1 commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents: 8734
diff changeset
89 call test_garbagecollect_now()
9810
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
90 sleep 100m
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
91 endfunc
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
92
17716
50b3b9c13ab8 patch 8.1.1855: another failing timer test
Bram Moolenaar <Bram@vim.org>
parents: 17710
diff changeset
93 func Test_timer_info()
9810
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
94 let id = timer_start(1000, 'MyHandler')
18035
11dca9732a48 patch 8.1.2013: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 18031
diff changeset
95 let info = id->timer_info()
9810
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
96 call assert_equal(id, info[0]['id'])
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
97 call assert_equal(1000, info[0]['time'])
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
98 call assert_true(info[0]['remaining'] > 500)
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
99 call assert_true(info[0]['remaining'] <= 1000)
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
100 call assert_equal(1, info[0]['repeat'])
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
101 call assert_equal("function('MyHandler')", string(info[0]['callback']))
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
102
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
103 let found = 0
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
104 for info in timer_info()
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
105 if info['id'] == id
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
106 let found += 1
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
107 endif
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
108 endfor
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
109 call assert_equal(1, found)
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
110
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
111 call timer_stop(id)
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
112 call assert_equal([], timer_info(id))
9153
c2fe86f2bda1 commit https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3
Christian Brabandt <cb@256bit.org>
parents: 8734
diff changeset
113 endfunc
9810
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
114
17716
50b3b9c13ab8 patch 8.1.1855: another failing timer test
Bram Moolenaar <Bram@vim.org>
parents: 17710
diff changeset
115 func Test_timer_stopall()
9810
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
116 let id1 = timer_start(1000, 'MyHandler')
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
117 let id2 = timer_start(2000, 'MyHandler')
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
118 let info = timer_info()
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
119 call assert_equal(2, len(info))
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
120
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
121 call timer_stopall()
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
122 let info = timer_info()
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
123 call assert_equal(0, len(info))
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
124 endfunc
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
125
17716
50b3b9c13ab8 patch 8.1.1855: another failing timer test
Bram Moolenaar <Bram@vim.org>
parents: 17710
diff changeset
126 func Test_timer_paused()
9810
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
127 let g:val = 0
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
128
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
129 let id = timer_start(50, 'MyHandler')
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
130 let info = timer_info(id)
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
131 call assert_equal(0, info[0]['paused'])
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
132
18035
11dca9732a48 patch 8.1.2013: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 18031
diff changeset
133 eval id->timer_pause(1)
9810
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
134 let info = timer_info(id)
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
135 call assert_equal(1, info[0]['paused'])
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
136 sleep 100m
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
137 call assert_equal(0, g:val)
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
138
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
139 call timer_pause(id, 0)
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
140 let info = timer_info(id)
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
141 call assert_equal(0, info[0]['paused'])
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
142
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
143 let slept = WaitFor('g:val == 1')
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
144 call assert_equal(1, g:val)
9933
7f38e72a9d65 commit https://github.com/vim/vim/commit/f267f8bdf777073e392ada5b31d837c7b6090eb4
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
145 if has('reltime')
13098
318577da90b1 patch 8.0.1424: the timer_pause test is flaky on Travis
Christian Brabandt <cb@256bit.org>
parents: 12568
diff changeset
146 if has('mac')
318577da90b1 patch 8.0.1424: the timer_pause test is flaky on Travis
Christian Brabandt <cb@256bit.org>
parents: 12568
diff changeset
147 " The travis Mac machines appear to be very busy.
18920
a76fdc6560c3 patch 8.2.0021: timer test fails too often on Travis with MacOS
Bram Moolenaar <Bram@vim.org>
parents: 18035
diff changeset
148 call assert_inrange(0, 90, slept)
13098
318577da90b1 patch 8.0.1424: the timer_pause test is flaky on Travis
Christian Brabandt <cb@256bit.org>
parents: 12568
diff changeset
149 else
318577da90b1 patch 8.0.1424: the timer_pause test is flaky on Travis
Christian Brabandt <cb@256bit.org>
parents: 12568
diff changeset
150 call assert_inrange(0, 30, slept)
318577da90b1 patch 8.0.1424: the timer_pause test is flaky on Travis
Christian Brabandt <cb@256bit.org>
parents: 12568
diff changeset
151 endif
9933
7f38e72a9d65 commit https://github.com/vim/vim/commit/f267f8bdf777073e392ada5b31d837c7b6090eb4
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
152 else
7f38e72a9d65 commit https://github.com/vim/vim/commit/f267f8bdf777073e392ada5b31d837c7b6090eb4
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
153 call assert_inrange(0, 10, slept)
7f38e72a9d65 commit https://github.com/vim/vim/commit/f267f8bdf777073e392ada5b31d837c7b6090eb4
Christian Brabandt <cb@256bit.org>
parents: 9909
diff changeset
154 endif
9810
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
155 endfunc
6a28d0c6f929 commit https://github.com/vim/vim/commit/b73598e2f022a22fec512ea681c70d2775e8fd87
Christian Brabandt <cb@256bit.org>
parents: 9153
diff changeset
156
10066
dc1610dc910f commit https://github.com/vim/vim/commit/417ccd7138d4d230d328de8b0d3892dd82ff1bee
Christian Brabandt <cb@256bit.org>
parents: 10017
diff changeset
157 func StopMyself(timer)
dc1610dc910f commit https://github.com/vim/vim/commit/417ccd7138d4d230d328de8b0d3892dd82ff1bee
Christian Brabandt <cb@256bit.org>
parents: 10017
diff changeset
158 let g:called += 1
dc1610dc910f commit https://github.com/vim/vim/commit/417ccd7138d4d230d328de8b0d3892dd82ff1bee
Christian Brabandt <cb@256bit.org>
parents: 10017
diff changeset
159 if g:called == 2
dc1610dc910f commit https://github.com/vim/vim/commit/417ccd7138d4d230d328de8b0d3892dd82ff1bee
Christian Brabandt <cb@256bit.org>
parents: 10017
diff changeset
160 call timer_stop(a:timer)
dc1610dc910f commit https://github.com/vim/vim/commit/417ccd7138d4d230d328de8b0d3892dd82ff1bee
Christian Brabandt <cb@256bit.org>
parents: 10017
diff changeset
161 endif
dc1610dc910f commit https://github.com/vim/vim/commit/417ccd7138d4d230d328de8b0d3892dd82ff1bee
Christian Brabandt <cb@256bit.org>
parents: 10017
diff changeset
162 endfunc
dc1610dc910f commit https://github.com/vim/vim/commit/417ccd7138d4d230d328de8b0d3892dd82ff1bee
Christian Brabandt <cb@256bit.org>
parents: 10017
diff changeset
163
17716
50b3b9c13ab8 patch 8.1.1855: another failing timer test
Bram Moolenaar <Bram@vim.org>
parents: 17710
diff changeset
164 func Test_timer_delete_myself()
10066
dc1610dc910f commit https://github.com/vim/vim/commit/417ccd7138d4d230d328de8b0d3892dd82ff1bee
Christian Brabandt <cb@256bit.org>
parents: 10017
diff changeset
165 let g:called = 0
dc1610dc910f commit https://github.com/vim/vim/commit/417ccd7138d4d230d328de8b0d3892dd82ff1bee
Christian Brabandt <cb@256bit.org>
parents: 10017
diff changeset
166 let t = timer_start(10, 'StopMyself', {'repeat': -1})
13808
16a062cf08c2 patch 8.0.1776: in tests, when WaitFor() fails it doesn't say why
Christian Brabandt <cb@256bit.org>
parents: 13164
diff changeset
167 call WaitForAssert({-> assert_equal(2, g:called)})
10066
dc1610dc910f commit https://github.com/vim/vim/commit/417ccd7138d4d230d328de8b0d3892dd82ff1bee
Christian Brabandt <cb@256bit.org>
parents: 10017
diff changeset
168 call assert_equal(2, g:called)
dc1610dc910f commit https://github.com/vim/vim/commit/417ccd7138d4d230d328de8b0d3892dd82ff1bee
Christian Brabandt <cb@256bit.org>
parents: 10017
diff changeset
169 call assert_equal([], timer_info(t))
dc1610dc910f commit https://github.com/vim/vim/commit/417ccd7138d4d230d328de8b0d3892dd82ff1bee
Christian Brabandt <cb@256bit.org>
parents: 10017
diff changeset
170 endfunc
dc1610dc910f commit https://github.com/vim/vim/commit/417ccd7138d4d230d328de8b0d3892dd82ff1bee
Christian Brabandt <cb@256bit.org>
parents: 10017
diff changeset
171
10122
3db463d4df25 commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents: 10066
diff changeset
172 func StopTimer1(timer)
18035
11dca9732a48 patch 8.1.2013: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 18031
diff changeset
173 let g:timer2 = 10->timer_start('StopTimer2')
10122
3db463d4df25 commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents: 10066
diff changeset
174 " avoid maxfuncdepth error
3db463d4df25 commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents: 10066
diff changeset
175 call timer_pause(g:timer1, 1)
17734
c92899aa761a patch 8.1.1864: still a timer test that is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17724
diff changeset
176 sleep 20m
10122
3db463d4df25 commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents: 10066
diff changeset
177 endfunc
3db463d4df25 commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents: 10066
diff changeset
178
3db463d4df25 commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents: 10066
diff changeset
179 func StopTimer2(timer)
3db463d4df25 commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents: 10066
diff changeset
180 call timer_stop(g:timer1)
3db463d4df25 commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents: 10066
diff changeset
181 endfunc
3db463d4df25 commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents: 10066
diff changeset
182
17716
50b3b9c13ab8 patch 8.1.1855: another failing timer test
Bram Moolenaar <Bram@vim.org>
parents: 17710
diff changeset
183 func Test_timer_stop_in_callback()
17724
76fba68d1c67 patch 8.1.1859: timer test sometimes fails on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17716
diff changeset
184 call assert_equal(0, len(timer_info()))
10122
3db463d4df25 commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents: 10066
diff changeset
185 let g:timer1 = timer_start(10, 'StopTimer1')
17740
01205ef5646d patch 8.1.1867: still a timer test that is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17734
diff changeset
186 let slept = 0
01205ef5646d patch 8.1.1867: still a timer test that is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17734
diff changeset
187 for i in range(10)
01205ef5646d patch 8.1.1867: still a timer test that is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17734
diff changeset
188 if len(timer_info()) == 0
01205ef5646d patch 8.1.1867: still a timer test that is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17734
diff changeset
189 break
01205ef5646d patch 8.1.1867: still a timer test that is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17734
diff changeset
190 endif
01205ef5646d patch 8.1.1867: still a timer test that is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17734
diff changeset
191 sleep 10m
01205ef5646d patch 8.1.1867: still a timer test that is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17734
diff changeset
192 let slept += 10
01205ef5646d patch 8.1.1867: still a timer test that is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17734
diff changeset
193 endfor
01205ef5646d patch 8.1.1867: still a timer test that is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17734
diff changeset
194 " This should take only 30 msec, but on Mac it's often longer
01205ef5646d patch 8.1.1867: still a timer test that is flaky on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17734
diff changeset
195 call assert_inrange(0, 50, slept)
10122
3db463d4df25 commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents: 10066
diff changeset
196 endfunc
3db463d4df25 commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents: 10066
diff changeset
197
3db463d4df25 commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents: 10066
diff changeset
198 func StopTimerAll(timer)
3db463d4df25 commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents: 10066
diff changeset
199 call timer_stopall()
3db463d4df25 commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents: 10066
diff changeset
200 endfunc
3db463d4df25 commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents: 10066
diff changeset
201
17716
50b3b9c13ab8 patch 8.1.1855: another failing timer test
Bram Moolenaar <Bram@vim.org>
parents: 17710
diff changeset
202 func Test_timer_stop_all_in_callback()
17724
76fba68d1c67 patch 8.1.1859: timer test sometimes fails on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17716
diff changeset
203 call assert_equal(0, len(timer_info()))
76fba68d1c67 patch 8.1.1859: timer test sometimes fails on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17716
diff changeset
204 call timer_start(10, 'StopTimerAll')
76fba68d1c67 patch 8.1.1859: timer test sometimes fails on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17716
diff changeset
205 call assert_equal(1, len(timer_info()))
76fba68d1c67 patch 8.1.1859: timer test sometimes fails on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17716
diff changeset
206 let slept = 0
76fba68d1c67 patch 8.1.1859: timer test sometimes fails on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17716
diff changeset
207 for i in range(10)
76fba68d1c67 patch 8.1.1859: timer test sometimes fails on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17716
diff changeset
208 if len(timer_info()) == 0
76fba68d1c67 patch 8.1.1859: timer test sometimes fails on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17716
diff changeset
209 break
76fba68d1c67 patch 8.1.1859: timer test sometimes fails on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17716
diff changeset
210 endif
76fba68d1c67 patch 8.1.1859: timer test sometimes fails on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17716
diff changeset
211 sleep 10m
76fba68d1c67 patch 8.1.1859: timer test sometimes fails on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17716
diff changeset
212 let slept += 10
76fba68d1c67 patch 8.1.1859: timer test sometimes fails on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17716
diff changeset
213 endfor
76fba68d1c67 patch 8.1.1859: timer test sometimes fails on Mac
Bram Moolenaar <Bram@vim.org>
parents: 17716
diff changeset
214 call assert_inrange(0, 30, slept)
10122
3db463d4df25 commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents: 10066
diff changeset
215 endfunc
3db463d4df25 commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents: 10066
diff changeset
216
11575
0ec755ff1fe2 patch 8.0.0670: can't use input() in a timer callback
Christian Brabandt <cb@256bit.org>
parents: 10178
diff changeset
217 func FeedkeysCb(timer)
0ec755ff1fe2 patch 8.0.0670: can't use input() in a timer callback
Christian Brabandt <cb@256bit.org>
parents: 10178
diff changeset
218 call feedkeys("hello\<CR>", 'nt')
0ec755ff1fe2 patch 8.0.0670: can't use input() in a timer callback
Christian Brabandt <cb@256bit.org>
parents: 10178
diff changeset
219 endfunc
0ec755ff1fe2 patch 8.0.0670: can't use input() in a timer callback
Christian Brabandt <cb@256bit.org>
parents: 10178
diff changeset
220
0ec755ff1fe2 patch 8.0.0670: can't use input() in a timer callback
Christian Brabandt <cb@256bit.org>
parents: 10178
diff changeset
221 func InputCb(timer)
0ec755ff1fe2 patch 8.0.0670: can't use input() in a timer callback
Christian Brabandt <cb@256bit.org>
parents: 10178
diff changeset
222 call timer_start(10, 'FeedkeysCb')
0ec755ff1fe2 patch 8.0.0670: can't use input() in a timer callback
Christian Brabandt <cb@256bit.org>
parents: 10178
diff changeset
223 let g:val = input('?')
0ec755ff1fe2 patch 8.0.0670: can't use input() in a timer callback
Christian Brabandt <cb@256bit.org>
parents: 10178
diff changeset
224 call Resume()
0ec755ff1fe2 patch 8.0.0670: can't use input() in a timer callback
Christian Brabandt <cb@256bit.org>
parents: 10178
diff changeset
225 endfunc
0ec755ff1fe2 patch 8.0.0670: can't use input() in a timer callback
Christian Brabandt <cb@256bit.org>
parents: 10178
diff changeset
226
17716
50b3b9c13ab8 patch 8.1.1855: another failing timer test
Bram Moolenaar <Bram@vim.org>
parents: 17710
diff changeset
227 func Test_timer_input_in_timer()
11575
0ec755ff1fe2 patch 8.0.0670: can't use input() in a timer callback
Christian Brabandt <cb@256bit.org>
parents: 10178
diff changeset
228 let g:val = ''
0ec755ff1fe2 patch 8.0.0670: can't use input() in a timer callback
Christian Brabandt <cb@256bit.org>
parents: 10178
diff changeset
229 call timer_start(10, 'InputCb')
0ec755ff1fe2 patch 8.0.0670: can't use input() in a timer callback
Christian Brabandt <cb@256bit.org>
parents: 10178
diff changeset
230 call Standby(1000)
0ec755ff1fe2 patch 8.0.0670: can't use input() in a timer callback
Christian Brabandt <cb@256bit.org>
parents: 10178
diff changeset
231 call assert_equal('hello', g:val)
0ec755ff1fe2 patch 8.0.0670: can't use input() in a timer callback
Christian Brabandt <cb@256bit.org>
parents: 10178
diff changeset
232 endfunc
10122
3db463d4df25 commit https://github.com/vim/vim/commit/75537a93e985ef32e6c267b06ce93629855dd983
Christian Brabandt <cb@256bit.org>
parents: 10066
diff changeset
233
11639
71d7b5ed08a0 patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents: 11575
diff changeset
234 func FuncWithError(timer)
71d7b5ed08a0 patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents: 11575
diff changeset
235 let g:call_count += 1
71d7b5ed08a0 patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents: 11575
diff changeset
236 if g:call_count == 4
71d7b5ed08a0 patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents: 11575
diff changeset
237 return
71d7b5ed08a0 patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents: 11575
diff changeset
238 endif
71d7b5ed08a0 patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents: 11575
diff changeset
239 doesnotexist
71d7b5ed08a0 patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents: 11575
diff changeset
240 endfunc
71d7b5ed08a0 patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents: 11575
diff changeset
241
71d7b5ed08a0 patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents: 11575
diff changeset
242 func Test_timer_errors()
71d7b5ed08a0 patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents: 11575
diff changeset
243 let g:call_count = 0
71d7b5ed08a0 patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents: 11575
diff changeset
244 let timer = timer_start(10, 'FuncWithError', {'repeat': -1})
71d7b5ed08a0 patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents: 11575
diff changeset
245 " Timer will be stopped after failing 3 out of 3 times.
13808
16a062cf08c2 patch 8.0.1776: in tests, when WaitFor() fails it doesn't say why
Christian Brabandt <cb@256bit.org>
parents: 13164
diff changeset
246 call WaitForAssert({-> assert_equal(3, g:call_count)})
11639
71d7b5ed08a0 patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents: 11575
diff changeset
247 sleep 50m
71d7b5ed08a0 patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents: 11575
diff changeset
248 call assert_equal(3, g:call_count)
71d7b5ed08a0 patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents: 11575
diff changeset
249 endfunc
71d7b5ed08a0 patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents: 11575
diff changeset
250
12375
ab0d827151a1 patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents: 12351
diff changeset
251 func FuncWithCaughtError(timer)
ab0d827151a1 patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents: 12351
diff changeset
252 let g:call_count += 1
ab0d827151a1 patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents: 12351
diff changeset
253 try
ab0d827151a1 patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents: 12351
diff changeset
254 doesnotexist
ab0d827151a1 patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents: 12351
diff changeset
255 catch
ab0d827151a1 patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents: 12351
diff changeset
256 " nop
ab0d827151a1 patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents: 12351
diff changeset
257 endtry
ab0d827151a1 patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents: 12351
diff changeset
258 endfunc
ab0d827151a1 patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents: 12351
diff changeset
259
ab0d827151a1 patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents: 12351
diff changeset
260 func Test_timer_catch_error()
ab0d827151a1 patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents: 12351
diff changeset
261 let g:call_count = 0
ab0d827151a1 patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents: 12351
diff changeset
262 let timer = timer_start(10, 'FuncWithCaughtError', {'repeat': 4})
ab0d827151a1 patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents: 12351
diff changeset
263 " Timer will not be stopped.
13808
16a062cf08c2 patch 8.0.1776: in tests, when WaitFor() fails it doesn't say why
Christian Brabandt <cb@256bit.org>
parents: 13164
diff changeset
264 call WaitForAssert({-> assert_equal(4, g:call_count)})
12375
ab0d827151a1 patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents: 12351
diff changeset
265 sleep 50m
ab0d827151a1 patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents: 12351
diff changeset
266 call assert_equal(4, g:call_count)
ab0d827151a1 patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents: 12351
diff changeset
267 endfunc
ab0d827151a1 patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents: 12351
diff changeset
268
12337
040a892d0eed patch 8.0.1048: no test for what 8.0.1020 fixes
Christian Brabandt <cb@256bit.org>
parents: 11639
diff changeset
269 func FeedAndPeek(timer)
040a892d0eed patch 8.0.1048: no test for what 8.0.1020 fixes
Christian Brabandt <cb@256bit.org>
parents: 11639
diff changeset
270 call test_feedinput('a')
040a892d0eed patch 8.0.1048: no test for what 8.0.1020 fixes
Christian Brabandt <cb@256bit.org>
parents: 11639
diff changeset
271 call getchar(1)
040a892d0eed patch 8.0.1048: no test for what 8.0.1020 fixes
Christian Brabandt <cb@256bit.org>
parents: 11639
diff changeset
272 endfunc
040a892d0eed patch 8.0.1048: no test for what 8.0.1020 fixes
Christian Brabandt <cb@256bit.org>
parents: 11639
diff changeset
273
040a892d0eed patch 8.0.1048: no test for what 8.0.1020 fixes
Christian Brabandt <cb@256bit.org>
parents: 11639
diff changeset
274 func Interrupt(timer)
18031
8a2fb21c23c0 patch 8.1.2011: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17740
diff changeset
275 eval "\<C-C>"->test_feedinput()
12337
040a892d0eed patch 8.0.1048: no test for what 8.0.1020 fixes
Christian Brabandt <cb@256bit.org>
parents: 11639
diff changeset
276 endfunc
040a892d0eed patch 8.0.1048: no test for what 8.0.1020 fixes
Christian Brabandt <cb@256bit.org>
parents: 11639
diff changeset
277
17716
50b3b9c13ab8 patch 8.1.1855: another failing timer test
Bram Moolenaar <Bram@vim.org>
parents: 17710
diff changeset
278 func Test_timer_peek_and_get_char()
17657
0da9bc55c31a patch 8.1.1826: tests use hand coded feature and option checks
Bram Moolenaar <Bram@vim.org>
parents: 17249
diff changeset
279 CheckUnix
0da9bc55c31a patch 8.1.1826: tests use hand coded feature and option checks
Bram Moolenaar <Bram@vim.org>
parents: 17249
diff changeset
280 CheckGui
0da9bc55c31a patch 8.1.1826: tests use hand coded feature and option checks
Bram Moolenaar <Bram@vim.org>
parents: 17249
diff changeset
281
12337
040a892d0eed patch 8.0.1048: no test for what 8.0.1020 fixes
Christian Brabandt <cb@256bit.org>
parents: 11639
diff changeset
282 call timer_start(0, 'FeedAndPeek')
040a892d0eed patch 8.0.1048: no test for what 8.0.1020 fixes
Christian Brabandt <cb@256bit.org>
parents: 11639
diff changeset
283 let intr = timer_start(100, 'Interrupt')
040a892d0eed patch 8.0.1048: no test for what 8.0.1020 fixes
Christian Brabandt <cb@256bit.org>
parents: 11639
diff changeset
284 let c = getchar()
040a892d0eed patch 8.0.1048: no test for what 8.0.1020 fixes
Christian Brabandt <cb@256bit.org>
parents: 11639
diff changeset
285 call assert_equal(char2nr('a'), c)
18035
11dca9732a48 patch 8.1.2013: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 18031
diff changeset
286 eval intr->timer_stop()
12337
040a892d0eed patch 8.0.1048: no test for what 8.0.1020 fixes
Christian Brabandt <cb@256bit.org>
parents: 11639
diff changeset
287 endfunc
11639
71d7b5ed08a0 patch 8.0.0702: an error in a timer can make Vim unusable
Christian Brabandt <cb@256bit.org>
parents: 11575
diff changeset
288
17716
50b3b9c13ab8 patch 8.1.1855: another failing timer test
Bram Moolenaar <Bram@vim.org>
parents: 17710
diff changeset
289 func Test_timer_getchar_zero()
15687
cb501b3c9fb5 patch 8.1.0851: feedkeys() with "L" does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 15673
diff changeset
290 if has('win32') && !has('gui_running')
17657
0da9bc55c31a patch 8.1.1826: tests use hand coded feature and option checks
Bram Moolenaar <Bram@vim.org>
parents: 17249
diff changeset
291 throw 'Skipped: cannot get low-level input'
15669
d2ec272ae777 patch 8.1.0842: getchar_zero test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 15665
diff changeset
292 endif
d2ec272ae777 patch 8.1.0842: getchar_zero test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 15665
diff changeset
293
15673
2973d8252740 patch 8.1.0844: when timer fails test will hang forever
Bram Moolenaar <Bram@vim.org>
parents: 15669
diff changeset
294 " Measure the elapsed time to avoid a hang when it fails.
2973d8252740 patch 8.1.0844: when timer fails test will hang forever
Bram Moolenaar <Bram@vim.org>
parents: 15669
diff changeset
295 let start = reltime()
15687
cb501b3c9fb5 patch 8.1.0851: feedkeys() with "L" does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 15673
diff changeset
296 let id = timer_start(20, {-> feedkeys('x', 'L')})
15665
31367ce5aac7 patch 8.1.0840: getchar(0) never returns a character in the terminal
Bram Moolenaar <Bram@vim.org>
parents: 13892
diff changeset
297 let c = 0
15673
2973d8252740 patch 8.1.0844: when timer fails test will hang forever
Bram Moolenaar <Bram@vim.org>
parents: 15669
diff changeset
298 while c == 0 && reltimefloat(reltime(start)) < 0.2
15665
31367ce5aac7 patch 8.1.0840: getchar(0) never returns a character in the terminal
Bram Moolenaar <Bram@vim.org>
parents: 13892
diff changeset
299 let c = getchar(0)
31367ce5aac7 patch 8.1.0840: getchar(0) never returns a character in the terminal
Bram Moolenaar <Bram@vim.org>
parents: 13892
diff changeset
300 sleep 10m
31367ce5aac7 patch 8.1.0840: getchar(0) never returns a character in the terminal
Bram Moolenaar <Bram@vim.org>
parents: 13892
diff changeset
301 endwhile
31367ce5aac7 patch 8.1.0840: getchar(0) never returns a character in the terminal
Bram Moolenaar <Bram@vim.org>
parents: 13892
diff changeset
302 call assert_equal('x', nr2char(c))
15669
d2ec272ae777 patch 8.1.0842: getchar_zero test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 15665
diff changeset
303 call timer_stop(id)
15665
31367ce5aac7 patch 8.1.0840: getchar(0) never returns a character in the terminal
Bram Moolenaar <Bram@vim.org>
parents: 13892
diff changeset
304 endfunc
31367ce5aac7 patch 8.1.0840: getchar(0) never returns a character in the terminal
Bram Moolenaar <Bram@vim.org>
parents: 13892
diff changeset
305
17716
50b3b9c13ab8 patch 8.1.1855: another failing timer test
Bram Moolenaar <Bram@vim.org>
parents: 17710
diff changeset
306 func Test_timer_ex_mode()
12459
937356f8f8d6 patch 8.0.1109: timer causes error on exit from Ex mode
Christian Brabandt <cb@256bit.org>
parents: 12375
diff changeset
307 " Function with an empty line.
937356f8f8d6 patch 8.0.1109: timer causes error on exit from Ex mode
Christian Brabandt <cb@256bit.org>
parents: 12375
diff changeset
308 func Foo(...)
937356f8f8d6 patch 8.0.1109: timer causes error on exit from Ex mode
Christian Brabandt <cb@256bit.org>
parents: 12375
diff changeset
309
937356f8f8d6 patch 8.0.1109: timer causes error on exit from Ex mode
Christian Brabandt <cb@256bit.org>
parents: 12375
diff changeset
310 endfunc
15669
d2ec272ae777 patch 8.1.0842: getchar_zero test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 15665
diff changeset
311 let timer = timer_start(40, function('g:Foo'), {'repeat':-1})
12459
937356f8f8d6 patch 8.0.1109: timer causes error on exit from Ex mode
Christian Brabandt <cb@256bit.org>
parents: 12375
diff changeset
312 " This used to throw error E749.
937356f8f8d6 patch 8.0.1109: timer causes error on exit from Ex mode
Christian Brabandt <cb@256bit.org>
parents: 12375
diff changeset
313 exe "normal Qsleep 100m\rvi\r"
937356f8f8d6 patch 8.0.1109: timer causes error on exit from Ex mode
Christian Brabandt <cb@256bit.org>
parents: 12375
diff changeset
314 call timer_stop(timer)
937356f8f8d6 patch 8.0.1109: timer causes error on exit from Ex mode
Christian Brabandt <cb@256bit.org>
parents: 12375
diff changeset
315 endfunc
937356f8f8d6 patch 8.0.1109: timer causes error on exit from Ex mode
Christian Brabandt <cb@256bit.org>
parents: 12375
diff changeset
316
17716
50b3b9c13ab8 patch 8.1.1855: another failing timer test
Bram Moolenaar <Bram@vim.org>
parents: 17710
diff changeset
317 func Test_timer_restore_count()
13892
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
318 if !CanRunVimInTerminal()
16965
ba7727889385 patch 8.1.1483: skipped tests are not properly listed
Bram Moolenaar <Bram@vim.org>
parents: 15687
diff changeset
319 throw 'Skipped: cannot run Vim in a terminal window'
13892
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
320 endif
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
321 " Check that v:count is saved and restored, not changed by a timer.
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
322 call writefile([
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
323 \ 'nnoremap <expr><silent> L v:count ? v:count . "l" : "l"',
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
324 \ 'func Doit(id)',
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
325 \ ' normal 3j',
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
326 \ 'endfunc',
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
327 \ 'call timer_start(100, "Doit")',
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
328 \ ], 'Xtrcscript')
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
329 call writefile([
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
330 \ '1-1234',
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
331 \ '2-1234',
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
332 \ '3-1234',
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
333 \ ], 'Xtrctext')
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
334 let buf = RunVimInTerminal('-S Xtrcscript Xtrctext', {})
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
335
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
336 " Wait for the timer to move the cursor to the third line.
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
337 call WaitForAssert({-> assert_equal(3, term_getcursor(buf)[0])})
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
338 call assert_equal(1, term_getcursor(buf)[1])
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
339 " Now check that v:count has not been set to 3
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
340 call term_sendkeys(buf, 'L')
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
341 call WaitForAssert({-> assert_equal(2, term_getcursor(buf)[1])})
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
342
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
343 call StopVimInTerminal(buf)
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
344 call delete('Xtrcscript')
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
345 call delete('Xtrctext')
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
346 endfunc
eadecbe4e390 patch 8.0.1817: a timer may change v:count unexpectedly
Christian Brabandt <cb@256bit.org>
parents: 13808
diff changeset
347
17159
3fd0765f454f patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
348 " Test that the garbage collector isn't triggered if a timer callback invokes
3fd0765f454f patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
349 " vgetc().
17716
50b3b9c13ab8 patch 8.1.1855: another failing timer test
Bram Moolenaar <Bram@vim.org>
parents: 17710
diff changeset
350 func Test_timer_nocatch_garbage_collect()
17159
3fd0765f454f patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
351 " 'uptimetime. must be bigger than the timer timeout
3fd0765f454f patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
352 set ut=200
3fd0765f454f patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
353 call test_garbagecollect_soon()
3fd0765f454f patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
354 call test_override('no_wait_return', 0)
3fd0765f454f patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
355 func CauseAnError(id)
3fd0765f454f patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
356 " This will show an error and wait for Enter.
3fd0765f454f patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
357 let a = {'foo', 'bar'}
3fd0765f454f patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
358 endfunc
3fd0765f454f patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
359 func FeedChar(id)
3fd0765f454f patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
360 call feedkeys('x', 't')
3fd0765f454f patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
361 endfunc
3fd0765f454f patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
362 call timer_start(300, 'FeedChar')
3fd0765f454f patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
363 call timer_start(100, 'CauseAnError')
3fd0765f454f patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
364 let x = getchar()
3fd0765f454f patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
365
3fd0765f454f patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
366 set ut&
3fd0765f454f patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
367 call test_override('no_wait_return', 1)
3fd0765f454f patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
368 delfunc CauseAnError
3fd0765f454f patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
369 delfunc FeedChar
3fd0765f454f patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
370 endfunc
3fd0765f454f patch 8.1.1579: dict and list could be GC'ed while displaying error
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
371
17716
50b3b9c13ab8 patch 8.1.1855: another failing timer test
Bram Moolenaar <Bram@vim.org>
parents: 17710
diff changeset
372 func Test_timer_error_in_timer_callback()
17249
3e2e998ce0db patch 8.1.1624: when testing in the GUI may try to run gvim in a terminal
Bram Moolenaar <Bram@vim.org>
parents: 17239
diff changeset
373 if !has('terminal') || (has('win32') && has('gui_running'))
17184
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
374 throw 'Skipped: cannot run Vim in a terminal window'
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
375 endif
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
376
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
377 let lines =<< trim [CODE]
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
378 func Func(timer)
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
379 " fail to create list
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
380 let x = [
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
381 endfunc
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
382 set updatetime=50
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
383 call timer_start(1, 'Func')
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
384 [CODE]
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
385 call writefile(lines, 'Xtest.vim')
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
386
17249
3e2e998ce0db patch 8.1.1624: when testing in the GUI may try to run gvim in a terminal
Bram Moolenaar <Bram@vim.org>
parents: 17239
diff changeset
387 let buf = term_start(GetVimCommandCleanTerm() .. ' -S Xtest.vim', {'term_rows': 8})
17184
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
388 let job = term_getjob(buf)
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
389 call WaitForAssert({-> assert_notequal('', term_getline(buf, 8))})
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
390
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
391 " GC must not run during timer callback, which can make Vim crash.
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
392 call term_wait(buf, 100)
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
393 call term_sendkeys(buf, "\<CR>")
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
394 call term_wait(buf, 100)
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
395 call assert_equal('run', job_status(job))
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
396
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
397 call term_sendkeys(buf, ":qall!\<CR>")
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
398 call WaitFor({-> job_status(job) ==# 'dead'})
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
399 if has('unix')
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
400 call assert_equal('', job_info(job).termsig)
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
401 endif
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
402
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
403 call delete('Xtest.vim')
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
404 exe buf .. 'bwipe!'
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
405 endfunc
a5c3d374e1d3 patch 8.1.1591: on error garbage collection may free memory in use
Bram Moolenaar <Bram@vim.org>
parents: 17164
diff changeset
406
9909
3ee84d270ea7 commit https://github.com/vim/vim/commit/9e4d8215d386100ab660d7d11e6620fd148b605e
Christian Brabandt <cb@256bit.org>
parents: 9822
diff changeset
407 " vim: shiftwidth=2 sts=2 expandtab