Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 1 | " Tests for the terminal window. |
Bram Moolenaar | 1112c0f | 2020-07-01 21:53:50 +0200 | [diff] [blame] | 2 | " This is split in two, because it can take a lot of time. |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 3 | " See test_terminal2.vim and test_terminal3.vim for further tests. |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 4 | |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 5 | source check.vim |
| 6 | CheckFeature terminal |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 7 | |
| 8 | source shared.vim |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 9 | source screendump.vim |
Bram Moolenaar | 91689ea | 2020-05-11 22:04:53 +0200 | [diff] [blame] | 10 | source mouse.vim |
Bram Moolenaar | 1112c0f | 2020-07-01 21:53:50 +0200 | [diff] [blame] | 11 | source term_util.vim |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 12 | |
Bram Moolenaar | b81bc77 | 2017-08-11 22:45:01 +0200 | [diff] [blame] | 13 | let s:python = PythonProg() |
Bram Moolenaar | ddd3308 | 2019-06-03 23:07:25 +0200 | [diff] [blame] | 14 | let $PROMPT_COMMAND='' |
Bram Moolenaar | b81bc77 | 2017-08-11 22:45:01 +0200 | [diff] [blame] | 15 | |
Bram Moolenaar | 20e6cd0 | 2017-08-01 20:25:22 +0200 | [diff] [blame] | 16 | func Test_terminal_basic() |
Bram Moolenaar | 606cb8b | 2018-05-03 20:40:20 +0200 | [diff] [blame] | 17 | au TerminalOpen * let b:done = 'yes' |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 18 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | b00fdf6 | 2017-09-21 22:16:21 +0200 | [diff] [blame] | 19 | |
Bram Moolenaar | 2bb7b6b | 2017-08-13 20:58:33 +0200 | [diff] [blame] | 20 | call assert_equal('t', mode()) |
Bram Moolenaar | b00fdf6 | 2017-09-21 22:16:21 +0200 | [diff] [blame] | 21 | call assert_equal('yes', b:done) |
Bram Moolenaar | 2bb7b6b | 2017-08-13 20:58:33 +0200 | [diff] [blame] | 22 | call assert_match('%aR[^\n]*running]', execute('ls')) |
Bram Moolenaar | 0751f51 | 2018-03-29 16:37:16 +0200 | [diff] [blame] | 23 | call assert_match('%aR[^\n]*running]', execute('ls R')) |
| 24 | call assert_notmatch('%[^\n]*running]', execute('ls F')) |
| 25 | call assert_notmatch('%[^\n]*running]', execute('ls ?')) |
Bram Moolenaar | 004a678 | 2020-04-11 17:09:31 +0200 | [diff] [blame] | 26 | call assert_fails('set modifiable', 'E946:') |
Bram Moolenaar | 2bb7b6b | 2017-08-13 20:58:33 +0200 | [diff] [blame] | 27 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 28 | call StopShellInTerminal(buf) |
Bram Moolenaar | 2bb7b6b | 2017-08-13 20:58:33 +0200 | [diff] [blame] | 29 | call assert_equal('n', mode()) |
| 30 | call assert_match('%aF[^\n]*finished]', execute('ls')) |
Bram Moolenaar | 0751f51 | 2018-03-29 16:37:16 +0200 | [diff] [blame] | 31 | call assert_match('%aF[^\n]*finished]', execute('ls F')) |
| 32 | call assert_notmatch('%[^\n]*finished]', execute('ls R')) |
| 33 | call assert_notmatch('%[^\n]*finished]', execute('ls ?')) |
Bram Moolenaar | 20e6cd0 | 2017-08-01 20:25:22 +0200 | [diff] [blame] | 34 | |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 35 | " closing window wipes out the terminal buffer a with finished job |
| 36 | close |
| 37 | call assert_equal("", bufname(buf)) |
| 38 | |
Bram Moolenaar | 606cb8b | 2018-05-03 20:40:20 +0200 | [diff] [blame] | 39 | au! TerminalOpen |
Bram Moolenaar | 20e6cd0 | 2017-08-01 20:25:22 +0200 | [diff] [blame] | 40 | unlet g:job |
| 41 | endfunc |
| 42 | |
Bram Moolenaar | 00806bc | 2020-11-05 19:36:38 +0100 | [diff] [blame] | 43 | func Test_terminal_no_name() |
| 44 | let buf = Run_shell_in_terminal({}) |
| 45 | call assert_match('^!', bufname(buf)) |
| 46 | 0file |
| 47 | call assert_equal("", bufname(buf)) |
| 48 | call assert_match('\[No Name\]', execute('file')) |
| 49 | call StopShellInTerminal(buf) |
Bram Moolenaar | 00806bc | 2020-11-05 19:36:38 +0100 | [diff] [blame] | 50 | endfunc |
| 51 | |
Bram Moolenaar | 28ed4df | 2019-10-26 16:21:40 +0200 | [diff] [blame] | 52 | func Test_terminal_TerminalWinOpen() |
| 53 | au TerminalWinOpen * let b:done = 'yes' |
| 54 | let buf = Run_shell_in_terminal({}) |
| 55 | call assert_equal('yes', b:done) |
| 56 | call StopShellInTerminal(buf) |
| 57 | " closing window wipes out the terminal buffer with the finished job |
| 58 | close |
| 59 | |
| 60 | if has("unix") |
| 61 | terminal ++hidden ++open sleep 1 |
| 62 | sleep 1 |
| 63 | call assert_fails("echo b:done", 'E121:') |
| 64 | endif |
| 65 | |
| 66 | au! TerminalWinOpen |
| 67 | endfunc |
| 68 | |
Bram Moolenaar | 20e6cd0 | 2017-08-01 20:25:22 +0200 | [diff] [blame] | 69 | func Test_terminal_make_change() |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 70 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 71 | call StopShellInTerminal(buf) |
Bram Moolenaar | 20e6cd0 | 2017-08-01 20:25:22 +0200 | [diff] [blame] | 72 | |
| 73 | setlocal modifiable |
| 74 | exe "normal Axxx\<Esc>" |
Bram Moolenaar | 28ee892 | 2020-10-28 20:20:00 +0100 | [diff] [blame] | 75 | call assert_fails(buf . 'bwipe', 'E89:') |
Bram Moolenaar | 20e6cd0 | 2017-08-01 20:25:22 +0200 | [diff] [blame] | 76 | undo |
| 77 | |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 78 | exe buf . 'bwipe' |
| 79 | unlet g:job |
| 80 | endfunc |
| 81 | |
Bram Moolenaar | 5b868a8 | 2019-02-25 06:11:53 +0100 | [diff] [blame] | 82 | func Test_terminal_paste_register() |
| 83 | let @" = "text to paste" |
| 84 | |
| 85 | let buf = Run_shell_in_terminal({}) |
| 86 | " Wait for the shell to display a prompt |
| 87 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
| 88 | |
| 89 | call feedkeys("echo \<C-W>\"\" \<C-W>\"=37 + 5\<CR>\<CR>", 'xt') |
| 90 | call WaitForAssert({-> assert_match("echo text to paste 42$", getline(1))}) |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 91 | call WaitForAssert({-> assert_equal('text to paste 42', 2->getline())}) |
Bram Moolenaar | 5b868a8 | 2019-02-25 06:11:53 +0100 | [diff] [blame] | 92 | |
| 93 | exe buf . 'bwipe!' |
| 94 | unlet g:job |
| 95 | endfunc |
| 96 | |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 97 | func Test_terminal_wipe_buffer() |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 98 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | 28ee892 | 2020-10-28 20:20:00 +0100 | [diff] [blame] | 99 | call assert_fails(buf . 'bwipe', 'E89:') |
Bram Moolenaar | eb44a68 | 2017-08-03 22:44:55 +0200 | [diff] [blame] | 100 | exe buf . 'bwipe!' |
Bram Moolenaar | 50182fa | 2018-04-28 21:34:40 +0200 | [diff] [blame] | 101 | call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 102 | call assert_equal("", bufname(buf)) |
| 103 | |
| 104 | unlet g:job |
| 105 | endfunc |
| 106 | |
Bram Moolenaar | 8adb0d0 | 2017-09-17 19:08:02 +0200 | [diff] [blame] | 107 | func Test_terminal_split_quit() |
| 108 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | 8adb0d0 | 2017-09-17 19:08:02 +0200 | [diff] [blame] | 109 | split |
| 110 | quit! |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 111 | call TermWait(buf) |
Bram Moolenaar | 8adb0d0 | 2017-09-17 19:08:02 +0200 | [diff] [blame] | 112 | sleep 50m |
| 113 | call assert_equal('run', job_status(g:job)) |
| 114 | |
| 115 | quit! |
Bram Moolenaar | 50182fa | 2018-04-28 21:34:40 +0200 | [diff] [blame] | 116 | call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) |
Bram Moolenaar | 8adb0d0 | 2017-09-17 19:08:02 +0200 | [diff] [blame] | 117 | |
| 118 | exe buf . 'bwipe' |
| 119 | unlet g:job |
| 120 | endfunc |
| 121 | |
Bram Moolenaar | c9f8b84 | 2020-11-24 19:36:16 +0100 | [diff] [blame] | 122 | func Test_terminal_hide_buffer_job_running() |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 123 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | 97a80e4 | 2017-08-30 13:31:49 +0200 | [diff] [blame] | 124 | setlocal bufhidden=hide |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 125 | quit |
| 126 | for nr in range(1, winnr('$')) |
| 127 | call assert_notequal(winbufnr(nr), buf) |
| 128 | endfor |
| 129 | call assert_true(bufloaded(buf)) |
| 130 | call assert_true(buflisted(buf)) |
| 131 | |
| 132 | exe 'split ' . buf . 'buf' |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 133 | call StopShellInTerminal(buf) |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 134 | exe buf . 'bwipe' |
| 135 | |
| 136 | unlet g:job |
| 137 | endfunc |
| 138 | |
Bram Moolenaar | c9f8b84 | 2020-11-24 19:36:16 +0100 | [diff] [blame] | 139 | func Test_terminal_hide_buffer_job_finished() |
| 140 | term echo hello |
| 141 | let buf = bufnr() |
| 142 | setlocal bufhidden=hide |
| 143 | call WaitForAssert({-> assert_equal('finished', term_getstatus(buf))}) |
| 144 | call assert_true(bufloaded(buf)) |
| 145 | call assert_true(buflisted(buf)) |
| 146 | edit Xasdfasdf |
| 147 | call assert_true(bufloaded(buf)) |
| 148 | call assert_true(buflisted(buf)) |
| 149 | exe buf .. 'buf' |
| 150 | call assert_equal(buf, bufnr()) |
| 151 | setlocal bufhidden= |
| 152 | edit Xasdfasdf |
| 153 | call assert_false(bufloaded(buf)) |
| 154 | call assert_false(buflisted(buf)) |
| 155 | bwipe Xasdfasdf |
| 156 | endfunc |
| 157 | |
Bram Moolenaar | 3ad6953 | 2021-11-19 17:01:08 +0000 | [diff] [blame] | 158 | func Test_terminal_rename_buffer() |
| 159 | let cmd = Get_cat_123_cmd() |
| 160 | let buf = term_start(cmd, {'term_name': 'foo'}) |
| 161 | call WaitForAssert({-> assert_equal('finished', term_getstatus(buf))}) |
| 162 | call assert_equal('foo', bufname()) |
| 163 | call assert_match('foo.*finished', execute('ls')) |
| 164 | file bar |
| 165 | call assert_equal('bar', bufname()) |
| 166 | call assert_match('bar.*finished', execute('ls')) |
| 167 | exe 'bwipe! ' .. buf |
| 168 | endfunc |
| 169 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 170 | func s:Nasty_exit_cb(job, st) |
Bram Moolenaar | 3c3a80d | 2017-08-03 17:06:45 +0200 | [diff] [blame] | 171 | exe g:buf . 'bwipe!' |
| 172 | let g:buf = 0 |
| 173 | endfunc |
| 174 | |
Bram Moolenaar | 9d18961 | 2017-09-09 18:11:00 +0200 | [diff] [blame] | 175 | func Get_cat_123_cmd() |
| 176 | if has('win32') |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 177 | if !has('conpty') |
| 178 | return 'cmd /c "cls && color 2 && echo 123"' |
| 179 | else |
| 180 | " When clearing twice, extra sequence is not output. |
| 181 | return 'cmd /c "cls && cls && color 2 && echo 123"' |
| 182 | endif |
Bram Moolenaar | 9d18961 | 2017-09-09 18:11:00 +0200 | [diff] [blame] | 183 | else |
| 184 | call writefile(["\<Esc>[32m123"], 'Xtext') |
| 185 | return "cat Xtext" |
| 186 | endif |
| 187 | endfunc |
| 188 | |
Bram Moolenaar | 3c3a80d | 2017-08-03 17:06:45 +0200 | [diff] [blame] | 189 | func Test_terminal_nasty_cb() |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 190 | let cmd = Get_cat_123_cmd() |
Bram Moolenaar | 3c3a80d | 2017-08-03 17:06:45 +0200 | [diff] [blame] | 191 | let g:buf = term_start(cmd, {'exit_cb': function('s:Nasty_exit_cb')}) |
| 192 | let g:job = term_getjob(g:buf) |
| 193 | |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 194 | call WaitForAssert({-> assert_equal("dead", job_status(g:job))}) |
| 195 | call WaitForAssert({-> assert_equal(0, g:buf)}) |
Bram Moolenaar | 3c3a80d | 2017-08-03 17:06:45 +0200 | [diff] [blame] | 196 | unlet g:job |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 197 | unlet g:buf |
Bram Moolenaar | 3c3a80d | 2017-08-03 17:06:45 +0200 | [diff] [blame] | 198 | call delete('Xtext') |
| 199 | endfunc |
| 200 | |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 201 | func Check_123(buf) |
Bram Moolenaar | 5c838a3 | 2017-08-02 22:10:34 +0200 | [diff] [blame] | 202 | let l = term_scrape(a:buf, 0) |
| 203 | call assert_true(len(l) == 0) |
| 204 | let l = term_scrape(a:buf, 999) |
| 205 | call assert_true(len(l) == 0) |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 206 | let l = a:buf->term_scrape(1) |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 207 | call assert_true(len(l) > 0) |
| 208 | call assert_equal('1', l[0].chars) |
| 209 | call assert_equal('2', l[1].chars) |
| 210 | call assert_equal('3', l[2].chars) |
| 211 | call assert_equal('#00e000', l[0].fg) |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 212 | call assert_equal(0, term_getattr(l[0].attr, 'bold')) |
| 213 | call assert_equal(0, l[0].attr->term_getattr('italic')) |
Bram Moolenaar | 81df635 | 2018-12-22 18:25:30 +0100 | [diff] [blame] | 214 | if has('win32') |
| 215 | " On Windows 'background' always defaults to dark, even though the terminal |
| 216 | " may use a light background. Therefore accept both white and black. |
| 217 | call assert_match('#ffffff\|#000000', l[0].bg) |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 218 | else |
Bram Moolenaar | 81df635 | 2018-12-22 18:25:30 +0100 | [diff] [blame] | 219 | if &background == 'light' |
| 220 | call assert_equal('#ffffff', l[0].bg) |
| 221 | else |
| 222 | call assert_equal('#000000', l[0].bg) |
| 223 | endif |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 224 | endif |
| 225 | |
Bram Moolenaar | 5c838a3 | 2017-08-02 22:10:34 +0200 | [diff] [blame] | 226 | let l = term_getline(a:buf, -1) |
| 227 | call assert_equal('', l) |
| 228 | let l = term_getline(a:buf, 0) |
| 229 | call assert_equal('', l) |
| 230 | let l = term_getline(a:buf, 999) |
| 231 | call assert_equal('', l) |
Bram Moolenaar | 9c84484 | 2017-08-01 18:41:21 +0200 | [diff] [blame] | 232 | let l = term_getline(a:buf, 1) |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 233 | call assert_equal('123', l) |
| 234 | endfunc |
| 235 | |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 236 | func Test_terminal_scrape_123() |
| 237 | let cmd = Get_cat_123_cmd() |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 238 | let buf = term_start(cmd) |
| 239 | |
| 240 | let termlist = term_list() |
| 241 | call assert_equal(1, len(termlist)) |
| 242 | call assert_equal(buf, termlist[0]) |
| 243 | |
Bram Moolenaar | f144a3f | 2017-07-30 18:02:12 +0200 | [diff] [blame] | 244 | " Nothing happens with invalid buffer number |
| 245 | call term_wait(1234) |
| 246 | |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 247 | call TermWait(buf) |
Bram Moolenaar | 1783337 | 2017-09-04 22:23:19 +0200 | [diff] [blame] | 248 | " On MS-Windows we first get a startup message of two lines, wait for the |
Bram Moolenaar | 1bfdc07 | 2017-09-05 20:19:42 +0200 | [diff] [blame] | 249 | " "cls" to happen, after that we have one line with three characters. |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 250 | call WaitForAssert({-> assert_equal(3, len(term_scrape(buf, 1)))}) |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 251 | call Check_123(buf) |
| 252 | |
| 253 | " Must still work after the job ended. |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 254 | let job = term_getjob(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 255 | call WaitForAssert({-> assert_equal("dead", job_status(job))}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 256 | call TermWait(buf) |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 257 | call Check_123(buf) |
| 258 | |
| 259 | exe buf . 'bwipe' |
Bram Moolenaar | f144a3f | 2017-07-30 18:02:12 +0200 | [diff] [blame] | 260 | call delete('Xtext') |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 261 | endfunc |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 262 | |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 263 | func Test_terminal_scrape_multibyte() |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 264 | call writefile(["léttまrs"], 'Xtext') |
| 265 | if has('win32') |
Bram Moolenaar | 3678393 | 2017-08-14 23:07:30 +0200 | [diff] [blame] | 266 | " Run cmd with UTF-8 codepage to make the type command print the expected |
| 267 | " multibyte characters. |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 268 | let buf = term_start("cmd /K chcp 65001") |
| 269 | call term_sendkeys(buf, "type Xtext\<CR>") |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 270 | eval buf->term_sendkeys("exit\<CR>") |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 271 | let line = 4 |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 272 | else |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 273 | let buf = term_start("cat Xtext") |
| 274 | let line = 1 |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 275 | endif |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 276 | |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 277 | call WaitFor({-> len(term_scrape(buf, line)) >= 7 && term_scrape(buf, line)[0].chars == "l"}) |
| 278 | let l = term_scrape(buf, line) |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 279 | call assert_true(len(l) >= 7) |
| 280 | call assert_equal('l', l[0].chars) |
| 281 | call assert_equal('é', l[1].chars) |
| 282 | call assert_equal(1, l[1].width) |
| 283 | call assert_equal('t', l[2].chars) |
| 284 | call assert_equal('t', l[3].chars) |
| 285 | call assert_equal('ま', l[4].chars) |
| 286 | call assert_equal(2, l[4].width) |
| 287 | call assert_equal('r', l[5].chars) |
| 288 | call assert_equal('s', l[6].chars) |
| 289 | |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 290 | let job = term_getjob(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 291 | call WaitForAssert({-> assert_equal("dead", job_status(job))}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 292 | call TermWait(buf) |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 293 | |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 294 | exe buf . 'bwipe' |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 295 | call delete('Xtext') |
| 296 | endfunc |
| 297 | |
Bram Moolenaar | 8b89614 | 2020-08-02 15:05:05 +0200 | [diff] [blame] | 298 | func Test_terminal_one_column() |
| 299 | " This creates a terminal, displays a double-wide character and makes the |
| 300 | " window one column wide. This used to cause a crash. |
| 301 | let width = &columns |
| 302 | botright vert term |
| 303 | let buf = bufnr('$') |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 304 | call TermWait(buf, 100) |
Bram Moolenaar | 8b89614 | 2020-08-02 15:05:05 +0200 | [diff] [blame] | 305 | exe "set columns=" .. (width / 2) |
| 306 | redraw |
| 307 | call term_sendkeys(buf, "キ") |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 308 | call TermWait(buf, 10) |
Bram Moolenaar | 8b89614 | 2020-08-02 15:05:05 +0200 | [diff] [blame] | 309 | exe "set columns=" .. width |
| 310 | exe buf . 'bwipe!' |
| 311 | endfunc |
| 312 | |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 313 | func Test_terminal_scroll() |
| 314 | call writefile(range(1, 200), 'Xtext') |
| 315 | if has('win32') |
| 316 | let cmd = 'cmd /c "type Xtext"' |
| 317 | else |
| 318 | let cmd = "cat Xtext" |
| 319 | endif |
| 320 | let buf = term_start(cmd) |
| 321 | |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 322 | let job = term_getjob(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 323 | call WaitForAssert({-> assert_equal("dead", job_status(job))}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 324 | call TermWait(buf) |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 325 | |
Bram Moolenaar | bfcfd57 | 2020-03-25 21:27:22 +0100 | [diff] [blame] | 326 | " wait until the scrolling stops |
| 327 | while 1 |
| 328 | let scrolled = buf->term_getscrolled() |
| 329 | sleep 20m |
| 330 | if scrolled == buf->term_getscrolled() |
| 331 | break |
| 332 | endif |
| 333 | endwhile |
| 334 | |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 335 | call assert_equal('1', getline(1)) |
Bram Moolenaar | 82b9ca0 | 2017-08-08 23:06:46 +0200 | [diff] [blame] | 336 | call assert_equal('1', term_getline(buf, 1 - scrolled)) |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 337 | call assert_equal('49', getline(49)) |
Bram Moolenaar | 82b9ca0 | 2017-08-08 23:06:46 +0200 | [diff] [blame] | 338 | call assert_equal('49', term_getline(buf, 49 - scrolled)) |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 339 | call assert_equal('200', getline(200)) |
Bram Moolenaar | 82b9ca0 | 2017-08-08 23:06:46 +0200 | [diff] [blame] | 340 | call assert_equal('200', term_getline(buf, 200 - scrolled)) |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 341 | |
| 342 | exe buf . 'bwipe' |
| 343 | call delete('Xtext') |
| 344 | endfunc |
| 345 | |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 346 | func Test_terminal_scrollback() |
Bram Moolenaar | 33c5e9f | 2018-05-26 18:58:51 +0200 | [diff] [blame] | 347 | let buf = Run_shell_in_terminal({'term_rows': 15}) |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 348 | set termwinscroll=100 |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 349 | call writefile(range(150), 'Xtext') |
| 350 | if has('win32') |
| 351 | call term_sendkeys(buf, "type Xtext\<CR>") |
| 352 | else |
| 353 | call term_sendkeys(buf, "cat Xtext\<CR>") |
| 354 | endif |
| 355 | let rows = term_getsize(buf)[0] |
Bram Moolenaar | 6c67219 | 2018-04-15 13:28:42 +0200 | [diff] [blame] | 356 | " On MS-Windows there is an empty line, check both last line and above it. |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 357 | call WaitForAssert({-> assert_match( '149', term_getline(buf, rows - 1) . term_getline(buf, rows - 2))}) |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 358 | let lines = line('$') |
Bram Moolenaar | ac3e830 | 2018-04-15 13:10:44 +0200 | [diff] [blame] | 359 | call assert_inrange(91, 100, lines) |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 360 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 361 | call StopShellInTerminal(buf) |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 362 | exe buf . 'bwipe' |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 363 | set termwinscroll& |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 364 | call delete('Xtext') |
| 365 | endfunc |
| 366 | |
| 367 | func Test_terminal_postponed_scrollback() |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 368 | " tail -f only works on Unix |
| 369 | CheckUnix |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 370 | |
| 371 | call writefile(range(50), 'Xtext') |
| 372 | call writefile([ |
Bram Moolenaar | 5ff7df5 | 2019-02-15 01:06:13 +0100 | [diff] [blame] | 373 | \ 'set shell=/bin/sh noruler', |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 374 | \ 'terminal', |
Bram Moolenaar | 7e841e3 | 2019-02-15 00:26:14 +0100 | [diff] [blame] | 375 | \ 'sleep 200m', |
Bram Moolenaar | 5ff7df5 | 2019-02-15 01:06:13 +0100 | [diff] [blame] | 376 | \ 'call feedkeys("tail -n 100 -f Xtext\<CR>", "xt")', |
| 377 | \ 'sleep 100m', |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 378 | \ 'call feedkeys("\<C-W>N", "xt")', |
| 379 | \ ], 'XTest_postponed') |
| 380 | let buf = RunVimInTerminal('-S XTest_postponed', {}) |
| 381 | " Check that the Xtext lines are displayed and in Terminal-Normal mode |
Bram Moolenaar | ddbfe23 | 2020-03-15 20:33:40 +0100 | [diff] [blame] | 382 | call VerifyScreenDump(buf, 'Test_terminal_scrollback_1', {}) |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 383 | |
| 384 | silent !echo 'one more line' >>Xtext |
Bram Moolenaar | 700dfaa | 2019-04-13 14:21:19 +0200 | [diff] [blame] | 385 | " Screen will not change, move cursor to get a different dump |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 386 | call term_sendkeys(buf, "k") |
Bram Moolenaar | ddbfe23 | 2020-03-15 20:33:40 +0100 | [diff] [blame] | 387 | call VerifyScreenDump(buf, 'Test_terminal_scrollback_2', {}) |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 388 | |
| 389 | " Back to Terminal-Job mode, text will scroll and show the extra line. |
| 390 | call term_sendkeys(buf, "a") |
Bram Moolenaar | ddbfe23 | 2020-03-15 20:33:40 +0100 | [diff] [blame] | 391 | call VerifyScreenDump(buf, 'Test_terminal_scrollback_3', {}) |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 392 | |
Bram Moolenaar | ddbfe23 | 2020-03-15 20:33:40 +0100 | [diff] [blame] | 393 | " stop "tail -f" |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 394 | call term_sendkeys(buf, "\<C-C>") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 395 | call TermWait(buf, 25) |
Bram Moolenaar | ddbfe23 | 2020-03-15 20:33:40 +0100 | [diff] [blame] | 396 | " stop shell |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 397 | call term_sendkeys(buf, "exit\<CR>") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 398 | call TermWait(buf, 50) |
Bram Moolenaar | ddbfe23 | 2020-03-15 20:33:40 +0100 | [diff] [blame] | 399 | " close terminal window |
Bram Moolenaar | 3a05ce6 | 2020-03-11 19:30:01 +0100 | [diff] [blame] | 400 | let tsk_ret = term_sendkeys(buf, ":q\<CR>") |
| 401 | |
| 402 | " check type of term_sendkeys() return value |
| 403 | echo type(tsk_ret) |
| 404 | |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 405 | call StopVimInTerminal(buf) |
| 406 | call delete('XTest_postponed') |
| 407 | call delete('Xtext') |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 408 | endfunc |
| 409 | |
Bram Moolenaar | 81aa0f5 | 2019-02-14 23:23:19 +0100 | [diff] [blame] | 410 | " Run diff on two dumps with different size. |
| 411 | func Test_terminal_dumpdiff_size() |
| 412 | call assert_equal(1, winnr('$')) |
| 413 | call term_dumpdiff('dumps/Test_incsearch_search_01.dump', 'dumps/Test_popup_command_01.dump') |
| 414 | call assert_equal(2, winnr('$')) |
| 415 | call assert_match('Test_incsearch_search_01.dump', getline(10)) |
| 416 | call assert_match(' +++++$', getline(11)) |
| 417 | call assert_match('Test_popup_command_01.dump', getline(31)) |
| 418 | call assert_equal(repeat('+', 75), getline(30)) |
| 419 | quit |
| 420 | endfunc |
| 421 | |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 422 | func Test_terminal_size() |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 423 | let cmd = Get_cat_123_cmd() |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 424 | |
Bram Moolenaar | b241208 | 2017-08-20 18:09:14 +0200 | [diff] [blame] | 425 | exe 'terminal ++rows=5 ' . cmd |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 426 | let size = term_getsize('') |
| 427 | bwipe! |
| 428 | call assert_equal(5, size[0]) |
| 429 | |
Bram Moolenaar | 08d384f | 2017-08-11 21:51:23 +0200 | [diff] [blame] | 430 | call term_start(cmd, {'term_rows': 6}) |
| 431 | let size = term_getsize('') |
| 432 | bwipe! |
| 433 | call assert_equal(6, size[0]) |
| 434 | |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 435 | vsplit |
Bram Moolenaar | b241208 | 2017-08-20 18:09:14 +0200 | [diff] [blame] | 436 | exe 'terminal ++rows=5 ++cols=33 ' . cmd |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 437 | call assert_equal([5, 33], ''->term_getsize()) |
Bram Moolenaar | a42d363 | 2018-04-14 17:05:38 +0200 | [diff] [blame] | 438 | |
| 439 | call term_setsize('', 6, 0) |
| 440 | call assert_equal([6, 33], term_getsize('')) |
| 441 | |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 442 | eval ''->term_setsize(0, 35) |
Bram Moolenaar | a42d363 | 2018-04-14 17:05:38 +0200 | [diff] [blame] | 443 | call assert_equal([6, 35], term_getsize('')) |
| 444 | |
| 445 | call term_setsize('', 7, 30) |
| 446 | call assert_equal([7, 30], term_getsize('')) |
| 447 | |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 448 | bwipe! |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 449 | call assert_fails("call term_setsize('', 7, 30)", "E955:") |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 450 | |
Bram Moolenaar | 08d384f | 2017-08-11 21:51:23 +0200 | [diff] [blame] | 451 | call term_start(cmd, {'term_rows': 6, 'term_cols': 36}) |
| 452 | let size = term_getsize('') |
| 453 | bwipe! |
| 454 | call assert_equal([6, 36], size) |
| 455 | |
Bram Moolenaar | b241208 | 2017-08-20 18:09:14 +0200 | [diff] [blame] | 456 | exe 'vertical terminal ++cols=20 ' . cmd |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 457 | let size = term_getsize('') |
| 458 | bwipe! |
| 459 | call assert_equal(20, size[1]) |
| 460 | |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 461 | eval cmd->term_start({'vertical': 1, 'term_cols': 26}) |
Bram Moolenaar | 08d384f | 2017-08-11 21:51:23 +0200 | [diff] [blame] | 462 | let size = term_getsize('') |
| 463 | bwipe! |
| 464 | call assert_equal(26, size[1]) |
| 465 | |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 466 | split |
Bram Moolenaar | b241208 | 2017-08-20 18:09:14 +0200 | [diff] [blame] | 467 | exe 'vertical terminal ++rows=6 ++cols=20 ' . cmd |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 468 | let size = term_getsize('') |
| 469 | bwipe! |
| 470 | call assert_equal([6, 20], size) |
Bram Moolenaar | 08d384f | 2017-08-11 21:51:23 +0200 | [diff] [blame] | 471 | |
| 472 | call term_start(cmd, {'vertical': 1, 'term_rows': 7, 'term_cols': 27}) |
| 473 | let size = term_getsize('') |
| 474 | bwipe! |
| 475 | call assert_equal([7, 27], size) |
Bram Moolenaar | 9d654a8 | 2017-09-03 19:52:17 +0200 | [diff] [blame] | 476 | |
Bram Moolenaar | 5300be6 | 2021-11-13 10:27:40 +0000 | [diff] [blame] | 477 | call assert_fails("call term_start(cmd, {'term_rows': -1})", 'E475:') |
| 478 | call assert_fails("call term_start(cmd, {'term_rows': 1001})", 'E475:') |
Bram Moolenaar | 8813739 | 2021-11-12 16:01:15 +0000 | [diff] [blame] | 479 | if has('float') |
| 480 | call assert_fails("call term_start(cmd, {'term_rows': 10.0})", 'E805:') |
| 481 | endif |
| 482 | |
Bram Moolenaar | 9d654a8 | 2017-09-03 19:52:17 +0200 | [diff] [blame] | 483 | call delete('Xtext') |
Bram Moolenaar | da43b61 | 2017-08-11 22:27:50 +0200 | [diff] [blame] | 484 | endfunc |
| 485 | |
Bram Moolenaar | eba13e4 | 2021-02-23 17:47:23 +0100 | [diff] [blame] | 486 | func Test_terminal_zero_height() |
| 487 | split |
| 488 | wincmd j |
| 489 | anoremenu 1.1 WinBar.test : |
| 490 | terminal ++curwin |
| 491 | wincmd k |
| 492 | wincmd _ |
| 493 | redraw |
| 494 | |
| 495 | call term_sendkeys(bufnr(), "exit\r") |
| 496 | bwipe! |
| 497 | endfunc |
| 498 | |
Bram Moolenaar | da43b61 | 2017-08-11 22:27:50 +0200 | [diff] [blame] | 499 | func Test_terminal_curwin() |
| 500 | let cmd = Get_cat_123_cmd() |
| 501 | call assert_equal(1, winnr('$')) |
| 502 | |
Bram Moolenaar | b100909 | 2020-05-31 16:04:42 +0200 | [diff] [blame] | 503 | split Xdummy |
| 504 | call setline(1, 'dummy') |
| 505 | write |
| 506 | call assert_equal(1, getbufinfo('Xdummy')[0].loaded) |
Bram Moolenaar | da43b61 | 2017-08-11 22:27:50 +0200 | [diff] [blame] | 507 | exe 'terminal ++curwin ' . cmd |
| 508 | call assert_equal(2, winnr('$')) |
Bram Moolenaar | b100909 | 2020-05-31 16:04:42 +0200 | [diff] [blame] | 509 | call assert_equal(0, getbufinfo('Xdummy')[0].loaded) |
Bram Moolenaar | da43b61 | 2017-08-11 22:27:50 +0200 | [diff] [blame] | 510 | bwipe! |
| 511 | |
Bram Moolenaar | b100909 | 2020-05-31 16:04:42 +0200 | [diff] [blame] | 512 | split Xdummy |
Bram Moolenaar | da43b61 | 2017-08-11 22:27:50 +0200 | [diff] [blame] | 513 | call term_start(cmd, {'curwin': 1}) |
| 514 | call assert_equal(2, winnr('$')) |
| 515 | bwipe! |
| 516 | |
Bram Moolenaar | b100909 | 2020-05-31 16:04:42 +0200 | [diff] [blame] | 517 | split Xdummy |
Bram Moolenaar | da43b61 | 2017-08-11 22:27:50 +0200 | [diff] [blame] | 518 | call setline(1, 'change') |
| 519 | call assert_fails('terminal ++curwin ' . cmd, 'E37:') |
| 520 | call assert_equal(2, winnr('$')) |
| 521 | exe 'terminal! ++curwin ' . cmd |
| 522 | call assert_equal(2, winnr('$')) |
| 523 | bwipe! |
| 524 | |
Bram Moolenaar | b100909 | 2020-05-31 16:04:42 +0200 | [diff] [blame] | 525 | split Xdummy |
Bram Moolenaar | da43b61 | 2017-08-11 22:27:50 +0200 | [diff] [blame] | 526 | call setline(1, 'change') |
| 527 | call assert_fails("call term_start(cmd, {'curwin': 1})", 'E37:') |
| 528 | call assert_equal(2, winnr('$')) |
| 529 | bwipe! |
| 530 | |
Bram Moolenaar | b100909 | 2020-05-31 16:04:42 +0200 | [diff] [blame] | 531 | split Xdummy |
Bram Moolenaar | da43b61 | 2017-08-11 22:27:50 +0200 | [diff] [blame] | 532 | bwipe! |
Bram Moolenaar | 9d654a8 | 2017-09-03 19:52:17 +0200 | [diff] [blame] | 533 | call delete('Xtext') |
Bram Moolenaar | b100909 | 2020-05-31 16:04:42 +0200 | [diff] [blame] | 534 | call delete('Xdummy') |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 535 | endfunc |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 536 | |
Bram Moolenaar | ff54679 | 2017-11-21 14:47:57 +0100 | [diff] [blame] | 537 | func s:get_sleep_cmd() |
Bram Moolenaar | b81bc77 | 2017-08-11 22:45:01 +0200 | [diff] [blame] | 538 | if s:python != '' |
| 539 | let cmd = s:python . " test_short_sleep.py" |
Bram Moolenaar | c8523e2 | 2018-06-03 18:22:02 +0200 | [diff] [blame] | 540 | " 500 was not enough for Travis |
| 541 | let waittime = 900 |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 542 | else |
Bram Moolenaar | b81bc77 | 2017-08-11 22:45:01 +0200 | [diff] [blame] | 543 | echo 'This will take five seconds...' |
| 544 | let waittime = 2000 |
| 545 | if has('win32') |
| 546 | let cmd = $windir . '\system32\timeout.exe 1' |
| 547 | else |
| 548 | let cmd = 'sleep 1' |
| 549 | endif |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 550 | endif |
Bram Moolenaar | ff54679 | 2017-11-21 14:47:57 +0100 | [diff] [blame] | 551 | return [cmd, waittime] |
| 552 | endfunc |
| 553 | |
| 554 | func Test_terminal_finish_open_close() |
| 555 | call assert_equal(1, winnr('$')) |
| 556 | |
| 557 | let [cmd, waittime] = s:get_sleep_cmd() |
Bram Moolenaar | b81bc77 | 2017-08-11 22:45:01 +0200 | [diff] [blame] | 558 | |
Bram Moolenaar | 1dd9833 | 2018-03-16 22:54:53 +0100 | [diff] [blame] | 559 | " shell terminal closes automatically |
| 560 | terminal |
| 561 | let buf = bufnr('%') |
| 562 | call assert_equal(2, winnr('$')) |
| 563 | " Wait for the shell to display a prompt |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 564 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 565 | call StopShellInTerminal(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 566 | call WaitForAssert({-> assert_equal(1, winnr('$'))}, waittime) |
Bram Moolenaar | 1dd9833 | 2018-03-16 22:54:53 +0100 | [diff] [blame] | 567 | |
| 568 | " shell terminal that does not close automatically |
| 569 | terminal ++noclose |
| 570 | let buf = bufnr('%') |
| 571 | call assert_equal(2, winnr('$')) |
| 572 | " Wait for the shell to display a prompt |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 573 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 574 | call StopShellInTerminal(buf) |
Bram Moolenaar | 1dd9833 | 2018-03-16 22:54:53 +0100 | [diff] [blame] | 575 | call assert_equal(2, winnr('$')) |
| 576 | quit |
| 577 | call assert_equal(1, winnr('$')) |
| 578 | |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 579 | exe 'terminal ++close ' . cmd |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 580 | call assert_equal(2, winnr('$')) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 581 | wincmd p |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 582 | call WaitForAssert({-> assert_equal(1, winnr('$'))}, waittime) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 583 | |
| 584 | call term_start(cmd, {'term_finish': 'close'}) |
| 585 | call assert_equal(2, winnr('$')) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 586 | wincmd p |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 587 | call WaitForAssert({-> assert_equal(1, winnr('$'))}, waittime) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 588 | call assert_equal(1, winnr('$')) |
| 589 | |
| 590 | exe 'terminal ++open ' . cmd |
Bram Moolenaar | 97a80e4 | 2017-08-30 13:31:49 +0200 | [diff] [blame] | 591 | close! |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 592 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 593 | bwipe |
| 594 | |
| 595 | call term_start(cmd, {'term_finish': 'open'}) |
Bram Moolenaar | 97a80e4 | 2017-08-30 13:31:49 +0200 | [diff] [blame] | 596 | close! |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 597 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | 8cad930 | 2017-08-12 14:32:32 +0200 | [diff] [blame] | 598 | bwipe |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 599 | |
Bram Moolenaar | 8cad930 | 2017-08-12 14:32:32 +0200 | [diff] [blame] | 600 | exe 'terminal ++hidden ++open ' . cmd |
| 601 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 602 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | 8cad930 | 2017-08-12 14:32:32 +0200 | [diff] [blame] | 603 | bwipe |
| 604 | |
| 605 | call term_start(cmd, {'term_finish': 'open', 'hidden': 1}) |
| 606 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 607 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 608 | bwipe |
Bram Moolenaar | 37c4583 | 2017-08-12 16:01:04 +0200 | [diff] [blame] | 609 | |
| 610 | call assert_fails("call term_start(cmd, {'term_opencmd': 'open'})", 'E475:') |
| 611 | call assert_fails("call term_start(cmd, {'term_opencmd': 'split %x'})", 'E475:') |
| 612 | call assert_fails("call term_start(cmd, {'term_opencmd': 'split %d and %s'})", 'E475:') |
| 613 | call assert_fails("call term_start(cmd, {'term_opencmd': 'split % and %d'})", 'E475:') |
| 614 | |
Bram Moolenaar | 47c5ea4 | 2020-11-12 15:12:15 +0100 | [diff] [blame] | 615 | call term_start(cmd, {'term_finish': 'open', 'term_opencmd': '4split | buffer %d | let g:result = "opened the buffer in a window"'}) |
Bram Moolenaar | 97a80e4 | 2017-08-30 13:31:49 +0200 | [diff] [blame] | 616 | close! |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 617 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | 37c4583 | 2017-08-12 16:01:04 +0200 | [diff] [blame] | 618 | call assert_equal(4, winheight(0)) |
Bram Moolenaar | 47c5ea4 | 2020-11-12 15:12:15 +0100 | [diff] [blame] | 619 | call assert_equal('opened the buffer in a window', g:result) |
| 620 | unlet g:result |
Bram Moolenaar | 37c4583 | 2017-08-12 16:01:04 +0200 | [diff] [blame] | 621 | bwipe |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 622 | endfunc |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 623 | |
| 624 | func Test_terminal_cwd() |
Bram Moolenaar | 077ff43 | 2019-10-28 00:42:21 +0100 | [diff] [blame] | 625 | if has('win32') |
| 626 | let cmd = 'cmd /c cd' |
| 627 | else |
| 628 | CheckExecutable pwd |
| 629 | let cmd = 'pwd' |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 630 | endif |
| 631 | call mkdir('Xdir') |
Bram Moolenaar | 077ff43 | 2019-10-28 00:42:21 +0100 | [diff] [blame] | 632 | let buf = term_start(cmd, {'cwd': 'Xdir'}) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 633 | call WaitForAssert({-> assert_equal('Xdir', fnamemodify(getline(1), ":t"))}) |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 634 | |
| 635 | exe buf . 'bwipe' |
| 636 | call delete('Xdir', 'rf') |
| 637 | endfunc |
| 638 | |
Bram Moolenaar | 839e81e | 2018-10-19 16:53:39 +0200 | [diff] [blame] | 639 | func Test_terminal_cwd_failure() |
| 640 | " Case 1: Provided directory is not actually a directory. Attempt to make |
| 641 | " the file executable as well. |
| 642 | call writefile([], 'Xfile') |
| 643 | call setfperm('Xfile', 'rwx------') |
| 644 | call assert_fails("call term_start(&shell, {'cwd': 'Xfile'})", 'E475:') |
| 645 | call delete('Xfile') |
| 646 | |
| 647 | " Case 2: Directory does not exist. |
| 648 | call assert_fails("call term_start(&shell, {'cwd': 'Xdir'})", 'E475:') |
| 649 | |
| 650 | " Case 3: Directory exists but is not accessible. |
Bram Moolenaar | 0b38f54 | 2018-11-03 21:47:16 +0100 | [diff] [blame] | 651 | " Skip this for root, it will be accessible anyway. |
Bram Moolenaar | 07282f0 | 2019-10-10 16:46:17 +0200 | [diff] [blame] | 652 | if !IsRoot() |
Bram Moolenaar | 0b38f54 | 2018-11-03 21:47:16 +0100 | [diff] [blame] | 653 | call mkdir('XdirNoAccess', '', '0600') |
| 654 | " return early if the directory permissions could not be set properly |
| 655 | if getfperm('XdirNoAccess')[2] == 'x' |
| 656 | call delete('XdirNoAccess', 'rf') |
| 657 | return |
| 658 | endif |
| 659 | call assert_fails("call term_start(&shell, {'cwd': 'XdirNoAccess'})", 'E475:') |
| 660 | call delete('XdirNoAccess', 'rf') |
Bram Moolenaar | 839e81e | 2018-10-19 16:53:39 +0200 | [diff] [blame] | 661 | endif |
Bram Moolenaar | 839e81e | 2018-10-19 16:53:39 +0200 | [diff] [blame] | 662 | endfunc |
| 663 | |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 664 | func Test_terminal_servername() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 665 | CheckFeature clientserver |
Bram Moolenaar | d7a137f | 2018-06-12 18:05:24 +0200 | [diff] [blame] | 666 | call s:test_environment("VIM_SERVERNAME", v:servername) |
| 667 | endfunc |
| 668 | |
| 669 | func Test_terminal_version() |
| 670 | call s:test_environment("VIM_TERMINAL", string(v:version)) |
| 671 | endfunc |
| 672 | |
| 673 | func s:test_environment(name, value) |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 674 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 675 | " Wait for the shell to display a prompt |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 676 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 677 | if has('win32') |
Bram Moolenaar | d7a137f | 2018-06-12 18:05:24 +0200 | [diff] [blame] | 678 | call term_sendkeys(buf, "echo %" . a:name . "%\r") |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 679 | else |
Bram Moolenaar | d7a137f | 2018-06-12 18:05:24 +0200 | [diff] [blame] | 680 | call term_sendkeys(buf, "echo $" . a:name . "\r") |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 681 | endif |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 682 | call TermWait(buf) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 683 | call StopShellInTerminal(buf) |
Bram Moolenaar | d7a137f | 2018-06-12 18:05:24 +0200 | [diff] [blame] | 684 | call WaitForAssert({-> assert_equal(a:value, getline(2))}) |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 685 | |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 686 | exe buf . 'bwipe' |
| 687 | unlet buf |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 688 | endfunc |
| 689 | |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 690 | func Test_terminal_env() |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 691 | let buf = Run_shell_in_terminal({'env': {'TESTENV': 'correct'}}) |
Bram Moolenaar | 51c2368 | 2017-08-14 21:45:00 +0200 | [diff] [blame] | 692 | " Wait for the shell to display a prompt |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 693 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
Bram Moolenaar | ba6febd | 2017-10-30 21:56:23 +0100 | [diff] [blame] | 694 | if has('win32') |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 695 | call term_sendkeys(buf, "echo %TESTENV%\r") |
Bram Moolenaar | ba6febd | 2017-10-30 21:56:23 +0100 | [diff] [blame] | 696 | else |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 697 | call term_sendkeys(buf, "echo $TESTENV\r") |
Bram Moolenaar | ba6febd | 2017-10-30 21:56:23 +0100 | [diff] [blame] | 698 | endif |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 699 | eval buf->TermWait() |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 700 | call StopShellInTerminal(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 701 | call WaitForAssert({-> assert_equal('correct', getline(2))}) |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 702 | |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 703 | exe buf . 'bwipe' |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 704 | endfunc |
Bram Moolenaar | 679653e | 2017-08-13 14:13:19 +0200 | [diff] [blame] | 705 | |
Bram Moolenaar | dcaa613 | 2017-08-13 17:13:09 +0200 | [diff] [blame] | 706 | func Test_terminal_list_args() |
| 707 | let buf = term_start([&shell, &shellcmdflag, 'echo "123"']) |
Bram Moolenaar | 28ee892 | 2020-10-28 20:20:00 +0100 | [diff] [blame] | 708 | call assert_fails(buf . 'bwipe', 'E89:') |
Bram Moolenaar | dcaa613 | 2017-08-13 17:13:09 +0200 | [diff] [blame] | 709 | exe buf . 'bwipe!' |
| 710 | call assert_equal("", bufname(buf)) |
| 711 | endfunction |
Bram Moolenaar | 97bd5e6 | 2017-08-18 20:50:30 +0200 | [diff] [blame] | 712 | |
| 713 | func Test_terminal_noblock() |
Bram Moolenaar | f08b0eb | 2021-10-16 13:00:14 +0100 | [diff] [blame] | 714 | let g:test_is_flaky = 1 |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 715 | let buf = term_start(&shell) |
Bram Moolenaar | f3710ee | 2020-03-24 12:12:30 +0100 | [diff] [blame] | 716 | let wait_time = 5000 |
| 717 | let letters = 'abcdefghijklmnopqrstuvwxyz' |
Bram Moolenaar | 39536dd | 2019-01-29 22:58:21 +0100 | [diff] [blame] | 718 | if has('bsd') || has('mac') || has('sun') |
Bram Moolenaar | d8d85bf | 2017-09-03 18:08:00 +0200 | [diff] [blame] | 719 | " The shell or something else has a problem dealing with more than 1000 |
Bram Moolenaar | f3710ee | 2020-03-24 12:12:30 +0100 | [diff] [blame] | 720 | " characters at the same time. It's very slow too. |
Bram Moolenaar | d8d85bf | 2017-09-03 18:08:00 +0200 | [diff] [blame] | 721 | let len = 1000 |
Bram Moolenaar | d06dbf3 | 2020-03-24 10:33:00 +0100 | [diff] [blame] | 722 | let wait_time = 15000 |
Bram Moolenaar | f3710ee | 2020-03-24 12:12:30 +0100 | [diff] [blame] | 723 | let letters = 'abcdefghijklm' |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 724 | " NPFS is used in Windows, nonblocking mode does not work properly. |
| 725 | elseif has('win32') |
| 726 | let len = 1 |
Bram Moolenaar | d8d85bf | 2017-09-03 18:08:00 +0200 | [diff] [blame] | 727 | else |
| 728 | let len = 5000 |
| 729 | endif |
Bram Moolenaar | 97bd5e6 | 2017-08-18 20:50:30 +0200 | [diff] [blame] | 730 | |
Bram Moolenaar | d06dbf3 | 2020-03-24 10:33:00 +0100 | [diff] [blame] | 731 | " Send a lot of text lines, should be buffered properly. |
Bram Moolenaar | f3710ee | 2020-03-24 12:12:30 +0100 | [diff] [blame] | 732 | for c in split(letters, '\zs') |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 733 | call term_sendkeys(buf, 'echo ' . repeat(c, len) . "\<cr>") |
Bram Moolenaar | 97bd5e6 | 2017-08-18 20:50:30 +0200 | [diff] [blame] | 734 | endfor |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 735 | call term_sendkeys(buf, "echo done\<cr>") |
Bram Moolenaar | eef0531 | 2017-08-20 20:21:23 +0200 | [diff] [blame] | 736 | |
| 737 | " On MS-Windows there is an extra empty line below "done". Find "done" in |
| 738 | " the last-but-one or the last-but-two line. |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 739 | let lnum = term_getsize(buf)[0] - 1 |
Bram Moolenaar | d06dbf3 | 2020-03-24 10:33:00 +0100 | [diff] [blame] | 740 | call WaitForAssert({-> assert_match('done', term_getline(buf, lnum - 1) .. '//' .. term_getline(buf, lnum))}, wait_time) |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 741 | let line = term_getline(buf, lnum) |
Bram Moolenaar | eef0531 | 2017-08-20 20:21:23 +0200 | [diff] [blame] | 742 | if line !~ 'done' |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 743 | let line = term_getline(buf, lnum - 1) |
Bram Moolenaar | eef0531 | 2017-08-20 20:21:23 +0200 | [diff] [blame] | 744 | endif |
| 745 | call assert_match('done', line) |
Bram Moolenaar | 97bd5e6 | 2017-08-18 20:50:30 +0200 | [diff] [blame] | 746 | |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 747 | let g:job = term_getjob(buf) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 748 | call StopShellInTerminal(buf) |
Bram Moolenaar | d21f8b5 | 2017-08-19 15:40:01 +0200 | [diff] [blame] | 749 | unlet g:job |
Bram Moolenaar | 97bd5e6 | 2017-08-18 20:50:30 +0200 | [diff] [blame] | 750 | bwipe |
| 751 | endfunc |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 752 | |
| 753 | func Test_terminal_write_stdin() |
Bram Moolenaar | 2110927 | 2020-01-30 16:27:20 +0100 | [diff] [blame] | 754 | " TODO: enable once writing to stdin works on MS-Windows |
| 755 | CheckNotMSWindows |
| 756 | CheckExecutable wc |
| 757 | |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 758 | call setline(1, ['one', 'two', 'three']) |
| 759 | %term wc |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 760 | call WaitForAssert({-> assert_match('3', getline("$"))}) |
Bram Moolenaar | 3346cc4 | 2017-09-02 14:54:21 +0200 | [diff] [blame] | 761 | let nrs = split(getline('$')) |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 762 | call assert_equal(['3', '3', '14'], nrs) |
Bram Moolenaar | 2110927 | 2020-01-30 16:27:20 +0100 | [diff] [blame] | 763 | %bwipe! |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 764 | |
| 765 | call setline(1, ['one', 'two', 'three', 'four']) |
| 766 | 2,3term wc |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 767 | call WaitForAssert({-> assert_match('2', getline("$"))}) |
Bram Moolenaar | 3346cc4 | 2017-09-02 14:54:21 +0200 | [diff] [blame] | 768 | let nrs = split(getline('$')) |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 769 | call assert_equal(['2', '2', '10'], nrs) |
Bram Moolenaar | 2110927 | 2020-01-30 16:27:20 +0100 | [diff] [blame] | 770 | %bwipe! |
| 771 | endfunc |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 772 | |
Bram Moolenaar | 2110927 | 2020-01-30 16:27:20 +0100 | [diff] [blame] | 773 | func Test_terminal_eof_arg() |
Bram Moolenaar | a161cb5 | 2020-04-30 19:09:35 +0200 | [diff] [blame] | 774 | call CheckPython(s:python) |
Bram Moolenaar | dada6d2 | 2017-09-02 17:18:35 +0200 | [diff] [blame] | 775 | |
Bram Moolenaar | 2110927 | 2020-01-30 16:27:20 +0100 | [diff] [blame] | 776 | call setline(1, ['print("hello")']) |
Bram Moolenaar | a161cb5 | 2020-04-30 19:09:35 +0200 | [diff] [blame] | 777 | exe '1term ++eof=exit(123) ' .. s:python |
Bram Moolenaar | 2110927 | 2020-01-30 16:27:20 +0100 | [diff] [blame] | 778 | " MS-Windows echoes the input, Unix doesn't. |
| 779 | if has('win32') |
| 780 | call WaitFor({-> getline('$') =~ 'exit(123)'}) |
| 781 | call assert_equal('hello', getline(line('$') - 1)) |
| 782 | else |
| 783 | call WaitFor({-> getline('$') =~ 'hello'}) |
| 784 | call assert_equal('hello', getline('$')) |
Bram Moolenaar | dada6d2 | 2017-09-02 17:18:35 +0200 | [diff] [blame] | 785 | endif |
Bram Moolenaar | 2110927 | 2020-01-30 16:27:20 +0100 | [diff] [blame] | 786 | call assert_equal(123, bufnr()->term_getjob()->job_info().exitval) |
| 787 | %bwipe! |
| 788 | endfunc |
Bram Moolenaar | dada6d2 | 2017-09-02 17:18:35 +0200 | [diff] [blame] | 789 | |
Bram Moolenaar | 2110927 | 2020-01-30 16:27:20 +0100 | [diff] [blame] | 790 | func Test_terminal_eof_arg_win32_ctrl_z() |
| 791 | CheckMSWindows |
Bram Moolenaar | a161cb5 | 2020-04-30 19:09:35 +0200 | [diff] [blame] | 792 | call CheckPython(s:python) |
Bram Moolenaar | 2110927 | 2020-01-30 16:27:20 +0100 | [diff] [blame] | 793 | |
| 794 | call setline(1, ['print("hello")']) |
Bram Moolenaar | a161cb5 | 2020-04-30 19:09:35 +0200 | [diff] [blame] | 795 | exe '1term ++eof=<C-Z> ' .. s:python |
Bram Moolenaar | 2110927 | 2020-01-30 16:27:20 +0100 | [diff] [blame] | 796 | call WaitForAssert({-> assert_match('\^Z', getline(line('$') - 1))}) |
| 797 | call assert_match('\^Z', getline(line('$') - 1)) |
| 798 | %bwipe! |
| 799 | endfunc |
| 800 | |
| 801 | func Test_terminal_duplicate_eof_arg() |
Bram Moolenaar | a161cb5 | 2020-04-30 19:09:35 +0200 | [diff] [blame] | 802 | call CheckPython(s:python) |
Bram Moolenaar | 2110927 | 2020-01-30 16:27:20 +0100 | [diff] [blame] | 803 | |
| 804 | " Check the last specified ++eof arg is used and should not memory leak. |
| 805 | new |
| 806 | call setline(1, ['print("hello")']) |
Bram Moolenaar | a161cb5 | 2020-04-30 19:09:35 +0200 | [diff] [blame] | 807 | exe '1term ++eof=<C-Z> ++eof=exit(123) ' .. s:python |
Bram Moolenaar | 2110927 | 2020-01-30 16:27:20 +0100 | [diff] [blame] | 808 | " MS-Windows echoes the input, Unix doesn't. |
| 809 | if has('win32') |
| 810 | call WaitFor({-> getline('$') =~ 'exit(123)'}) |
| 811 | call assert_equal('hello', getline(line('$') - 1)) |
| 812 | else |
| 813 | call WaitFor({-> getline('$') =~ 'hello'}) |
| 814 | call assert_equal('hello', getline('$')) |
| 815 | endif |
| 816 | call assert_equal(123, bufnr()->term_getjob()->job_info().exitval) |
| 817 | %bwipe! |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 818 | endfunc |
Bram Moolenaar | 13ebb03 | 2017-08-26 22:02:51 +0200 | [diff] [blame] | 819 | |
| 820 | func Test_terminal_no_cmd() |
Bram Moolenaar | f08b0eb | 2021-10-16 13:00:14 +0100 | [diff] [blame] | 821 | let g:test_is_flaky = 1 |
Bram Moolenaar | 13ebb03 | 2017-08-26 22:02:51 +0200 | [diff] [blame] | 822 | let buf = term_start('NONE', {}) |
| 823 | call assert_notequal(0, buf) |
| 824 | |
Bram Moolenaar | 2dc9d26 | 2017-09-08 14:39:30 +0200 | [diff] [blame] | 825 | let pty = job_info(term_getjob(buf))['tty_out'] |
Bram Moolenaar | 13ebb03 | 2017-08-26 22:02:51 +0200 | [diff] [blame] | 826 | call assert_notequal('', pty) |
Bram Moolenaar | cfc1523 | 2019-01-23 22:33:18 +0100 | [diff] [blame] | 827 | if has('gui_running') && !has('win32') |
| 828 | " In the GUI job_start() doesn't work, it does not read from the pty. |
Bram Moolenaar | 2dc9d26 | 2017-09-08 14:39:30 +0200 | [diff] [blame] | 829 | call system('echo "look here" > ' . pty) |
Bram Moolenaar | cfc1523 | 2019-01-23 22:33:18 +0100 | [diff] [blame] | 830 | else |
| 831 | " Otherwise using a job works on all systems. |
| 832 | call job_start([&shell, &shellcmdflag, 'echo "look here" > ' . pty]) |
Bram Moolenaar | 2dc9d26 | 2017-09-08 14:39:30 +0200 | [diff] [blame] | 833 | endif |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 834 | call WaitForAssert({-> assert_match('look here', term_getline(buf, 1))}) |
Bram Moolenaar | 2dc9d26 | 2017-09-08 14:39:30 +0200 | [diff] [blame] | 835 | |
Bram Moolenaar | 13ebb03 | 2017-08-26 22:02:51 +0200 | [diff] [blame] | 836 | bwipe! |
| 837 | endfunc |
Bram Moolenaar | 9d654a8 | 2017-09-03 19:52:17 +0200 | [diff] [blame] | 838 | |
| 839 | func Test_terminal_special_chars() |
| 840 | " this file name only works on Unix |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 841 | CheckUnix |
| 842 | |
Bram Moolenaar | 9d654a8 | 2017-09-03 19:52:17 +0200 | [diff] [blame] | 843 | call mkdir('Xdir with spaces') |
| 844 | call writefile(['x'], 'Xdir with spaces/quoted"file') |
| 845 | term ls Xdir\ with\ spaces/quoted\"file |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 846 | call WaitForAssert({-> assert_match('quoted"file', term_getline('', 1))}) |
Bram Moolenaar | 95ffd43 | 2020-02-23 13:29:31 +0100 | [diff] [blame] | 847 | " make sure the job has finished |
| 848 | call WaitForAssert({-> assert_match('finish', term_getstatus(bufnr()))}) |
Bram Moolenaar | 9d654a8 | 2017-09-03 19:52:17 +0200 | [diff] [blame] | 849 | |
| 850 | call delete('Xdir with spaces', 'rf') |
| 851 | bwipe |
| 852 | endfunc |
Bram Moolenaar | e88fc7a | 2017-09-03 20:59:40 +0200 | [diff] [blame] | 853 | |
| 854 | func Test_terminal_wrong_options() |
| 855 | call assert_fails('call term_start(&shell, { |
| 856 | \ "in_io": "file", |
| 857 | \ "in_name": "xxx", |
| 858 | \ "out_io": "file", |
| 859 | \ "out_name": "xxx", |
| 860 | \ "err_io": "file", |
| 861 | \ "err_name": "xxx" |
| 862 | \ })', 'E474:') |
| 863 | call assert_fails('call term_start(&shell, { |
| 864 | \ "out_buf": bufnr("%") |
| 865 | \ })', 'E474:') |
| 866 | call assert_fails('call term_start(&shell, { |
| 867 | \ "err_buf": bufnr("%") |
| 868 | \ })', 'E474:') |
| 869 | endfunc |
| 870 | |
| 871 | func Test_terminal_redir_file() |
Bram Moolenaar | f08b0eb | 2021-10-16 13:00:14 +0100 | [diff] [blame] | 872 | let g:test_is_flaky = 1 |
Bram Moolenaar | f25329c | 2018-05-06 21:49:32 +0200 | [diff] [blame] | 873 | let cmd = Get_cat_123_cmd() |
| 874 | let buf = term_start(cmd, {'out_io': 'file', 'out_name': 'Xfile'}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 875 | call TermWait(buf) |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 876 | " ConPTY may precede escape sequence. There are things that are not so. |
| 877 | if !has('conpty') |
| 878 | call WaitForAssert({-> assert_notequal(0, len(readfile("Xfile")))}) |
| 879 | call assert_match('123', readfile('Xfile')[0]) |
| 880 | endif |
Bram Moolenaar | f25329c | 2018-05-06 21:49:32 +0200 | [diff] [blame] | 881 | let g:job = term_getjob(buf) |
| 882 | call WaitForAssert({-> assert_equal("dead", job_status(g:job))}) |
Bram Moolenaar | c69950a | 2020-07-22 22:23:40 +0200 | [diff] [blame] | 883 | |
| 884 | if has('win32') |
| 885 | " On Windows we cannot delete a file being used by a process. When |
| 886 | " job_status() returns "dead", the process remains for a short time. |
| 887 | " Just wait for a moment. |
| 888 | sleep 50m |
| 889 | endif |
Bram Moolenaar | f25329c | 2018-05-06 21:49:32 +0200 | [diff] [blame] | 890 | call delete('Xfile') |
| 891 | bwipe |
Bram Moolenaar | e88fc7a | 2017-09-03 20:59:40 +0200 | [diff] [blame] | 892 | |
| 893 | if has('unix') |
Bram Moolenaar | e88fc7a | 2017-09-03 20:59:40 +0200 | [diff] [blame] | 894 | call writefile(['one line'], 'Xfile') |
| 895 | let buf = term_start('cat', {'in_io': 'file', 'in_name': 'Xfile'}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 896 | call TermWait(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 897 | call WaitForAssert({-> assert_equal('one line', term_getline(buf, 1))}) |
Bram Moolenaar | 8b53b79 | 2017-09-05 20:29:25 +0200 | [diff] [blame] | 898 | let g:job = term_getjob(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 899 | call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) |
Bram Moolenaar | e88fc7a | 2017-09-03 20:59:40 +0200 | [diff] [blame] | 900 | bwipe |
| 901 | call delete('Xfile') |
| 902 | endif |
| 903 | endfunc |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 904 | |
| 905 | func TerminalTmap(remap) |
| 906 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | f4a2ed0 | 2021-03-23 16:25:09 +0100 | [diff] [blame] | 907 | " Wait for the shell to display a prompt |
| 908 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 909 | call assert_equal('t', mode()) |
| 910 | |
| 911 | if a:remap |
| 912 | tmap 123 456 |
| 913 | else |
| 914 | tnoremap 123 456 |
| 915 | endif |
Bram Moolenaar | 461fe50 | 2017-12-05 12:30:03 +0100 | [diff] [blame] | 916 | " don't use abcde, it's an existing command |
| 917 | tmap 456 abxde |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 918 | call assert_equal('456', maparg('123', 't')) |
Bram Moolenaar | 461fe50 | 2017-12-05 12:30:03 +0100 | [diff] [blame] | 919 | call assert_equal('abxde', maparg('456', 't')) |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 920 | call feedkeys("123", 'tx') |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 921 | call WaitForAssert({-> assert_match('abxde\|456', term_getline(buf, term_getcursor(buf)[0]))}) |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 922 | let lnum = term_getcursor(buf)[0] |
| 923 | if a:remap |
Bram Moolenaar | 461fe50 | 2017-12-05 12:30:03 +0100 | [diff] [blame] | 924 | call assert_match('abxde', term_getline(buf, lnum)) |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 925 | else |
| 926 | call assert_match('456', term_getline(buf, lnum)) |
| 927 | endif |
| 928 | |
| 929 | call term_sendkeys(buf, "\r") |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 930 | call StopShellInTerminal(buf) |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 931 | |
| 932 | tunmap 123 |
| 933 | tunmap 456 |
| 934 | call assert_equal('', maparg('123', 't')) |
| 935 | close |
| 936 | unlet g:job |
| 937 | endfunc |
| 938 | |
| 939 | func Test_terminal_tmap() |
| 940 | call TerminalTmap(1) |
| 941 | call TerminalTmap(0) |
| 942 | endfunc |
Bram Moolenaar | 059db5c | 2017-10-15 22:42:23 +0200 | [diff] [blame] | 943 | |
| 944 | func Test_terminal_wall() |
| 945 | let buf = Run_shell_in_terminal({}) |
| 946 | wall |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 947 | call StopShellInTerminal(buf) |
Bram Moolenaar | 059db5c | 2017-10-15 22:42:23 +0200 | [diff] [blame] | 948 | exe buf . 'bwipe' |
| 949 | unlet g:job |
| 950 | endfunc |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 951 | |
Bram Moolenaar | 7a76092 | 2018-02-19 23:10:02 +0100 | [diff] [blame] | 952 | func Test_terminal_wqall() |
| 953 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 954 | call assert_fails('wqall', 'E948:') |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 955 | call StopShellInTerminal(buf) |
Bram Moolenaar | 7a76092 | 2018-02-19 23:10:02 +0100 | [diff] [blame] | 956 | exe buf . 'bwipe' |
| 957 | unlet g:job |
| 958 | endfunc |
| 959 | |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 960 | func Test_terminal_composing_unicode() |
Bram Moolenaar | f08b0eb | 2021-10-16 13:00:14 +0100 | [diff] [blame] | 961 | let g:test_is_flaky = 1 |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 962 | let save_enc = &encoding |
| 963 | set encoding=utf-8 |
| 964 | |
| 965 | if has('win32') |
| 966 | let cmd = "cmd /K chcp 65001" |
| 967 | let lnum = [3, 6, 9] |
| 968 | else |
| 969 | let cmd = &shell |
| 970 | let lnum = [1, 3, 5] |
| 971 | endif |
| 972 | |
| 973 | enew |
Bram Moolenaar | c98cdb3 | 2020-09-06 21:13:00 +0200 | [diff] [blame] | 974 | let buf = term_start(cmd, {'curwin': 1}) |
Bram Moolenaar | 3e1c617 | 2017-11-02 16:58:00 +0100 | [diff] [blame] | 975 | let g:job = term_getjob(buf) |
Bram Moolenaar | 41d4299 | 2020-05-03 16:29:50 +0200 | [diff] [blame] | 976 | call WaitFor({-> term_getline(buf, 1) !=# ''}, 1000) |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 977 | |
Bram Moolenaar | ebe74b7 | 2018-04-21 23:34:43 +0200 | [diff] [blame] | 978 | if has('win32') |
| 979 | call assert_equal('cmd', job_info(g:job).cmd[0]) |
| 980 | else |
| 981 | call assert_equal(&shell, job_info(g:job).cmd[0]) |
| 982 | endif |
| 983 | |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 984 | " ascii + composing |
| 985 | let txt = "a\u0308bc" |
Bram Moolenaar | 41d4299 | 2020-05-03 16:29:50 +0200 | [diff] [blame] | 986 | call term_sendkeys(buf, "echo " . txt) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 987 | call TermWait(buf, 25) |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 988 | call assert_match("echo " . txt, term_getline(buf, lnum[0])) |
Bram Moolenaar | 41d4299 | 2020-05-03 16:29:50 +0200 | [diff] [blame] | 989 | call term_sendkeys(buf, "\<cr>") |
| 990 | call WaitForAssert({-> assert_equal(txt, term_getline(buf, lnum[0] + 1))}, 1000) |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 991 | let l = term_scrape(buf, lnum[0] + 1) |
| 992 | call assert_equal("a\u0308", l[0].chars) |
| 993 | call assert_equal("b", l[1].chars) |
| 994 | call assert_equal("c", l[2].chars) |
| 995 | |
Bram Moolenaar | 4549dad | 2021-02-08 21:29:48 +0100 | [diff] [blame] | 996 | " multibyte + composing: がぎぐげご |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 997 | let txt = "\u304b\u3099\u304e\u304f\u3099\u3052\u3053\u3099" |
Bram Moolenaar | 41d4299 | 2020-05-03 16:29:50 +0200 | [diff] [blame] | 998 | call term_sendkeys(buf, "echo " . txt) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 999 | call TermWait(buf, 25) |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 1000 | call assert_match("echo " . txt, term_getline(buf, lnum[1])) |
Bram Moolenaar | 41d4299 | 2020-05-03 16:29:50 +0200 | [diff] [blame] | 1001 | call term_sendkeys(buf, "\<cr>") |
| 1002 | call WaitForAssert({-> assert_equal(txt, term_getline(buf, lnum[1] + 1))}, 1000) |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 1003 | let l = term_scrape(buf, lnum[1] + 1) |
| 1004 | call assert_equal("\u304b\u3099", l[0].chars) |
Bram Moolenaar | 4549dad | 2021-02-08 21:29:48 +0100 | [diff] [blame] | 1005 | call assert_equal(2, l[0].width) |
| 1006 | call assert_equal("\u304e", l[1].chars) |
| 1007 | call assert_equal(2, l[1].width) |
| 1008 | call assert_equal("\u304f\u3099", l[2].chars) |
| 1009 | call assert_equal(2, l[2].width) |
| 1010 | call assert_equal("\u3052", l[3].chars) |
| 1011 | call assert_equal(2, l[3].width) |
| 1012 | call assert_equal("\u3053\u3099", l[4].chars) |
| 1013 | call assert_equal(2, l[4].width) |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 1014 | |
| 1015 | " \u00a0 + composing |
| 1016 | let txt = "abc\u00a0\u0308" |
Bram Moolenaar | 41d4299 | 2020-05-03 16:29:50 +0200 | [diff] [blame] | 1017 | call term_sendkeys(buf, "echo " . txt) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 1018 | call TermWait(buf, 25) |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 1019 | call assert_match("echo " . txt, term_getline(buf, lnum[2])) |
Bram Moolenaar | 41d4299 | 2020-05-03 16:29:50 +0200 | [diff] [blame] | 1020 | call term_sendkeys(buf, "\<cr>") |
| 1021 | call WaitForAssert({-> assert_equal(txt, term_getline(buf, lnum[2] + 1))}, 1000) |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 1022 | let l = term_scrape(buf, lnum[2] + 1) |
| 1023 | call assert_equal("\u00a0\u0308", l[3].chars) |
| 1024 | |
| 1025 | call term_sendkeys(buf, "exit\r") |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1026 | call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 1027 | bwipe! |
Bram Moolenaar | 3e1c617 | 2017-11-02 16:58:00 +0100 | [diff] [blame] | 1028 | unlet g:job |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 1029 | let &encoding = save_enc |
| 1030 | endfunc |
Bram Moolenaar | ff54679 | 2017-11-21 14:47:57 +0100 | [diff] [blame] | 1031 | |
| 1032 | func Test_terminal_aucmd_on_close() |
| 1033 | fun Nop() |
| 1034 | let s:called = 1 |
| 1035 | endfun |
| 1036 | |
| 1037 | aug repro |
| 1038 | au! |
| 1039 | au BufWinLeave * call Nop() |
| 1040 | aug END |
| 1041 | |
| 1042 | let [cmd, waittime] = s:get_sleep_cmd() |
| 1043 | |
| 1044 | call assert_equal(1, winnr('$')) |
| 1045 | new |
| 1046 | call setline(1, ['one', 'two']) |
| 1047 | exe 'term ++close ' . cmd |
| 1048 | wincmd p |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1049 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | ff54679 | 2017-11-21 14:47:57 +0100 | [diff] [blame] | 1050 | call assert_equal(1, s:called) |
| 1051 | bwipe! |
| 1052 | |
| 1053 | unlet s:called |
| 1054 | au! repro |
| 1055 | delfunc Nop |
| 1056 | endfunc |
Bram Moolenaar | ede35bb | 2018-01-26 20:05:18 +0100 | [diff] [blame] | 1057 | |
| 1058 | func Test_terminal_term_start_empty_command() |
| 1059 | let cmd = "call term_start('', {'curwin' : 1, 'term_finish' : 'close'})" |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 1060 | call assert_fails(cmd, 'E474:') |
Bram Moolenaar | ede35bb | 2018-01-26 20:05:18 +0100 | [diff] [blame] | 1061 | let cmd = "call term_start('', {'curwin' : 1, 'term_finish' : 'close'})" |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 1062 | call assert_fails(cmd, 'E474:') |
Bram Moolenaar | ede35bb | 2018-01-26 20:05:18 +0100 | [diff] [blame] | 1063 | let cmd = "call term_start({}, {'curwin' : 1, 'term_finish' : 'close'})" |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 1064 | call assert_fails(cmd, 'E474:') |
Bram Moolenaar | ede35bb | 2018-01-26 20:05:18 +0100 | [diff] [blame] | 1065 | let cmd = "call term_start(0, {'curwin' : 1, 'term_finish' : 'close'})" |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 1066 | call assert_fails(cmd, 'E474:') |
Bram Moolenaar | ca68ae1 | 2020-03-30 19:32:53 +0200 | [diff] [blame] | 1067 | let cmd = "call term_start('', {'term_name' : []})" |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 1068 | call assert_fails(cmd, 'E730:') |
Bram Moolenaar | ca68ae1 | 2020-03-30 19:32:53 +0200 | [diff] [blame] | 1069 | let cmd = "call term_start('', {'term_finish' : 'axby'})" |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 1070 | call assert_fails(cmd, 'E475:') |
Bram Moolenaar | ca68ae1 | 2020-03-30 19:32:53 +0200 | [diff] [blame] | 1071 | let cmd = "call term_start('', {'eof_chars' : []})" |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1072 | call assert_fails(cmd, 'E730:') |
Bram Moolenaar | ca68ae1 | 2020-03-30 19:32:53 +0200 | [diff] [blame] | 1073 | let cmd = "call term_start('', {'term_kill' : []})" |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1074 | call assert_fails(cmd, 'E730:') |
Bram Moolenaar | ca68ae1 | 2020-03-30 19:32:53 +0200 | [diff] [blame] | 1075 | let cmd = "call term_start('', {'tty_type' : []})" |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1076 | call assert_fails(cmd, 'E730:') |
Bram Moolenaar | ca68ae1 | 2020-03-30 19:32:53 +0200 | [diff] [blame] | 1077 | let cmd = "call term_start('', {'tty_type' : 'abc'})" |
| 1078 | call assert_fails(cmd, 'E475:') |
| 1079 | let cmd = "call term_start('', {'term_highlight' : []})" |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1080 | call assert_fails(cmd, 'E730:') |
Bram Moolenaar | 8720226 | 2020-05-24 17:23:45 +0200 | [diff] [blame] | 1081 | if has('gui') || has('termguicolors') |
Bram Moolenaar | ca68ae1 | 2020-03-30 19:32:53 +0200 | [diff] [blame] | 1082 | let cmd = "call term_start('', {'ansi_colors' : 'abc'})" |
| 1083 | call assert_fails(cmd, 'E475:') |
| 1084 | let cmd = "call term_start('', {'ansi_colors' : [[]]})" |
| 1085 | call assert_fails(cmd, 'E730:') |
| 1086 | let cmd = "call term_start('', {'ansi_colors' : repeat(['blue'], 18)})" |
Bram Moolenaar | 8720226 | 2020-05-24 17:23:45 +0200 | [diff] [blame] | 1087 | if has('gui_running') || has('termguicolors') |
| 1088 | call assert_fails(cmd, 'E475:') |
| 1089 | else |
| 1090 | call assert_fails(cmd, 'E254:') |
| 1091 | endif |
Bram Moolenaar | ca68ae1 | 2020-03-30 19:32:53 +0200 | [diff] [blame] | 1092 | endif |
Bram Moolenaar | ede35bb | 2018-01-26 20:05:18 +0100 | [diff] [blame] | 1093 | endfunc |
Bram Moolenaar | b50773c | 2018-01-30 22:31:19 +0100 | [diff] [blame] | 1094 | |
| 1095 | func Test_terminal_response_to_control_sequence() |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 1096 | CheckUnix |
Bram Moolenaar | b50773c | 2018-01-30 22:31:19 +0100 | [diff] [blame] | 1097 | |
| 1098 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1099 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
Bram Moolenaar | b50773c | 2018-01-30 22:31:19 +0100 | [diff] [blame] | 1100 | |
Bram Moolenaar | 086eb87 | 2018-03-25 21:24:12 +0200 | [diff] [blame] | 1101 | call term_sendkeys(buf, "cat\<CR>") |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1102 | call WaitForAssert({-> assert_match('cat', term_getline(buf, 1))}) |
Bram Moolenaar | d4a282f | 2018-02-02 18:22:31 +0100 | [diff] [blame] | 1103 | |
Bram Moolenaar | 086eb87 | 2018-03-25 21:24:12 +0200 | [diff] [blame] | 1104 | " Request the cursor position. |
| 1105 | call term_sendkeys(buf, "\x1b[6n\<CR>") |
Bram Moolenaar | d4a282f | 2018-02-02 18:22:31 +0100 | [diff] [blame] | 1106 | |
| 1107 | " Wait for output from tty to display, below an empty line. |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1108 | call WaitForAssert({-> assert_match('3;1R', term_getline(buf, 4))}) |
Bram Moolenaar | b50773c | 2018-01-30 22:31:19 +0100 | [diff] [blame] | 1109 | |
Bram Moolenaar | 086eb87 | 2018-03-25 21:24:12 +0200 | [diff] [blame] | 1110 | " End "cat" gently. |
| 1111 | call term_sendkeys(buf, "\<CR>\<C-D>") |
| 1112 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 1113 | call StopShellInTerminal(buf) |
Bram Moolenaar | b50773c | 2018-01-30 22:31:19 +0100 | [diff] [blame] | 1114 | exe buf . 'bwipe' |
| 1115 | unlet g:job |
| 1116 | endfunc |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 1117 | |
Bram Moolenaar | c295858 | 2021-12-14 11:16:31 +0000 | [diff] [blame] | 1118 | " Run this first, it fails when run after other tests. |
| 1119 | func Test_aa_terminal_focus_events() |
Bram Moolenaar | a48d4e4 | 2021-12-08 22:13:38 +0000 | [diff] [blame] | 1120 | CheckNotGui |
| 1121 | CheckUnix |
| 1122 | CheckRunVimInTerminal |
| 1123 | |
| 1124 | let save_term = &term |
| 1125 | let save_ttymouse = &ttymouse |
| 1126 | set term=xterm ttymouse=xterm2 |
| 1127 | |
| 1128 | let lines =<< trim END |
| 1129 | set term=xterm ttymouse=xterm2 |
Bram Moolenaar | e505071 | 2021-12-09 10:51:05 +0000 | [diff] [blame] | 1130 | au FocusLost * call setline(1, 'I am lost') | set nomod |
| 1131 | au FocusGained * call setline(1, 'I am back') | set nomod |
Bram Moolenaar | a48d4e4 | 2021-12-08 22:13:38 +0000 | [diff] [blame] | 1132 | END |
| 1133 | call writefile(lines, 'XtermFocus') |
| 1134 | let buf = RunVimInTerminal('-S XtermFocus', #{rows: 6}) |
| 1135 | |
| 1136 | " Send a focus event to ourselves, it should be forwarded to the terminal |
| 1137 | call feedkeys("\<Esc>[O", "Lx!") |
| 1138 | call TermWait(buf) |
| 1139 | call VerifyScreenDump(buf, 'Test_terminal_focus_1', {}) |
| 1140 | |
| 1141 | call feedkeys("\<Esc>[I", "Lx!") |
| 1142 | call TermWait(buf) |
| 1143 | call VerifyScreenDump(buf, 'Test_terminal_focus_2', {}) |
| 1144 | |
Bram Moolenaar | e505071 | 2021-12-09 10:51:05 +0000 | [diff] [blame] | 1145 | " check that a command line being edited is redrawn in place |
| 1146 | call term_sendkeys(buf, ":" .. repeat('x', 80)) |
| 1147 | call TermWait(buf) |
| 1148 | call feedkeys("\<Esc>[O", "Lx!") |
| 1149 | call TermWait(buf) |
| 1150 | call VerifyScreenDump(buf, 'Test_terminal_focus_3', {}) |
| 1151 | call term_sendkeys(buf, "\<Esc>") |
| 1152 | |
Bram Moolenaar | a48d4e4 | 2021-12-08 22:13:38 +0000 | [diff] [blame] | 1153 | call StopVimInTerminal(buf) |
| 1154 | call delete('XtermFocus') |
| 1155 | let &term = save_term |
| 1156 | let &ttymouse = save_ttymouse |
| 1157 | endfunc |
| 1158 | |
Bram Moolenaar | 3e8d385 | 2018-03-20 17:43:01 +0100 | [diff] [blame] | 1159 | " Run Vim, start a terminal in that Vim with the kill argument, |
| 1160 | " :qall works. |
| 1161 | func Run_terminal_qall_kill(line1, line2) |
| 1162 | " 1. Open a terminal window and wait for the prompt to appear |
| 1163 | " 2. set kill using term_setkill() |
| 1164 | " 3. make Vim exit, it will kill the shell |
| 1165 | let after = [ |
| 1166 | \ a:line1, |
| 1167 | \ 'let buf = bufnr("%")', |
| 1168 | \ 'while term_getline(buf, 1) =~ "^\\s*$"', |
| 1169 | \ ' sleep 10m', |
| 1170 | \ 'endwhile', |
| 1171 | \ a:line2, |
| 1172 | \ 'au VimLeavePre * call writefile(["done"], "Xdone")', |
| 1173 | \ 'qall', |
| 1174 | \ ] |
| 1175 | if !RunVim([], after, '') |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 1176 | return |
| 1177 | endif |
Bram Moolenaar | 3e8d385 | 2018-03-20 17:43:01 +0100 | [diff] [blame] | 1178 | call assert_equal("done", readfile("Xdone")[0]) |
| 1179 | call delete("Xdone") |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 1180 | endfunc |
| 1181 | |
| 1182 | " Run Vim in a terminal, then start a terminal in that Vim with a kill |
| 1183 | " argument, check that :qall works. |
Bram Moolenaar | 3e8d385 | 2018-03-20 17:43:01 +0100 | [diff] [blame] | 1184 | func Test_terminal_qall_kill_arg() |
| 1185 | call Run_terminal_qall_kill('term ++kill=kill', '') |
| 1186 | endfunc |
| 1187 | |
| 1188 | " Run Vim, start a terminal in that Vim, set the kill argument with |
| 1189 | " term_setkill(), check that :qall works. |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 1190 | func Test_terminal_qall_kill_func() |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 1191 | call Run_terminal_qall_kill('term', 'eval buf->term_setkill("kill")') |
Bram Moolenaar | 3e8d385 | 2018-03-20 17:43:01 +0100 | [diff] [blame] | 1192 | endfunc |
| 1193 | |
| 1194 | " Run Vim, start a terminal in that Vim without the kill argument, |
| 1195 | " check that :qall does not exit, :qall! does. |
| 1196 | func Test_terminal_qall_exit() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1197 | let after =<< trim [CODE] |
| 1198 | term |
| 1199 | let buf = bufnr("%") |
| 1200 | while term_getline(buf, 1) =~ "^\\s*$" |
| 1201 | sleep 10m |
| 1202 | endwhile |
| 1203 | set nomore |
| 1204 | au VimLeavePre * call writefile(["too early"], "Xdone") |
| 1205 | qall |
| 1206 | au! VimLeavePre * exe buf . "bwipe!" | call writefile(["done"], "Xdone") |
| 1207 | cquit |
| 1208 | [CODE] |
| 1209 | |
Bram Moolenaar | 3e8d385 | 2018-03-20 17:43:01 +0100 | [diff] [blame] | 1210 | if !RunVim([], after, '') |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 1211 | return |
| 1212 | endif |
Bram Moolenaar | 3e8d385 | 2018-03-20 17:43:01 +0100 | [diff] [blame] | 1213 | call assert_equal("done", readfile("Xdone")[0]) |
| 1214 | call delete("Xdone") |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 1215 | endfunc |
Bram Moolenaar | 435acdb | 2018-03-10 20:51:25 +0100 | [diff] [blame] | 1216 | |
| 1217 | " Run Vim in a terminal, then start a terminal in that Vim without a kill |
| 1218 | " argument, check that :confirm qall works. |
| 1219 | func Test_terminal_qall_prompt() |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1220 | CheckRunVimInTerminal |
Bram Moolenaar | 435acdb | 2018-03-10 20:51:25 +0100 | [diff] [blame] | 1221 | let buf = RunVimInTerminal('', {}) |
| 1222 | |
| 1223 | " Open a terminal window and wait for the prompt to appear |
| 1224 | call term_sendkeys(buf, ":term\<CR>") |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1225 | call WaitForAssert({-> assert_match('\[running]', term_getline(buf, 10))}) |
| 1226 | call WaitForAssert({-> assert_notmatch('^\s*$', term_getline(buf, 1))}) |
Bram Moolenaar | 435acdb | 2018-03-10 20:51:25 +0100 | [diff] [blame] | 1227 | |
| 1228 | " make Vim exit, it will prompt to kill the shell |
| 1229 | call term_sendkeys(buf, "\<C-W>:confirm qall\<CR>") |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1230 | call WaitForAssert({-> assert_match('ancel:', term_getline(buf, 20))}) |
Bram Moolenaar | 435acdb | 2018-03-10 20:51:25 +0100 | [diff] [blame] | 1231 | call term_sendkeys(buf, "y") |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1232 | call WaitForAssert({-> assert_equal('finished', term_getstatus(buf))}) |
Bram Moolenaar | 435acdb | 2018-03-10 20:51:25 +0100 | [diff] [blame] | 1233 | |
| 1234 | " close the terminal window where Vim was running |
| 1235 | quit |
| 1236 | endfunc |
Bram Moolenaar | b852c3e | 2018-03-11 16:55:36 +0100 | [diff] [blame] | 1237 | |
Bram Moolenaar | 4d14bac | 2019-10-20 21:15:15 +0200 | [diff] [blame] | 1238 | " Run Vim in a terminal, then start a terminal window with a shell and check |
| 1239 | " that Vim exits if it is closed. |
| 1240 | func Test_terminal_exit() |
| 1241 | CheckRunVimInTerminal |
| 1242 | |
| 1243 | let lines =<< trim END |
| 1244 | let winid = win_getid() |
| 1245 | help |
| 1246 | term |
| 1247 | let termid = win_getid() |
| 1248 | call win_gotoid(winid) |
| 1249 | close |
| 1250 | call win_gotoid(termid) |
| 1251 | END |
| 1252 | call writefile(lines, 'XtermExit') |
| 1253 | let buf = RunVimInTerminal('-S XtermExit', #{rows: 10}) |
| 1254 | let job = term_getjob(buf) |
| 1255 | call WaitForAssert({-> assert_equal("run", job_status(job))}) |
| 1256 | |
| 1257 | " quit the shell, it will make Vim exit |
| 1258 | call term_sendkeys(buf, "exit\<CR>") |
| 1259 | call WaitForAssert({-> assert_equal("dead", job_status(job))}) |
| 1260 | |
| 1261 | call delete('XtermExit') |
| 1262 | endfunc |
| 1263 | |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 1264 | func Test_terminal_open_autocmd() |
Bram Moolenaar | b852c3e | 2018-03-11 16:55:36 +0100 | [diff] [blame] | 1265 | augroup repro |
| 1266 | au! |
| 1267 | au TerminalOpen * let s:called += 1 |
| 1268 | augroup END |
| 1269 | |
| 1270 | let s:called = 0 |
| 1271 | |
| 1272 | " Open a terminal window with :terminal |
| 1273 | terminal |
| 1274 | call assert_equal(1, s:called) |
| 1275 | bwipe! |
| 1276 | |
| 1277 | " Open a terminal window with term_start() |
| 1278 | call term_start(&shell) |
| 1279 | call assert_equal(2, s:called) |
| 1280 | bwipe! |
| 1281 | |
| 1282 | " Open a hidden terminal buffer with :terminal |
| 1283 | terminal ++hidden |
| 1284 | call assert_equal(3, s:called) |
| 1285 | for buf in term_list() |
| 1286 | exe buf . "bwipe!" |
| 1287 | endfor |
| 1288 | |
| 1289 | " Open a hidden terminal buffer with term_start() |
| 1290 | let buf = term_start(&shell, {'hidden': 1}) |
| 1291 | call assert_equal(4, s:called) |
| 1292 | exe buf . "bwipe!" |
| 1293 | |
| 1294 | unlet s:called |
| 1295 | au! repro |
Bram Moolenaar | f4d61bc | 2020-11-14 14:22:28 +0100 | [diff] [blame] | 1296 | endfunc |
| 1297 | |
| 1298 | func Test_open_term_from_cmd() |
| 1299 | CheckUnix |
| 1300 | CheckRunVimInTerminal |
| 1301 | |
| 1302 | let lines =<< trim END |
| 1303 | call setline(1, ['a', 'b', 'c']) |
| 1304 | 3 |
| 1305 | set incsearch |
| 1306 | cnoremap <F3> <Cmd>call term_start(['/bin/sh', '-c', ':'])<CR> |
| 1307 | END |
| 1308 | call writefile(lines, 'Xopenterm') |
| 1309 | let buf = RunVimInTerminal('-S Xopenterm', {}) |
| 1310 | |
| 1311 | " this opens a window, incsearch should not use the old cursor position |
| 1312 | call term_sendkeys(buf, "/\<F3>") |
| 1313 | call VerifyScreenDump(buf, 'Test_terminal_from_cmd', {}) |
| 1314 | call term_sendkeys(buf, "\<Esc>") |
| 1315 | call term_sendkeys(buf, ":q\<CR>") |
| 1316 | |
| 1317 | call StopVimInTerminal(buf) |
| 1318 | call delete('Xopenterm') |
| 1319 | endfunc |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1320 | |
Bram Moolenaar | 4549dad | 2021-02-08 21:29:48 +0100 | [diff] [blame] | 1321 | func Test_combining_double_width() |
| 1322 | CheckUnix |
| 1323 | CheckRunVimInTerminal |
| 1324 | |
| 1325 | call writefile(["\xe3\x83\x9b\xe3\x82\x9a"], 'Xonedouble') |
| 1326 | let lines =<< trim END |
| 1327 | call term_start(['/bin/sh', '-c', 'cat Xonedouble']) |
| 1328 | END |
| 1329 | call writefile(lines, 'Xcombining') |
| 1330 | let buf = RunVimInTerminal('-S Xcombining', #{rows: 9}) |
| 1331 | |
| 1332 | " this opens a window, incsearch should not use the old cursor position |
| 1333 | call VerifyScreenDump(buf, 'Test_terminal_combining', {}) |
| 1334 | call term_sendkeys(buf, ":q\<CR>") |
| 1335 | |
| 1336 | call StopVimInTerminal(buf) |
| 1337 | call delete('Xonedouble') |
| 1338 | call delete('Xcombining') |
| 1339 | endfunc |
| 1340 | |
Bram Moolenaar | 0276471 | 2020-11-14 20:21:55 +0100 | [diff] [blame] | 1341 | func Test_terminal_popup_with_cmd() |
| 1342 | " this was crashing |
| 1343 | let buf = term_start(&shell, #{hidden: v:true}) |
| 1344 | let s:winid = popup_create(buf, {}) |
| 1345 | tnoremap <F3> <Cmd>call popup_close(s:winid)<CR> |
| 1346 | call feedkeys("\<F3>", 'xt') |
| 1347 | |
| 1348 | tunmap <F3> |
| 1349 | exe 'bwipe! ' .. buf |
| 1350 | unlet s:winid |
| 1351 | endfunc |
| 1352 | |
Bram Moolenaar | 8adc8d9 | 2020-11-16 20:47:31 +0100 | [diff] [blame] | 1353 | func Test_terminal_popup_bufload() |
| 1354 | let termbuf = term_start(&shell, #{hidden: v:true, term_finish: 'close'}) |
| 1355 | let winid = popup_create(termbuf, {}) |
| 1356 | sleep 50m |
| 1357 | |
| 1358 | let newbuf = bufadd('') |
| 1359 | call bufload(newbuf) |
| 1360 | call setbufline(newbuf, 1, 'foobar') |
| 1361 | |
| 1362 | " must not have switched to another window |
| 1363 | call assert_equal(winid, win_getid()) |
| 1364 | |
Bram Moolenaar | e6329e4 | 2020-11-16 21:10:34 +0100 | [diff] [blame] | 1365 | call StopShellInTerminal(termbuf) |
| 1366 | call WaitFor({-> win_getid() != winid}) |
Bram Moolenaar | 8adc8d9 | 2020-11-16 20:47:31 +0100 | [diff] [blame] | 1367 | exe 'bwipe! ' .. newbuf |
| 1368 | endfunc |
| 1369 | |
Bram Moolenaar | 3194e5b | 2021-12-13 21:59:09 +0000 | [diff] [blame] | 1370 | func Test_terminal_popup_two_windows() |
Bram Moolenaar | 0407d27 | 2021-12-13 22:17:44 +0000 | [diff] [blame] | 1371 | CheckRunVimInTerminal |
Bram Moolenaar | 3194e5b | 2021-12-13 21:59:09 +0000 | [diff] [blame] | 1372 | CheckUnix |
| 1373 | |
| 1374 | " use "sh" instead of "&shell" in the hope it will use a short prompt |
| 1375 | let lines =<< trim END |
| 1376 | let termbuf = term_start('sh', #{hidden: v:true, term_finish: 'close'}) |
| 1377 | exe 'buffer ' .. termbuf |
| 1378 | |
| 1379 | let winid = popup_create(termbuf, #{line: 2, minwidth: 30, border: []}) |
| 1380 | sleep 50m |
| 1381 | |
| 1382 | call term_sendkeys(termbuf, "echo 'test'") |
| 1383 | END |
| 1384 | call writefile(lines, 'XpopupScript') |
| 1385 | let buf = RunVimInTerminal('-S XpopupScript', {}) |
| 1386 | |
| 1387 | " typed text appears both in normal window and in popup |
| 1388 | call WaitForAssert({-> assert_match("echo 'test'", term_getline(buf, 1))}) |
| 1389 | call WaitForAssert({-> assert_match("echo 'test'", term_getline(buf, 3))}) |
| 1390 | |
Bram Moolenaar | 0407d27 | 2021-12-13 22:17:44 +0000 | [diff] [blame] | 1391 | call term_sendkeys(buf, "\<CR>\<CR>exit\<CR>") |
| 1392 | call TermWait(buf) |
| 1393 | call term_sendkeys(buf, ":q\<CR>") |
Bram Moolenaar | 3194e5b | 2021-12-13 21:59:09 +0000 | [diff] [blame] | 1394 | call StopVimInTerminal(buf) |
| 1395 | call delete('XpopupScript') |
| 1396 | endfunc |
| 1397 | |
Bram Moolenaar | e41decc | 2020-11-14 21:34:59 +0100 | [diff] [blame] | 1398 | func Test_terminal_popup_insert_cmd() |
| 1399 | CheckUnix |
| 1400 | |
| 1401 | inoremap <F3> <Cmd>call StartTermInPopup()<CR> |
| 1402 | func StartTermInPopup() |
Bram Moolenaar | 27f4f6b | 2020-11-16 21:02:28 +0100 | [diff] [blame] | 1403 | call term_start(['/bin/sh', '-c', 'cat'], #{hidden: v:true, term_finish: 'close'})->popup_create(#{highlight: 'Pmenu'}) |
Bram Moolenaar | e41decc | 2020-11-14 21:34:59 +0100 | [diff] [blame] | 1404 | endfunc |
| 1405 | call feedkeys("i\<F3>") |
| 1406 | sleep 10m |
| 1407 | call assert_equal('n', mode()) |
| 1408 | |
| 1409 | call feedkeys("\<C-D>", 'xt') |
Bram Moolenaar | 17ab28d | 2020-11-18 12:24:01 +0100 | [diff] [blame] | 1410 | call WaitFor({-> popup_list() == []}) |
Bram Moolenaar | e41decc | 2020-11-14 21:34:59 +0100 | [diff] [blame] | 1411 | delfunc StartTermInPopup |
| 1412 | iunmap <F3> |
| 1413 | endfunc |
| 1414 | |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1415 | func Check_dump01(off) |
| 1416 | call assert_equal('one two three four five', trim(getline(a:off + 1))) |
| 1417 | call assert_equal('~ Select Word', trim(getline(a:off + 7))) |
Bram Moolenaar | 1834d37 | 2018-03-29 17:40:46 +0200 | [diff] [blame] | 1418 | call assert_equal(':popup PopUp', trim(getline(a:off + 20))) |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1419 | endfunc |
| 1420 | |
Bram Moolenaar | f06b0b6 | 2018-03-29 17:22:24 +0200 | [diff] [blame] | 1421 | func Test_terminal_dumpwrite_composing() |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1422 | CheckRunVimInTerminal |
Bram Moolenaar | 3194e5b | 2021-12-13 21:59:09 +0000 | [diff] [blame] | 1423 | |
Bram Moolenaar | f06b0b6 | 2018-03-29 17:22:24 +0200 | [diff] [blame] | 1424 | let save_enc = &encoding |
| 1425 | set encoding=utf-8 |
| 1426 | call assert_equal(1, winnr('$')) |
| 1427 | |
| 1428 | let text = " a\u0300 e\u0302 o\u0308" |
| 1429 | call writefile([text], 'Xcomposing') |
Bram Moolenaar | 77bfd75 | 2018-04-30 18:03:10 +0200 | [diff] [blame] | 1430 | let buf = RunVimInTerminal('--cmd "set encoding=utf-8" Xcomposing', {}) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1431 | call WaitForAssert({-> assert_match(text, term_getline(buf, 1))}) |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 1432 | eval 'Xdump'->term_dumpwrite(buf) |
Bram Moolenaar | f06b0b6 | 2018-03-29 17:22:24 +0200 | [diff] [blame] | 1433 | let dumpline = readfile('Xdump')[0] |
| 1434 | call assert_match('|à| |ê| |ö', dumpline) |
| 1435 | |
| 1436 | call StopVimInTerminal(buf) |
| 1437 | call delete('Xcomposing') |
| 1438 | call delete('Xdump') |
| 1439 | let &encoding = save_enc |
| 1440 | endfunc |
| 1441 | |
Bram Moolenaar | 91689ea | 2020-05-11 22:04:53 +0200 | [diff] [blame] | 1442 | " Tests for failures in the term_dumpwrite() function |
| 1443 | func Test_terminal_dumpwrite_errors() |
| 1444 | CheckRunVimInTerminal |
| 1445 | call assert_fails("call term_dumpwrite({}, 'Xtest.dump')", 'E728:') |
| 1446 | let buf = RunVimInTerminal('', {}) |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 1447 | call TermWait(buf) |
Bram Moolenaar | 91689ea | 2020-05-11 22:04:53 +0200 | [diff] [blame] | 1448 | call assert_fails("call term_dumpwrite(buf, 'Xtest.dump', '')", 'E715:') |
| 1449 | call assert_fails("call term_dumpwrite(buf, [])", 'E730:') |
| 1450 | call writefile([], 'Xtest.dump') |
| 1451 | call assert_fails("call term_dumpwrite(buf, 'Xtest.dump')", 'E953:') |
| 1452 | call delete('Xtest.dump') |
| 1453 | call assert_fails("call term_dumpwrite(buf, '')", 'E482:') |
| 1454 | call assert_fails("call term_dumpwrite(buf, test_null_string())", 'E482:') |
Bram Moolenaar | 98f1671 | 2020-05-22 13:34:01 +0200 | [diff] [blame] | 1455 | call test_garbagecollect_now() |
Bram Moolenaar | a46765a | 2020-11-01 20:58:26 +0100 | [diff] [blame] | 1456 | call StopVimInTerminal(buf, 0) |
Bram Moolenaar | 733d259 | 2020-08-20 18:59:06 +0200 | [diff] [blame] | 1457 | call TermWait(buf) |
Bram Moolenaar | 91689ea | 2020-05-11 22:04:53 +0200 | [diff] [blame] | 1458 | call assert_fails("call term_dumpwrite(buf, 'Xtest.dump')", 'E958:') |
| 1459 | call assert_fails('call term_sendkeys([], ":q\<CR>")', 'E745:') |
| 1460 | call assert_equal(0, term_sendkeys(buf, ":q\<CR>")) |
| 1461 | endfunc |
| 1462 | |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1463 | " just testing basic functionality. |
| 1464 | func Test_terminal_dumpload() |
Bram Moolenaar | 87abab9 | 2019-06-03 21:14:59 +0200 | [diff] [blame] | 1465 | let curbuf = winbufnr('') |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1466 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | 87abab9 | 2019-06-03 21:14:59 +0200 | [diff] [blame] | 1467 | let buf = term_dumpload('dumps/Test_popup_command_01.dump') |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1468 | call assert_equal(2, winnr('$')) |
| 1469 | call assert_equal(20, line('$')) |
| 1470 | call Check_dump01(0) |
Bram Moolenaar | 87abab9 | 2019-06-03 21:14:59 +0200 | [diff] [blame] | 1471 | |
| 1472 | " Load another dump in the same window |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 1473 | let buf2 = 'dumps/Test_diff_01.dump'->term_dumpload({'bufnr': buf}) |
Bram Moolenaar | 87abab9 | 2019-06-03 21:14:59 +0200 | [diff] [blame] | 1474 | call assert_equal(buf, buf2) |
| 1475 | call assert_notequal('one two three four five', trim(getline(1))) |
| 1476 | |
| 1477 | " Load the first dump again in the same window |
| 1478 | let buf2 = term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': buf}) |
| 1479 | call assert_equal(buf, buf2) |
| 1480 | call Check_dump01(0) |
| 1481 | |
| 1482 | call assert_fails("call term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': curbuf})", 'E475:') |
| 1483 | call assert_fails("call term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': 9999})", 'E86:') |
| 1484 | new |
| 1485 | let closedbuf = winbufnr('') |
| 1486 | quit |
| 1487 | call assert_fails("call term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': closedbuf})", 'E475:') |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1488 | call assert_fails('call term_dumpload([])', 'E730:') |
Bram Moolenaar | 91689ea | 2020-05-11 22:04:53 +0200 | [diff] [blame] | 1489 | call assert_fails('call term_dumpload("xabcy.dump")', 'E485:') |
Bram Moolenaar | 87abab9 | 2019-06-03 21:14:59 +0200 | [diff] [blame] | 1490 | |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1491 | quit |
| 1492 | endfunc |
| 1493 | |
Bram Moolenaar | 17efc7f | 2019-10-16 18:11:31 +0200 | [diff] [blame] | 1494 | func Test_terminal_dumpload_dump() |
| 1495 | CheckRunVimInTerminal |
| 1496 | |
| 1497 | let lines =<< trim END |
| 1498 | call term_dumpload('dumps/Test_popupwin_22.dump', #{term_rows: 12}) |
| 1499 | END |
| 1500 | call writefile(lines, 'XtermDumpload') |
| 1501 | let buf = RunVimInTerminal('-S XtermDumpload', #{rows: 15}) |
| 1502 | call VerifyScreenDump(buf, 'Test_terminal_dumpload', {}) |
| 1503 | |
| 1504 | call StopVimInTerminal(buf) |
| 1505 | call delete('XtermDumpload') |
| 1506 | endfunc |
| 1507 | |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1508 | func Test_terminal_dumpdiff() |
| 1509 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 1510 | eval 'dumps/Test_popup_command_01.dump'->term_dumpdiff('dumps/Test_popup_command_02.dump') |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1511 | call assert_equal(2, winnr('$')) |
| 1512 | call assert_equal(62, line('$')) |
| 1513 | call Check_dump01(0) |
| 1514 | call Check_dump01(42) |
| 1515 | call assert_equal(' bbbbbbbbbbbbbbbbbb ', getline(26)[0:29]) |
| 1516 | quit |
Bram Moolenaar | 91689ea | 2020-05-11 22:04:53 +0200 | [diff] [blame] | 1517 | |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1518 | call assert_fails('call term_dumpdiff("X1.dump", [])', 'E730:') |
Bram Moolenaar | 91689ea | 2020-05-11 22:04:53 +0200 | [diff] [blame] | 1519 | call assert_fails('call term_dumpdiff("X1.dump", "X2.dump")', 'E485:') |
| 1520 | call writefile([], 'X1.dump') |
| 1521 | call assert_fails('call term_dumpdiff("X1.dump", "X2.dump")', 'E485:') |
| 1522 | call delete('X1.dump') |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1523 | endfunc |
Bram Moolenaar | 897e63c | 2018-03-24 17:16:33 +0100 | [diff] [blame] | 1524 | |
Bram Moolenaar | c3ef896 | 2019-02-15 00:16:13 +0100 | [diff] [blame] | 1525 | func Test_terminal_dumpdiff_swap() |
| 1526 | call assert_equal(1, winnr('$')) |
| 1527 | call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_03.dump') |
| 1528 | call assert_equal(2, winnr('$')) |
| 1529 | call assert_equal(62, line('$')) |
| 1530 | call assert_match('Test_popup_command_01.dump', getline(21)) |
| 1531 | call assert_match('Test_popup_command_03.dump', getline(42)) |
| 1532 | call assert_match('Undo', getline(3)) |
| 1533 | call assert_match('three four five', getline(45)) |
| 1534 | |
| 1535 | normal s |
| 1536 | call assert_match('Test_popup_command_03.dump', getline(21)) |
| 1537 | call assert_match('Test_popup_command_01.dump', getline(42)) |
| 1538 | call assert_match('three four five', getline(3)) |
| 1539 | call assert_match('Undo', getline(45)) |
| 1540 | quit |
Bram Moolenaar | 98f1671 | 2020-05-22 13:34:01 +0200 | [diff] [blame] | 1541 | |
| 1542 | " Diff two terminal dump files with different number of rows |
| 1543 | " Swap the diffs |
| 1544 | call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_winline_rnu.dump') |
| 1545 | call assert_match('Test_popup_command_01.dump', getline(21)) |
| 1546 | call assert_match('Test_winline_rnu.dump', getline(42)) |
| 1547 | normal s |
| 1548 | call assert_match('Test_winline_rnu.dump', getline(6)) |
| 1549 | call assert_match('Test_popup_command_01.dump', getline(27)) |
| 1550 | quit |
Bram Moolenaar | c3ef896 | 2019-02-15 00:16:13 +0100 | [diff] [blame] | 1551 | endfunc |
| 1552 | |
Bram Moolenaar | 897e63c | 2018-03-24 17:16:33 +0100 | [diff] [blame] | 1553 | func Test_terminal_dumpdiff_options() |
| 1554 | set laststatus=0 |
| 1555 | call assert_equal(1, winnr('$')) |
| 1556 | let height = winheight(0) |
| 1557 | call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_02.dump', {'vertical': 1, 'term_cols': 33}) |
| 1558 | call assert_equal(2, winnr('$')) |
| 1559 | call assert_equal(height, winheight(winnr())) |
| 1560 | call assert_equal(33, winwidth(winnr())) |
| 1561 | call assert_equal('dump diff dumps/Test_popup_command_01.dump', bufname('%')) |
| 1562 | quit |
| 1563 | |
| 1564 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | 897e63c | 2018-03-24 17:16:33 +0100 | [diff] [blame] | 1565 | call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_02.dump', {'vertical': 0, 'term_rows': 13, 'term_name': 'something else'}) |
| 1566 | call assert_equal(2, winnr('$')) |
Bram Moolenaar | e809a4e | 2019-07-04 17:35:05 +0200 | [diff] [blame] | 1567 | call assert_equal(&columns, winwidth(0)) |
| 1568 | call assert_equal(13, winheight(0)) |
Bram Moolenaar | 897e63c | 2018-03-24 17:16:33 +0100 | [diff] [blame] | 1569 | call assert_equal('something else', bufname('%')) |
| 1570 | quit |
| 1571 | |
| 1572 | call assert_equal(1, winnr('$')) |
| 1573 | call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_02.dump', {'curwin': 1}) |
| 1574 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | ca68ae1 | 2020-03-30 19:32:53 +0200 | [diff] [blame] | 1575 | call assert_fails("call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_02.dump', {'bufnr': -1})", 'E475:') |
Bram Moolenaar | 897e63c | 2018-03-24 17:16:33 +0100 | [diff] [blame] | 1576 | bwipe |
| 1577 | |
| 1578 | set laststatus& |
| 1579 | endfunc |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1580 | |
Bram Moolenaar | 1077230 | 2019-01-20 18:25:54 +0100 | [diff] [blame] | 1581 | " When drawing the statusline the cursor position may not have been updated |
| 1582 | " yet. |
| 1583 | " 1. create a terminal, make it show 2 lines |
| 1584 | " 2. 0.5 sec later: leave terminal window, execute "i" |
| 1585 | " 3. 0.5 sec later: clear terminal window, now it's 1 line |
| 1586 | " 4. 0.5 sec later: redraw, including statusline (used to trigger bug) |
| 1587 | " 4. 0.5 sec later: should be done, clean up |
| 1588 | func Test_terminal_statusline() |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 1589 | CheckUnix |
Bram Moolenaar | 8103527 | 2021-12-16 18:02:07 +0000 | [diff] [blame] | 1590 | CheckFeature timers |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 1591 | |
Bram Moolenaar | 1077230 | 2019-01-20 18:25:54 +0100 | [diff] [blame] | 1592 | set statusline=x |
| 1593 | terminal |
| 1594 | let tbuf = bufnr('') |
| 1595 | call term_sendkeys(tbuf, "clear; echo a; echo b; sleep 1; clear\n") |
| 1596 | call timer_start(500, { tid -> feedkeys("\<C-w>j", 'tx') }) |
| 1597 | call timer_start(1500, { tid -> feedkeys("\<C-l>", 'tx') }) |
| 1598 | au BufLeave * if &buftype == 'terminal' | silent! normal i | endif |
| 1599 | |
| 1600 | sleep 2 |
| 1601 | exe tbuf . 'bwipe!' |
| 1602 | au! BufLeave |
| 1603 | set statusline= |
| 1604 | endfunc |
Bram Moolenaar | fa1e90c | 2019-04-06 17:47:40 +0200 | [diff] [blame] | 1605 | |
Bram Moolenaar | 8103527 | 2021-12-16 18:02:07 +0000 | [diff] [blame] | 1606 | func CheckTerminalWindowWorks(buf) |
| 1607 | call WaitForAssert({-> assert_match('!sh \[running\]', term_getline(a:buf, 10))}) |
| 1608 | call term_sendkeys(a:buf, "exit\<CR>") |
| 1609 | call WaitForAssert({-> assert_match('!sh \[finished\]', term_getline(a:buf, 10))}) |
| 1610 | call term_sendkeys(a:buf, ":q\<CR>") |
| 1611 | call WaitForAssert({-> assert_match('^\~', term_getline(a:buf, 10))}) |
| 1612 | endfunc |
| 1613 | |
| 1614 | func Test_start_terminal_from_timer() |
| 1615 | CheckUnix |
| 1616 | CheckFeature timers |
| 1617 | |
| 1618 | " Open a terminal window from a timer, typed text goes to the terminal |
| 1619 | call writefile(["call timer_start(100, { -> term_start('sh') })"], 'XtimerTerm') |
| 1620 | let buf = RunVimInTerminal('-S XtimerTerm', {}) |
| 1621 | call CheckTerminalWindowWorks(buf) |
| 1622 | |
| 1623 | " do the same in Insert mode |
| 1624 | call term_sendkeys(buf, ":call timer_start(200, { -> term_start('sh') })\<CR>a") |
| 1625 | call CheckTerminalWindowWorks(buf) |
| 1626 | |
| 1627 | call StopVimInTerminal(buf) |
| 1628 | call delete('XtimerTerm') |
| 1629 | endfunc |
| 1630 | |
Bram Moolenaar | f43e7ac | 2020-09-29 21:23:25 +0200 | [diff] [blame] | 1631 | func Test_terminal_window_focus() |
| 1632 | let winid1 = win_getid() |
| 1633 | terminal |
| 1634 | let winid2 = win_getid() |
| 1635 | call feedkeys("\<C-W>j", 'xt') |
| 1636 | call assert_equal(winid1, win_getid()) |
| 1637 | call feedkeys("\<C-W>k", 'xt') |
| 1638 | call assert_equal(winid2, win_getid()) |
| 1639 | " can use a cursor key here |
| 1640 | call feedkeys("\<C-W>\<Down>", 'xt') |
| 1641 | call assert_equal(winid1, win_getid()) |
| 1642 | call feedkeys("\<C-W>\<Up>", 'xt') |
| 1643 | call assert_equal(winid2, win_getid()) |
| 1644 | |
| 1645 | bwipe! |
| 1646 | endfunc |
| 1647 | |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 1648 | func Api_drop_common(options) |
| 1649 | call assert_equal(1, winnr('$')) |
| 1650 | |
| 1651 | " Use the title termcap entries to output the escape sequence. |
| 1652 | call writefile([ |
| 1653 | \ 'set title', |
| 1654 | \ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"', |
| 1655 | \ 'let &titlestring = ''["drop","Xtextfile"' . a:options . ']''', |
| 1656 | \ 'redraw', |
| 1657 | \ "set t_ts=", |
| 1658 | \ ], 'Xscript') |
| 1659 | let buf = RunVimInTerminal('-S Xscript', {}) |
| 1660 | call WaitFor({-> bufnr('Xtextfile') > 0}) |
| 1661 | call assert_equal('Xtextfile', expand('%:t')) |
| 1662 | call assert_true(winnr('$') >= 3) |
| 1663 | return buf |
| 1664 | endfunc |
| 1665 | |
| 1666 | func Test_terminal_api_drop_newwin() |
| 1667 | CheckRunVimInTerminal |
| 1668 | let buf = Api_drop_common('') |
| 1669 | call assert_equal(0, &bin) |
| 1670 | call assert_equal('', &fenc) |
| 1671 | |
| 1672 | call StopVimInTerminal(buf) |
| 1673 | call delete('Xscript') |
| 1674 | bwipe Xtextfile |
| 1675 | endfunc |
| 1676 | |
| 1677 | func Test_terminal_api_drop_newwin_bin() |
| 1678 | CheckRunVimInTerminal |
| 1679 | let buf = Api_drop_common(',{"bin":1}') |
| 1680 | call assert_equal(1, &bin) |
| 1681 | |
| 1682 | call StopVimInTerminal(buf) |
| 1683 | call delete('Xscript') |
| 1684 | bwipe Xtextfile |
| 1685 | endfunc |
| 1686 | |
| 1687 | func Test_terminal_api_drop_newwin_binary() |
| 1688 | CheckRunVimInTerminal |
| 1689 | let buf = Api_drop_common(',{"binary":1}') |
| 1690 | call assert_equal(1, &bin) |
| 1691 | |
| 1692 | call StopVimInTerminal(buf) |
| 1693 | call delete('Xscript') |
| 1694 | bwipe Xtextfile |
| 1695 | endfunc |
| 1696 | |
| 1697 | func Test_terminal_api_drop_newwin_nobin() |
| 1698 | CheckRunVimInTerminal |
| 1699 | set binary |
| 1700 | let buf = Api_drop_common(',{"nobin":1}') |
| 1701 | call assert_equal(0, &bin) |
| 1702 | |
| 1703 | call StopVimInTerminal(buf) |
| 1704 | call delete('Xscript') |
| 1705 | bwipe Xtextfile |
| 1706 | set nobinary |
| 1707 | endfunc |
| 1708 | |
| 1709 | func Test_terminal_api_drop_newwin_nobinary() |
| 1710 | CheckRunVimInTerminal |
| 1711 | set binary |
| 1712 | let buf = Api_drop_common(',{"nobinary":1}') |
| 1713 | call assert_equal(0, &bin) |
| 1714 | |
| 1715 | call StopVimInTerminal(buf) |
| 1716 | call delete('Xscript') |
| 1717 | bwipe Xtextfile |
| 1718 | set nobinary |
| 1719 | endfunc |
| 1720 | |
| 1721 | func Test_terminal_api_drop_newwin_ff() |
| 1722 | CheckRunVimInTerminal |
| 1723 | let buf = Api_drop_common(',{"ff":"dos"}') |
| 1724 | call assert_equal("dos", &ff) |
| 1725 | |
| 1726 | call StopVimInTerminal(buf) |
| 1727 | call delete('Xscript') |
| 1728 | bwipe Xtextfile |
| 1729 | endfunc |
| 1730 | |
| 1731 | func Test_terminal_api_drop_newwin_fileformat() |
| 1732 | CheckRunVimInTerminal |
| 1733 | let buf = Api_drop_common(',{"fileformat":"dos"}') |
| 1734 | call assert_equal("dos", &ff) |
| 1735 | |
| 1736 | call StopVimInTerminal(buf) |
| 1737 | call delete('Xscript') |
| 1738 | bwipe Xtextfile |
| 1739 | endfunc |
| 1740 | |
| 1741 | func Test_terminal_api_drop_newwin_enc() |
| 1742 | CheckRunVimInTerminal |
| 1743 | let buf = Api_drop_common(',{"enc":"utf-16"}') |
| 1744 | call assert_equal("utf-16", &fenc) |
| 1745 | |
| 1746 | call StopVimInTerminal(buf) |
| 1747 | call delete('Xscript') |
| 1748 | bwipe Xtextfile |
| 1749 | endfunc |
| 1750 | |
| 1751 | func Test_terminal_api_drop_newwin_encoding() |
| 1752 | CheckRunVimInTerminal |
| 1753 | let buf = Api_drop_common(',{"encoding":"utf-16"}') |
| 1754 | call assert_equal("utf-16", &fenc) |
| 1755 | |
| 1756 | call StopVimInTerminal(buf) |
| 1757 | call delete('Xscript') |
| 1758 | bwipe Xtextfile |
| 1759 | endfunc |
| 1760 | |
| 1761 | func Test_terminal_api_drop_oldwin() |
| 1762 | CheckRunVimInTerminal |
| 1763 | let firstwinid = win_getid() |
| 1764 | split Xtextfile |
| 1765 | let textfile_winid = win_getid() |
| 1766 | call assert_equal(2, winnr('$')) |
| 1767 | call win_gotoid(firstwinid) |
| 1768 | |
| 1769 | " Use the title termcap entries to output the escape sequence. |
| 1770 | call writefile([ |
| 1771 | \ 'set title', |
| 1772 | \ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"', |
| 1773 | \ 'let &titlestring = ''["drop","Xtextfile"]''', |
| 1774 | \ 'redraw', |
| 1775 | \ "set t_ts=", |
| 1776 | \ ], 'Xscript') |
| 1777 | let buf = RunVimInTerminal('-S Xscript', {'rows': 10}) |
| 1778 | call WaitForAssert({-> assert_equal('Xtextfile', expand('%:t'))}) |
| 1779 | call assert_equal(textfile_winid, win_getid()) |
| 1780 | |
| 1781 | call StopVimInTerminal(buf) |
| 1782 | call delete('Xscript') |
| 1783 | bwipe Xtextfile |
| 1784 | endfunc |
| 1785 | |
| 1786 | func Tapi_TryThis(bufnum, arg) |
| 1787 | let g:called_bufnum = a:bufnum |
| 1788 | let g:called_arg = a:arg |
| 1789 | endfunc |
| 1790 | |
| 1791 | func WriteApiCall(funcname) |
| 1792 | " Use the title termcap entries to output the escape sequence. |
| 1793 | call writefile([ |
| 1794 | \ 'set title', |
| 1795 | \ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"', |
| 1796 | \ 'let &titlestring = ''["call","' . a:funcname . '",["hello",123]]''', |
| 1797 | \ 'redraw', |
| 1798 | \ "set t_ts=", |
| 1799 | \ ], 'Xscript') |
| 1800 | endfunc |
| 1801 | |
| 1802 | func Test_terminal_api_call() |
| 1803 | CheckRunVimInTerminal |
| 1804 | |
| 1805 | unlet! g:called_bufnum |
| 1806 | unlet! g:called_arg |
| 1807 | |
| 1808 | call WriteApiCall('Tapi_TryThis') |
| 1809 | |
| 1810 | " Default |
| 1811 | let buf = RunVimInTerminal('-S Xscript', {}) |
| 1812 | call WaitFor({-> exists('g:called_bufnum')}) |
| 1813 | call assert_equal(buf, g:called_bufnum) |
| 1814 | call assert_equal(['hello', 123], g:called_arg) |
| 1815 | call StopVimInTerminal(buf) |
| 1816 | |
| 1817 | unlet! g:called_bufnum |
| 1818 | unlet! g:called_arg |
| 1819 | |
| 1820 | " Enable explicitly |
| 1821 | let buf = RunVimInTerminal('-S Xscript', {'term_api': 'Tapi_Try'}) |
| 1822 | call WaitFor({-> exists('g:called_bufnum')}) |
| 1823 | call assert_equal(buf, g:called_bufnum) |
| 1824 | call assert_equal(['hello', 123], g:called_arg) |
| 1825 | call StopVimInTerminal(buf) |
| 1826 | |
| 1827 | unlet! g:called_bufnum |
| 1828 | unlet! g:called_arg |
| 1829 | |
| 1830 | func! ApiCall_TryThis(bufnum, arg) |
| 1831 | let g:called_bufnum2 = a:bufnum |
| 1832 | let g:called_arg2 = a:arg |
| 1833 | endfunc |
| 1834 | |
| 1835 | call WriteApiCall('ApiCall_TryThis') |
| 1836 | |
| 1837 | " Use prefix match |
| 1838 | let buf = RunVimInTerminal('-S Xscript', {'term_api': 'ApiCall_'}) |
| 1839 | call WaitFor({-> exists('g:called_bufnum2')}) |
| 1840 | call assert_equal(buf, g:called_bufnum2) |
| 1841 | call assert_equal(['hello', 123], g:called_arg2) |
| 1842 | call StopVimInTerminal(buf) |
| 1843 | |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1844 | call assert_fails("call term_start('ls', {'term_api' : []})", 'E730:') |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 1845 | |
| 1846 | unlet! g:called_bufnum2 |
| 1847 | unlet! g:called_arg2 |
| 1848 | |
| 1849 | call delete('Xscript') |
| 1850 | delfunction! ApiCall_TryThis |
| 1851 | unlet! g:called_bufnum2 |
| 1852 | unlet! g:called_arg2 |
| 1853 | endfunc |
| 1854 | |
| 1855 | func Test_terminal_api_call_fails() |
| 1856 | CheckRunVimInTerminal |
| 1857 | |
| 1858 | func! TryThis(bufnum, arg) |
| 1859 | let g:called_bufnum3 = a:bufnum |
| 1860 | let g:called_arg3 = a:arg |
| 1861 | endfunc |
| 1862 | |
| 1863 | call WriteApiCall('TryThis') |
| 1864 | |
| 1865 | unlet! g:called_bufnum3 |
| 1866 | unlet! g:called_arg3 |
| 1867 | |
| 1868 | " Not permitted |
| 1869 | call ch_logfile('Xlog', 'w') |
| 1870 | let buf = RunVimInTerminal('-S Xscript', {'term_api': ''}) |
| 1871 | call WaitForAssert({-> assert_match('Unpermitted function: TryThis', string(readfile('Xlog')))}) |
| 1872 | call assert_false(exists('g:called_bufnum3')) |
| 1873 | call assert_false(exists('g:called_arg3')) |
| 1874 | call StopVimInTerminal(buf) |
| 1875 | |
| 1876 | " No match |
| 1877 | call ch_logfile('Xlog', 'w') |
| 1878 | let buf = RunVimInTerminal('-S Xscript', {'term_api': 'TryThat'}) |
| 1879 | call WaitFor({-> string(readfile('Xlog')) =~ 'Unpermitted function: TryThis'}) |
| 1880 | call assert_false(exists('g:called_bufnum3')) |
| 1881 | call assert_false(exists('g:called_arg3')) |
| 1882 | call StopVimInTerminal(buf) |
| 1883 | |
| 1884 | call delete('Xscript') |
| 1885 | call ch_logfile('') |
| 1886 | call delete('Xlog') |
| 1887 | delfunction! TryThis |
| 1888 | unlet! g:called_bufnum3 |
| 1889 | unlet! g:called_arg3 |
| 1890 | endfunc |
| 1891 | |
| 1892 | let s:caught_e937 = 0 |
| 1893 | |
| 1894 | func Tapi_Delete(bufnum, arg) |
| 1895 | try |
| 1896 | execute 'bdelete!' a:bufnum |
| 1897 | catch /E937:/ |
| 1898 | let s:caught_e937 = 1 |
| 1899 | endtry |
| 1900 | endfunc |
| 1901 | |
| 1902 | func Test_terminal_api_call_fail_delete() |
| 1903 | CheckRunVimInTerminal |
| 1904 | |
| 1905 | call WriteApiCall('Tapi_Delete') |
| 1906 | let buf = RunVimInTerminal('-S Xscript', {}) |
| 1907 | call WaitForAssert({-> assert_equal(1, s:caught_e937)}) |
| 1908 | |
| 1909 | call StopVimInTerminal(buf) |
| 1910 | call delete('Xscript') |
| 1911 | call ch_logfile('', '') |
| 1912 | endfunc |
| 1913 | |
| 1914 | func Test_terminal_setapi_and_call() |
| 1915 | CheckRunVimInTerminal |
| 1916 | |
| 1917 | call WriteApiCall('Tapi_TryThis') |
| 1918 | call ch_logfile('Xlog', 'w') |
| 1919 | |
| 1920 | unlet! g:called_bufnum |
| 1921 | unlet! g:called_arg |
| 1922 | |
| 1923 | let buf = RunVimInTerminal('-S Xscript', {'term_api': ''}) |
| 1924 | call WaitForAssert({-> assert_match('Unpermitted function: Tapi_TryThis', string(readfile('Xlog')))}) |
| 1925 | call assert_false(exists('g:called_bufnum')) |
| 1926 | call assert_false(exists('g:called_arg')) |
| 1927 | |
| 1928 | eval buf->term_setapi('Tapi_') |
| 1929 | call term_sendkeys(buf, ":set notitle\<CR>") |
| 1930 | call term_sendkeys(buf, ":source Xscript\<CR>") |
| 1931 | call WaitFor({-> exists('g:called_bufnum')}) |
| 1932 | call assert_equal(buf, g:called_bufnum) |
| 1933 | call assert_equal(['hello', 123], g:called_arg) |
| 1934 | |
| 1935 | call StopVimInTerminal(buf) |
| 1936 | |
| 1937 | call delete('Xscript') |
| 1938 | call ch_logfile('') |
| 1939 | call delete('Xlog') |
| 1940 | unlet! g:called_bufnum |
| 1941 | unlet! g:called_arg |
| 1942 | endfunc |
| 1943 | |
| 1944 | func Test_terminal_api_arg() |
| 1945 | CheckRunVimInTerminal |
| 1946 | |
| 1947 | call WriteApiCall('Tapi_TryThis') |
| 1948 | call ch_logfile('Xlog', 'w') |
| 1949 | |
| 1950 | unlet! g:called_bufnum |
| 1951 | unlet! g:called_arg |
| 1952 | |
| 1953 | execute 'term ++api= ' .. GetVimCommandCleanTerm() .. '-S Xscript' |
| 1954 | let buf = bufnr('%') |
| 1955 | call WaitForAssert({-> assert_match('Unpermitted function: Tapi_TryThis', string(readfile('Xlog')))}) |
| 1956 | call assert_false(exists('g:called_bufnum')) |
| 1957 | call assert_false(exists('g:called_arg')) |
| 1958 | |
| 1959 | call StopVimInTerminal(buf) |
| 1960 | |
| 1961 | call ch_logfile('Xlog', 'w') |
| 1962 | |
| 1963 | execute 'term ++api=Tapi_ ' .. GetVimCommandCleanTerm() .. '-S Xscript' |
| 1964 | let buf = bufnr('%') |
| 1965 | call WaitFor({-> exists('g:called_bufnum')}) |
| 1966 | call assert_equal(buf, g:called_bufnum) |
| 1967 | call assert_equal(['hello', 123], g:called_arg) |
| 1968 | |
| 1969 | call StopVimInTerminal(buf) |
| 1970 | |
| 1971 | call delete('Xscript') |
| 1972 | call ch_logfile('') |
| 1973 | call delete('Xlog') |
| 1974 | unlet! g:called_bufnum |
| 1975 | unlet! g:called_arg |
| 1976 | endfunc |
| 1977 | |
| 1978 | func Test_terminal_ansicolors_default() |
| 1979 | CheckFunction term_getansicolors |
| 1980 | |
| 1981 | let colors = [ |
| 1982 | \ '#000000', '#e00000', |
| 1983 | \ '#00e000', '#e0e000', |
| 1984 | \ '#0000e0', '#e000e0', |
| 1985 | \ '#00e0e0', '#e0e0e0', |
| 1986 | \ '#808080', '#ff4040', |
| 1987 | \ '#40ff40', '#ffff40', |
| 1988 | \ '#4040ff', '#ff40ff', |
| 1989 | \ '#40ffff', '#ffffff', |
| 1990 | \] |
| 1991 | |
| 1992 | let buf = Run_shell_in_terminal({}) |
| 1993 | call assert_equal(colors, term_getansicolors(buf)) |
| 1994 | call StopShellInTerminal(buf) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 1995 | call assert_equal([], term_getansicolors(buf)) |
| 1996 | |
| 1997 | exe buf . 'bwipe' |
| 1998 | endfunc |
| 1999 | |
| 2000 | let s:test_colors = [ |
| 2001 | \ '#616e64', '#0d0a79', |
| 2002 | \ '#6d610d', '#0a7373', |
| 2003 | \ '#690d0a', '#6d696e', |
| 2004 | \ '#0d0a6f', '#616e0d', |
| 2005 | \ '#0a6479', '#6d0d0a', |
| 2006 | \ '#617373', '#0d0a69', |
| 2007 | \ '#6d690d', '#0a6e6f', |
| 2008 | \ '#610d0a', '#6e6479', |
| 2009 | \] |
| 2010 | |
| 2011 | func Test_terminal_ansicolors_global() |
| 2012 | CheckFeature termguicolors |
| 2013 | CheckFunction term_getansicolors |
| 2014 | |
| 2015 | let g:terminal_ansi_colors = reverse(copy(s:test_colors)) |
| 2016 | let buf = Run_shell_in_terminal({}) |
| 2017 | call assert_equal(g:terminal_ansi_colors, term_getansicolors(buf)) |
| 2018 | call StopShellInTerminal(buf) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 2019 | |
| 2020 | exe buf . 'bwipe' |
| 2021 | unlet g:terminal_ansi_colors |
| 2022 | endfunc |
| 2023 | |
| 2024 | func Test_terminal_ansicolors_func() |
| 2025 | CheckFeature termguicolors |
| 2026 | CheckFunction term_getansicolors |
| 2027 | |
| 2028 | let g:terminal_ansi_colors = reverse(copy(s:test_colors)) |
| 2029 | let buf = Run_shell_in_terminal({'ansi_colors': s:test_colors}) |
| 2030 | call assert_equal(s:test_colors, term_getansicolors(buf)) |
| 2031 | |
| 2032 | call term_setansicolors(buf, g:terminal_ansi_colors) |
| 2033 | call assert_equal(g:terminal_ansi_colors, buf->term_getansicolors()) |
| 2034 | |
| 2035 | let colors = [ |
| 2036 | \ 'ivory', 'AliceBlue', |
| 2037 | \ 'grey67', 'dark goldenrod', |
| 2038 | \ 'SteelBlue3', 'PaleVioletRed4', |
| 2039 | \ 'MediumPurple2', 'yellow2', |
| 2040 | \ 'RosyBrown3', 'OrangeRed2', |
| 2041 | \ 'white smoke', 'navy blue', |
| 2042 | \ 'grey47', 'gray97', |
| 2043 | \ 'MistyRose2', 'DodgerBlue4', |
| 2044 | \] |
| 2045 | eval buf->term_setansicolors(colors) |
| 2046 | |
| 2047 | let colors[4] = 'Invalid' |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 2048 | call assert_fails('call term_setansicolors(buf, colors)', 'E254:') |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 2049 | call assert_fails('call term_setansicolors(buf, {})', 'E714:') |
| 2050 | |
| 2051 | call StopShellInTerminal(buf) |
Bram Moolenaar | 18aa13d | 2020-07-11 13:09:36 +0200 | [diff] [blame] | 2052 | call assert_equal(0, term_setansicolors(buf, [])) |
| 2053 | exe buf . 'bwipe' |
| 2054 | endfunc |
| 2055 | |
| 2056 | func Test_terminal_all_ansi_colors() |
| 2057 | CheckRunVimInTerminal |
| 2058 | |
| 2059 | " Use all the ANSI colors. |
| 2060 | call writefile([ |
| 2061 | \ 'call setline(1, "AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPP XXYYZZ")', |
| 2062 | \ 'hi Tblack ctermfg=0 ctermbg=8', |
| 2063 | \ 'hi Tdarkred ctermfg=1 ctermbg=9', |
| 2064 | \ 'hi Tdarkgreen ctermfg=2 ctermbg=10', |
| 2065 | \ 'hi Tbrown ctermfg=3 ctermbg=11', |
| 2066 | \ 'hi Tdarkblue ctermfg=4 ctermbg=12', |
| 2067 | \ 'hi Tdarkmagenta ctermfg=5 ctermbg=13', |
| 2068 | \ 'hi Tdarkcyan ctermfg=6 ctermbg=14', |
| 2069 | \ 'hi Tlightgrey ctermfg=7 ctermbg=15', |
| 2070 | \ 'hi Tdarkgrey ctermfg=8 ctermbg=0', |
| 2071 | \ 'hi Tred ctermfg=9 ctermbg=1', |
| 2072 | \ 'hi Tgreen ctermfg=10 ctermbg=2', |
| 2073 | \ 'hi Tyellow ctermfg=11 ctermbg=3', |
| 2074 | \ 'hi Tblue ctermfg=12 ctermbg=4', |
| 2075 | \ 'hi Tmagenta ctermfg=13 ctermbg=5', |
| 2076 | \ 'hi Tcyan ctermfg=14 ctermbg=6', |
| 2077 | \ 'hi Twhite ctermfg=15 ctermbg=7', |
| 2078 | \ 'hi TdarkredBold ctermfg=1 cterm=bold', |
| 2079 | \ 'hi TgreenBold ctermfg=10 cterm=bold', |
| 2080 | \ 'hi TmagentaBold ctermfg=13 cterm=bold ctermbg=5', |
| 2081 | \ '', |
| 2082 | \ 'call matchadd("Tblack", "A")', |
| 2083 | \ 'call matchadd("Tdarkred", "B")', |
| 2084 | \ 'call matchadd("Tdarkgreen", "C")', |
| 2085 | \ 'call matchadd("Tbrown", "D")', |
| 2086 | \ 'call matchadd("Tdarkblue", "E")', |
| 2087 | \ 'call matchadd("Tdarkmagenta", "F")', |
| 2088 | \ 'call matchadd("Tdarkcyan", "G")', |
| 2089 | \ 'call matchadd("Tlightgrey", "H")', |
| 2090 | \ 'call matchadd("Tdarkgrey", "I")', |
| 2091 | \ 'call matchadd("Tred", "J")', |
| 2092 | \ 'call matchadd("Tgreen", "K")', |
| 2093 | \ 'call matchadd("Tyellow", "L")', |
| 2094 | \ 'call matchadd("Tblue", "M")', |
| 2095 | \ 'call matchadd("Tmagenta", "N")', |
| 2096 | \ 'call matchadd("Tcyan", "O")', |
| 2097 | \ 'call matchadd("Twhite", "P")', |
| 2098 | \ 'call matchadd("TdarkredBold", "X")', |
| 2099 | \ 'call matchadd("TgreenBold", "Y")', |
| 2100 | \ 'call matchadd("TmagentaBold", "Z")', |
| 2101 | \ 'redraw', |
| 2102 | \ ], 'Xcolorscript') |
| 2103 | let buf = RunVimInTerminal('-S Xcolorscript', {'rows': 10}) |
| 2104 | call VerifyScreenDump(buf, 'Test_terminal_all_ansi_colors', {}) |
| 2105 | |
| 2106 | call term_sendkeys(buf, ":q\<CR>") |
| 2107 | call StopVimInTerminal(buf) |
| 2108 | call delete('Xcolorscript') |
| 2109 | endfunc |
| 2110 | |
Bram Moolenaar | 1e6bbfb | 2021-04-03 13:19:26 +0200 | [diff] [blame] | 2111 | function On_BufFilePost() |
| 2112 | doautocmd <nomodeline> User UserEvent |
| 2113 | endfunction |
| 2114 | |
| 2115 | func Test_terminal_nested_autocmd() |
| 2116 | new |
| 2117 | call setline(1, range(500)) |
| 2118 | $ |
| 2119 | let lastline = line('.') |
| 2120 | |
| 2121 | augroup TermTest |
| 2122 | autocmd BufFilePost * call On_BufFilePost() |
| 2123 | autocmd User UserEvent silent |
| 2124 | augroup END |
| 2125 | |
| 2126 | let cmd = Get_cat_123_cmd() |
| 2127 | let buf = term_start(cmd, #{term_finish: 'close', hidden: 1}) |
| 2128 | call assert_equal(lastline, line('.')) |
| 2129 | |
Bram Moolenaar | 6437475 | 2021-04-03 17:22:29 +0200 | [diff] [blame] | 2130 | let job = term_getjob(buf) |
| 2131 | call WaitForAssert({-> assert_equal("dead", job_status(job))}) |
Bram Moolenaar | 1e6bbfb | 2021-04-03 13:19:26 +0200 | [diff] [blame] | 2132 | call delete('Xtext') |
| 2133 | augroup TermTest |
| 2134 | au! |
| 2135 | augroup END |
| 2136 | endfunc |
| 2137 | |
Bram Moolenaar | aeed2a6 | 2021-04-29 20:18:45 +0200 | [diff] [blame] | 2138 | func Test_terminal_adds_jump() |
| 2139 | clearjumps |
| 2140 | call term_start("ls", #{curwin: 1}) |
| 2141 | call assert_equal(1, getjumplist()[0]->len()) |
| 2142 | bwipe! |
| 2143 | endfunc |
| 2144 | |
Bram Moolenaar | eea32af | 2021-11-21 14:51:13 +0000 | [diff] [blame] | 2145 | func Close_cb(ch, ctx) |
| 2146 | call term_wait(a:ctx.bufnr) |
| 2147 | let g:close_done = 'done' |
| 2148 | endfunc |
| 2149 | |
| 2150 | func Test_term_wait_in_close_cb() |
| 2151 | let g:close_done = '' |
| 2152 | let ctx = {} |
| 2153 | let ctx.bufnr = term_start('echo "HELLO WORLD"', |
| 2154 | \ {'close_cb': {ch -> Close_cb(ch, ctx)}}) |
| 2155 | |
| 2156 | call WaitForAssert({-> assert_equal("done", g:close_done)}) |
| 2157 | |
| 2158 | unlet g:close_done |
| 2159 | bwipe! |
| 2160 | endfunc |
| 2161 | |
Bram Moolenaar | 91689ea | 2020-05-11 22:04:53 +0200 | [diff] [blame] | 2162 | |
Bram Moolenaar | ca68ae1 | 2020-03-30 19:32:53 +0200 | [diff] [blame] | 2163 | " vim: shiftwidth=2 sts=2 expandtab |