Bram Moolenaar | 3b30168 | 2018-09-22 21:37:39 +0200 | [diff] [blame] | 1 | " Test :suspend |
| 2 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 3 | source check.vim |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 4 | source term_util.vim |
Bram Moolenaar | a0a6f3a | 2022-12-04 22:26:40 +0000 | [diff] [blame] | 5 | source shared.vim |
Bram Moolenaar | 3b30168 | 2018-09-22 21:37:39 +0200 | [diff] [blame] | 6 | |
Bram Moolenaar | a8356bc | 2019-04-14 14:31:11 +0200 | [diff] [blame] | 7 | func CheckSuspended(buf, fileExists) |
| 8 | call WaitForAssert({-> assert_match('[$#] $', term_getline(a:buf, '.'))}) |
| 9 | |
| 10 | if a:fileExists |
| 11 | call assert_equal(['foo'], readfile('Xfoo')) |
| 12 | else |
| 13 | " Without 'autowrite', buffer should not be written. |
| 14 | call assert_equal(0, filereadable('Xfoo')) |
| 15 | endif |
| 16 | |
| 17 | call term_sendkeys(a:buf, "fg\<CR>\<C-L>") |
| 18 | call WaitForAssert({-> assert_equal(' 1 foo', term_getline(a:buf, '.'))}) |
| 19 | endfunc |
| 20 | |
Bram Moolenaar | 3b30168 | 2018-09-22 21:37:39 +0200 | [diff] [blame] | 21 | func Test_suspend() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 22 | CheckFeature terminal |
| 23 | CheckExecutable /bin/sh |
Bram Moolenaar | 3b30168 | 2018-09-22 21:37:39 +0200 | [diff] [blame] | 24 | |
Bram Moolenaar | 7155fb6 | 2022-12-06 09:11:39 +0000 | [diff] [blame] | 25 | " Somehow the modifyOtherKeys response may get to the terminal when using |
| 26 | " Mac OS. Make t_RK and 'keyprotocol' empty to avoid that. |
| 27 | set t_RK= keyprotocol= |
Bram Moolenaar | 0a2f891 | 2022-12-05 21:21:46 +0000 | [diff] [blame] | 28 | |
Bram Moolenaar | a0a6f3a | 2022-12-04 22:26:40 +0000 | [diff] [blame] | 29 | call WaitForResponses() |
| 30 | |
Bram Moolenaar | 3b30168 | 2018-09-22 21:37:39 +0200 | [diff] [blame] | 31 | let buf = term_start('/bin/sh') |
| 32 | " Wait for shell prompt. |
Bram Moolenaar | 0f62cf5 | 2018-11-03 21:09:15 +0100 | [diff] [blame] | 33 | call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))}) |
Bram Moolenaar | 3b30168 | 2018-09-22 21:37:39 +0200 | [diff] [blame] | 34 | |
Bram Moolenaar | 185d68a | 2019-08-15 11:21:15 +0200 | [diff] [blame] | 35 | call term_sendkeys(buf, v:progpath |
| 36 | \ . " --clean -X" |
Bram Moolenaar | 3b30168 | 2018-09-22 21:37:39 +0200 | [diff] [blame] | 37 | \ . " -c 'set nu'" |
| 38 | \ . " -c 'call setline(1, \"foo\")'" |
| 39 | \ . " Xfoo\<CR>") |
| 40 | " Cursor in terminal buffer should be on first line in spawned vim. |
| 41 | call WaitForAssert({-> assert_equal(' 1 foo', term_getline(buf, '.'))}) |
| 42 | |
| 43 | for suspend_cmd in [":suspend\<CR>", |
| 44 | \ ":stop\<CR>", |
| 45 | \ ":suspend!\<CR>", |
| 46 | \ ":stop!\<CR>", |
| 47 | \ "\<C-Z>"] |
| 48 | " Suspend and wait for shell prompt. |
| 49 | call term_sendkeys(buf, suspend_cmd) |
Bram Moolenaar | a8356bc | 2019-04-14 14:31:11 +0200 | [diff] [blame] | 50 | call CheckSuspended(buf, 0) |
Bram Moolenaar | 3b30168 | 2018-09-22 21:37:39 +0200 | [diff] [blame] | 51 | endfor |
| 52 | |
| 53 | " Test that :suspend! with 'autowrite' writes content of buffers if modified. |
| 54 | call term_sendkeys(buf, ":set autowrite\<CR>") |
| 55 | call assert_equal(0, filereadable('Xfoo')) |
| 56 | call term_sendkeys(buf, ":suspend\<CR>") |
| 57 | " Wait for shell prompt. |
Bram Moolenaar | a8356bc | 2019-04-14 14:31:11 +0200 | [diff] [blame] | 58 | call CheckSuspended(buf, 1) |
Bram Moolenaar | 3b30168 | 2018-09-22 21:37:39 +0200 | [diff] [blame] | 59 | |
Bram Moolenaar | 3020ccb | 2019-01-17 22:13:54 +0100 | [diff] [blame] | 60 | " Quit gracefully to dump coverage information. |
| 61 | call term_sendkeys(buf, ":qall!\<CR>") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 62 | call TermWait(buf) |
Bram Moolenaar | 9992244 | 2019-07-08 20:58:25 +0200 | [diff] [blame] | 63 | " Wait until Vim actually exited and shell shows a prompt |
| 64 | call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))}) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 65 | call StopShellInTerminal(buf) |
Bram Moolenaar | 3020ccb | 2019-01-17 22:13:54 +0100 | [diff] [blame] | 66 | |
Bram Moolenaar | 3b30168 | 2018-09-22 21:37:39 +0200 | [diff] [blame] | 67 | exe buf . 'bwipe!' |
| 68 | call delete('Xfoo') |
Bram Moolenaar | 3b30168 | 2018-09-22 21:37:39 +0200 | [diff] [blame] | 69 | endfunc |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 70 | |
Bram Moolenaar | 100118c | 2020-12-11 19:30:34 +0100 | [diff] [blame] | 71 | func Test_suspend_autocmd() |
| 72 | CheckFeature terminal |
| 73 | CheckExecutable /bin/sh |
| 74 | |
Bram Moolenaar | 7155fb6 | 2022-12-06 09:11:39 +0000 | [diff] [blame] | 75 | " Somehow the modifyOtherKeys response may get to the terminal when using |
| 76 | " Mac OS. Make t_RK and 'keyprotocol' empty to avoid that. |
| 77 | set t_RK= keyprotocol= |
Bram Moolenaar | 0a2f891 | 2022-12-05 21:21:46 +0000 | [diff] [blame] | 78 | |
Bram Moolenaar | a0a6f3a | 2022-12-04 22:26:40 +0000 | [diff] [blame] | 79 | call WaitForResponses() |
| 80 | |
Bram Moolenaar | 100118c | 2020-12-11 19:30:34 +0100 | [diff] [blame] | 81 | let buf = term_start('/bin/sh', #{term_rows: 6}) |
| 82 | " Wait for shell prompt. |
| 83 | call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))}) |
| 84 | |
| 85 | call term_sendkeys(buf, v:progpath |
| 86 | \ . " --clean -X" |
| 87 | \ . " -c 'set nu'" |
| 88 | \ . " -c 'let g:count = 0'" |
| 89 | \ . " -c 'au VimSuspend * let g:count += 1'" |
| 90 | \ . " -c 'au VimResume * let g:count += 1'" |
| 91 | \ . " -c 'call setline(1, \"foo\")'" |
| 92 | \ . " Xfoo\<CR>") |
| 93 | " Cursor in terminal buffer should be on first line in spawned vim. |
| 94 | call WaitForAssert({-> assert_equal(' 1 foo', term_getline(buf, '.'))}) |
| 95 | |
| 96 | for suspend_cmd in [":suspend\<CR>", |
| 97 | \ ":stop\<CR>", |
| 98 | \ ":suspend!\<CR>", |
| 99 | \ ":stop!\<CR>", |
| 100 | \ "\<C-Z>"] |
| 101 | " Suspend and wait for shell prompt. Then "fg" will restore Vim. |
| 102 | call term_sendkeys(buf, suspend_cmd) |
| 103 | call CheckSuspended(buf, 0) |
| 104 | endfor |
| 105 | |
| 106 | call term_sendkeys(buf, ":echo g:count\<CR>") |
| 107 | call TermWait(buf) |
| 108 | call WaitForAssert({-> assert_match('^10', term_getline(buf, 6))}) |
| 109 | |
| 110 | " Quit gracefully to dump coverage information. |
| 111 | call term_sendkeys(buf, ":qall!\<CR>") |
| 112 | call TermWait(buf) |
| 113 | " Wait until Vim actually exited and shell shows a prompt |
| 114 | call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))}) |
| 115 | call StopShellInTerminal(buf) |
| 116 | |
| 117 | exe buf . 'bwipe!' |
| 118 | call delete('Xfoo') |
| 119 | endfunc |
| 120 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 121 | " vim: shiftwidth=2 sts=2 expandtab |