blob: cc1c3fb502e7373d9d2f7500c357408701044e66 [file] [log] [blame]
Bram Moolenaardb77b842019-03-24 14:58:31 +01001" Test signal handling.
2
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02003source check.vim
4CheckUnix
Bram Moolenaardb77b842019-03-24 14:58:31 +01005
Bram Moolenaardb77b842019-03-24 14:58:31 +01006source shared.vim
7
Bram Moolenaar520e2452019-04-27 17:32:40 +02008" Check whether a signal is available on this system.
9func HasSignal(signal)
10 let signals = system('kill -l')
11 return signals =~# '\<' .. a:signal .. '\>'
12endfunc
13
Bram Moolenaardb77b842019-03-24 14:58:31 +010014" Test signal WINCH (window resize signal)
15func Test_signal_WINCH()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +020016 CheckNotGui
17 if !HasSignal('WINCH')
18 throw 'Skipped: WINCH signal not supported'
Bram Moolenaardb77b842019-03-24 14:58:31 +010019 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