1" Test signal handling. 2 3if !has('unix') 4 finish 5endif 6 7source shared.vim 8 9" 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 15" Test signal WINCH (window resize signal) 16func Test_signal_WINCH() 17 if has('gui_running') || !HasSignal('WINCH') 18 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 33 exe 'set lines=' .. new_lines 34 exe 'set columns=' .. new_columns 35 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. 41 exe 'silent !kill -s WINCH ' .. getpid() 42 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 49 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 78