Bram Moolenaar | db77b84 | 2019-03-24 14:58:31 +0100 | [diff] [blame] | 1 | " Test signal handling. |
| 2 | |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 3 | source check.vim |
| 4 | CheckUnix |
Bram Moolenaar | db77b84 | 2019-03-24 14:58:31 +0100 | [diff] [blame] | 5 | |
Bram Moolenaar | db77b84 | 2019-03-24 14:58:31 +0100 | [diff] [blame] | 6 | source shared.vim |
| 7 | |
Bram Moolenaar | 520e245 | 2019-04-27 17:32:40 +0200 | [diff] [blame] | 8 | " Check whether a signal is available on this system. |
| 9 | func HasSignal(signal) |
| 10 | let signals = system('kill -l') |
| 11 | return signals =~# '\<' .. a:signal .. '\>' |
| 12 | endfunc |
| 13 | |
Bram Moolenaar | db77b84 | 2019-03-24 14:58:31 +0100 | [diff] [blame] | 14 | " Test signal WINCH (window resize signal) |
| 15 | func Test_signal_WINCH() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 16 | CheckNotGui |
| 17 | if !HasSignal('WINCH') |
| 18 | throw 'Skipped: WINCH signal not supported' |
Bram Moolenaar | db77b84 | 2019-03-24 14:58:31 +0100 | [diff] [blame] | 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 Moolenaar | 520e245 | 2019-04-27 17:32:40 +0200 | [diff] [blame] | 33 | exe 'set lines=' .. new_lines |
| 34 | exe 'set columns=' .. new_columns |
Bram Moolenaar | db77b84 | 2019-03-24 14:58:31 +0100 | [diff] [blame] | 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. |
Bram Moolenaar | 520e245 | 2019-04-27 17:32:40 +0200 | [diff] [blame] | 41 | exe 'silent !kill -s WINCH ' .. getpid() |
Bram Moolenaar | db77b84 | 2019-03-24 14:58:31 +0100 | [diff] [blame] | 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 |
| 48 | endfunc |
Bram Moolenaar | 520e245 | 2019-04-27 17:32:40 +0200 | [diff] [blame] | 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 |