@@ -4,18 +4,17 @@ if !has('unix')
44 finish
55endif
66
7- if has (' gui_running' )
8- " Signals only work for terminals, and won't work for GUI.
9- finish
10- endif
11-
127source shared.vim
138
9+ " Check whether a signal is available on this system.
10+ func HasSignal (signal)
11+ let signals = system (' kill -l' )
12+ return signals = ~# ' \<' .. a: signal .. ' \>'
13+ endfunc
14+
1415" Test signal WINCH (window resize signal)
1516func Test_signal_WINCH ()
16- let signals = system (' kill -l' )
17- if signals !~ ' \<WINCH\>'
18- " signal WINCH is not available, skip the test.
17+ if has (' gui_running' ) || ! HasSignal (' WINCH' )
1918 return
2019 endif
2120
@@ -31,19 +30,48 @@ func Test_signal_WINCH()
3130 let new_lines = &lines - 2
3231 let new_columns = &columns - 2
3332
34- exe ' set lines=' . new_lines
35- exe ' set columns=' . new_columns
33+ exe ' set lines=' .. new_lines
34+ exe ' set columns=' .. new_columns
3635 call assert_equal (new_lines, &lines )
3736 call assert_equal (new_columns, &columns )
3837
3938 " Send signal and wait for signal to be processed.
4039 " 'lines' and 'columns' should have been restored
4140 " after handing signal WINCH.
42- exe ' silent !kill -s WINCH ' . getpid ()
41+ exe ' silent !kill -s WINCH ' .. getpid ()
4342 call WaitForAssert ({- > assert_equal (old_lines, &lines )})
4443 call assert_equal (old_columns, &columns )
4544
4645 if old_WS != ' '
4746 let &t_WS = old_WS
4847 endif
4948endfunc
49+
50+ " Test signal PWR, which should update the swap file.
51+ func 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 &
77+ endfunc
0 commit comments