Mercurial > vim
annotate src/testdir/test_signals.vim @ 20087:b378f860d4ab v8.2.0599
patch 8.2.0599: Netbeans interface insufficiently tested
Commit: https://github.com/vim/vim/commit/173d841e86cf205d8e398091b1da7bb4951714f9
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Apr 19 14:02:26 2020 +0200
patch 8.2.0599: Netbeans interface insufficiently tested
Problem: Netbeans interface insufficiently tested.
Solution: Add more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5921)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 19 Apr 2020 14:15:04 +0200 |
parents | c9cc9e5c87e0 |
children | f8835e16c34e |
rev | line source |
---|---|
16084
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 " Test signal handling. |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 |
17657
0da9bc55c31a
patch 8.1.1826: tests use hand coded feature and option checks
Bram Moolenaar <Bram@vim.org>
parents:
17089
diff
changeset
|
3 source check.vim |
19754
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
4 source term_util.vim |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
5 |
17657
0da9bc55c31a
patch 8.1.1826: tests use hand coded feature and option checks
Bram Moolenaar <Bram@vim.org>
parents:
17089
diff
changeset
|
6 CheckUnix |
16084
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 |
16415
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
8 source shared.vim |
16192
1ab0d1f7807a
patch 8.1.1101: signals test may fail in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
16084
diff
changeset
|
9 |
16415
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
10 " Check whether a signal is available on this system. |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
11 func HasSignal(signal) |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
12 let signals = system('kill -l') |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
13 return signals =~# '\<' .. a:signal .. '\>' |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
14 endfunc |
16084
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 " Test signal WINCH (window resize signal) |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 func Test_signal_WINCH() |
17657
0da9bc55c31a
patch 8.1.1826: tests use hand coded feature and option checks
Bram Moolenaar <Bram@vim.org>
parents:
17089
diff
changeset
|
18 CheckNotGui |
0da9bc55c31a
patch 8.1.1826: tests use hand coded feature and option checks
Bram Moolenaar <Bram@vim.org>
parents:
17089
diff
changeset
|
19 if !HasSignal('WINCH') |
0da9bc55c31a
patch 8.1.1826: tests use hand coded feature and option checks
Bram Moolenaar <Bram@vim.org>
parents:
17089
diff
changeset
|
20 throw 'Skipped: WINCH signal not supported' |
16084
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 endif |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 " We do not actually want to change the size of the terminal. |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 let old_WS = '' |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 if exists('&t_WS') |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 let old_WS = &t_WS |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 let &t_WS = '' |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 endif |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 let old_lines = &lines |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 let old_columns = &columns |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 let new_lines = &lines - 2 |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 let new_columns = &columns - 2 |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 |
16415
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
35 exe 'set lines=' .. new_lines |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
36 exe 'set columns=' .. new_columns |
16084
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 call assert_equal(new_lines, &lines) |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 call assert_equal(new_columns, &columns) |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 " Send signal and wait for signal to be processed. |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 " 'lines' and 'columns' should have been restored |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 " after handing signal WINCH. |
16415
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
43 exe 'silent !kill -s WINCH ' .. getpid() |
16084
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 call WaitForAssert({-> assert_equal(old_lines, &lines)}) |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 call assert_equal(old_columns, &columns) |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 if old_WS != '' |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 let &t_WS = old_WS |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 endif |
ed1482db2d72
patch 8.1.1047: WINCH signal is not tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 endfunc |
16415
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
51 |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
52 " Test signal PWR, which should update the swap file. |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
53 func Test_signal_PWR() |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
54 if !HasSignal('PWR') |
19754
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
55 throw 'Skipped: PWR signal not supported' |
16415
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
56 endif |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
57 |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
58 " Set a very large 'updatetime' and 'updatecount', so that we can be sure |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
59 " that swap file is updated as a result of sending PWR signal, and not |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
60 " because of exceeding 'updatetime' or 'updatecount' when changing buffer. |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
61 set updatetime=100000 updatecount=100000 |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
62 new Xtest_signal_PWR |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
63 let swap_name = swapname('%') |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
64 call setline(1, '123') |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
65 preserve |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
66 let swap_content = readfile(swap_name, 'b') |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
67 |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
68 " Update the buffer and check that the swap file is not yet updated, |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
69 " since we set 'updatetime' and 'updatecount' to large values. |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
70 call setline(1, 'abc') |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
71 call assert_equal(swap_content, readfile(swap_name, 'b')) |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
72 |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
73 " Sending PWR signal should update the swap file. |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
74 exe 'silent !kill -s PWR ' .. getpid() |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
75 call WaitForAssert({-> assert_notequal(swap_content, readfile(swap_name, 'b'))}) |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
76 |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
77 bwipe! |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
78 set updatetime& updatecount& |
a0e98821a2ed
patch 8.1.1212: signal PWR is not tested
Bram Moolenaar <Bram@vim.org>
parents:
16192
diff
changeset
|
79 endfunc |
19754
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
80 |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
81 " Test signal INT. Handler sets got_int. It should be like typing CTRL-C. |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
82 func Test_signal_INT() |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
83 if !HasSignal('INT') |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
84 throw 'Skipped: INT signal not supported' |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
85 endif |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
86 |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
87 " Skip the rest of the test when running with valgrind as signal INT is not |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
88 " received somehow by Vim when running with valgrind. |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
89 let cmd = GetVimCommand() |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
90 if cmd =~ 'valgrind' |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
91 throw 'Skipped: cannot test signal INT with valgrind' |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
92 endif |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
93 |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
94 if !CanRunVimInTerminal() |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
95 throw 'Skipped: cannot run vim in terminal' |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
96 endif |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
97 let buf = RunVimInTerminal('', {'rows': 6}) |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
98 let pid_vim = term_getjob(buf)->job_info().process |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
99 |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
100 " Check that an endless loop in Vim is interrupted by signal INT. |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
101 call term_sendkeys(buf, ":while 1 | endwhile\n") |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
102 call WaitForAssert({-> assert_equal(':while 1 | endwhile', term_getline(buf, 6))}) |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
103 exe 'silent !kill -s INT ' .. pid_vim |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
104 call term_sendkeys(buf, ":call setline(1, 'INTERUPTED')\n") |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
105 call WaitForAssert({-> assert_equal('INTERUPTED', term_getline(buf, 1))}) |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
106 |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
107 call StopVimInTerminal(buf) |
c9cc9e5c87e0
patch 8.2.0433: INT signal not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
17657
diff
changeset
|
108 endfunc |