blob: 44732df88d3f0e29e1ef096075617b88d588cafd [file] [log] [blame]
Bram Moolenaardb77b842019-03-24 14:58:31 +01001" Test signal handling.
2
3if !has('unix')
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02004 throw 'Skipped: not on Unix'
Bram Moolenaardb77b842019-03-24 14:58:31 +01005endif
6
Bram Moolenaardb77b842019-03-24 14:58:31 +01007source shared.vim
8
Bram Moolenaar520e2452019-04-27 17:32:40 +02009" Check whether a signal is available on this system.
10func HasSignal(signal)
11 let signals = system('kill -l')
12 return signals =~# '\<' .. a:signal .. '\>'
13endfunc
14
Bram Moolenaardb77b842019-03-24 14:58:31 +010015" Test signal WINCH (window resize signal)
16func Test_signal_WINCH()
Bram Moolenaar520e2452019-04-27 17:32:40 +020017 if has('gui_running') || !HasSignal('WINCH')
Bram Moolenaardb77b842019-03-24 14:58:31 +010018 return
19 endif
20
21 " We do not actually want to change the size of the terminal.
22 let old_WS = ''
23 if exists('&t_WS')
24 let old_WS = &t_WS
25 let &t_WS = ''
26 endif
27
28 let old_lines = &lines
29 let old_columns = &columns
30 let new_lines = &lines - 2
31 let new_columns = &columns - 2
32
Bram Moolenaar520e2452019-04-27 17:32:40 +020033 exe 'set lines=' .. new_lines
34 exe 'set columns=' .. new_columns
Bram Moolenaardb77b842019-03-24 14:58:31 +010035 call assert_equal(new_lines, &lines)
36 call assert_equal(new_columns, &columns)
37
38 " Send signal and wait for signal to be processed.
39 " 'lines' and 'columns' should have been restored
40 " after handing signal WINCH.
Bram Moolenaar520e2452019-04-27 17:32:40 +020041 exe 'silent !kill -s WINCH ' .. getpid()
Bram Moolenaardb77b842019-03-24 14:58:31 +010042 call WaitForAssert({-> assert_equal(old_lines, &lines)})
43 call assert_equal(old_columns, &columns)
44
45 if old_WS != ''
46 let &t_WS = old_WS
47 endif
48endfunc
Bram Moolenaar520e2452019-04-27 17:32:40 +020049
50" Test signal PWR, which should update the swap file.
51func Test_signal_PWR()
52 if !HasSignal('PWR')
53 return
54 endif
55
56 " Set a very large 'updatetime' and 'updatecount', so that we can be sure
57 " that swap file is updated as a result of sending PWR signal, and not
58 " because of exceeding 'updatetime' or 'updatecount' when changing buffer.
59 set updatetime=100000 updatecount=100000
60 new Xtest_signal_PWR
61 let swap_name = swapname('%')
62 call setline(1, '123')
63 preserve
64 let swap_content = readfile(swap_name, 'b')
65
66 " Update the buffer and check that the swap file is not yet updated,
67 " since we set 'updatetime' and 'updatecount' to large values.
68 call setline(1, 'abc')
69 call assert_equal(swap_content, readfile(swap_name, 'b'))
70
71 " Sending PWR signal should update the swap file.
72 exe 'silent !kill -s PWR ' .. getpid()
73 call WaitForAssert({-> assert_notequal(swap_content, readfile(swap_name, 'b'))})
74
75 bwipe!
76 set updatetime& updatecount&
77endfunc