Skip to content

Commit 520e245

Browse files
committed
patch 8.1.1212: signal PWR is not tested
Problem: Signal PWR is not tested. Solution: Test that PWR updates the swap file. (Dominique Pelle, closes #4312)
1 parent e61e548 commit 520e245

2 files changed

Lines changed: 41 additions & 11 deletions

File tree

src/testdir/test_signals.vim

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@ if !has('unix')
44
finish
55
endif
66

7-
if has('gui_running')
8-
" Signals only work for terminals, and won't work for GUI.
9-
finish
10-
endif
11-
127
source 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)
1516
func 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
4948
endfunc
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

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,8 @@ static char *(features[]) =
767767

768768
static int included_patches[] =
769769
{ /* Add new patch number below this line */
770+
/**/
771+
1212,
770772
/**/
771773
1211,
772774
/**/

0 commit comments

Comments
 (0)