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