Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 1 | " Tests for the terminal window. |
| 2 | |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 3 | source check.vim |
| 4 | CheckFeature terminal |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 5 | |
| 6 | source shared.vim |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 7 | source screendump.vim |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 8 | |
Bram Moolenaar | b81bc77 | 2017-08-11 22:45:01 +0200 | [diff] [blame] | 9 | let s:python = PythonProg() |
Bram Moolenaar | ddd3308 | 2019-06-03 23:07:25 +0200 | [diff] [blame] | 10 | let $PROMPT_COMMAND='' |
Bram Moolenaar | b81bc77 | 2017-08-11 22:45:01 +0200 | [diff] [blame] | 11 | |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 12 | " Open a terminal with a shell, assign the job to g:job and return the buffer |
| 13 | " number. |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 14 | func Run_shell_in_terminal(options) |
Bram Moolenaar | ba6febd | 2017-10-30 21:56:23 +0100 | [diff] [blame] | 15 | if has('win32') |
| 16 | let buf = term_start([&shell,'/k'], a:options) |
| 17 | else |
| 18 | let buf = term_start(&shell, a:options) |
| 19 | endif |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 20 | |
| 21 | let termlist = term_list() |
| 22 | call assert_equal(1, len(termlist)) |
| 23 | call assert_equal(buf, termlist[0]) |
| 24 | |
| 25 | let g:job = term_getjob(buf) |
| 26 | call assert_equal(v:t_job, type(g:job)) |
| 27 | |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 28 | let string = string({'job': buf->term_getjob()}) |
Bram Moolenaar | 35422f4 | 2017-08-05 16:33:56 +0200 | [diff] [blame] | 29 | call assert_match("{'job': 'process \\d\\+ run'}", string) |
| 30 | |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 31 | return buf |
| 32 | endfunc |
| 33 | |
Bram Moolenaar | 20e6cd0 | 2017-08-01 20:25:22 +0200 | [diff] [blame] | 34 | func Test_terminal_basic() |
Bram Moolenaar | 606cb8b | 2018-05-03 20:40:20 +0200 | [diff] [blame] | 35 | au TerminalOpen * let b:done = 'yes' |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 36 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | b00fdf6 | 2017-09-21 22:16:21 +0200 | [diff] [blame] | 37 | |
Bram Moolenaar | 7c9aec4 | 2017-08-03 13:51:25 +0200 | [diff] [blame] | 38 | if has("unix") |
Bram Moolenaar | 2dc9d26 | 2017-09-08 14:39:30 +0200 | [diff] [blame] | 39 | call assert_match('^/dev/', job_info(g:job).tty_out) |
| 40 | call assert_match('^/dev/', term_gettty('')) |
Bram Moolenaar | 7c9aec4 | 2017-08-03 13:51:25 +0200 | [diff] [blame] | 41 | else |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 42 | " ConPTY works on anonymous pipe. |
| 43 | if !has('conpty') |
| 44 | call assert_match('^\\\\.\\pipe\\', job_info(g:job).tty_out) |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 45 | call assert_match('^\\\\.\\pipe\\', ''->term_gettty()) |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 46 | endif |
Bram Moolenaar | 7c9aec4 | 2017-08-03 13:51:25 +0200 | [diff] [blame] | 47 | endif |
Bram Moolenaar | 2bb7b6b | 2017-08-13 20:58:33 +0200 | [diff] [blame] | 48 | call assert_equal('t', mode()) |
Bram Moolenaar | b00fdf6 | 2017-09-21 22:16:21 +0200 | [diff] [blame] | 49 | call assert_equal('yes', b:done) |
Bram Moolenaar | 2bb7b6b | 2017-08-13 20:58:33 +0200 | [diff] [blame] | 50 | call assert_match('%aR[^\n]*running]', execute('ls')) |
Bram Moolenaar | 0751f51 | 2018-03-29 16:37:16 +0200 | [diff] [blame] | 51 | call assert_match('%aR[^\n]*running]', execute('ls R')) |
| 52 | call assert_notmatch('%[^\n]*running]', execute('ls F')) |
| 53 | call assert_notmatch('%[^\n]*running]', execute('ls ?')) |
Bram Moolenaar | 2bb7b6b | 2017-08-13 20:58:33 +0200 | [diff] [blame] | 54 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 55 | call StopShellInTerminal(buf) |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 56 | call term_wait(buf) |
Bram Moolenaar | 2bb7b6b | 2017-08-13 20:58:33 +0200 | [diff] [blame] | 57 | call assert_equal('n', mode()) |
| 58 | call assert_match('%aF[^\n]*finished]', execute('ls')) |
Bram Moolenaar | 0751f51 | 2018-03-29 16:37:16 +0200 | [diff] [blame] | 59 | call assert_match('%aF[^\n]*finished]', execute('ls F')) |
| 60 | call assert_notmatch('%[^\n]*finished]', execute('ls R')) |
| 61 | call assert_notmatch('%[^\n]*finished]', execute('ls ?')) |
Bram Moolenaar | 20e6cd0 | 2017-08-01 20:25:22 +0200 | [diff] [blame] | 62 | |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 63 | " closing window wipes out the terminal buffer a with finished job |
| 64 | close |
| 65 | call assert_equal("", bufname(buf)) |
| 66 | |
Bram Moolenaar | 606cb8b | 2018-05-03 20:40:20 +0200 | [diff] [blame] | 67 | au! TerminalOpen |
Bram Moolenaar | 20e6cd0 | 2017-08-01 20:25:22 +0200 | [diff] [blame] | 68 | unlet g:job |
| 69 | endfunc |
| 70 | |
Bram Moolenaar | 28ed4df | 2019-10-26 16:21:40 +0200 | [diff] [blame] | 71 | func Test_terminal_TerminalWinOpen() |
| 72 | au TerminalWinOpen * let b:done = 'yes' |
| 73 | let buf = Run_shell_in_terminal({}) |
| 74 | call assert_equal('yes', b:done) |
| 75 | call StopShellInTerminal(buf) |
| 76 | " closing window wipes out the terminal buffer with the finished job |
| 77 | close |
| 78 | |
| 79 | if has("unix") |
| 80 | terminal ++hidden ++open sleep 1 |
| 81 | sleep 1 |
| 82 | call assert_fails("echo b:done", 'E121:') |
| 83 | endif |
| 84 | |
| 85 | au! TerminalWinOpen |
| 86 | endfunc |
| 87 | |
Bram Moolenaar | 20e6cd0 | 2017-08-01 20:25:22 +0200 | [diff] [blame] | 88 | func Test_terminal_make_change() |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 89 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 90 | call StopShellInTerminal(buf) |
Bram Moolenaar | 20e6cd0 | 2017-08-01 20:25:22 +0200 | [diff] [blame] | 91 | call term_wait(buf) |
| 92 | |
| 93 | setlocal modifiable |
| 94 | exe "normal Axxx\<Esc>" |
| 95 | call assert_fails(buf . 'bwipe', 'E517') |
| 96 | undo |
| 97 | |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 98 | exe buf . 'bwipe' |
| 99 | unlet g:job |
| 100 | endfunc |
| 101 | |
Bram Moolenaar | 5b868a8 | 2019-02-25 06:11:53 +0100 | [diff] [blame] | 102 | func Test_terminal_paste_register() |
| 103 | let @" = "text to paste" |
| 104 | |
| 105 | let buf = Run_shell_in_terminal({}) |
| 106 | " Wait for the shell to display a prompt |
| 107 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
| 108 | |
| 109 | call feedkeys("echo \<C-W>\"\" \<C-W>\"=37 + 5\<CR>\<CR>", 'xt') |
| 110 | call WaitForAssert({-> assert_match("echo text to paste 42$", getline(1))}) |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 111 | call WaitForAssert({-> assert_equal('text to paste 42', 2->getline())}) |
Bram Moolenaar | 5b868a8 | 2019-02-25 06:11:53 +0100 | [diff] [blame] | 112 | |
| 113 | exe buf . 'bwipe!' |
| 114 | unlet g:job |
| 115 | endfunc |
| 116 | |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 117 | func Test_terminal_wipe_buffer() |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 118 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | eb44a68 | 2017-08-03 22:44:55 +0200 | [diff] [blame] | 119 | call assert_fails(buf . 'bwipe', 'E517') |
| 120 | exe buf . 'bwipe!' |
Bram Moolenaar | 50182fa | 2018-04-28 21:34:40 +0200 | [diff] [blame] | 121 | call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 122 | call assert_equal("", bufname(buf)) |
| 123 | |
| 124 | unlet g:job |
| 125 | endfunc |
| 126 | |
Bram Moolenaar | 8adb0d0 | 2017-09-17 19:08:02 +0200 | [diff] [blame] | 127 | func Test_terminal_split_quit() |
| 128 | let buf = Run_shell_in_terminal({}) |
| 129 | call term_wait(buf) |
| 130 | split |
| 131 | quit! |
| 132 | call term_wait(buf) |
| 133 | sleep 50m |
| 134 | call assert_equal('run', job_status(g:job)) |
| 135 | |
| 136 | quit! |
Bram Moolenaar | 50182fa | 2018-04-28 21:34:40 +0200 | [diff] [blame] | 137 | call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) |
Bram Moolenaar | 8adb0d0 | 2017-09-17 19:08:02 +0200 | [diff] [blame] | 138 | |
| 139 | exe buf . 'bwipe' |
| 140 | unlet g:job |
| 141 | endfunc |
| 142 | |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 143 | func Test_terminal_hide_buffer() |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 144 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | 97a80e4 | 2017-08-30 13:31:49 +0200 | [diff] [blame] | 145 | setlocal bufhidden=hide |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 146 | quit |
| 147 | for nr in range(1, winnr('$')) |
| 148 | call assert_notequal(winbufnr(nr), buf) |
| 149 | endfor |
| 150 | call assert_true(bufloaded(buf)) |
| 151 | call assert_true(buflisted(buf)) |
| 152 | |
| 153 | exe 'split ' . buf . 'buf' |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 154 | call StopShellInTerminal(buf) |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 155 | exe buf . 'bwipe' |
| 156 | |
| 157 | unlet g:job |
| 158 | endfunc |
| 159 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 160 | func s:Nasty_exit_cb(job, st) |
Bram Moolenaar | 3c3a80d | 2017-08-03 17:06:45 +0200 | [diff] [blame] | 161 | exe g:buf . 'bwipe!' |
| 162 | let g:buf = 0 |
| 163 | endfunc |
| 164 | |
Bram Moolenaar | 9d18961 | 2017-09-09 18:11:00 +0200 | [diff] [blame] | 165 | func Get_cat_123_cmd() |
| 166 | if has('win32') |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 167 | if !has('conpty') |
| 168 | return 'cmd /c "cls && color 2 && echo 123"' |
| 169 | else |
| 170 | " When clearing twice, extra sequence is not output. |
| 171 | return 'cmd /c "cls && cls && color 2 && echo 123"' |
| 172 | endif |
Bram Moolenaar | 9d18961 | 2017-09-09 18:11:00 +0200 | [diff] [blame] | 173 | else |
| 174 | call writefile(["\<Esc>[32m123"], 'Xtext') |
| 175 | return "cat Xtext" |
| 176 | endif |
| 177 | endfunc |
| 178 | |
Bram Moolenaar | 3c3a80d | 2017-08-03 17:06:45 +0200 | [diff] [blame] | 179 | func Test_terminal_nasty_cb() |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 180 | let cmd = Get_cat_123_cmd() |
Bram Moolenaar | 3c3a80d | 2017-08-03 17:06:45 +0200 | [diff] [blame] | 181 | let g:buf = term_start(cmd, {'exit_cb': function('s:Nasty_exit_cb')}) |
| 182 | let g:job = term_getjob(g:buf) |
| 183 | |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 184 | call WaitForAssert({-> assert_equal("dead", job_status(g:job))}) |
| 185 | call WaitForAssert({-> assert_equal(0, g:buf)}) |
Bram Moolenaar | 3c3a80d | 2017-08-03 17:06:45 +0200 | [diff] [blame] | 186 | unlet g:job |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 187 | unlet g:buf |
Bram Moolenaar | 3c3a80d | 2017-08-03 17:06:45 +0200 | [diff] [blame] | 188 | call delete('Xtext') |
| 189 | endfunc |
| 190 | |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 191 | func Check_123(buf) |
Bram Moolenaar | 5c838a3 | 2017-08-02 22:10:34 +0200 | [diff] [blame] | 192 | let l = term_scrape(a:buf, 0) |
| 193 | call assert_true(len(l) == 0) |
| 194 | let l = term_scrape(a:buf, 999) |
| 195 | call assert_true(len(l) == 0) |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 196 | let l = a:buf->term_scrape(1) |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 197 | call assert_true(len(l) > 0) |
| 198 | call assert_equal('1', l[0].chars) |
| 199 | call assert_equal('2', l[1].chars) |
| 200 | call assert_equal('3', l[2].chars) |
| 201 | call assert_equal('#00e000', l[0].fg) |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 202 | call assert_equal(0, term_getattr(l[0].attr, 'bold')) |
| 203 | call assert_equal(0, l[0].attr->term_getattr('italic')) |
Bram Moolenaar | 81df635 | 2018-12-22 18:25:30 +0100 | [diff] [blame] | 204 | if has('win32') |
| 205 | " On Windows 'background' always defaults to dark, even though the terminal |
| 206 | " may use a light background. Therefore accept both white and black. |
| 207 | call assert_match('#ffffff\|#000000', l[0].bg) |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 208 | else |
Bram Moolenaar | 81df635 | 2018-12-22 18:25:30 +0100 | [diff] [blame] | 209 | if &background == 'light' |
| 210 | call assert_equal('#ffffff', l[0].bg) |
| 211 | else |
| 212 | call assert_equal('#000000', l[0].bg) |
| 213 | endif |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 214 | endif |
| 215 | |
Bram Moolenaar | 5c838a3 | 2017-08-02 22:10:34 +0200 | [diff] [blame] | 216 | let l = term_getline(a:buf, -1) |
| 217 | call assert_equal('', l) |
| 218 | let l = term_getline(a:buf, 0) |
| 219 | call assert_equal('', l) |
| 220 | let l = term_getline(a:buf, 999) |
| 221 | call assert_equal('', l) |
Bram Moolenaar | 9c84484 | 2017-08-01 18:41:21 +0200 | [diff] [blame] | 222 | let l = term_getline(a:buf, 1) |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 223 | call assert_equal('123', l) |
| 224 | endfunc |
| 225 | |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 226 | func Test_terminal_scrape_123() |
| 227 | let cmd = Get_cat_123_cmd() |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 228 | let buf = term_start(cmd) |
| 229 | |
| 230 | let termlist = term_list() |
| 231 | call assert_equal(1, len(termlist)) |
| 232 | call assert_equal(buf, termlist[0]) |
| 233 | |
Bram Moolenaar | f144a3f | 2017-07-30 18:02:12 +0200 | [diff] [blame] | 234 | " Nothing happens with invalid buffer number |
| 235 | call term_wait(1234) |
| 236 | |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 237 | call term_wait(buf) |
Bram Moolenaar | 1783337 | 2017-09-04 22:23:19 +0200 | [diff] [blame] | 238 | " 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] | 239 | " "cls" to happen, after that we have one line with three characters. |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 240 | call WaitForAssert({-> assert_equal(3, len(term_scrape(buf, 1)))}) |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 241 | call Check_123(buf) |
| 242 | |
| 243 | " Must still work after the job ended. |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 244 | let job = term_getjob(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 245 | call WaitForAssert({-> assert_equal("dead", job_status(job))}) |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 246 | call term_wait(buf) |
| 247 | call Check_123(buf) |
| 248 | |
| 249 | exe buf . 'bwipe' |
Bram Moolenaar | f144a3f | 2017-07-30 18:02:12 +0200 | [diff] [blame] | 250 | call delete('Xtext') |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 251 | endfunc |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 252 | |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 253 | func Test_terminal_scrape_multibyte() |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 254 | call writefile(["léttまrs"], 'Xtext') |
| 255 | if has('win32') |
Bram Moolenaar | 3678393 | 2017-08-14 23:07:30 +0200 | [diff] [blame] | 256 | " Run cmd with UTF-8 codepage to make the type command print the expected |
| 257 | " multibyte characters. |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 258 | let buf = term_start("cmd /K chcp 65001") |
| 259 | call term_sendkeys(buf, "type Xtext\<CR>") |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 260 | eval buf->term_sendkeys("exit\<CR>") |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 261 | let line = 4 |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 262 | else |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 263 | let buf = term_start("cat Xtext") |
| 264 | let line = 1 |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 265 | endif |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 266 | |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 267 | call WaitFor({-> len(term_scrape(buf, line)) >= 7 && term_scrape(buf, line)[0].chars == "l"}) |
| 268 | let l = term_scrape(buf, line) |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 269 | call assert_true(len(l) >= 7) |
| 270 | call assert_equal('l', l[0].chars) |
| 271 | call assert_equal('é', l[1].chars) |
| 272 | call assert_equal(1, l[1].width) |
| 273 | call assert_equal('t', l[2].chars) |
| 274 | call assert_equal('t', l[3].chars) |
| 275 | call assert_equal('ま', l[4].chars) |
| 276 | call assert_equal(2, l[4].width) |
| 277 | call assert_equal('r', l[5].chars) |
| 278 | call assert_equal('s', l[6].chars) |
| 279 | |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 280 | let job = term_getjob(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 281 | call WaitForAssert({-> assert_equal("dead", job_status(job))}) |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 282 | call term_wait(buf) |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 283 | |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 284 | exe buf . 'bwipe' |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 285 | call delete('Xtext') |
| 286 | endfunc |
| 287 | |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 288 | func Test_terminal_scroll() |
| 289 | call writefile(range(1, 200), 'Xtext') |
| 290 | if has('win32') |
| 291 | let cmd = 'cmd /c "type Xtext"' |
| 292 | else |
| 293 | let cmd = "cat Xtext" |
| 294 | endif |
| 295 | let buf = term_start(cmd) |
| 296 | |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 297 | let job = term_getjob(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 298 | call WaitForAssert({-> assert_equal("dead", job_status(job))}) |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 299 | call term_wait(buf) |
| 300 | if has('win32') |
| 301 | " TODO: this should not be needed |
| 302 | sleep 100m |
| 303 | endif |
| 304 | |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 305 | let scrolled = buf->term_getscrolled() |
| 306 | call assert_equal(scrolled, term_getscrolled(buf)) |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 307 | call assert_equal('1', getline(1)) |
Bram Moolenaar | 82b9ca0 | 2017-08-08 23:06:46 +0200 | [diff] [blame] | 308 | call assert_equal('1', term_getline(buf, 1 - scrolled)) |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 309 | call assert_equal('49', getline(49)) |
Bram Moolenaar | 82b9ca0 | 2017-08-08 23:06:46 +0200 | [diff] [blame] | 310 | call assert_equal('49', term_getline(buf, 49 - scrolled)) |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 311 | call assert_equal('200', getline(200)) |
Bram Moolenaar | 82b9ca0 | 2017-08-08 23:06:46 +0200 | [diff] [blame] | 312 | call assert_equal('200', term_getline(buf, 200 - scrolled)) |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 313 | |
| 314 | exe buf . 'bwipe' |
| 315 | call delete('Xtext') |
| 316 | endfunc |
| 317 | |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 318 | func Test_terminal_scrollback() |
Bram Moolenaar | 33c5e9f | 2018-05-26 18:58:51 +0200 | [diff] [blame] | 319 | let buf = Run_shell_in_terminal({'term_rows': 15}) |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 320 | set termwinscroll=100 |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 321 | call writefile(range(150), 'Xtext') |
| 322 | if has('win32') |
| 323 | call term_sendkeys(buf, "type Xtext\<CR>") |
| 324 | else |
| 325 | call term_sendkeys(buf, "cat Xtext\<CR>") |
| 326 | endif |
| 327 | let rows = term_getsize(buf)[0] |
Bram Moolenaar | 6c67219 | 2018-04-15 13:28:42 +0200 | [diff] [blame] | 328 | " 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] | 329 | 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] | 330 | let lines = line('$') |
Bram Moolenaar | ac3e830 | 2018-04-15 13:10:44 +0200 | [diff] [blame] | 331 | call assert_inrange(91, 100, lines) |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 332 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 333 | call StopShellInTerminal(buf) |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 334 | call term_wait(buf) |
| 335 | exe buf . 'bwipe' |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 336 | set termwinscroll& |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 337 | call delete('Xtext') |
| 338 | endfunc |
| 339 | |
| 340 | func Test_terminal_postponed_scrollback() |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 341 | " tail -f only works on Unix |
| 342 | CheckUnix |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 343 | |
| 344 | call writefile(range(50), 'Xtext') |
| 345 | call writefile([ |
Bram Moolenaar | 5ff7df5 | 2019-02-15 01:06:13 +0100 | [diff] [blame] | 346 | \ 'set shell=/bin/sh noruler', |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 347 | \ 'terminal', |
Bram Moolenaar | 7e841e3 | 2019-02-15 00:26:14 +0100 | [diff] [blame] | 348 | \ 'sleep 200m', |
Bram Moolenaar | 5ff7df5 | 2019-02-15 01:06:13 +0100 | [diff] [blame] | 349 | \ 'call feedkeys("tail -n 100 -f Xtext\<CR>", "xt")', |
| 350 | \ 'sleep 100m', |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 351 | \ 'call feedkeys("\<C-W>N", "xt")', |
| 352 | \ ], 'XTest_postponed') |
| 353 | let buf = RunVimInTerminal('-S XTest_postponed', {}) |
| 354 | " Check that the Xtext lines are displayed and in Terminal-Normal mode |
Bram Moolenaar | 96baf02 | 2019-02-14 23:49:38 +0100 | [diff] [blame] | 355 | call VerifyScreenDump(buf, 'Test_terminal_01', {}) |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 356 | |
| 357 | silent !echo 'one more line' >>Xtext |
Bram Moolenaar | 700dfaa | 2019-04-13 14:21:19 +0200 | [diff] [blame] | 358 | " Screen will not change, move cursor to get a different dump |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 359 | call term_sendkeys(buf, "k") |
Bram Moolenaar | 96baf02 | 2019-02-14 23:49:38 +0100 | [diff] [blame] | 360 | call VerifyScreenDump(buf, 'Test_terminal_02', {}) |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 361 | |
| 362 | " Back to Terminal-Job mode, text will scroll and show the extra line. |
| 363 | call term_sendkeys(buf, "a") |
Bram Moolenaar | 96baf02 | 2019-02-14 23:49:38 +0100 | [diff] [blame] | 364 | call VerifyScreenDump(buf, 'Test_terminal_03', {}) |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 365 | |
| 366 | call term_wait(buf) |
| 367 | call term_sendkeys(buf, "\<C-C>") |
| 368 | call term_wait(buf) |
| 369 | call term_sendkeys(buf, "exit\<CR>") |
| 370 | call term_wait(buf) |
Bram Moolenaar | 3a05ce6 | 2020-03-11 19:30:01 +0100 | [diff] [blame] | 371 | let tsk_ret = term_sendkeys(buf, ":q\<CR>") |
| 372 | |
| 373 | " check type of term_sendkeys() return value |
| 374 | echo type(tsk_ret) |
| 375 | |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 376 | call StopVimInTerminal(buf) |
| 377 | call delete('XTest_postponed') |
| 378 | call delete('Xtext') |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 379 | endfunc |
| 380 | |
Bram Moolenaar | 81aa0f5 | 2019-02-14 23:23:19 +0100 | [diff] [blame] | 381 | " Run diff on two dumps with different size. |
| 382 | func Test_terminal_dumpdiff_size() |
| 383 | call assert_equal(1, winnr('$')) |
| 384 | call term_dumpdiff('dumps/Test_incsearch_search_01.dump', 'dumps/Test_popup_command_01.dump') |
| 385 | call assert_equal(2, winnr('$')) |
| 386 | call assert_match('Test_incsearch_search_01.dump', getline(10)) |
| 387 | call assert_match(' +++++$', getline(11)) |
| 388 | call assert_match('Test_popup_command_01.dump', getline(31)) |
| 389 | call assert_equal(repeat('+', 75), getline(30)) |
| 390 | quit |
| 391 | endfunc |
| 392 | |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 393 | func Test_terminal_size() |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 394 | let cmd = Get_cat_123_cmd() |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 395 | |
Bram Moolenaar | b241208 | 2017-08-20 18:09:14 +0200 | [diff] [blame] | 396 | exe 'terminal ++rows=5 ' . cmd |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 397 | let size = term_getsize('') |
| 398 | bwipe! |
| 399 | call assert_equal(5, size[0]) |
| 400 | |
Bram Moolenaar | 08d384f | 2017-08-11 21:51:23 +0200 | [diff] [blame] | 401 | call term_start(cmd, {'term_rows': 6}) |
| 402 | let size = term_getsize('') |
| 403 | bwipe! |
| 404 | call assert_equal(6, size[0]) |
| 405 | |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 406 | vsplit |
Bram Moolenaar | b241208 | 2017-08-20 18:09:14 +0200 | [diff] [blame] | 407 | exe 'terminal ++rows=5 ++cols=33 ' . cmd |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 408 | call assert_equal([5, 33], ''->term_getsize()) |
Bram Moolenaar | a42d363 | 2018-04-14 17:05:38 +0200 | [diff] [blame] | 409 | |
| 410 | call term_setsize('', 6, 0) |
| 411 | call assert_equal([6, 33], term_getsize('')) |
| 412 | |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 413 | eval ''->term_setsize(0, 35) |
Bram Moolenaar | a42d363 | 2018-04-14 17:05:38 +0200 | [diff] [blame] | 414 | call assert_equal([6, 35], term_getsize('')) |
| 415 | |
| 416 | call term_setsize('', 7, 30) |
| 417 | call assert_equal([7, 30], term_getsize('')) |
| 418 | |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 419 | bwipe! |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 420 | call assert_fails("call term_setsize('', 7, 30)", "E955:") |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 421 | |
Bram Moolenaar | 08d384f | 2017-08-11 21:51:23 +0200 | [diff] [blame] | 422 | call term_start(cmd, {'term_rows': 6, 'term_cols': 36}) |
| 423 | let size = term_getsize('') |
| 424 | bwipe! |
| 425 | call assert_equal([6, 36], size) |
| 426 | |
Bram Moolenaar | b241208 | 2017-08-20 18:09:14 +0200 | [diff] [blame] | 427 | exe 'vertical terminal ++cols=20 ' . cmd |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 428 | let size = term_getsize('') |
| 429 | bwipe! |
| 430 | call assert_equal(20, size[1]) |
| 431 | |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 432 | eval cmd->term_start({'vertical': 1, 'term_cols': 26}) |
Bram Moolenaar | 08d384f | 2017-08-11 21:51:23 +0200 | [diff] [blame] | 433 | let size = term_getsize('') |
| 434 | bwipe! |
| 435 | call assert_equal(26, size[1]) |
| 436 | |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 437 | split |
Bram Moolenaar | b241208 | 2017-08-20 18:09:14 +0200 | [diff] [blame] | 438 | exe 'vertical terminal ++rows=6 ++cols=20 ' . cmd |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 439 | let size = term_getsize('') |
| 440 | bwipe! |
| 441 | call assert_equal([6, 20], size) |
Bram Moolenaar | 08d384f | 2017-08-11 21:51:23 +0200 | [diff] [blame] | 442 | |
| 443 | call term_start(cmd, {'vertical': 1, 'term_rows': 7, 'term_cols': 27}) |
| 444 | let size = term_getsize('') |
| 445 | bwipe! |
| 446 | call assert_equal([7, 27], size) |
Bram Moolenaar | 9d654a8 | 2017-09-03 19:52:17 +0200 | [diff] [blame] | 447 | |
| 448 | call delete('Xtext') |
Bram Moolenaar | da43b61 | 2017-08-11 22:27:50 +0200 | [diff] [blame] | 449 | endfunc |
| 450 | |
| 451 | func Test_terminal_curwin() |
| 452 | let cmd = Get_cat_123_cmd() |
| 453 | call assert_equal(1, winnr('$')) |
| 454 | |
| 455 | split dummy |
| 456 | exe 'terminal ++curwin ' . cmd |
| 457 | call assert_equal(2, winnr('$')) |
| 458 | bwipe! |
| 459 | |
| 460 | split dummy |
| 461 | call term_start(cmd, {'curwin': 1}) |
| 462 | call assert_equal(2, winnr('$')) |
| 463 | bwipe! |
| 464 | |
| 465 | split dummy |
| 466 | call setline(1, 'change') |
| 467 | call assert_fails('terminal ++curwin ' . cmd, 'E37:') |
| 468 | call assert_equal(2, winnr('$')) |
| 469 | exe 'terminal! ++curwin ' . cmd |
| 470 | call assert_equal(2, winnr('$')) |
| 471 | bwipe! |
| 472 | |
| 473 | split dummy |
| 474 | call setline(1, 'change') |
| 475 | call assert_fails("call term_start(cmd, {'curwin': 1})", 'E37:') |
| 476 | call assert_equal(2, winnr('$')) |
| 477 | bwipe! |
| 478 | |
| 479 | split dummy |
| 480 | bwipe! |
Bram Moolenaar | 9d654a8 | 2017-09-03 19:52:17 +0200 | [diff] [blame] | 481 | call delete('Xtext') |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 482 | endfunc |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 483 | |
Bram Moolenaar | ff54679 | 2017-11-21 14:47:57 +0100 | [diff] [blame] | 484 | func s:get_sleep_cmd() |
Bram Moolenaar | b81bc77 | 2017-08-11 22:45:01 +0200 | [diff] [blame] | 485 | if s:python != '' |
| 486 | let cmd = s:python . " test_short_sleep.py" |
Bram Moolenaar | c8523e2 | 2018-06-03 18:22:02 +0200 | [diff] [blame] | 487 | " 500 was not enough for Travis |
| 488 | let waittime = 900 |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 489 | else |
Bram Moolenaar | b81bc77 | 2017-08-11 22:45:01 +0200 | [diff] [blame] | 490 | echo 'This will take five seconds...' |
| 491 | let waittime = 2000 |
| 492 | if has('win32') |
| 493 | let cmd = $windir . '\system32\timeout.exe 1' |
| 494 | else |
| 495 | let cmd = 'sleep 1' |
| 496 | endif |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 497 | endif |
Bram Moolenaar | ff54679 | 2017-11-21 14:47:57 +0100 | [diff] [blame] | 498 | return [cmd, waittime] |
| 499 | endfunc |
| 500 | |
| 501 | func Test_terminal_finish_open_close() |
| 502 | call assert_equal(1, winnr('$')) |
| 503 | |
| 504 | let [cmd, waittime] = s:get_sleep_cmd() |
Bram Moolenaar | b81bc77 | 2017-08-11 22:45:01 +0200 | [diff] [blame] | 505 | |
Bram Moolenaar | 1dd9833 | 2018-03-16 22:54:53 +0100 | [diff] [blame] | 506 | " shell terminal closes automatically |
| 507 | terminal |
| 508 | let buf = bufnr('%') |
| 509 | call assert_equal(2, winnr('$')) |
| 510 | " Wait for the shell to display a prompt |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 511 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 512 | call StopShellInTerminal(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 513 | call WaitForAssert({-> assert_equal(1, winnr('$'))}, waittime) |
Bram Moolenaar | 1dd9833 | 2018-03-16 22:54:53 +0100 | [diff] [blame] | 514 | |
| 515 | " shell terminal that does not close automatically |
| 516 | terminal ++noclose |
| 517 | let buf = bufnr('%') |
| 518 | call assert_equal(2, winnr('$')) |
| 519 | " Wait for the shell to display a prompt |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 520 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 521 | call StopShellInTerminal(buf) |
Bram Moolenaar | 1dd9833 | 2018-03-16 22:54:53 +0100 | [diff] [blame] | 522 | call assert_equal(2, winnr('$')) |
| 523 | quit |
| 524 | call assert_equal(1, winnr('$')) |
| 525 | |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 526 | exe 'terminal ++close ' . cmd |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 527 | call assert_equal(2, winnr('$')) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 528 | wincmd p |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 529 | call WaitForAssert({-> assert_equal(1, winnr('$'))}, waittime) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 530 | |
| 531 | call term_start(cmd, {'term_finish': 'close'}) |
| 532 | call assert_equal(2, winnr('$')) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 533 | wincmd p |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 534 | call WaitForAssert({-> assert_equal(1, winnr('$'))}, waittime) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 535 | call assert_equal(1, winnr('$')) |
| 536 | |
| 537 | exe 'terminal ++open ' . cmd |
Bram Moolenaar | 97a80e4 | 2017-08-30 13:31:49 +0200 | [diff] [blame] | 538 | close! |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 539 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 540 | bwipe |
| 541 | |
| 542 | call term_start(cmd, {'term_finish': 'open'}) |
Bram Moolenaar | 97a80e4 | 2017-08-30 13:31:49 +0200 | [diff] [blame] | 543 | close! |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 544 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | 8cad930 | 2017-08-12 14:32:32 +0200 | [diff] [blame] | 545 | bwipe |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 546 | |
Bram Moolenaar | 8cad930 | 2017-08-12 14:32:32 +0200 | [diff] [blame] | 547 | exe 'terminal ++hidden ++open ' . cmd |
| 548 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 549 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | 8cad930 | 2017-08-12 14:32:32 +0200 | [diff] [blame] | 550 | bwipe |
| 551 | |
| 552 | call term_start(cmd, {'term_finish': 'open', 'hidden': 1}) |
| 553 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 554 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 555 | bwipe |
Bram Moolenaar | 37c4583 | 2017-08-12 16:01:04 +0200 | [diff] [blame] | 556 | |
| 557 | call assert_fails("call term_start(cmd, {'term_opencmd': 'open'})", 'E475:') |
| 558 | call assert_fails("call term_start(cmd, {'term_opencmd': 'split %x'})", 'E475:') |
| 559 | call assert_fails("call term_start(cmd, {'term_opencmd': 'split %d and %s'})", 'E475:') |
| 560 | call assert_fails("call term_start(cmd, {'term_opencmd': 'split % and %d'})", 'E475:') |
| 561 | |
| 562 | call term_start(cmd, {'term_finish': 'open', 'term_opencmd': '4split | buffer %d'}) |
Bram Moolenaar | 97a80e4 | 2017-08-30 13:31:49 +0200 | [diff] [blame] | 563 | close! |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 564 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | 37c4583 | 2017-08-12 16:01:04 +0200 | [diff] [blame] | 565 | call assert_equal(4, winheight(0)) |
| 566 | bwipe |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 567 | endfunc |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 568 | |
| 569 | func Test_terminal_cwd() |
Bram Moolenaar | 077ff43 | 2019-10-28 00:42:21 +0100 | [diff] [blame] | 570 | if has('win32') |
| 571 | let cmd = 'cmd /c cd' |
| 572 | else |
| 573 | CheckExecutable pwd |
| 574 | let cmd = 'pwd' |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 575 | endif |
| 576 | call mkdir('Xdir') |
Bram Moolenaar | 077ff43 | 2019-10-28 00:42:21 +0100 | [diff] [blame] | 577 | let buf = term_start(cmd, {'cwd': 'Xdir'}) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 578 | call WaitForAssert({-> assert_equal('Xdir', fnamemodify(getline(1), ":t"))}) |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 579 | |
| 580 | exe buf . 'bwipe' |
| 581 | call delete('Xdir', 'rf') |
| 582 | endfunc |
| 583 | |
Bram Moolenaar | 839e81e | 2018-10-19 16:53:39 +0200 | [diff] [blame] | 584 | func Test_terminal_cwd_failure() |
| 585 | " Case 1: Provided directory is not actually a directory. Attempt to make |
| 586 | " the file executable as well. |
| 587 | call writefile([], 'Xfile') |
| 588 | call setfperm('Xfile', 'rwx------') |
| 589 | call assert_fails("call term_start(&shell, {'cwd': 'Xfile'})", 'E475:') |
| 590 | call delete('Xfile') |
| 591 | |
| 592 | " Case 2: Directory does not exist. |
| 593 | call assert_fails("call term_start(&shell, {'cwd': 'Xdir'})", 'E475:') |
| 594 | |
| 595 | " Case 3: Directory exists but is not accessible. |
Bram Moolenaar | 0b38f54 | 2018-11-03 21:47:16 +0100 | [diff] [blame] | 596 | " Skip this for root, it will be accessible anyway. |
Bram Moolenaar | 07282f0 | 2019-10-10 16:46:17 +0200 | [diff] [blame] | 597 | if !IsRoot() |
Bram Moolenaar | 0b38f54 | 2018-11-03 21:47:16 +0100 | [diff] [blame] | 598 | call mkdir('XdirNoAccess', '', '0600') |
| 599 | " return early if the directory permissions could not be set properly |
| 600 | if getfperm('XdirNoAccess')[2] == 'x' |
| 601 | call delete('XdirNoAccess', 'rf') |
| 602 | return |
| 603 | endif |
| 604 | call assert_fails("call term_start(&shell, {'cwd': 'XdirNoAccess'})", 'E475:') |
| 605 | call delete('XdirNoAccess', 'rf') |
Bram Moolenaar | 839e81e | 2018-10-19 16:53:39 +0200 | [diff] [blame] | 606 | endif |
Bram Moolenaar | 839e81e | 2018-10-19 16:53:39 +0200 | [diff] [blame] | 607 | endfunc |
| 608 | |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 609 | func Test_terminal_servername() |
| 610 | if !has('clientserver') |
| 611 | return |
| 612 | endif |
Bram Moolenaar | d7a137f | 2018-06-12 18:05:24 +0200 | [diff] [blame] | 613 | call s:test_environment("VIM_SERVERNAME", v:servername) |
| 614 | endfunc |
| 615 | |
| 616 | func Test_terminal_version() |
| 617 | call s:test_environment("VIM_TERMINAL", string(v:version)) |
| 618 | endfunc |
| 619 | |
| 620 | func s:test_environment(name, value) |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 621 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 622 | " Wait for the shell to display a prompt |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 623 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 624 | if has('win32') |
Bram Moolenaar | d7a137f | 2018-06-12 18:05:24 +0200 | [diff] [blame] | 625 | call term_sendkeys(buf, "echo %" . a:name . "%\r") |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 626 | else |
Bram Moolenaar | d7a137f | 2018-06-12 18:05:24 +0200 | [diff] [blame] | 627 | call term_sendkeys(buf, "echo $" . a:name . "\r") |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 628 | endif |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 629 | call term_wait(buf) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 630 | call StopShellInTerminal(buf) |
Bram Moolenaar | d7a137f | 2018-06-12 18:05:24 +0200 | [diff] [blame] | 631 | call WaitForAssert({-> assert_equal(a:value, getline(2))}) |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 632 | |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 633 | exe buf . 'bwipe' |
| 634 | unlet buf |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 635 | endfunc |
| 636 | |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 637 | func Test_terminal_env() |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 638 | let buf = Run_shell_in_terminal({'env': {'TESTENV': 'correct'}}) |
Bram Moolenaar | 51c2368 | 2017-08-14 21:45:00 +0200 | [diff] [blame] | 639 | " Wait for the shell to display a prompt |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 640 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
Bram Moolenaar | ba6febd | 2017-10-30 21:56:23 +0100 | [diff] [blame] | 641 | if has('win32') |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 642 | call term_sendkeys(buf, "echo %TESTENV%\r") |
Bram Moolenaar | ba6febd | 2017-10-30 21:56:23 +0100 | [diff] [blame] | 643 | else |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 644 | call term_sendkeys(buf, "echo $TESTENV\r") |
Bram Moolenaar | ba6febd | 2017-10-30 21:56:23 +0100 | [diff] [blame] | 645 | endif |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 646 | eval buf->term_wait() |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 647 | call StopShellInTerminal(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 648 | call WaitForAssert({-> assert_equal('correct', getline(2))}) |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 649 | |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 650 | exe buf . 'bwipe' |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 651 | endfunc |
Bram Moolenaar | 679653e | 2017-08-13 14:13:19 +0200 | [diff] [blame] | 652 | |
Bram Moolenaar | dcaa613 | 2017-08-13 17:13:09 +0200 | [diff] [blame] | 653 | func Test_terminal_list_args() |
| 654 | let buf = term_start([&shell, &shellcmdflag, 'echo "123"']) |
| 655 | call assert_fails(buf . 'bwipe', 'E517') |
| 656 | exe buf . 'bwipe!' |
| 657 | call assert_equal("", bufname(buf)) |
| 658 | endfunction |
Bram Moolenaar | 97bd5e6 | 2017-08-18 20:50:30 +0200 | [diff] [blame] | 659 | |
| 660 | func Test_terminal_noblock() |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 661 | let buf = term_start(&shell) |
Bram Moolenaar | 39536dd | 2019-01-29 22:58:21 +0100 | [diff] [blame] | 662 | if has('bsd') || has('mac') || has('sun') |
Bram Moolenaar | d8d85bf | 2017-09-03 18:08:00 +0200 | [diff] [blame] | 663 | " The shell or something else has a problem dealing with more than 1000 |
| 664 | " characters at the same time. |
| 665 | let len = 1000 |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 666 | " NPFS is used in Windows, nonblocking mode does not work properly. |
| 667 | elseif has('win32') |
| 668 | let len = 1 |
Bram Moolenaar | d8d85bf | 2017-09-03 18:08:00 +0200 | [diff] [blame] | 669 | else |
| 670 | let len = 5000 |
| 671 | endif |
Bram Moolenaar | 97bd5e6 | 2017-08-18 20:50:30 +0200 | [diff] [blame] | 672 | |
| 673 | for c in ['a','b','c','d','e','f','g','h','i','j','k'] |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 674 | call term_sendkeys(buf, 'echo ' . repeat(c, len) . "\<cr>") |
Bram Moolenaar | 97bd5e6 | 2017-08-18 20:50:30 +0200 | [diff] [blame] | 675 | endfor |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 676 | call term_sendkeys(buf, "echo done\<cr>") |
Bram Moolenaar | eef0531 | 2017-08-20 20:21:23 +0200 | [diff] [blame] | 677 | |
| 678 | " On MS-Windows there is an extra empty line below "done". Find "done" in |
| 679 | " the last-but-one or the last-but-two line. |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 680 | let lnum = term_getsize(buf)[0] - 1 |
Bram Moolenaar | 2181014 | 2018-02-02 18:30:36 +0100 | [diff] [blame] | 681 | call WaitFor({-> term_getline(buf, lnum) =~ "done" || term_getline(buf, lnum - 1) =~ "done"}, 10000) |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 682 | let line = term_getline(buf, lnum) |
Bram Moolenaar | eef0531 | 2017-08-20 20:21:23 +0200 | [diff] [blame] | 683 | if line !~ 'done' |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 684 | let line = term_getline(buf, lnum - 1) |
Bram Moolenaar | eef0531 | 2017-08-20 20:21:23 +0200 | [diff] [blame] | 685 | endif |
| 686 | call assert_match('done', line) |
Bram Moolenaar | 97bd5e6 | 2017-08-18 20:50:30 +0200 | [diff] [blame] | 687 | |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 688 | let g:job = term_getjob(buf) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 689 | call StopShellInTerminal(buf) |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 690 | call term_wait(buf) |
Bram Moolenaar | d21f8b5 | 2017-08-19 15:40:01 +0200 | [diff] [blame] | 691 | unlet g:job |
Bram Moolenaar | 97bd5e6 | 2017-08-18 20:50:30 +0200 | [diff] [blame] | 692 | bwipe |
| 693 | endfunc |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 694 | |
| 695 | func Test_terminal_write_stdin() |
Bram Moolenaar | 2110927 | 2020-01-30 16:27:20 +0100 | [diff] [blame] | 696 | " TODO: enable once writing to stdin works on MS-Windows |
| 697 | CheckNotMSWindows |
| 698 | CheckExecutable wc |
| 699 | |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 700 | call setline(1, ['one', 'two', 'three']) |
| 701 | %term wc |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 702 | call WaitForAssert({-> assert_match('3', getline("$"))}) |
Bram Moolenaar | 3346cc4 | 2017-09-02 14:54:21 +0200 | [diff] [blame] | 703 | let nrs = split(getline('$')) |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 704 | call assert_equal(['3', '3', '14'], nrs) |
Bram Moolenaar | 2110927 | 2020-01-30 16:27:20 +0100 | [diff] [blame] | 705 | %bwipe! |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 706 | |
| 707 | call setline(1, ['one', 'two', 'three', 'four']) |
| 708 | 2,3term wc |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 709 | call WaitForAssert({-> assert_match('2', getline("$"))}) |
Bram Moolenaar | 3346cc4 | 2017-09-02 14:54:21 +0200 | [diff] [blame] | 710 | let nrs = split(getline('$')) |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 711 | call assert_equal(['2', '2', '10'], nrs) |
Bram Moolenaar | 2110927 | 2020-01-30 16:27:20 +0100 | [diff] [blame] | 712 | %bwipe! |
| 713 | endfunc |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 714 | |
Bram Moolenaar | 2110927 | 2020-01-30 16:27:20 +0100 | [diff] [blame] | 715 | func Test_terminal_eof_arg() |
| 716 | CheckExecutable python |
Bram Moolenaar | dada6d2 | 2017-09-02 17:18:35 +0200 | [diff] [blame] | 717 | |
Bram Moolenaar | 2110927 | 2020-01-30 16:27:20 +0100 | [diff] [blame] | 718 | call setline(1, ['print("hello")']) |
| 719 | 1term ++eof=exit(123) python |
| 720 | " MS-Windows echoes the input, Unix doesn't. |
| 721 | if has('win32') |
| 722 | call WaitFor({-> getline('$') =~ 'exit(123)'}) |
| 723 | call assert_equal('hello', getline(line('$') - 1)) |
| 724 | else |
| 725 | call WaitFor({-> getline('$') =~ 'hello'}) |
| 726 | call assert_equal('hello', getline('$')) |
Bram Moolenaar | dada6d2 | 2017-09-02 17:18:35 +0200 | [diff] [blame] | 727 | endif |
Bram Moolenaar | 2110927 | 2020-01-30 16:27:20 +0100 | [diff] [blame] | 728 | call assert_equal(123, bufnr()->term_getjob()->job_info().exitval) |
| 729 | %bwipe! |
| 730 | endfunc |
Bram Moolenaar | dada6d2 | 2017-09-02 17:18:35 +0200 | [diff] [blame] | 731 | |
Bram Moolenaar | 2110927 | 2020-01-30 16:27:20 +0100 | [diff] [blame] | 732 | func Test_terminal_eof_arg_win32_ctrl_z() |
| 733 | CheckMSWindows |
| 734 | CheckExecutable python |
| 735 | |
| 736 | call setline(1, ['print("hello")']) |
| 737 | 1term ++eof=<C-Z> python |
| 738 | call WaitForAssert({-> assert_match('\^Z', getline(line('$') - 1))}) |
| 739 | call assert_match('\^Z', getline(line('$') - 1)) |
| 740 | %bwipe! |
| 741 | endfunc |
| 742 | |
| 743 | func Test_terminal_duplicate_eof_arg() |
| 744 | CheckExecutable python |
| 745 | |
| 746 | " Check the last specified ++eof arg is used and should not memory leak. |
| 747 | new |
| 748 | call setline(1, ['print("hello")']) |
| 749 | 1term ++eof=<C-Z> ++eof=exit(123) python |
| 750 | " MS-Windows echoes the input, Unix doesn't. |
| 751 | if has('win32') |
| 752 | call WaitFor({-> getline('$') =~ 'exit(123)'}) |
| 753 | call assert_equal('hello', getline(line('$') - 1)) |
| 754 | else |
| 755 | call WaitFor({-> getline('$') =~ 'hello'}) |
| 756 | call assert_equal('hello', getline('$')) |
| 757 | endif |
| 758 | call assert_equal(123, bufnr()->term_getjob()->job_info().exitval) |
| 759 | %bwipe! |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 760 | endfunc |
Bram Moolenaar | 13ebb03 | 2017-08-26 22:02:51 +0200 | [diff] [blame] | 761 | |
| 762 | func Test_terminal_no_cmd() |
Bram Moolenaar | 13ebb03 | 2017-08-26 22:02:51 +0200 | [diff] [blame] | 763 | let buf = term_start('NONE', {}) |
| 764 | call assert_notequal(0, buf) |
| 765 | |
Bram Moolenaar | 2dc9d26 | 2017-09-08 14:39:30 +0200 | [diff] [blame] | 766 | let pty = job_info(term_getjob(buf))['tty_out'] |
Bram Moolenaar | 13ebb03 | 2017-08-26 22:02:51 +0200 | [diff] [blame] | 767 | call assert_notequal('', pty) |
Bram Moolenaar | cfc1523 | 2019-01-23 22:33:18 +0100 | [diff] [blame] | 768 | if has('gui_running') && !has('win32') |
| 769 | " 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] | 770 | call system('echo "look here" > ' . pty) |
Bram Moolenaar | cfc1523 | 2019-01-23 22:33:18 +0100 | [diff] [blame] | 771 | else |
| 772 | " Otherwise using a job works on all systems. |
| 773 | call job_start([&shell, &shellcmdflag, 'echo "look here" > ' . pty]) |
Bram Moolenaar | 2dc9d26 | 2017-09-08 14:39:30 +0200 | [diff] [blame] | 774 | endif |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 775 | call WaitForAssert({-> assert_match('look here', term_getline(buf, 1))}) |
Bram Moolenaar | 2dc9d26 | 2017-09-08 14:39:30 +0200 | [diff] [blame] | 776 | |
Bram Moolenaar | 13ebb03 | 2017-08-26 22:02:51 +0200 | [diff] [blame] | 777 | bwipe! |
| 778 | endfunc |
Bram Moolenaar | 9d654a8 | 2017-09-03 19:52:17 +0200 | [diff] [blame] | 779 | |
| 780 | func Test_terminal_special_chars() |
| 781 | " this file name only works on Unix |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 782 | CheckUnix |
| 783 | |
Bram Moolenaar | 9d654a8 | 2017-09-03 19:52:17 +0200 | [diff] [blame] | 784 | call mkdir('Xdir with spaces') |
| 785 | call writefile(['x'], 'Xdir with spaces/quoted"file') |
| 786 | term ls Xdir\ with\ spaces/quoted\"file |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 787 | call WaitForAssert({-> assert_match('quoted"file', term_getline('', 1))}) |
Bram Moolenaar | 95ffd43 | 2020-02-23 13:29:31 +0100 | [diff] [blame] | 788 | " make sure the job has finished |
| 789 | call WaitForAssert({-> assert_match('finish', term_getstatus(bufnr()))}) |
Bram Moolenaar | 9d654a8 | 2017-09-03 19:52:17 +0200 | [diff] [blame] | 790 | |
| 791 | call delete('Xdir with spaces', 'rf') |
| 792 | bwipe |
| 793 | endfunc |
Bram Moolenaar | e88fc7a | 2017-09-03 20:59:40 +0200 | [diff] [blame] | 794 | |
| 795 | func Test_terminal_wrong_options() |
| 796 | call assert_fails('call term_start(&shell, { |
| 797 | \ "in_io": "file", |
| 798 | \ "in_name": "xxx", |
| 799 | \ "out_io": "file", |
| 800 | \ "out_name": "xxx", |
| 801 | \ "err_io": "file", |
| 802 | \ "err_name": "xxx" |
| 803 | \ })', 'E474:') |
| 804 | call assert_fails('call term_start(&shell, { |
| 805 | \ "out_buf": bufnr("%") |
| 806 | \ })', 'E474:') |
| 807 | call assert_fails('call term_start(&shell, { |
| 808 | \ "err_buf": bufnr("%") |
| 809 | \ })', 'E474:') |
| 810 | endfunc |
| 811 | |
| 812 | func Test_terminal_redir_file() |
Bram Moolenaar | f25329c | 2018-05-06 21:49:32 +0200 | [diff] [blame] | 813 | let cmd = Get_cat_123_cmd() |
| 814 | let buf = term_start(cmd, {'out_io': 'file', 'out_name': 'Xfile'}) |
| 815 | call term_wait(buf) |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 816 | " ConPTY may precede escape sequence. There are things that are not so. |
| 817 | if !has('conpty') |
| 818 | call WaitForAssert({-> assert_notequal(0, len(readfile("Xfile")))}) |
| 819 | call assert_match('123', readfile('Xfile')[0]) |
| 820 | endif |
Bram Moolenaar | f25329c | 2018-05-06 21:49:32 +0200 | [diff] [blame] | 821 | let g:job = term_getjob(buf) |
| 822 | call WaitForAssert({-> assert_equal("dead", job_status(g:job))}) |
| 823 | call delete('Xfile') |
| 824 | bwipe |
Bram Moolenaar | e88fc7a | 2017-09-03 20:59:40 +0200 | [diff] [blame] | 825 | |
| 826 | if has('unix') |
Bram Moolenaar | e88fc7a | 2017-09-03 20:59:40 +0200 | [diff] [blame] | 827 | call writefile(['one line'], 'Xfile') |
| 828 | let buf = term_start('cat', {'in_io': 'file', 'in_name': 'Xfile'}) |
| 829 | call term_wait(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 830 | call WaitForAssert({-> assert_equal('one line', term_getline(buf, 1))}) |
Bram Moolenaar | 8b53b79 | 2017-09-05 20:29:25 +0200 | [diff] [blame] | 831 | let g:job = term_getjob(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 832 | call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) |
Bram Moolenaar | e88fc7a | 2017-09-03 20:59:40 +0200 | [diff] [blame] | 833 | bwipe |
| 834 | call delete('Xfile') |
| 835 | endif |
| 836 | endfunc |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 837 | |
| 838 | func TerminalTmap(remap) |
| 839 | let buf = Run_shell_in_terminal({}) |
| 840 | call assert_equal('t', mode()) |
| 841 | |
| 842 | if a:remap |
| 843 | tmap 123 456 |
| 844 | else |
| 845 | tnoremap 123 456 |
| 846 | endif |
Bram Moolenaar | 461fe50 | 2017-12-05 12:30:03 +0100 | [diff] [blame] | 847 | " don't use abcde, it's an existing command |
| 848 | tmap 456 abxde |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 849 | call assert_equal('456', maparg('123', 't')) |
Bram Moolenaar | 461fe50 | 2017-12-05 12:30:03 +0100 | [diff] [blame] | 850 | call assert_equal('abxde', maparg('456', 't')) |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 851 | call feedkeys("123", 'tx') |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 852 | 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] | 853 | let lnum = term_getcursor(buf)[0] |
| 854 | if a:remap |
Bram Moolenaar | 461fe50 | 2017-12-05 12:30:03 +0100 | [diff] [blame] | 855 | call assert_match('abxde', term_getline(buf, lnum)) |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 856 | else |
| 857 | call assert_match('456', term_getline(buf, lnum)) |
| 858 | endif |
| 859 | |
| 860 | call term_sendkeys(buf, "\r") |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 861 | call StopShellInTerminal(buf) |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 862 | call term_wait(buf) |
| 863 | |
| 864 | tunmap 123 |
| 865 | tunmap 456 |
| 866 | call assert_equal('', maparg('123', 't')) |
| 867 | close |
| 868 | unlet g:job |
| 869 | endfunc |
| 870 | |
| 871 | func Test_terminal_tmap() |
| 872 | call TerminalTmap(1) |
| 873 | call TerminalTmap(0) |
| 874 | endfunc |
Bram Moolenaar | 059db5c | 2017-10-15 22:42:23 +0200 | [diff] [blame] | 875 | |
| 876 | func Test_terminal_wall() |
| 877 | let buf = Run_shell_in_terminal({}) |
| 878 | wall |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 879 | call StopShellInTerminal(buf) |
Bram Moolenaar | 059db5c | 2017-10-15 22:42:23 +0200 | [diff] [blame] | 880 | call term_wait(buf) |
| 881 | exe buf . 'bwipe' |
| 882 | unlet g:job |
| 883 | endfunc |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 884 | |
Bram Moolenaar | 7a76092 | 2018-02-19 23:10:02 +0100 | [diff] [blame] | 885 | func Test_terminal_wqall() |
| 886 | let buf = Run_shell_in_terminal({}) |
| 887 | call assert_fails('wqall', 'E948') |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 888 | call StopShellInTerminal(buf) |
Bram Moolenaar | 7a76092 | 2018-02-19 23:10:02 +0100 | [diff] [blame] | 889 | call term_wait(buf) |
| 890 | exe buf . 'bwipe' |
| 891 | unlet g:job |
| 892 | endfunc |
| 893 | |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 894 | func Test_terminal_composing_unicode() |
Bram Moolenaar | 9134f1e | 2019-11-29 20:26:13 +0100 | [diff] [blame] | 895 | CheckNotBSD |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 896 | let save_enc = &encoding |
| 897 | set encoding=utf-8 |
| 898 | |
| 899 | if has('win32') |
| 900 | let cmd = "cmd /K chcp 65001" |
| 901 | let lnum = [3, 6, 9] |
| 902 | else |
| 903 | let cmd = &shell |
| 904 | let lnum = [1, 3, 5] |
| 905 | endif |
| 906 | |
| 907 | enew |
| 908 | let buf = term_start(cmd, {'curwin': bufnr('')}) |
Bram Moolenaar | 3e1c617 | 2017-11-02 16:58:00 +0100 | [diff] [blame] | 909 | let g:job = term_getjob(buf) |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 910 | call term_wait(buf, 50) |
| 911 | |
Bram Moolenaar | ebe74b7 | 2018-04-21 23:34:43 +0200 | [diff] [blame] | 912 | if has('win32') |
| 913 | call assert_equal('cmd', job_info(g:job).cmd[0]) |
| 914 | else |
| 915 | call assert_equal(&shell, job_info(g:job).cmd[0]) |
| 916 | endif |
| 917 | |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 918 | " ascii + composing |
| 919 | let txt = "a\u0308bc" |
| 920 | call term_sendkeys(buf, "echo " . txt . "\r") |
| 921 | call term_wait(buf, 50) |
| 922 | call assert_match("echo " . txt, term_getline(buf, lnum[0])) |
| 923 | call assert_equal(txt, term_getline(buf, lnum[0] + 1)) |
| 924 | let l = term_scrape(buf, lnum[0] + 1) |
| 925 | call assert_equal("a\u0308", l[0].chars) |
| 926 | call assert_equal("b", l[1].chars) |
| 927 | call assert_equal("c", l[2].chars) |
| 928 | |
| 929 | " multibyte + composing |
| 930 | let txt = "\u304b\u3099\u304e\u304f\u3099\u3052\u3053\u3099" |
| 931 | call term_sendkeys(buf, "echo " . txt . "\r") |
| 932 | call term_wait(buf, 50) |
| 933 | call assert_match("echo " . txt, term_getline(buf, lnum[1])) |
| 934 | call assert_equal(txt, term_getline(buf, lnum[1] + 1)) |
| 935 | let l = term_scrape(buf, lnum[1] + 1) |
| 936 | call assert_equal("\u304b\u3099", l[0].chars) |
| 937 | call assert_equal("\u304e", l[1].chars) |
| 938 | call assert_equal("\u304f\u3099", l[2].chars) |
| 939 | call assert_equal("\u3052", l[3].chars) |
| 940 | call assert_equal("\u3053\u3099", l[4].chars) |
| 941 | |
| 942 | " \u00a0 + composing |
| 943 | let txt = "abc\u00a0\u0308" |
| 944 | call term_sendkeys(buf, "echo " . txt . "\r") |
| 945 | call term_wait(buf, 50) |
| 946 | call assert_match("echo " . txt, term_getline(buf, lnum[2])) |
| 947 | call assert_equal(txt, term_getline(buf, lnum[2] + 1)) |
| 948 | let l = term_scrape(buf, lnum[2] + 1) |
| 949 | call assert_equal("\u00a0\u0308", l[3].chars) |
| 950 | |
| 951 | call term_sendkeys(buf, "exit\r") |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 952 | call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 953 | bwipe! |
Bram Moolenaar | 3e1c617 | 2017-11-02 16:58:00 +0100 | [diff] [blame] | 954 | unlet g:job |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 955 | let &encoding = save_enc |
| 956 | endfunc |
Bram Moolenaar | ff54679 | 2017-11-21 14:47:57 +0100 | [diff] [blame] | 957 | |
| 958 | func Test_terminal_aucmd_on_close() |
| 959 | fun Nop() |
| 960 | let s:called = 1 |
| 961 | endfun |
| 962 | |
| 963 | aug repro |
| 964 | au! |
| 965 | au BufWinLeave * call Nop() |
| 966 | aug END |
| 967 | |
| 968 | let [cmd, waittime] = s:get_sleep_cmd() |
| 969 | |
| 970 | call assert_equal(1, winnr('$')) |
| 971 | new |
| 972 | call setline(1, ['one', 'two']) |
| 973 | exe 'term ++close ' . cmd |
| 974 | wincmd p |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 975 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | ff54679 | 2017-11-21 14:47:57 +0100 | [diff] [blame] | 976 | call assert_equal(1, s:called) |
| 977 | bwipe! |
| 978 | |
| 979 | unlet s:called |
| 980 | au! repro |
| 981 | delfunc Nop |
| 982 | endfunc |
Bram Moolenaar | ede35bb | 2018-01-26 20:05:18 +0100 | [diff] [blame] | 983 | |
| 984 | func Test_terminal_term_start_empty_command() |
| 985 | let cmd = "call term_start('', {'curwin' : 1, 'term_finish' : 'close'})" |
| 986 | call assert_fails(cmd, 'E474') |
| 987 | let cmd = "call term_start('', {'curwin' : 1, 'term_finish' : 'close'})" |
| 988 | call assert_fails(cmd, 'E474') |
| 989 | let cmd = "call term_start({}, {'curwin' : 1, 'term_finish' : 'close'})" |
| 990 | call assert_fails(cmd, 'E474') |
| 991 | let cmd = "call term_start(0, {'curwin' : 1, 'term_finish' : 'close'})" |
| 992 | call assert_fails(cmd, 'E474') |
| 993 | endfunc |
Bram Moolenaar | b50773c | 2018-01-30 22:31:19 +0100 | [diff] [blame] | 994 | |
| 995 | func Test_terminal_response_to_control_sequence() |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 996 | CheckUnix |
Bram Moolenaar | b50773c | 2018-01-30 22:31:19 +0100 | [diff] [blame] | 997 | |
| 998 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 999 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
Bram Moolenaar | b50773c | 2018-01-30 22:31:19 +0100 | [diff] [blame] | 1000 | |
Bram Moolenaar | 086eb87 | 2018-03-25 21:24:12 +0200 | [diff] [blame] | 1001 | call term_sendkeys(buf, "cat\<CR>") |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1002 | call WaitForAssert({-> assert_match('cat', term_getline(buf, 1))}) |
Bram Moolenaar | d4a282f | 2018-02-02 18:22:31 +0100 | [diff] [blame] | 1003 | |
Bram Moolenaar | 086eb87 | 2018-03-25 21:24:12 +0200 | [diff] [blame] | 1004 | " Request the cursor position. |
| 1005 | call term_sendkeys(buf, "\x1b[6n\<CR>") |
Bram Moolenaar | d4a282f | 2018-02-02 18:22:31 +0100 | [diff] [blame] | 1006 | |
| 1007 | " Wait for output from tty to display, below an empty line. |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1008 | call WaitForAssert({-> assert_match('3;1R', term_getline(buf, 4))}) |
Bram Moolenaar | b50773c | 2018-01-30 22:31:19 +0100 | [diff] [blame] | 1009 | |
Bram Moolenaar | 086eb87 | 2018-03-25 21:24:12 +0200 | [diff] [blame] | 1010 | " End "cat" gently. |
| 1011 | call term_sendkeys(buf, "\<CR>\<C-D>") |
| 1012 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 1013 | call StopShellInTerminal(buf) |
Bram Moolenaar | b50773c | 2018-01-30 22:31:19 +0100 | [diff] [blame] | 1014 | exe buf . 'bwipe' |
| 1015 | unlet g:job |
| 1016 | endfunc |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 1017 | |
Bram Moolenaar | 3e8d385 | 2018-03-20 17:43:01 +0100 | [diff] [blame] | 1018 | " Run Vim, start a terminal in that Vim with the kill argument, |
| 1019 | " :qall works. |
| 1020 | func Run_terminal_qall_kill(line1, line2) |
| 1021 | " 1. Open a terminal window and wait for the prompt to appear |
| 1022 | " 2. set kill using term_setkill() |
| 1023 | " 3. make Vim exit, it will kill the shell |
| 1024 | let after = [ |
| 1025 | \ a:line1, |
| 1026 | \ 'let buf = bufnr("%")', |
| 1027 | \ 'while term_getline(buf, 1) =~ "^\\s*$"', |
| 1028 | \ ' sleep 10m', |
| 1029 | \ 'endwhile', |
| 1030 | \ a:line2, |
| 1031 | \ 'au VimLeavePre * call writefile(["done"], "Xdone")', |
| 1032 | \ 'qall', |
| 1033 | \ ] |
| 1034 | if !RunVim([], after, '') |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 1035 | return |
| 1036 | endif |
Bram Moolenaar | 3e8d385 | 2018-03-20 17:43:01 +0100 | [diff] [blame] | 1037 | call assert_equal("done", readfile("Xdone")[0]) |
| 1038 | call delete("Xdone") |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 1039 | endfunc |
| 1040 | |
| 1041 | " Run Vim in a terminal, then start a terminal in that Vim with a kill |
| 1042 | " argument, check that :qall works. |
Bram Moolenaar | 3e8d385 | 2018-03-20 17:43:01 +0100 | [diff] [blame] | 1043 | func Test_terminal_qall_kill_arg() |
| 1044 | call Run_terminal_qall_kill('term ++kill=kill', '') |
| 1045 | endfunc |
| 1046 | |
| 1047 | " Run Vim, start a terminal in that Vim, set the kill argument with |
| 1048 | " term_setkill(), check that :qall works. |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 1049 | func Test_terminal_qall_kill_func() |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 1050 | call Run_terminal_qall_kill('term', 'eval buf->term_setkill("kill")') |
Bram Moolenaar | 3e8d385 | 2018-03-20 17:43:01 +0100 | [diff] [blame] | 1051 | endfunc |
| 1052 | |
| 1053 | " Run Vim, start a terminal in that Vim without the kill argument, |
| 1054 | " check that :qall does not exit, :qall! does. |
| 1055 | func Test_terminal_qall_exit() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1056 | let after =<< trim [CODE] |
| 1057 | term |
| 1058 | let buf = bufnr("%") |
| 1059 | while term_getline(buf, 1) =~ "^\\s*$" |
| 1060 | sleep 10m |
| 1061 | endwhile |
| 1062 | set nomore |
| 1063 | au VimLeavePre * call writefile(["too early"], "Xdone") |
| 1064 | qall |
| 1065 | au! VimLeavePre * exe buf . "bwipe!" | call writefile(["done"], "Xdone") |
| 1066 | cquit |
| 1067 | [CODE] |
| 1068 | |
Bram Moolenaar | 3e8d385 | 2018-03-20 17:43:01 +0100 | [diff] [blame] | 1069 | if !RunVim([], after, '') |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 1070 | return |
| 1071 | endif |
Bram Moolenaar | 3e8d385 | 2018-03-20 17:43:01 +0100 | [diff] [blame] | 1072 | call assert_equal("done", readfile("Xdone")[0]) |
| 1073 | call delete("Xdone") |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 1074 | endfunc |
Bram Moolenaar | 435acdb | 2018-03-10 20:51:25 +0100 | [diff] [blame] | 1075 | |
| 1076 | " Run Vim in a terminal, then start a terminal in that Vim without a kill |
| 1077 | " argument, check that :confirm qall works. |
| 1078 | func Test_terminal_qall_prompt() |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1079 | CheckRunVimInTerminal |
Bram Moolenaar | 435acdb | 2018-03-10 20:51:25 +0100 | [diff] [blame] | 1080 | let buf = RunVimInTerminal('', {}) |
| 1081 | |
| 1082 | " Open a terminal window and wait for the prompt to appear |
| 1083 | call term_sendkeys(buf, ":term\<CR>") |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1084 | call WaitForAssert({-> assert_match('\[running]', term_getline(buf, 10))}) |
| 1085 | call WaitForAssert({-> assert_notmatch('^\s*$', term_getline(buf, 1))}) |
Bram Moolenaar | 435acdb | 2018-03-10 20:51:25 +0100 | [diff] [blame] | 1086 | |
| 1087 | " make Vim exit, it will prompt to kill the shell |
| 1088 | call term_sendkeys(buf, "\<C-W>:confirm qall\<CR>") |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1089 | call WaitForAssert({-> assert_match('ancel:', term_getline(buf, 20))}) |
Bram Moolenaar | 435acdb | 2018-03-10 20:51:25 +0100 | [diff] [blame] | 1090 | call term_sendkeys(buf, "y") |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1091 | call WaitForAssert({-> assert_equal('finished', term_getstatus(buf))}) |
Bram Moolenaar | 435acdb | 2018-03-10 20:51:25 +0100 | [diff] [blame] | 1092 | |
| 1093 | " close the terminal window where Vim was running |
| 1094 | quit |
| 1095 | endfunc |
Bram Moolenaar | b852c3e | 2018-03-11 16:55:36 +0100 | [diff] [blame] | 1096 | |
Bram Moolenaar | 4d14bac | 2019-10-20 21:15:15 +0200 | [diff] [blame] | 1097 | " Run Vim in a terminal, then start a terminal window with a shell and check |
| 1098 | " that Vim exits if it is closed. |
| 1099 | func Test_terminal_exit() |
| 1100 | CheckRunVimInTerminal |
| 1101 | |
| 1102 | let lines =<< trim END |
| 1103 | let winid = win_getid() |
| 1104 | help |
| 1105 | term |
| 1106 | let termid = win_getid() |
| 1107 | call win_gotoid(winid) |
| 1108 | close |
| 1109 | call win_gotoid(termid) |
| 1110 | END |
| 1111 | call writefile(lines, 'XtermExit') |
| 1112 | let buf = RunVimInTerminal('-S XtermExit', #{rows: 10}) |
| 1113 | let job = term_getjob(buf) |
| 1114 | call WaitForAssert({-> assert_equal("run", job_status(job))}) |
| 1115 | |
| 1116 | " quit the shell, it will make Vim exit |
| 1117 | call term_sendkeys(buf, "exit\<CR>") |
| 1118 | call WaitForAssert({-> assert_equal("dead", job_status(job))}) |
| 1119 | |
| 1120 | call delete('XtermExit') |
| 1121 | endfunc |
| 1122 | |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 1123 | func Test_terminal_open_autocmd() |
Bram Moolenaar | b852c3e | 2018-03-11 16:55:36 +0100 | [diff] [blame] | 1124 | augroup repro |
| 1125 | au! |
| 1126 | au TerminalOpen * let s:called += 1 |
| 1127 | augroup END |
| 1128 | |
| 1129 | let s:called = 0 |
| 1130 | |
| 1131 | " Open a terminal window with :terminal |
| 1132 | terminal |
| 1133 | call assert_equal(1, s:called) |
| 1134 | bwipe! |
| 1135 | |
| 1136 | " Open a terminal window with term_start() |
| 1137 | call term_start(&shell) |
| 1138 | call assert_equal(2, s:called) |
| 1139 | bwipe! |
| 1140 | |
| 1141 | " Open a hidden terminal buffer with :terminal |
| 1142 | terminal ++hidden |
| 1143 | call assert_equal(3, s:called) |
| 1144 | for buf in term_list() |
| 1145 | exe buf . "bwipe!" |
| 1146 | endfor |
| 1147 | |
| 1148 | " Open a hidden terminal buffer with term_start() |
| 1149 | let buf = term_start(&shell, {'hidden': 1}) |
| 1150 | call assert_equal(4, s:called) |
| 1151 | exe buf . "bwipe!" |
| 1152 | |
| 1153 | unlet s:called |
| 1154 | au! repro |
| 1155 | endfunction |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1156 | |
| 1157 | func Check_dump01(off) |
| 1158 | call assert_equal('one two three four five', trim(getline(a:off + 1))) |
| 1159 | call assert_equal('~ Select Word', trim(getline(a:off + 7))) |
Bram Moolenaar | 1834d37 | 2018-03-29 17:40:46 +0200 | [diff] [blame] | 1160 | call assert_equal(':popup PopUp', trim(getline(a:off + 20))) |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1161 | endfunc |
| 1162 | |
Bram Moolenaar | f06b0b6 | 2018-03-29 17:22:24 +0200 | [diff] [blame] | 1163 | func Test_terminal_dumpwrite_composing() |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1164 | CheckRunVimInTerminal |
Bram Moolenaar | f06b0b6 | 2018-03-29 17:22:24 +0200 | [diff] [blame] | 1165 | let save_enc = &encoding |
| 1166 | set encoding=utf-8 |
| 1167 | call assert_equal(1, winnr('$')) |
| 1168 | |
| 1169 | let text = " a\u0300 e\u0302 o\u0308" |
| 1170 | call writefile([text], 'Xcomposing') |
Bram Moolenaar | 77bfd75 | 2018-04-30 18:03:10 +0200 | [diff] [blame] | 1171 | let buf = RunVimInTerminal('--cmd "set encoding=utf-8" Xcomposing', {}) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1172 | call WaitForAssert({-> assert_match(text, term_getline(buf, 1))}) |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 1173 | eval 'Xdump'->term_dumpwrite(buf) |
Bram Moolenaar | f06b0b6 | 2018-03-29 17:22:24 +0200 | [diff] [blame] | 1174 | let dumpline = readfile('Xdump')[0] |
| 1175 | call assert_match('|à| |ê| |ö', dumpline) |
| 1176 | |
| 1177 | call StopVimInTerminal(buf) |
| 1178 | call delete('Xcomposing') |
| 1179 | call delete('Xdump') |
| 1180 | let &encoding = save_enc |
| 1181 | endfunc |
| 1182 | |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1183 | " just testing basic functionality. |
| 1184 | func Test_terminal_dumpload() |
Bram Moolenaar | 87abab9 | 2019-06-03 21:14:59 +0200 | [diff] [blame] | 1185 | let curbuf = winbufnr('') |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1186 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | 87abab9 | 2019-06-03 21:14:59 +0200 | [diff] [blame] | 1187 | let buf = term_dumpload('dumps/Test_popup_command_01.dump') |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1188 | call assert_equal(2, winnr('$')) |
| 1189 | call assert_equal(20, line('$')) |
| 1190 | call Check_dump01(0) |
Bram Moolenaar | 87abab9 | 2019-06-03 21:14:59 +0200 | [diff] [blame] | 1191 | |
| 1192 | " Load another dump in the same window |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 1193 | let buf2 = 'dumps/Test_diff_01.dump'->term_dumpload({'bufnr': buf}) |
Bram Moolenaar | 87abab9 | 2019-06-03 21:14:59 +0200 | [diff] [blame] | 1194 | call assert_equal(buf, buf2) |
| 1195 | call assert_notequal('one two three four five', trim(getline(1))) |
| 1196 | |
| 1197 | " Load the first dump again in the same window |
| 1198 | let buf2 = term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': buf}) |
| 1199 | call assert_equal(buf, buf2) |
| 1200 | call Check_dump01(0) |
| 1201 | |
| 1202 | call assert_fails("call term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': curbuf})", 'E475:') |
| 1203 | call assert_fails("call term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': 9999})", 'E86:') |
| 1204 | new |
| 1205 | let closedbuf = winbufnr('') |
| 1206 | quit |
| 1207 | call assert_fails("call term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': closedbuf})", 'E475:') |
| 1208 | |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1209 | quit |
| 1210 | endfunc |
| 1211 | |
Bram Moolenaar | 17efc7f | 2019-10-16 18:11:31 +0200 | [diff] [blame] | 1212 | func Test_terminal_dumpload_dump() |
| 1213 | CheckRunVimInTerminal |
| 1214 | |
| 1215 | let lines =<< trim END |
| 1216 | call term_dumpload('dumps/Test_popupwin_22.dump', #{term_rows: 12}) |
| 1217 | END |
| 1218 | call writefile(lines, 'XtermDumpload') |
| 1219 | let buf = RunVimInTerminal('-S XtermDumpload', #{rows: 15}) |
| 1220 | call VerifyScreenDump(buf, 'Test_terminal_dumpload', {}) |
| 1221 | |
| 1222 | call StopVimInTerminal(buf) |
| 1223 | call delete('XtermDumpload') |
| 1224 | endfunc |
| 1225 | |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1226 | func Test_terminal_dumpdiff() |
| 1227 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 1228 | 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] | 1229 | call assert_equal(2, winnr('$')) |
| 1230 | call assert_equal(62, line('$')) |
| 1231 | call Check_dump01(0) |
| 1232 | call Check_dump01(42) |
| 1233 | call assert_equal(' bbbbbbbbbbbbbbbbbb ', getline(26)[0:29]) |
| 1234 | quit |
| 1235 | endfunc |
Bram Moolenaar | 897e63c | 2018-03-24 17:16:33 +0100 | [diff] [blame] | 1236 | |
Bram Moolenaar | c3ef896 | 2019-02-15 00:16:13 +0100 | [diff] [blame] | 1237 | func Test_terminal_dumpdiff_swap() |
| 1238 | call assert_equal(1, winnr('$')) |
| 1239 | call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_03.dump') |
| 1240 | call assert_equal(2, winnr('$')) |
| 1241 | call assert_equal(62, line('$')) |
| 1242 | call assert_match('Test_popup_command_01.dump', getline(21)) |
| 1243 | call assert_match('Test_popup_command_03.dump', getline(42)) |
| 1244 | call assert_match('Undo', getline(3)) |
| 1245 | call assert_match('three four five', getline(45)) |
| 1246 | |
| 1247 | normal s |
| 1248 | call assert_match('Test_popup_command_03.dump', getline(21)) |
| 1249 | call assert_match('Test_popup_command_01.dump', getline(42)) |
| 1250 | call assert_match('three four five', getline(3)) |
| 1251 | call assert_match('Undo', getline(45)) |
| 1252 | quit |
| 1253 | endfunc |
| 1254 | |
Bram Moolenaar | 897e63c | 2018-03-24 17:16:33 +0100 | [diff] [blame] | 1255 | func Test_terminal_dumpdiff_options() |
| 1256 | set laststatus=0 |
| 1257 | call assert_equal(1, winnr('$')) |
| 1258 | let height = winheight(0) |
| 1259 | call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_02.dump', {'vertical': 1, 'term_cols': 33}) |
| 1260 | call assert_equal(2, winnr('$')) |
| 1261 | call assert_equal(height, winheight(winnr())) |
| 1262 | call assert_equal(33, winwidth(winnr())) |
| 1263 | call assert_equal('dump diff dumps/Test_popup_command_01.dump', bufname('%')) |
| 1264 | quit |
| 1265 | |
| 1266 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | 897e63c | 2018-03-24 17:16:33 +0100 | [diff] [blame] | 1267 | call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_02.dump', {'vertical': 0, 'term_rows': 13, 'term_name': 'something else'}) |
| 1268 | call assert_equal(2, winnr('$')) |
Bram Moolenaar | e809a4e | 2019-07-04 17:35:05 +0200 | [diff] [blame] | 1269 | call assert_equal(&columns, winwidth(0)) |
| 1270 | call assert_equal(13, winheight(0)) |
Bram Moolenaar | 897e63c | 2018-03-24 17:16:33 +0100 | [diff] [blame] | 1271 | call assert_equal('something else', bufname('%')) |
| 1272 | quit |
| 1273 | |
| 1274 | call assert_equal(1, winnr('$')) |
| 1275 | call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_02.dump', {'curwin': 1}) |
| 1276 | call assert_equal(1, winnr('$')) |
| 1277 | bwipe |
| 1278 | |
| 1279 | set laststatus& |
| 1280 | endfunc |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1281 | |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1282 | func Api_drop_common(options) |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1283 | call assert_equal(1, winnr('$')) |
| 1284 | |
| 1285 | " Use the title termcap entries to output the escape sequence. |
| 1286 | call writefile([ |
Bram Moolenaar | cf67a50 | 2018-03-25 20:31:32 +0200 | [diff] [blame] | 1287 | \ 'set title', |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1288 | \ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"', |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1289 | \ 'let &titlestring = ''["drop","Xtextfile"' . a:options . ']''', |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1290 | \ 'redraw', |
| 1291 | \ "set t_ts=", |
| 1292 | \ ], 'Xscript') |
| 1293 | let buf = RunVimInTerminal('-S Xscript', {}) |
Bram Moolenaar | 769e9d2 | 2018-04-11 20:53:49 +0200 | [diff] [blame] | 1294 | call WaitFor({-> bufnr('Xtextfile') > 0}) |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1295 | call assert_equal('Xtextfile', expand('%:t')) |
| 1296 | call assert_true(winnr('$') >= 3) |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1297 | return buf |
| 1298 | endfunc |
| 1299 | |
| 1300 | func Test_terminal_api_drop_newwin() |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1301 | CheckRunVimInTerminal |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1302 | let buf = Api_drop_common('') |
| 1303 | call assert_equal(0, &bin) |
| 1304 | call assert_equal('', &fenc) |
| 1305 | |
| 1306 | call StopVimInTerminal(buf) |
| 1307 | call delete('Xscript') |
| 1308 | bwipe Xtextfile |
| 1309 | endfunc |
| 1310 | |
| 1311 | func Test_terminal_api_drop_newwin_bin() |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1312 | CheckRunVimInTerminal |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1313 | let buf = Api_drop_common(',{"bin":1}') |
| 1314 | call assert_equal(1, &bin) |
| 1315 | |
| 1316 | call StopVimInTerminal(buf) |
| 1317 | call delete('Xscript') |
| 1318 | bwipe Xtextfile |
| 1319 | endfunc |
| 1320 | |
| 1321 | func Test_terminal_api_drop_newwin_binary() |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1322 | CheckRunVimInTerminal |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1323 | let buf = Api_drop_common(',{"binary":1}') |
| 1324 | call assert_equal(1, &bin) |
| 1325 | |
| 1326 | call StopVimInTerminal(buf) |
| 1327 | call delete('Xscript') |
| 1328 | bwipe Xtextfile |
| 1329 | endfunc |
| 1330 | |
| 1331 | func Test_terminal_api_drop_newwin_nobin() |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1332 | CheckRunVimInTerminal |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1333 | set binary |
| 1334 | let buf = Api_drop_common(',{"nobin":1}') |
| 1335 | call assert_equal(0, &bin) |
| 1336 | |
| 1337 | call StopVimInTerminal(buf) |
| 1338 | call delete('Xscript') |
| 1339 | bwipe Xtextfile |
| 1340 | set nobinary |
| 1341 | endfunc |
| 1342 | |
| 1343 | func Test_terminal_api_drop_newwin_nobinary() |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1344 | CheckRunVimInTerminal |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1345 | set binary |
| 1346 | let buf = Api_drop_common(',{"nobinary":1}') |
| 1347 | call assert_equal(0, &bin) |
| 1348 | |
| 1349 | call StopVimInTerminal(buf) |
| 1350 | call delete('Xscript') |
| 1351 | bwipe Xtextfile |
| 1352 | set nobinary |
| 1353 | endfunc |
| 1354 | |
| 1355 | func Test_terminal_api_drop_newwin_ff() |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1356 | CheckRunVimInTerminal |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1357 | let buf = Api_drop_common(',{"ff":"dos"}') |
| 1358 | call assert_equal("dos", &ff) |
| 1359 | |
| 1360 | call StopVimInTerminal(buf) |
| 1361 | call delete('Xscript') |
| 1362 | bwipe Xtextfile |
| 1363 | endfunc |
| 1364 | |
| 1365 | func Test_terminal_api_drop_newwin_fileformat() |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1366 | CheckRunVimInTerminal |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1367 | let buf = Api_drop_common(',{"fileformat":"dos"}') |
| 1368 | call assert_equal("dos", &ff) |
| 1369 | |
| 1370 | call StopVimInTerminal(buf) |
| 1371 | call delete('Xscript') |
| 1372 | bwipe Xtextfile |
| 1373 | endfunc |
| 1374 | |
| 1375 | func Test_terminal_api_drop_newwin_enc() |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1376 | CheckRunVimInTerminal |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1377 | let buf = Api_drop_common(',{"enc":"utf-16"}') |
| 1378 | call assert_equal("utf-16", &fenc) |
| 1379 | |
| 1380 | call StopVimInTerminal(buf) |
| 1381 | call delete('Xscript') |
| 1382 | bwipe Xtextfile |
| 1383 | endfunc |
| 1384 | |
| 1385 | func Test_terminal_api_drop_newwin_encoding() |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1386 | CheckRunVimInTerminal |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1387 | let buf = Api_drop_common(',{"encoding":"utf-16"}') |
| 1388 | call assert_equal("utf-16", &fenc) |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1389 | |
| 1390 | call StopVimInTerminal(buf) |
| 1391 | call delete('Xscript') |
| 1392 | bwipe Xtextfile |
| 1393 | endfunc |
| 1394 | |
| 1395 | func Test_terminal_api_drop_oldwin() |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1396 | CheckRunVimInTerminal |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1397 | let firstwinid = win_getid() |
| 1398 | split Xtextfile |
| 1399 | let textfile_winid = win_getid() |
| 1400 | call assert_equal(2, winnr('$')) |
| 1401 | call win_gotoid(firstwinid) |
| 1402 | |
| 1403 | " Use the title termcap entries to output the escape sequence. |
| 1404 | call writefile([ |
Bram Moolenaar | cf67a50 | 2018-03-25 20:31:32 +0200 | [diff] [blame] | 1405 | \ 'set title', |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1406 | \ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"', |
| 1407 | \ 'let &titlestring = ''["drop","Xtextfile"]''', |
| 1408 | \ 'redraw', |
| 1409 | \ "set t_ts=", |
| 1410 | \ ], 'Xscript') |
Bram Moolenaar | 15a1c3f | 2018-03-25 18:56:25 +0200 | [diff] [blame] | 1411 | let buf = RunVimInTerminal('-S Xscript', {'rows': 10}) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1412 | call WaitForAssert({-> assert_equal('Xtextfile', expand('%:t'))}) |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1413 | call assert_equal(textfile_winid, win_getid()) |
| 1414 | |
| 1415 | call StopVimInTerminal(buf) |
| 1416 | call delete('Xscript') |
| 1417 | bwipe Xtextfile |
| 1418 | endfunc |
| 1419 | |
Bram Moolenaar | 2a77d21 | 2018-03-26 21:38:52 +0200 | [diff] [blame] | 1420 | func Tapi_TryThis(bufnum, arg) |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1421 | let g:called_bufnum = a:bufnum |
| 1422 | let g:called_arg = a:arg |
| 1423 | endfunc |
| 1424 | |
Bram Moolenaar | 2a77d21 | 2018-03-26 21:38:52 +0200 | [diff] [blame] | 1425 | func WriteApiCall(funcname) |
| 1426 | " Use the title termcap entries to output the escape sequence. |
| 1427 | call writefile([ |
| 1428 | \ 'set title', |
| 1429 | \ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"', |
| 1430 | \ 'let &titlestring = ''["call","' . a:funcname . '",["hello",123]]''', |
| 1431 | \ 'redraw', |
| 1432 | \ "set t_ts=", |
| 1433 | \ ], 'Xscript') |
| 1434 | endfunc |
| 1435 | |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1436 | func Test_terminal_api_call() |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1437 | CheckRunVimInTerminal |
Bram Moolenaar | 2de50f8 | 2018-03-25 19:09:56 +0200 | [diff] [blame] | 1438 | |
Bram Moolenaar | d2842ea | 2019-09-26 23:08:54 +0200 | [diff] [blame] | 1439 | unlet! g:called_bufnum |
| 1440 | unlet! g:called_arg |
| 1441 | |
Bram Moolenaar | 2a77d21 | 2018-03-26 21:38:52 +0200 | [diff] [blame] | 1442 | call WriteApiCall('Tapi_TryThis') |
Bram Moolenaar | d2842ea | 2019-09-26 23:08:54 +0200 | [diff] [blame] | 1443 | |
| 1444 | " Default |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1445 | let buf = RunVimInTerminal('-S Xscript', {}) |
| 1446 | call WaitFor({-> exists('g:called_bufnum')}) |
| 1447 | call assert_equal(buf, g:called_bufnum) |
| 1448 | call assert_equal(['hello', 123], g:called_arg) |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1449 | call StopVimInTerminal(buf) |
Bram Moolenaar | d2842ea | 2019-09-26 23:08:54 +0200 | [diff] [blame] | 1450 | |
| 1451 | unlet! g:called_bufnum |
| 1452 | unlet! g:called_arg |
| 1453 | |
| 1454 | " Enable explicitly |
| 1455 | let buf = RunVimInTerminal('-S Xscript', {'term_api': 'Tapi_Try'}) |
| 1456 | call WaitFor({-> exists('g:called_bufnum')}) |
| 1457 | call assert_equal(buf, g:called_bufnum) |
| 1458 | call assert_equal(['hello', 123], g:called_arg) |
| 1459 | call StopVimInTerminal(buf) |
| 1460 | |
| 1461 | unlet! g:called_bufnum |
| 1462 | unlet! g:called_arg |
| 1463 | |
| 1464 | func! ApiCall_TryThis(bufnum, arg) |
| 1465 | let g:called_bufnum2 = a:bufnum |
| 1466 | let g:called_arg2 = a:arg |
| 1467 | endfunc |
| 1468 | |
| 1469 | call WriteApiCall('ApiCall_TryThis') |
| 1470 | |
| 1471 | " Use prefix match |
| 1472 | let buf = RunVimInTerminal('-S Xscript', {'term_api': 'ApiCall_'}) |
| 1473 | call WaitFor({-> exists('g:called_bufnum2')}) |
| 1474 | call assert_equal(buf, g:called_bufnum2) |
| 1475 | call assert_equal(['hello', 123], g:called_arg2) |
| 1476 | call StopVimInTerminal(buf) |
| 1477 | |
| 1478 | unlet! g:called_bufnum2 |
| 1479 | unlet! g:called_arg2 |
| 1480 | |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1481 | call delete('Xscript') |
Bram Moolenaar | d2842ea | 2019-09-26 23:08:54 +0200 | [diff] [blame] | 1482 | delfunction! ApiCall_TryThis |
| 1483 | unlet! g:called_bufnum2 |
| 1484 | unlet! g:called_arg2 |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1485 | endfunc |
Bram Moolenaar | 2a77d21 | 2018-03-26 21:38:52 +0200 | [diff] [blame] | 1486 | |
| 1487 | func Test_terminal_api_call_fails() |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1488 | CheckRunVimInTerminal |
Bram Moolenaar | 2a77d21 | 2018-03-26 21:38:52 +0200 | [diff] [blame] | 1489 | |
Bram Moolenaar | d2842ea | 2019-09-26 23:08:54 +0200 | [diff] [blame] | 1490 | func! TryThis(bufnum, arg) |
| 1491 | let g:called_bufnum3 = a:bufnum |
| 1492 | let g:called_arg3 = a:arg |
| 1493 | endfunc |
Bram Moolenaar | 2a77d21 | 2018-03-26 21:38:52 +0200 | [diff] [blame] | 1494 | |
Bram Moolenaar | d2842ea | 2019-09-26 23:08:54 +0200 | [diff] [blame] | 1495 | call WriteApiCall('TryThis') |
| 1496 | |
| 1497 | unlet! g:called_bufnum3 |
| 1498 | unlet! g:called_arg3 |
| 1499 | |
| 1500 | " Not permitted |
| 1501 | call ch_logfile('Xlog', 'w') |
| 1502 | let buf = RunVimInTerminal('-S Xscript', {'term_api': ''}) |
| 1503 | call WaitForAssert({-> assert_match('Unpermitted function: TryThis', string(readfile('Xlog')))}) |
| 1504 | call assert_false(exists('g:called_bufnum3')) |
| 1505 | call assert_false(exists('g:called_arg3')) |
Bram Moolenaar | 2a77d21 | 2018-03-26 21:38:52 +0200 | [diff] [blame] | 1506 | call StopVimInTerminal(buf) |
Bram Moolenaar | d2842ea | 2019-09-26 23:08:54 +0200 | [diff] [blame] | 1507 | |
| 1508 | " No match |
| 1509 | call ch_logfile('Xlog', 'w') |
| 1510 | let buf = RunVimInTerminal('-S Xscript', {'term_api': 'TryThat'}) |
| 1511 | call WaitFor({-> string(readfile('Xlog')) =~ 'Unpermitted function: TryThis'}) |
| 1512 | call assert_false(exists('g:called_bufnum3')) |
| 1513 | call assert_false(exists('g:called_arg3')) |
| 1514 | call StopVimInTerminal(buf) |
| 1515 | |
Bram Moolenaar | 2a77d21 | 2018-03-26 21:38:52 +0200 | [diff] [blame] | 1516 | call delete('Xscript') |
Bram Moolenaar | d2842ea | 2019-09-26 23:08:54 +0200 | [diff] [blame] | 1517 | call ch_logfile('') |
Bram Moolenaar | 2a77d21 | 2018-03-26 21:38:52 +0200 | [diff] [blame] | 1518 | call delete('Xlog') |
Bram Moolenaar | d2842ea | 2019-09-26 23:08:54 +0200 | [diff] [blame] | 1519 | delfunction! TryThis |
| 1520 | unlet! g:called_bufnum3 |
| 1521 | unlet! g:called_arg3 |
Bram Moolenaar | 2a77d21 | 2018-03-26 21:38:52 +0200 | [diff] [blame] | 1522 | endfunc |
Bram Moolenaar | f59c6e8 | 2018-04-10 15:59:11 +0200 | [diff] [blame] | 1523 | |
Bram Moolenaar | a997b45 | 2018-04-17 23:24:06 +0200 | [diff] [blame] | 1524 | let s:caught_e937 = 0 |
| 1525 | |
| 1526 | func Tapi_Delete(bufnum, arg) |
| 1527 | try |
| 1528 | execute 'bdelete!' a:bufnum |
| 1529 | catch /E937:/ |
| 1530 | let s:caught_e937 = 1 |
| 1531 | endtry |
| 1532 | endfunc |
| 1533 | |
| 1534 | func Test_terminal_api_call_fail_delete() |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1535 | CheckRunVimInTerminal |
Bram Moolenaar | a997b45 | 2018-04-17 23:24:06 +0200 | [diff] [blame] | 1536 | |
| 1537 | call WriteApiCall('Tapi_Delete') |
| 1538 | let buf = RunVimInTerminal('-S Xscript', {}) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1539 | call WaitForAssert({-> assert_equal(1, s:caught_e937)}) |
Bram Moolenaar | a997b45 | 2018-04-17 23:24:06 +0200 | [diff] [blame] | 1540 | |
| 1541 | call StopVimInTerminal(buf) |
| 1542 | call delete('Xscript') |
| 1543 | call ch_logfile('', '') |
| 1544 | endfunc |
| 1545 | |
Bram Moolenaar | f59c6e8 | 2018-04-10 15:59:11 +0200 | [diff] [blame] | 1546 | func Test_terminal_ansicolors_default() |
Bram Moolenaar | 981d9dc | 2019-07-04 22:32:39 +0200 | [diff] [blame] | 1547 | if !exists('*term_getansicolors') |
| 1548 | throw 'Skipped: term_getansicolors() not supported' |
| 1549 | endif |
Bram Moolenaar | f59c6e8 | 2018-04-10 15:59:11 +0200 | [diff] [blame] | 1550 | let colors = [ |
| 1551 | \ '#000000', '#e00000', |
| 1552 | \ '#00e000', '#e0e000', |
| 1553 | \ '#0000e0', '#e000e0', |
| 1554 | \ '#00e0e0', '#e0e0e0', |
| 1555 | \ '#808080', '#ff4040', |
| 1556 | \ '#40ff40', '#ffff40', |
| 1557 | \ '#4040ff', '#ff40ff', |
| 1558 | \ '#40ffff', '#ffffff', |
| 1559 | \] |
| 1560 | |
| 1561 | let buf = Run_shell_in_terminal({}) |
| 1562 | call assert_equal(colors, term_getansicolors(buf)) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 1563 | call StopShellInTerminal(buf) |
Bram Moolenaar | f59c6e8 | 2018-04-10 15:59:11 +0200 | [diff] [blame] | 1564 | call term_wait(buf) |
| 1565 | |
| 1566 | exe buf . 'bwipe' |
| 1567 | endfunc |
| 1568 | |
| 1569 | let s:test_colors = [ |
| 1570 | \ '#616e64', '#0d0a79', |
| 1571 | \ '#6d610d', '#0a7373', |
| 1572 | \ '#690d0a', '#6d696e', |
| 1573 | \ '#0d0a6f', '#616e0d', |
| 1574 | \ '#0a6479', '#6d0d0a', |
| 1575 | \ '#617373', '#0d0a69', |
| 1576 | \ '#6d690d', '#0a6e6f', |
| 1577 | \ '#610d0a', '#6e6479', |
| 1578 | \] |
| 1579 | |
| 1580 | func Test_terminal_ansicolors_global() |
Bram Moolenaar | 1e82a78 | 2019-09-21 22:57:06 +0200 | [diff] [blame] | 1581 | CheckFeature termguicolors |
Bram Moolenaar | 981d9dc | 2019-07-04 22:32:39 +0200 | [diff] [blame] | 1582 | if !exists('*term_getansicolors') |
| 1583 | throw 'Skipped: term_getansicolors() not supported' |
| 1584 | endif |
Bram Moolenaar | f59c6e8 | 2018-04-10 15:59:11 +0200 | [diff] [blame] | 1585 | let g:terminal_ansi_colors = reverse(copy(s:test_colors)) |
| 1586 | let buf = Run_shell_in_terminal({}) |
| 1587 | call assert_equal(g:terminal_ansi_colors, term_getansicolors(buf)) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 1588 | call StopShellInTerminal(buf) |
Bram Moolenaar | f59c6e8 | 2018-04-10 15:59:11 +0200 | [diff] [blame] | 1589 | call term_wait(buf) |
| 1590 | |
| 1591 | exe buf . 'bwipe' |
| 1592 | unlet g:terminal_ansi_colors |
| 1593 | endfunc |
| 1594 | |
| 1595 | func Test_terminal_ansicolors_func() |
Bram Moolenaar | 1e82a78 | 2019-09-21 22:57:06 +0200 | [diff] [blame] | 1596 | CheckFeature termguicolors |
Bram Moolenaar | 981d9dc | 2019-07-04 22:32:39 +0200 | [diff] [blame] | 1597 | if !exists('*term_getansicolors') |
| 1598 | throw 'Skipped: term_getansicolors() not supported' |
| 1599 | endif |
Bram Moolenaar | f59c6e8 | 2018-04-10 15:59:11 +0200 | [diff] [blame] | 1600 | let g:terminal_ansi_colors = reverse(copy(s:test_colors)) |
| 1601 | let buf = Run_shell_in_terminal({'ansi_colors': s:test_colors}) |
| 1602 | call assert_equal(s:test_colors, term_getansicolors(buf)) |
| 1603 | |
| 1604 | call term_setansicolors(buf, g:terminal_ansi_colors) |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 1605 | call assert_equal(g:terminal_ansi_colors, buf->term_getansicolors()) |
Bram Moolenaar | f59c6e8 | 2018-04-10 15:59:11 +0200 | [diff] [blame] | 1606 | |
| 1607 | let colors = [ |
| 1608 | \ 'ivory', 'AliceBlue', |
| 1609 | \ 'grey67', 'dark goldenrod', |
| 1610 | \ 'SteelBlue3', 'PaleVioletRed4', |
| 1611 | \ 'MediumPurple2', 'yellow2', |
| 1612 | \ 'RosyBrown3', 'OrangeRed2', |
| 1613 | \ 'white smoke', 'navy blue', |
| 1614 | \ 'grey47', 'gray97', |
| 1615 | \ 'MistyRose2', 'DodgerBlue4', |
| 1616 | \] |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 1617 | eval buf->term_setansicolors(colors) |
Bram Moolenaar | f59c6e8 | 2018-04-10 15:59:11 +0200 | [diff] [blame] | 1618 | |
| 1619 | let colors[4] = 'Invalid' |
| 1620 | call assert_fails('call term_setansicolors(buf, colors)', 'E474:') |
| 1621 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 1622 | call StopShellInTerminal(buf) |
Bram Moolenaar | f59c6e8 | 2018-04-10 15:59:11 +0200 | [diff] [blame] | 1623 | call term_wait(buf) |
| 1624 | exe buf . 'bwipe' |
| 1625 | endfunc |
Bram Moolenaar | a7eef3d | 2018-04-15 22:25:54 +0200 | [diff] [blame] | 1626 | |
Bram Moolenaar | 1d79ce8 | 2019-04-12 22:27:39 +0200 | [diff] [blame] | 1627 | func Test_terminal_all_ansi_colors() |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1628 | CheckRunVimInTerminal |
Bram Moolenaar | 1d79ce8 | 2019-04-12 22:27:39 +0200 | [diff] [blame] | 1629 | |
| 1630 | " Use all the ANSI colors. |
| 1631 | call writefile([ |
Bram Moolenaar | 9e58787 | 2019-05-13 20:27:23 +0200 | [diff] [blame] | 1632 | \ 'call setline(1, "AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPP XXYYZZ")', |
Bram Moolenaar | a0aaf3c | 2019-04-13 23:18:21 +0200 | [diff] [blame] | 1633 | \ 'hi Tblack ctermfg=0 ctermbg=8', |
| 1634 | \ 'hi Tdarkred ctermfg=1 ctermbg=9', |
| 1635 | \ 'hi Tdarkgreen ctermfg=2 ctermbg=10', |
| 1636 | \ 'hi Tbrown ctermfg=3 ctermbg=11', |
| 1637 | \ 'hi Tdarkblue ctermfg=4 ctermbg=12', |
| 1638 | \ 'hi Tdarkmagenta ctermfg=5 ctermbg=13', |
| 1639 | \ 'hi Tdarkcyan ctermfg=6 ctermbg=14', |
| 1640 | \ 'hi Tlightgrey ctermfg=7 ctermbg=15', |
| 1641 | \ 'hi Tdarkgrey ctermfg=8 ctermbg=0', |
| 1642 | \ 'hi Tred ctermfg=9 ctermbg=1', |
| 1643 | \ 'hi Tgreen ctermfg=10 ctermbg=2', |
| 1644 | \ 'hi Tyellow ctermfg=11 ctermbg=3', |
| 1645 | \ 'hi Tblue ctermfg=12 ctermbg=4', |
| 1646 | \ 'hi Tmagenta ctermfg=13 ctermbg=5', |
| 1647 | \ 'hi Tcyan ctermfg=14 ctermbg=6', |
| 1648 | \ 'hi Twhite ctermfg=15 ctermbg=7', |
Bram Moolenaar | 9e58787 | 2019-05-13 20:27:23 +0200 | [diff] [blame] | 1649 | \ 'hi TdarkredBold ctermfg=1 cterm=bold', |
| 1650 | \ 'hi TgreenBold ctermfg=10 cterm=bold', |
| 1651 | \ 'hi TmagentaBold ctermfg=13 cterm=bold ctermbg=5', |
Bram Moolenaar | 1d79ce8 | 2019-04-12 22:27:39 +0200 | [diff] [blame] | 1652 | \ '', |
| 1653 | \ 'call matchadd("Tblack", "A")', |
| 1654 | \ 'call matchadd("Tdarkred", "B")', |
| 1655 | \ 'call matchadd("Tdarkgreen", "C")', |
| 1656 | \ 'call matchadd("Tbrown", "D")', |
| 1657 | \ 'call matchadd("Tdarkblue", "E")', |
| 1658 | \ 'call matchadd("Tdarkmagenta", "F")', |
| 1659 | \ 'call matchadd("Tdarkcyan", "G")', |
| 1660 | \ 'call matchadd("Tlightgrey", "H")', |
| 1661 | \ 'call matchadd("Tdarkgrey", "I")', |
| 1662 | \ 'call matchadd("Tred", "J")', |
| 1663 | \ 'call matchadd("Tgreen", "K")', |
| 1664 | \ 'call matchadd("Tyellow", "L")', |
| 1665 | \ 'call matchadd("Tblue", "M")', |
| 1666 | \ 'call matchadd("Tmagenta", "N")', |
| 1667 | \ 'call matchadd("Tcyan", "O")', |
| 1668 | \ 'call matchadd("Twhite", "P")', |
Bram Moolenaar | 9e58787 | 2019-05-13 20:27:23 +0200 | [diff] [blame] | 1669 | \ 'call matchadd("TdarkredBold", "X")', |
| 1670 | \ 'call matchadd("TgreenBold", "Y")', |
| 1671 | \ 'call matchadd("TmagentaBold", "Z")', |
Bram Moolenaar | 1d79ce8 | 2019-04-12 22:27:39 +0200 | [diff] [blame] | 1672 | \ 'redraw', |
| 1673 | \ ], 'Xcolorscript') |
| 1674 | let buf = RunVimInTerminal('-S Xcolorscript', {'rows': 10}) |
| 1675 | call VerifyScreenDump(buf, 'Test_terminal_all_ansi_colors', {}) |
| 1676 | |
| 1677 | call term_sendkeys(buf, ":q\<CR>") |
| 1678 | call StopVimInTerminal(buf) |
| 1679 | call delete('Xcolorscript') |
| 1680 | endfunc |
| 1681 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1682 | func Test_terminal_termwinsize_option_fixed() |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 1683 | CheckRunVimInTerminal |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1684 | set termwinsize=6x40 |
Bram Moolenaar | a7eef3d | 2018-04-15 22:25:54 +0200 | [diff] [blame] | 1685 | let text = [] |
| 1686 | for n in range(10) |
| 1687 | call add(text, repeat(n, 50)) |
| 1688 | endfor |
| 1689 | call writefile(text, 'Xwinsize') |
| 1690 | let buf = RunVimInTerminal('Xwinsize', {}) |
| 1691 | let win = bufwinid(buf) |
| 1692 | call assert_equal([6, 40], term_getsize(buf)) |
| 1693 | call assert_equal(6, winheight(win)) |
| 1694 | call assert_equal(40, winwidth(win)) |
| 1695 | |
| 1696 | " resizing the window doesn't resize the terminal. |
| 1697 | resize 10 |
| 1698 | vertical resize 60 |
| 1699 | call assert_equal([6, 40], term_getsize(buf)) |
| 1700 | call assert_equal(10, winheight(win)) |
| 1701 | call assert_equal(60, winwidth(win)) |
| 1702 | |
| 1703 | call StopVimInTerminal(buf) |
| 1704 | call delete('Xwinsize') |
| 1705 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1706 | call assert_fails('set termwinsize=40', 'E474') |
| 1707 | call assert_fails('set termwinsize=10+40', 'E474') |
| 1708 | call assert_fails('set termwinsize=abc', 'E474') |
Bram Moolenaar | a7eef3d | 2018-04-15 22:25:54 +0200 | [diff] [blame] | 1709 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1710 | set termwinsize= |
Bram Moolenaar | a7eef3d | 2018-04-15 22:25:54 +0200 | [diff] [blame] | 1711 | endfunc |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1712 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1713 | func Test_terminal_termwinsize_option_zero() |
| 1714 | set termwinsize=0x0 |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1715 | let buf = Run_shell_in_terminal({}) |
| 1716 | let win = bufwinid(buf) |
| 1717 | call assert_equal([winheight(win), winwidth(win)], term_getsize(buf)) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 1718 | call StopShellInTerminal(buf) |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1719 | call term_wait(buf) |
| 1720 | exe buf . 'bwipe' |
| 1721 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1722 | set termwinsize=7x0 |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1723 | let buf = Run_shell_in_terminal({}) |
| 1724 | let win = bufwinid(buf) |
| 1725 | call assert_equal([7, winwidth(win)], term_getsize(buf)) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 1726 | call StopShellInTerminal(buf) |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1727 | call term_wait(buf) |
| 1728 | exe buf . 'bwipe' |
| 1729 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1730 | set termwinsize=0x33 |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1731 | let buf = Run_shell_in_terminal({}) |
| 1732 | let win = bufwinid(buf) |
| 1733 | call assert_equal([winheight(win), 33], term_getsize(buf)) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 1734 | call StopShellInTerminal(buf) |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1735 | call term_wait(buf) |
| 1736 | exe buf . 'bwipe' |
| 1737 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1738 | set termwinsize= |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1739 | endfunc |
| 1740 | |
Bram Moolenaar | 700dfaa | 2019-04-13 14:21:19 +0200 | [diff] [blame] | 1741 | func Test_terminal_termwinsize_minimum() |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1742 | set termwinsize=10*50 |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1743 | vsplit |
| 1744 | let buf = Run_shell_in_terminal({}) |
| 1745 | let win = bufwinid(buf) |
| 1746 | call assert_inrange(10, 1000, winheight(win)) |
| 1747 | call assert_inrange(50, 1000, winwidth(win)) |
| 1748 | call assert_equal([winheight(win), winwidth(win)], term_getsize(buf)) |
| 1749 | |
| 1750 | resize 15 |
| 1751 | vertical resize 60 |
| 1752 | redraw |
| 1753 | call assert_equal([15, 60], term_getsize(buf)) |
| 1754 | call assert_equal(15, winheight(win)) |
| 1755 | call assert_equal(60, winwidth(win)) |
| 1756 | |
| 1757 | resize 7 |
| 1758 | vertical resize 30 |
| 1759 | redraw |
| 1760 | call assert_equal([10, 50], term_getsize(buf)) |
| 1761 | call assert_equal(7, winheight(win)) |
| 1762 | call assert_equal(30, winwidth(win)) |
| 1763 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 1764 | call StopShellInTerminal(buf) |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1765 | call term_wait(buf) |
| 1766 | exe buf . 'bwipe' |
| 1767 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1768 | set termwinsize=0*0 |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1769 | let buf = Run_shell_in_terminal({}) |
| 1770 | let win = bufwinid(buf) |
| 1771 | call assert_equal([winheight(win), winwidth(win)], term_getsize(buf)) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 1772 | call StopShellInTerminal(buf) |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1773 | call term_wait(buf) |
| 1774 | exe buf . 'bwipe' |
| 1775 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1776 | set termwinsize= |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1777 | endfunc |
Bram Moolenaar | b2ac14c | 2018-05-01 18:47:59 +0200 | [diff] [blame] | 1778 | |
| 1779 | func Test_terminal_termwinkey() |
Bram Moolenaar | 882d02e | 2019-02-22 17:56:43 +0100 | [diff] [blame] | 1780 | " make three tabpages, terminal in the middle |
| 1781 | 0tabnew |
Bram Moolenaar | 72e83c1 | 2019-02-22 16:09:52 +0100 | [diff] [blame] | 1782 | tabnext |
Bram Moolenaar | 882d02e | 2019-02-22 17:56:43 +0100 | [diff] [blame] | 1783 | tabnew |
| 1784 | tabprev |
| 1785 | call assert_equal(1, winnr('$')) |
| 1786 | call assert_equal(2, tabpagenr()) |
| 1787 | let thiswin = win_getid() |
Bram Moolenaar | b2ac14c | 2018-05-01 18:47:59 +0200 | [diff] [blame] | 1788 | |
| 1789 | let buf = Run_shell_in_terminal({}) |
| 1790 | let termwin = bufwinid(buf) |
| 1791 | set termwinkey=<C-L> |
| 1792 | call feedkeys("\<C-L>w", 'tx') |
| 1793 | call assert_equal(thiswin, win_getid()) |
| 1794 | call feedkeys("\<C-W>w", 'tx') |
Bram Moolenaar | 72e83c1 | 2019-02-22 16:09:52 +0100 | [diff] [blame] | 1795 | call assert_equal(termwin, win_getid()) |
| 1796 | |
Bram Moolenaar | 997d424 | 2019-09-14 21:23:40 +0200 | [diff] [blame] | 1797 | if has('langmap') |
| 1798 | set langmap=xjyk |
| 1799 | call feedkeys("\<C-L>x", 'tx') |
| 1800 | call assert_equal(thiswin, win_getid()) |
| 1801 | call feedkeys("\<C-W>y", 'tx') |
| 1802 | call assert_equal(termwin, win_getid()) |
| 1803 | set langmap= |
| 1804 | endif |
Bram Moolenaar | a4b2699 | 2019-08-15 20:58:54 +0200 | [diff] [blame] | 1805 | |
Bram Moolenaar | 72e83c1 | 2019-02-22 16:09:52 +0100 | [diff] [blame] | 1806 | call feedkeys("\<C-L>gt", "xt") |
Bram Moolenaar | 882d02e | 2019-02-22 17:56:43 +0100 | [diff] [blame] | 1807 | call assert_equal(3, tabpagenr()) |
| 1808 | tabprev |
| 1809 | call assert_equal(2, tabpagenr()) |
| 1810 | call assert_equal(termwin, win_getid()) |
| 1811 | |
| 1812 | call feedkeys("\<C-L>gT", "xt") |
| 1813 | call assert_equal(1, tabpagenr()) |
Bram Moolenaar | 72e83c1 | 2019-02-22 16:09:52 +0100 | [diff] [blame] | 1814 | tabnext |
Bram Moolenaar | 882d02e | 2019-02-22 17:56:43 +0100 | [diff] [blame] | 1815 | call assert_equal(2, tabpagenr()) |
Bram Moolenaar | 72e83c1 | 2019-02-22 16:09:52 +0100 | [diff] [blame] | 1816 | call assert_equal(termwin, win_getid()) |
Bram Moolenaar | b2ac14c | 2018-05-01 18:47:59 +0200 | [diff] [blame] | 1817 | |
| 1818 | let job = term_getjob(buf) |
| 1819 | call feedkeys("\<C-L>\<C-C>", 'tx') |
| 1820 | call WaitForAssert({-> assert_equal("dead", job_status(job))}) |
Bram Moolenaar | 29ae223 | 2019-02-14 21:22:01 +0100 | [diff] [blame] | 1821 | |
| 1822 | set termwinkey& |
Bram Moolenaar | 72e83c1 | 2019-02-22 16:09:52 +0100 | [diff] [blame] | 1823 | tabnext |
| 1824 | tabclose |
Bram Moolenaar | 882d02e | 2019-02-22 17:56:43 +0100 | [diff] [blame] | 1825 | tabprev |
| 1826 | tabclose |
Bram Moolenaar | b2ac14c | 2018-05-01 18:47:59 +0200 | [diff] [blame] | 1827 | endfunc |
Bram Moolenaar | cd8fb44 | 2018-05-12 17:42:42 +0200 | [diff] [blame] | 1828 | |
| 1829 | func Test_terminal_out_err() |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 1830 | CheckUnix |
| 1831 | |
Bram Moolenaar | cd8fb44 | 2018-05-12 17:42:42 +0200 | [diff] [blame] | 1832 | call writefile([ |
| 1833 | \ '#!/bin/sh', |
| 1834 | \ 'echo "this is standard error" >&2', |
| 1835 | \ 'echo "this is standard out" >&1', |
| 1836 | \ ], 'Xechoerrout.sh') |
| 1837 | call setfperm('Xechoerrout.sh', 'rwxrwx---') |
| 1838 | |
| 1839 | let outfile = 'Xtermstdout' |
| 1840 | let buf = term_start(['./Xechoerrout.sh'], {'out_io': 'file', 'out_name': outfile}) |
Bram Moolenaar | 5319191 | 2018-06-19 20:08:14 +0200 | [diff] [blame] | 1841 | |
| 1842 | call WaitFor({-> !empty(readfile(outfile)) && !empty(term_getline(buf, 1))}) |
| 1843 | call assert_equal(['this is standard out'], readfile(outfile)) |
Bram Moolenaar | cd8fb44 | 2018-05-12 17:42:42 +0200 | [diff] [blame] | 1844 | call assert_equal('this is standard error', term_getline(buf, 1)) |
| 1845 | |
Bram Moolenaar | 54c6baf | 2018-05-12 21:12:12 +0200 | [diff] [blame] | 1846 | call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))}) |
Bram Moolenaar | cd8fb44 | 2018-05-12 17:42:42 +0200 | [diff] [blame] | 1847 | exe buf . 'bwipe' |
| 1848 | call delete('Xechoerrout.sh') |
| 1849 | call delete(outfile) |
| 1850 | endfunc |
Bram Moolenaar | 4d6cd29 | 2018-05-15 23:53:26 +0200 | [diff] [blame] | 1851 | |
Bram Moolenaar | e219f73 | 2019-11-30 15:34:08 +0100 | [diff] [blame] | 1852 | func Test_termwinscroll() |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 1853 | CheckUnix |
Bram Moolenaar | 4d6cd29 | 2018-05-15 23:53:26 +0200 | [diff] [blame] | 1854 | |
| 1855 | " Let the terminal output more than 'termwinscroll' lines, some at the start |
| 1856 | " will be dropped. |
| 1857 | exe 'set termwinscroll=' . &lines |
| 1858 | let buf = term_start('/bin/sh') |
| 1859 | for i in range(1, &lines) |
| 1860 | call feedkeys("echo " . i . "\<CR>", 'xt') |
| 1861 | call WaitForAssert({-> assert_match(string(i), term_getline(buf, term_getcursor(buf)[0] - 1))}) |
| 1862 | endfor |
| 1863 | " Go to Terminal-Normal mode to update the buffer. |
| 1864 | call feedkeys("\<C-W>N", 'xt') |
| 1865 | call assert_inrange(&lines, &lines * 110 / 100 + winheight(0), line('$')) |
| 1866 | |
| 1867 | " Every "echo nr" must only appear once |
| 1868 | let lines = getline(1, line('$')) |
| 1869 | for i in range(&lines - len(lines) / 2 + 2, &lines) |
| 1870 | let filtered = filter(copy(lines), {idx, val -> val =~ 'echo ' . i . '\>'}) |
| 1871 | call assert_equal(1, len(filtered), 'for "echo ' . i . '"') |
| 1872 | endfor |
| 1873 | |
| 1874 | exe buf . 'bwipe!' |
| 1875 | endfunc |
Bram Moolenaar | f9c3883 | 2018-06-19 19:59:20 +0200 | [diff] [blame] | 1876 | |
Bram Moolenaar | 875cf87 | 2018-07-08 20:49:07 +0200 | [diff] [blame] | 1877 | " Resizing the terminal window caused an ml_get error. |
| 1878 | " TODO: This does not reproduce the original problem. |
| 1879 | func Test_terminal_resize() |
| 1880 | set statusline=x |
| 1881 | terminal |
| 1882 | call assert_equal(2, winnr('$')) |
| 1883 | |
| 1884 | " Fill the terminal with text. |
| 1885 | if has('win32') |
| 1886 | call feedkeys("dir\<CR>", 'xt') |
| 1887 | else |
| 1888 | call feedkeys("ls\<CR>", 'xt') |
| 1889 | endif |
| 1890 | " Go to Terminal-Normal mode for a moment. |
| 1891 | call feedkeys("\<C-W>N", 'xt') |
| 1892 | " Open a new window |
| 1893 | call feedkeys("i\<C-W>n", 'xt') |
| 1894 | call assert_equal(3, winnr('$')) |
| 1895 | redraw |
| 1896 | |
| 1897 | close |
| 1898 | call assert_equal(2, winnr('$')) |
| 1899 | call feedkeys("exit\<CR>", 'xt') |
| 1900 | set statusline& |
| 1901 | endfunc |
| 1902 | |
Bram Moolenaar | f9c3883 | 2018-06-19 19:59:20 +0200 | [diff] [blame] | 1903 | " must be nearly the last, we can't go back from GUI to terminal |
| 1904 | func Test_zz1_terminal_in_gui() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 1905 | CheckCanRunGui |
Bram Moolenaar | f9c3883 | 2018-06-19 19:59:20 +0200 | [diff] [blame] | 1906 | |
| 1907 | " Ignore the "failed to create input context" error. |
| 1908 | call test_ignore_error('E285:') |
| 1909 | |
| 1910 | gui -f |
| 1911 | |
| 1912 | call assert_equal(1, winnr('$')) |
| 1913 | let buf = Run_shell_in_terminal({'term_finish': 'close'}) |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 1914 | call StopShellInTerminal(buf) |
Bram Moolenaar | f9c3883 | 2018-06-19 19:59:20 +0200 | [diff] [blame] | 1915 | call term_wait(buf) |
| 1916 | |
| 1917 | " closing window wipes out the terminal buffer a with finished job |
| 1918 | call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
| 1919 | call assert_equal("", bufname(buf)) |
| 1920 | |
| 1921 | unlet g:job |
| 1922 | endfunc |
| 1923 | |
| 1924 | func Test_zz2_terminal_guioptions_bang() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 1925 | CheckGui |
Bram Moolenaar | f9c3883 | 2018-06-19 19:59:20 +0200 | [diff] [blame] | 1926 | set guioptions+=! |
| 1927 | |
| 1928 | let filename = 'Xtestscript' |
| 1929 | if has('win32') |
| 1930 | let filename .= '.bat' |
| 1931 | let prefix = '' |
| 1932 | let contents = ['@echo off', 'exit %1'] |
| 1933 | else |
| 1934 | let filename .= '.sh' |
| 1935 | let prefix = './' |
| 1936 | let contents = ['#!/bin/sh', 'exit $1'] |
| 1937 | endif |
| 1938 | call writefile(contents, filename) |
| 1939 | call setfperm(filename, 'rwxrwx---') |
| 1940 | |
| 1941 | " Check if v:shell_error is equal to the exit status. |
| 1942 | let exitval = 0 |
| 1943 | execute printf(':!%s%s %d', prefix, filename, exitval) |
| 1944 | call assert_equal(exitval, v:shell_error) |
| 1945 | |
| 1946 | let exitval = 9 |
| 1947 | execute printf(':!%s%s %d', prefix, filename, exitval) |
| 1948 | call assert_equal(exitval, v:shell_error) |
| 1949 | |
| 1950 | set guioptions& |
| 1951 | call delete(filename) |
| 1952 | endfunc |
Bram Moolenaar | 7da1fb5 | 2018-08-04 16:54:11 +0200 | [diff] [blame] | 1953 | |
| 1954 | func Test_terminal_hidden() |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 1955 | CheckUnix |
| 1956 | |
Bram Moolenaar | 7da1fb5 | 2018-08-04 16:54:11 +0200 | [diff] [blame] | 1957 | term ++hidden cat |
| 1958 | let bnr = bufnr('$') |
| 1959 | call assert_equal('terminal', getbufvar(bnr, '&buftype')) |
| 1960 | exe 'sbuf ' . bnr |
| 1961 | call assert_equal('terminal', &buftype) |
| 1962 | call term_sendkeys(bnr, "asdf\<CR>") |
| 1963 | call WaitForAssert({-> assert_match('asdf', term_getline(bnr, 2))}) |
| 1964 | call term_sendkeys(bnr, "\<C-D>") |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 1965 | call WaitForAssert({-> assert_equal('finished', bnr->term_getstatus())}) |
Bram Moolenaar | 7da1fb5 | 2018-08-04 16:54:11 +0200 | [diff] [blame] | 1966 | bwipe! |
| 1967 | endfunc |
Bram Moolenaar | 5db7eec | 2018-08-07 16:33:18 +0200 | [diff] [blame] | 1968 | |
Bram Moolenaar | a4c2a24 | 2019-03-25 23:01:38 +0100 | [diff] [blame] | 1969 | func Test_terminal_switch_mode() |
| 1970 | term |
| 1971 | let bnr = bufnr('$') |
| 1972 | call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))}) |
| 1973 | call feedkeys("\<C-W>N", 'xt') |
| 1974 | call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))}) |
| 1975 | call feedkeys("A", 'xt') |
| 1976 | call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))}) |
| 1977 | call feedkeys("\<C-W>N", 'xt') |
| 1978 | call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))}) |
| 1979 | call feedkeys("I", 'xt') |
| 1980 | call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))}) |
| 1981 | call feedkeys("\<C-W>Nv", 'xt') |
| 1982 | call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))}) |
| 1983 | call feedkeys("I", 'xt') |
| 1984 | call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))}) |
| 1985 | call feedkeys("\<C-W>Nv", 'xt') |
| 1986 | call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))}) |
| 1987 | call feedkeys("A", 'xt') |
| 1988 | call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))}) |
| 1989 | bwipe! |
| 1990 | endfunc |
| 1991 | |
Bram Moolenaar | a381773 | 2019-10-16 16:31:44 +0200 | [diff] [blame] | 1992 | func Test_terminal_normal_mode() |
| 1993 | CheckRunVimInTerminal |
| 1994 | |
| 1995 | " Run Vim in a terminal and open a terminal window to run Vim in. |
| 1996 | let lines =<< trim END |
| 1997 | call setline(1, range(11111, 11122)) |
| 1998 | 3 |
| 1999 | END |
| 2000 | call writefile(lines, 'XtermNormal') |
| 2001 | let buf = RunVimInTerminal('-S XtermNormal', {'rows': 8}) |
| 2002 | call term_wait(buf) |
| 2003 | |
| 2004 | call term_sendkeys(buf, "\<C-W>N") |
| 2005 | call term_sendkeys(buf, ":set number cursorline culopt=both\r") |
| 2006 | call VerifyScreenDump(buf, 'Test_terminal_normal_1', {}) |
| 2007 | |
| 2008 | call term_sendkeys(buf, ":set culopt=number\r") |
| 2009 | call VerifyScreenDump(buf, 'Test_terminal_normal_2', {}) |
| 2010 | |
| 2011 | call term_sendkeys(buf, ":set culopt=line\r") |
| 2012 | call VerifyScreenDump(buf, 'Test_terminal_normal_3', {}) |
| 2013 | |
| 2014 | call term_sendkeys(buf, "a:q!\<CR>:q\<CR>:q\<CR>") |
| 2015 | call StopVimInTerminal(buf) |
| 2016 | call delete('XtermNormal') |
| 2017 | endfunc |
| 2018 | |
Bram Moolenaar | 5db7eec | 2018-08-07 16:33:18 +0200 | [diff] [blame] | 2019 | func Test_terminal_hidden_and_close() |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 2020 | CheckUnix |
| 2021 | |
Bram Moolenaar | 5db7eec | 2018-08-07 16:33:18 +0200 | [diff] [blame] | 2022 | call assert_equal(1, winnr('$')) |
| 2023 | term ++hidden ++close ls |
| 2024 | let bnr = bufnr('$') |
| 2025 | call assert_equal('terminal', getbufvar(bnr, '&buftype')) |
| 2026 | call WaitForAssert({-> assert_false(bufexists(bnr))}) |
| 2027 | call assert_equal(1, winnr('$')) |
| 2028 | endfunc |
Bram Moolenaar | f3aea59 | 2018-11-11 22:18:21 +0100 | [diff] [blame] | 2029 | |
| 2030 | func Test_terminal_does_not_truncate_last_newlines() |
Bram Moolenaar | aa5df7e | 2019-02-03 14:53:10 +0100 | [diff] [blame] | 2031 | " This test does not pass through ConPTY. |
| 2032 | if has('conpty') |
| 2033 | return |
| 2034 | endif |
Bram Moolenaar | f3aea59 | 2018-11-11 22:18:21 +0100 | [diff] [blame] | 2035 | let contents = [ |
| 2036 | \ [ 'One', '', 'X' ], |
| 2037 | \ [ 'Two', '', '' ], |
| 2038 | \ [ 'Three' ] + repeat([''], 30) |
| 2039 | \ ] |
| 2040 | |
| 2041 | for c in contents |
| 2042 | call writefile(c, 'Xfile') |
Bram Moolenaar | d3471e5 | 2018-11-12 21:42:24 +0100 | [diff] [blame] | 2043 | if has('win32') |
| 2044 | term cmd /c type Xfile |
| 2045 | else |
| 2046 | term cat Xfile |
| 2047 | endif |
Bram Moolenaar | f3aea59 | 2018-11-11 22:18:21 +0100 | [diff] [blame] | 2048 | let bnr = bufnr('$') |
| 2049 | call assert_equal('terminal', getbufvar(bnr, '&buftype')) |
| 2050 | call WaitForAssert({-> assert_equal('finished', term_getstatus(bnr))}) |
Bram Moolenaar | d3471e5 | 2018-11-12 21:42:24 +0100 | [diff] [blame] | 2051 | sleep 100m |
Bram Moolenaar | f3aea59 | 2018-11-11 22:18:21 +0100 | [diff] [blame] | 2052 | call assert_equal(c, getline(1, line('$'))) |
| 2053 | quit |
| 2054 | endfor |
| 2055 | |
| 2056 | call delete('Xfile') |
| 2057 | endfunc |
Bram Moolenaar | e751a5f | 2018-12-16 16:16:10 +0100 | [diff] [blame] | 2058 | |
Bram Moolenaar | 528ccfb | 2018-12-21 20:55:22 +0100 | [diff] [blame] | 2059 | func Test_terminal_no_job() |
Bram Moolenaar | 077ff43 | 2019-10-28 00:42:21 +0100 | [diff] [blame] | 2060 | if has('win32') |
| 2061 | let cmd = 'cmd /c ""' |
| 2062 | else |
| 2063 | CheckExecutable false |
| 2064 | let cmd = 'false' |
| 2065 | endif |
| 2066 | let term = term_start(cmd, {'term_finish': 'close'}) |
Bram Moolenaar | 528ccfb | 2018-12-21 20:55:22 +0100 | [diff] [blame] | 2067 | call WaitForAssert({-> assert_equal(v:null, term_getjob(term)) }) |
| 2068 | endfunc |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 2069 | |
Bram Moolenaar | 74e3d4e | 2019-04-14 14:16:46 +0200 | [diff] [blame] | 2070 | func Test_term_getcursor() |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 2071 | CheckUnix |
| 2072 | |
Bram Moolenaar | 74e3d4e | 2019-04-14 14:16:46 +0200 | [diff] [blame] | 2073 | let buf = Run_shell_in_terminal({}) |
| 2074 | |
| 2075 | " Wait for the shell to display a prompt. |
| 2076 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
| 2077 | |
| 2078 | " Hide the cursor. |
| 2079 | call term_sendkeys(buf, "echo -e '\\033[?25l'\r") |
| 2080 | call WaitForAssert({-> assert_equal(0, term_getcursor(buf)[2].visible)}) |
| 2081 | |
| 2082 | " Show the cursor. |
| 2083 | call term_sendkeys(buf, "echo -e '\\033[?25h'\r") |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 2084 | call WaitForAssert({-> assert_equal(1, buf->term_getcursor()[2].visible)}) |
Bram Moolenaar | 74e3d4e | 2019-04-14 14:16:46 +0200 | [diff] [blame] | 2085 | |
| 2086 | " Change color of cursor. |
| 2087 | call WaitForAssert({-> assert_equal('', term_getcursor(buf)[2].color)}) |
| 2088 | call term_sendkeys(buf, "echo -e '\\033]12;blue\\007'\r") |
| 2089 | call WaitForAssert({-> assert_equal('blue', term_getcursor(buf)[2].color)}) |
| 2090 | call term_sendkeys(buf, "echo -e '\\033]12;green\\007'\r") |
| 2091 | call WaitForAssert({-> assert_equal('green', term_getcursor(buf)[2].color)}) |
| 2092 | |
| 2093 | " Make cursor a blinking block. |
| 2094 | call term_sendkeys(buf, "echo -e '\\033[1 q'\r") |
| 2095 | call WaitForAssert({-> assert_equal([1, 1], |
| 2096 | \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])}) |
| 2097 | |
| 2098 | " Make cursor a steady block. |
| 2099 | call term_sendkeys(buf, "echo -e '\\033[2 q'\r") |
| 2100 | call WaitForAssert({-> assert_equal([0, 1], |
| 2101 | \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])}) |
| 2102 | |
| 2103 | " Make cursor a blinking underline. |
| 2104 | call term_sendkeys(buf, "echo -e '\\033[3 q'\r") |
| 2105 | call WaitForAssert({-> assert_equal([1, 2], |
| 2106 | \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])}) |
| 2107 | |
| 2108 | " Make cursor a steady underline. |
| 2109 | call term_sendkeys(buf, "echo -e '\\033[4 q'\r") |
| 2110 | call WaitForAssert({-> assert_equal([0, 2], |
| 2111 | \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])}) |
| 2112 | |
| 2113 | " Make cursor a blinking vertical bar. |
| 2114 | call term_sendkeys(buf, "echo -e '\\033[5 q'\r") |
| 2115 | call WaitForAssert({-> assert_equal([1, 3], |
| 2116 | \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])}) |
| 2117 | |
| 2118 | " Make cursor a steady vertical bar. |
| 2119 | call term_sendkeys(buf, "echo -e '\\033[6 q'\r") |
| 2120 | call WaitForAssert({-> assert_equal([0, 3], |
| 2121 | \ [term_getcursor(buf)[2].blink, term_getcursor(buf)[2].shape])}) |
| 2122 | |
Bram Moolenaar | 7a39dd7 | 2019-06-23 00:50:15 +0200 | [diff] [blame] | 2123 | call StopShellInTerminal(buf) |
Bram Moolenaar | 74e3d4e | 2019-04-14 14:16:46 +0200 | [diff] [blame] | 2124 | endfunc |
| 2125 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 2126 | func Test_term_gettitle() |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 2127 | " term_gettitle() returns an empty string for a non-terminal buffer |
Bram Moolenaar | 4a5711b | 2019-04-06 12:39:55 +0200 | [diff] [blame] | 2128 | " and for a non-existing buffer. |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 2129 | call assert_equal('', bufnr('%')->term_gettitle()) |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 2130 | call assert_equal('', term_gettitle(bufnr('$') + 1)) |
| 2131 | |
Bram Moolenaar | 4a5711b | 2019-04-06 12:39:55 +0200 | [diff] [blame] | 2132 | if !has('title') || &title == 0 || empty(&t_ts) |
| 2133 | throw "Skipped: can't get/set title" |
| 2134 | endif |
| 2135 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 2136 | let term = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile']) |
Bram Moolenaar | 700dfaa | 2019-04-13 14:21:19 +0200 | [diff] [blame] | 2137 | if has('autoservername') |
Bram Moolenaar | 9c35d05 | 2019-04-13 20:39:15 +0200 | [diff] [blame] | 2138 | call WaitForAssert({-> assert_match('^\[No Name\] - VIM\d\+$', term_gettitle(term)) }) |
| 2139 | call term_sendkeys(term, ":e Xfoo\r") |
| 2140 | call WaitForAssert({-> assert_match('^Xfoo (.*[/\\]testdir) - VIM\d\+$', term_gettitle(term)) }) |
Bram Moolenaar | 700dfaa | 2019-04-13 14:21:19 +0200 | [diff] [blame] | 2141 | else |
| 2142 | call WaitForAssert({-> assert_equal('[No Name] - VIM', term_gettitle(term)) }) |
Bram Moolenaar | 9c35d05 | 2019-04-13 20:39:15 +0200 | [diff] [blame] | 2143 | call term_sendkeys(term, ":e Xfoo\r") |
| 2144 | call WaitForAssert({-> assert_match('^Xfoo (.*[/\\]testdir) - VIM$', term_gettitle(term)) }) |
Bram Moolenaar | 700dfaa | 2019-04-13 14:21:19 +0200 | [diff] [blame] | 2145 | endif |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 2146 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 2147 | call term_sendkeys(term, ":set titlestring=foo\r") |
| 2148 | call WaitForAssert({-> assert_equal('foo', term_gettitle(term)) }) |
| 2149 | |
| 2150 | exe term . 'bwipe!' |
| 2151 | endfunc |
Bram Moolenaar | 1077230 | 2019-01-20 18:25:54 +0100 | [diff] [blame] | 2152 | |
| 2153 | " When drawing the statusline the cursor position may not have been updated |
| 2154 | " yet. |
| 2155 | " 1. create a terminal, make it show 2 lines |
| 2156 | " 2. 0.5 sec later: leave terminal window, execute "i" |
| 2157 | " 3. 0.5 sec later: clear terminal window, now it's 1 line |
| 2158 | " 4. 0.5 sec later: redraw, including statusline (used to trigger bug) |
| 2159 | " 4. 0.5 sec later: should be done, clean up |
| 2160 | func Test_terminal_statusline() |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 2161 | CheckUnix |
| 2162 | |
Bram Moolenaar | 1077230 | 2019-01-20 18:25:54 +0100 | [diff] [blame] | 2163 | set statusline=x |
| 2164 | terminal |
| 2165 | let tbuf = bufnr('') |
| 2166 | call term_sendkeys(tbuf, "clear; echo a; echo b; sleep 1; clear\n") |
| 2167 | call timer_start(500, { tid -> feedkeys("\<C-w>j", 'tx') }) |
| 2168 | call timer_start(1500, { tid -> feedkeys("\<C-l>", 'tx') }) |
| 2169 | au BufLeave * if &buftype == 'terminal' | silent! normal i | endif |
| 2170 | |
| 2171 | sleep 2 |
| 2172 | exe tbuf . 'bwipe!' |
| 2173 | au! BufLeave |
| 2174 | set statusline= |
| 2175 | endfunc |
Bram Moolenaar | fa1e90c | 2019-04-06 17:47:40 +0200 | [diff] [blame] | 2176 | |
| 2177 | func Test_terminal_getwinpos() |
Bram Moolenaar | c258549 | 2019-09-22 21:29:53 +0200 | [diff] [blame] | 2178 | CheckRunVimInTerminal |
Bram Moolenaar | 616aeef | 2019-04-06 22:21:22 +0200 | [diff] [blame] | 2179 | |
Bram Moolenaar | fa1e90c | 2019-04-06 17:47:40 +0200 | [diff] [blame] | 2180 | " split, go to the bottom-right window |
| 2181 | split |
| 2182 | wincmd j |
| 2183 | set splitright |
| 2184 | |
| 2185 | call writefile([ |
| 2186 | \ 'echo getwinpos()', |
| 2187 | \ ], 'XTest_getwinpos') |
| 2188 | let buf = RunVimInTerminal('-S XTest_getwinpos', {'cols': 60}) |
| 2189 | call term_wait(buf) |
| 2190 | |
| 2191 | " Find the output of getwinpos() in the bottom line. |
| 2192 | let rows = term_getsize(buf)[0] |
| 2193 | call WaitForAssert({-> assert_match('\[\d\+, \d\+\]', term_getline(buf, rows))}) |
| 2194 | let line = term_getline(buf, rows) |
| 2195 | let xpos = str2nr(substitute(line, '\[\(\d\+\), \d\+\]', '\1', '')) |
| 2196 | let ypos = str2nr(substitute(line, '\[\d\+, \(\d\+\)\]', '\1', '')) |
| 2197 | |
Bram Moolenaar | 616aeef | 2019-04-06 22:21:22 +0200 | [diff] [blame] | 2198 | " Position must be bigger than the getwinpos() result of Vim itself. |
Bram Moolenaar | 700dfaa | 2019-04-13 14:21:19 +0200 | [diff] [blame] | 2199 | " The calculation in the console assumes a 10 x 7 character cell. |
Bram Moolenaar | 1b55797 | 2019-04-09 21:17:32 +0200 | [diff] [blame] | 2200 | " In the GUI it can be more, let's assume a 20 x 14 cell. |
| 2201 | " And then add 100 / 200 tolerance. |
Bram Moolenaar | 616aeef | 2019-04-06 22:21:22 +0200 | [diff] [blame] | 2202 | let [xroot, yroot] = getwinpos() |
Bram Moolenaar | 5d69fdb | 2019-08-31 19:13:58 +0200 | [diff] [blame] | 2203 | let winpos = 50->getwinpos() |
| 2204 | call assert_equal(xroot, winpos[0]) |
| 2205 | call assert_equal(yroot, winpos[1]) |
Bram Moolenaar | 1b55797 | 2019-04-09 21:17:32 +0200 | [diff] [blame] | 2206 | let [winrow, wincol] = win_screenpos('.') |
| 2207 | let xoff = wincol * (has('gui_running') ? 14 : 7) + 100 |
| 2208 | let yoff = winrow * (has('gui_running') ? 20 : 10) + 200 |
| 2209 | call assert_inrange(xroot + 2, xroot + xoff, xpos) |
| 2210 | call assert_inrange(yroot + 2, yroot + yoff, ypos) |
Bram Moolenaar | fa1e90c | 2019-04-06 17:47:40 +0200 | [diff] [blame] | 2211 | |
| 2212 | call term_wait(buf) |
| 2213 | call term_sendkeys(buf, ":q\<CR>") |
| 2214 | call StopVimInTerminal(buf) |
| 2215 | call delete('XTest_getwinpos') |
| 2216 | exe buf . 'bwipe!' |
| 2217 | set splitright& |
| 2218 | only! |
| 2219 | endfunc |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 2220 | |
| 2221 | func Test_terminal_altscreen() |
Bram Moolenaar | adbde3f | 2019-09-08 22:57:14 +0200 | [diff] [blame] | 2222 | " somehow doesn't work on MS-Windows |
| 2223 | CheckUnix |
| 2224 | let cmd = "cat Xtext\<CR>" |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 2225 | |
| 2226 | let buf = term_start(&shell, {}) |
Bram Moolenaar | bf9a3b0 | 2019-09-08 22:35:48 +0200 | [diff] [blame] | 2227 | call writefile(["\<Esc>[?1047h"], 'Xtext') |
| 2228 | call term_sendkeys(buf, cmd) |
Bram Moolenaar | b9c79cf | 2019-09-08 22:09:52 +0200 | [diff] [blame] | 2229 | call WaitForAssert({-> assert_equal(1, term_getaltscreen(buf))}) |
| 2230 | |
Bram Moolenaar | bf9a3b0 | 2019-09-08 22:35:48 +0200 | [diff] [blame] | 2231 | call writefile(["\<Esc>[?1047l"], 'Xtext') |
| 2232 | call term_sendkeys(buf, cmd) |
Bram Moolenaar | b9c79cf | 2019-09-08 22:09:52 +0200 | [diff] [blame] | 2233 | call WaitForAssert({-> assert_equal(0, term_getaltscreen(buf))}) |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 2234 | |
| 2235 | call term_sendkeys(buf, "exit\r") |
| 2236 | exe buf . "bwipe!" |
Bram Moolenaar | bf9a3b0 | 2019-09-08 22:35:48 +0200 | [diff] [blame] | 2237 | call delete('Xtext') |
Bram Moolenaar | 7ee80f7 | 2019-09-08 20:55:06 +0200 | [diff] [blame] | 2238 | endfunc |
Bram Moolenaar | d2842ea | 2019-09-26 23:08:54 +0200 | [diff] [blame] | 2239 | |
Bram Moolenaar | 197c6b7 | 2019-11-03 23:37:12 +0100 | [diff] [blame] | 2240 | func Test_terminal_shell_option() |
Bram Moolenaar | 2d6d76f | 2019-11-04 23:18:35 +0100 | [diff] [blame] | 2241 | if has('unix') |
| 2242 | " exec is a shell builtin command, should fail without a shell. |
| 2243 | term exec ls runtest.vim |
| 2244 | call WaitForAssert({-> assert_match('job failed', term_getline(bufnr(), 1))}) |
| 2245 | bwipe! |
Bram Moolenaar | 197c6b7 | 2019-11-03 23:37:12 +0100 | [diff] [blame] | 2246 | |
Bram Moolenaar | 2d6d76f | 2019-11-04 23:18:35 +0100 | [diff] [blame] | 2247 | term ++shell exec ls runtest.vim |
| 2248 | call WaitForAssert({-> assert_match('runtest.vim', term_getline(bufnr(), 1))}) |
| 2249 | bwipe! |
| 2250 | elseif has('win32') |
| 2251 | " dir is a shell builtin command, should fail without a shell. |
Bram Moolenaar | 36ec6f6 | 2019-11-05 22:38:47 +0100 | [diff] [blame] | 2252 | try |
| 2253 | term dir /b runtest.vim |
| 2254 | call WaitForAssert({-> assert_match('job failed\|cannot access .*: No such file or directory', term_getline(bufnr(), 1))}) |
| 2255 | catch /CreateProcess/ |
| 2256 | " ignore |
| 2257 | endtry |
Bram Moolenaar | 2d6d76f | 2019-11-04 23:18:35 +0100 | [diff] [blame] | 2258 | bwipe! |
| 2259 | |
| 2260 | term ++shell dir /b runtest.vim |
| 2261 | call WaitForAssert({-> assert_match('runtest.vim', term_getline(bufnr(), 1))}) |
| 2262 | bwipe! |
| 2263 | endif |
Bram Moolenaar | 197c6b7 | 2019-11-03 23:37:12 +0100 | [diff] [blame] | 2264 | endfunc |
| 2265 | |
Bram Moolenaar | d2842ea | 2019-09-26 23:08:54 +0200 | [diff] [blame] | 2266 | func Test_terminal_setapi_and_call() |
Bram Moolenaar | 2110927 | 2020-01-30 16:27:20 +0100 | [diff] [blame] | 2267 | CheckRunVimInTerminal |
Bram Moolenaar | d2842ea | 2019-09-26 23:08:54 +0200 | [diff] [blame] | 2268 | |
| 2269 | call WriteApiCall('Tapi_TryThis') |
| 2270 | call ch_logfile('Xlog', 'w') |
| 2271 | |
| 2272 | unlet! g:called_bufnum |
| 2273 | unlet! g:called_arg |
| 2274 | |
Bram Moolenaar | 2110927 | 2020-01-30 16:27:20 +0100 | [diff] [blame] | 2275 | let buf = RunVimInTerminal('-S Xscript', {'term_api': ''}) |
Bram Moolenaar | d2842ea | 2019-09-26 23:08:54 +0200 | [diff] [blame] | 2276 | call WaitForAssert({-> assert_match('Unpermitted function: Tapi_TryThis', string(readfile('Xlog')))}) |
| 2277 | call assert_false(exists('g:called_bufnum')) |
| 2278 | call assert_false(exists('g:called_arg')) |
| 2279 | |
Bram Moolenaar | 2110927 | 2020-01-30 16:27:20 +0100 | [diff] [blame] | 2280 | eval buf->term_setapi('Tapi_') |
Bram Moolenaar | d2842ea | 2019-09-26 23:08:54 +0200 | [diff] [blame] | 2281 | call term_sendkeys(buf, ":set notitle\<CR>") |
| 2282 | call term_sendkeys(buf, ":source Xscript\<CR>") |
| 2283 | call WaitFor({-> exists('g:called_bufnum')}) |
| 2284 | call assert_equal(buf, g:called_bufnum) |
| 2285 | call assert_equal(['hello', 123], g:called_arg) |
Bram Moolenaar | 2110927 | 2020-01-30 16:27:20 +0100 | [diff] [blame] | 2286 | |
| 2287 | call StopVimInTerminal(buf) |
| 2288 | |
| 2289 | call delete('Xscript') |
| 2290 | call ch_logfile('') |
| 2291 | call delete('Xlog') |
| 2292 | unlet! g:called_bufnum |
| 2293 | unlet! g:called_arg |
| 2294 | endfunc |
| 2295 | |
| 2296 | func Test_terminal_api_arg() |
| 2297 | CheckRunVimInTerminal |
| 2298 | |
| 2299 | call WriteApiCall('Tapi_TryThis') |
| 2300 | call ch_logfile('Xlog', 'w') |
| 2301 | |
| 2302 | unlet! g:called_bufnum |
| 2303 | unlet! g:called_arg |
| 2304 | |
| 2305 | execute 'term ++api= ' .. GetVimCommandCleanTerm() .. '-S Xscript' |
| 2306 | let buf = bufnr('%') |
| 2307 | call WaitForAssert({-> assert_match('Unpermitted function: Tapi_TryThis', string(readfile('Xlog')))}) |
| 2308 | call assert_false(exists('g:called_bufnum')) |
| 2309 | call assert_false(exists('g:called_arg')) |
| 2310 | |
| 2311 | call StopVimInTerminal(buf) |
| 2312 | |
| 2313 | call ch_logfile('Xlog', 'w') |
| 2314 | |
| 2315 | execute 'term ++api=Tapi_ ' .. GetVimCommandCleanTerm() .. '-S Xscript' |
| 2316 | let buf = bufnr('%') |
| 2317 | call WaitFor({-> exists('g:called_bufnum')}) |
| 2318 | call assert_equal(buf, g:called_bufnum) |
| 2319 | call assert_equal(['hello', 123], g:called_arg) |
| 2320 | |
Bram Moolenaar | d2842ea | 2019-09-26 23:08:54 +0200 | [diff] [blame] | 2321 | call StopVimInTerminal(buf) |
| 2322 | |
| 2323 | call delete('Xscript') |
| 2324 | call ch_logfile('') |
| 2325 | call delete('Xlog') |
| 2326 | unlet! g:called_bufnum |
| 2327 | unlet! g:called_arg |
| 2328 | endfunc |
Bram Moolenaar | 219c7d0 | 2020-02-01 21:57:29 +0100 | [diff] [blame] | 2329 | |
| 2330 | func Test_terminal_in_popup() |
| 2331 | CheckRunVimInTerminal |
| 2332 | |
| 2333 | let text =<< trim END |
| 2334 | some text |
| 2335 | to edit |
| 2336 | in a popup window |
| 2337 | END |
| 2338 | call writefile(text, 'Xtext') |
Bram Moolenaar | 3180fe6 | 2020-02-02 13:47:06 +0100 | [diff] [blame] | 2339 | let cmd = GetVimCommandCleanTerm() |
Bram Moolenaar | 219c7d0 | 2020-02-01 21:57:29 +0100 | [diff] [blame] | 2340 | let lines = [ |
Bram Moolenaar | 00f3b4e | 2020-02-14 14:32:22 +0100 | [diff] [blame] | 2341 | \ 'set t_u7=', |
Bram Moolenaar | 219c7d0 | 2020-02-01 21:57:29 +0100 | [diff] [blame] | 2342 | \ 'call setline(1, range(20))', |
| 2343 | \ 'hi PopTerm ctermbg=grey', |
| 2344 | \ 'func OpenTerm(setColor)', |
Bram Moolenaar | 353c351 | 2020-03-15 14:19:26 +0100 | [diff] [blame] | 2345 | \ " set noruler", |
Bram Moolenaar | 11ec807 | 2020-02-20 20:12:29 +0100 | [diff] [blame] | 2346 | \ " let s:buf = term_start('" .. cmd .. " Xtext', #{hidden: 1, term_finish: 'close'})", |
Bram Moolenaar | 57c3395 | 2020-02-29 16:09:16 +0100 | [diff] [blame] | 2347 | \ ' let g:winid = popup_create(s:buf, #{minwidth: 45, minheight: 7, border: [], drag: 1, resize: 1})', |
Bram Moolenaar | 219c7d0 | 2020-02-01 21:57:29 +0100 | [diff] [blame] | 2348 | \ ' if a:setColor', |
Bram Moolenaar | 57c3395 | 2020-02-29 16:09:16 +0100 | [diff] [blame] | 2349 | \ ' call win_execute(g:winid, "set wincolor=PopTerm")', |
Bram Moolenaar | 219c7d0 | 2020-02-01 21:57:29 +0100 | [diff] [blame] | 2350 | \ ' endif', |
| 2351 | \ 'endfunc', |
Bram Moolenaar | 2e6638d | 2020-02-05 21:07:18 +0100 | [diff] [blame] | 2352 | \ 'func HidePopup()', |
Bram Moolenaar | 57c3395 | 2020-02-29 16:09:16 +0100 | [diff] [blame] | 2353 | \ ' call popup_hide(g:winid)', |
Bram Moolenaar | 2e6638d | 2020-02-05 21:07:18 +0100 | [diff] [blame] | 2354 | \ 'endfunc', |
Bram Moolenaar | 11ec807 | 2020-02-20 20:12:29 +0100 | [diff] [blame] | 2355 | \ 'func ClosePopup()', |
Bram Moolenaar | 57c3395 | 2020-02-29 16:09:16 +0100 | [diff] [blame] | 2356 | \ ' call popup_close(g:winid)', |
Bram Moolenaar | 11ec807 | 2020-02-20 20:12:29 +0100 | [diff] [blame] | 2357 | \ 'endfunc', |
| 2358 | \ 'func ReopenPopup()', |
| 2359 | \ ' call popup_create(s:buf, #{minwidth: 40, minheight: 6, border: []})', |
| 2360 | \ 'endfunc', |
Bram Moolenaar | 219c7d0 | 2020-02-01 21:57:29 +0100 | [diff] [blame] | 2361 | \ ] |
| 2362 | call writefile(lines, 'XtermPopup') |
| 2363 | let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15}) |
Bram Moolenaar | 353c351 | 2020-03-15 14:19:26 +0100 | [diff] [blame] | 2364 | call term_wait(buf, 200) |
Bram Moolenaar | 57c3395 | 2020-02-29 16:09:16 +0100 | [diff] [blame] | 2365 | call term_sendkeys(buf, ":call OpenTerm(0)\<CR>") |
Bram Moolenaar | 353c351 | 2020-03-15 14:19:26 +0100 | [diff] [blame] | 2366 | call term_wait(buf, 200) |
Bram Moolenaar | c2adc00 | 2020-02-14 17:05:18 +0100 | [diff] [blame] | 2367 | call term_sendkeys(buf, ":\<CR>") |
Bram Moolenaar | 353c351 | 2020-03-15 14:19:26 +0100 | [diff] [blame] | 2368 | call term_wait(buf, 200) |
Bram Moolenaar | 57c3395 | 2020-02-29 16:09:16 +0100 | [diff] [blame] | 2369 | call term_sendkeys(buf, "\<C-W>:echo getwinvar(g:winid, \"&buftype\") win_gettype(g:winid)\<CR>") |
Bram Moolenaar | 219c7d0 | 2020-02-01 21:57:29 +0100 | [diff] [blame] | 2370 | call VerifyScreenDump(buf, 'Test_terminal_popup_1', {}) |
| 2371 | |
| 2372 | call term_sendkeys(buf, ":q\<CR>") |
| 2373 | call VerifyScreenDump(buf, 'Test_terminal_popup_2', {}) |
| 2374 | |
| 2375 | call term_sendkeys(buf, ":call OpenTerm(1)\<CR>") |
Bram Moolenaar | 353c351 | 2020-03-15 14:19:26 +0100 | [diff] [blame] | 2376 | call term_wait(buf, 300) |
Bram Moolenaar | 219c7d0 | 2020-02-01 21:57:29 +0100 | [diff] [blame] | 2377 | call term_sendkeys(buf, ":set hlsearch\<CR>") |
| 2378 | call term_sendkeys(buf, "/edit\<CR>") |
| 2379 | call VerifyScreenDump(buf, 'Test_terminal_popup_3', {}) |
| 2380 | |
Bram Moolenaar | 1af5ce0 | 2020-02-06 11:54:35 +0100 | [diff] [blame] | 2381 | call term_sendkeys(buf, "\<C-W>:call HidePopup()\<CR>") |
| 2382 | call VerifyScreenDump(buf, 'Test_terminal_popup_4', {}) |
| 2383 | call term_sendkeys(buf, "\<CR>") |
Bram Moolenaar | 6702188 | 2020-02-07 22:20:53 +0100 | [diff] [blame] | 2384 | call term_wait(buf, 100) |
Bram Moolenaar | 2e6638d | 2020-02-05 21:07:18 +0100 | [diff] [blame] | 2385 | |
Bram Moolenaar | 11ec807 | 2020-02-20 20:12:29 +0100 | [diff] [blame] | 2386 | call term_sendkeys(buf, "\<C-W>:call ClosePopup()\<CR>") |
| 2387 | call VerifyScreenDump(buf, 'Test_terminal_popup_5', {}) |
| 2388 | |
| 2389 | call term_sendkeys(buf, "\<C-W>:call ReopenPopup()\<CR>") |
| 2390 | call VerifyScreenDump(buf, 'Test_terminal_popup_6', {}) |
Bram Moolenaar | 11ec807 | 2020-02-20 20:12:29 +0100 | [diff] [blame] | 2391 | |
Bram Moolenaar | e52e0c8 | 2020-02-28 22:20:10 +0100 | [diff] [blame] | 2392 | " Go to terminal-Normal mode and visually select text. |
| 2393 | call term_sendkeys(buf, "\<C-W>Ngg/in\<CR>vww") |
| 2394 | call VerifyScreenDump(buf, 'Test_terminal_popup_7', {}) |
| 2395 | |
| 2396 | " Back to job mode, redraws |
| 2397 | call term_sendkeys(buf, "A") |
| 2398 | call VerifyScreenDump(buf, 'Test_terminal_popup_8', {}) |
| 2399 | |
| 2400 | call term_wait(buf, 100) |
Bram Moolenaar | 219c7d0 | 2020-02-01 21:57:29 +0100 | [diff] [blame] | 2401 | call term_sendkeys(buf, ":q\<CR>") |
Bram Moolenaar | 353c351 | 2020-03-15 14:19:26 +0100 | [diff] [blame] | 2402 | call term_wait(buf, 200) " wait for terminal to vanish |
Bram Moolenaar | 219c7d0 | 2020-02-01 21:57:29 +0100 | [diff] [blame] | 2403 | |
| 2404 | call StopVimInTerminal(buf) |
Bram Moolenaar | 1939826 | 2020-03-14 15:28:08 +0100 | [diff] [blame] | 2405 | call delete('Xtext') |
| 2406 | call delete('XtermPopup') |
| 2407 | endfunc |
| 2408 | |
| 2409 | " Check a terminal in popup window uses the default mininum size. |
| 2410 | func Test_terminal_in_popup_min_size() |
| 2411 | CheckRunVimInTerminal |
| 2412 | |
| 2413 | let text =<< trim END |
| 2414 | another text |
| 2415 | to show |
| 2416 | in a popup window |
| 2417 | END |
| 2418 | call writefile(text, 'Xtext') |
| 2419 | let lines = [ |
| 2420 | \ 'set t_u7=', |
| 2421 | \ 'call setline(1, range(20))', |
| 2422 | \ 'hi PopTerm ctermbg=grey', |
| 2423 | \ 'func OpenTerm()', |
| 2424 | \ " let s:buf = term_start('cat Xtext', #{hidden: 1})", |
| 2425 | \ ' let g:winid = popup_create(s:buf, #{ border: []})', |
| 2426 | \ 'endfunc', |
| 2427 | \ ] |
| 2428 | call writefile(lines, 'XtermPopup') |
| 2429 | let buf = RunVimInTerminal('-S XtermPopup', #{rows: 15}) |
Bram Moolenaar | 353c351 | 2020-03-15 14:19:26 +0100 | [diff] [blame] | 2430 | call term_wait(buf, 200) |
| 2431 | call term_sendkeys(buf, ":set noruler\<CR>") |
Bram Moolenaar | 1939826 | 2020-03-14 15:28:08 +0100 | [diff] [blame] | 2432 | call term_sendkeys(buf, ":call OpenTerm()\<CR>") |
| 2433 | call term_wait(buf, 100) |
| 2434 | call term_sendkeys(buf, ":\<CR>") |
| 2435 | call VerifyScreenDump(buf, 'Test_terminal_popup_m1', {}) |
| 2436 | |
| 2437 | call term_wait(buf, 100) |
| 2438 | call term_sendkeys(buf, ":q\<CR>") |
| 2439 | call term_wait(buf, 100) " wait for terminal to vanish |
| 2440 | call StopVimInTerminal(buf) |
| 2441 | call delete('Xtext') |
Bram Moolenaar | 219c7d0 | 2020-02-01 21:57:29 +0100 | [diff] [blame] | 2442 | call delete('XtermPopup') |
| 2443 | endfunc |
Bram Moolenaar | 7ba3b91 | 2020-02-10 20:34:04 +0100 | [diff] [blame] | 2444 | |
Bram Moolenaar | 80ae880 | 2020-02-28 19:11:18 +0100 | [diff] [blame] | 2445 | func Test_double_popup_terminal() |
| 2446 | let buf1 = term_start(&shell, #{hidden: 1}) |
| 2447 | let win1 = popup_create(buf1, {}) |
| 2448 | let buf2 = term_start(&shell, #{hidden: 1}) |
| 2449 | let win2 = popup_create(buf2, {}) |
| 2450 | call popup_close(win1) |
| 2451 | call popup_close(win2) |
| 2452 | exe buf1 .. 'bwipe!' |
| 2453 | exe buf2 .. 'bwipe!' |
| 2454 | endfunc |
| 2455 | |
Bram Moolenaar | 7ba3b91 | 2020-02-10 20:34:04 +0100 | [diff] [blame] | 2456 | func Test_issue_5607() |
| 2457 | let wincount = winnr('$') |
| 2458 | exe 'terminal' &shell &shellcmdflag 'exit' |
| 2459 | let job = term_getjob(bufnr()) |
| 2460 | call WaitForAssert({-> assert_equal("dead", job_status(job))}) |
| 2461 | |
| 2462 | let old_wincolor = &wincolor |
| 2463 | try |
| 2464 | set wincolor= |
| 2465 | finally |
| 2466 | let &wincolor = old_wincolor |
| 2467 | bw! |
| 2468 | endtry |
| 2469 | endfunc |
Bram Moolenaar | e010c72 | 2020-02-24 21:37:54 +0100 | [diff] [blame] | 2470 | |
| 2471 | func Test_hidden_terminal() |
| 2472 | let buf = term_start(&shell, #{hidden: 1}) |
| 2473 | call assert_equal('', bufname('^$')) |
| 2474 | call StopShellInTerminal(buf) |
| 2475 | endfunc |
Bram Moolenaar | cee5220 | 2020-03-11 14:19:58 +0100 | [diff] [blame] | 2476 | |
| 2477 | func Test_term_nasty_callback() |
| 2478 | func OpenTerms() |
| 2479 | set hidden |
| 2480 | let g:buf0 = term_start('sh', #{hidden: 1}) |
| 2481 | call popup_create(g:buf0, {}) |
| 2482 | let g:buf1 = term_start('sh', #{hidden: 1, term_finish: 'close'}) |
| 2483 | call popup_create(g:buf1, {}) |
| 2484 | let g:buf2 = term_start(['sh', '-c'], #{curwin: 1, exit_cb: function('TermExit')}) |
| 2485 | sleep 100m |
| 2486 | call popup_close(win_getid()) |
| 2487 | endfunc |
| 2488 | func TermExit(...) |
| 2489 | call term_sendkeys(bufnr('#'), "exit\<CR>") |
| 2490 | call popup_close(win_getid()) |
| 2491 | endfu |
| 2492 | call OpenTerms() |
| 2493 | |
| 2494 | call term_sendkeys(g:buf0, "exit\<CR>") |
Bram Moolenaar | fa5d8a1 | 2020-03-13 14:55:23 +0100 | [diff] [blame] | 2495 | sleep 100m |
Bram Moolenaar | cee5220 | 2020-03-11 14:19:58 +0100 | [diff] [blame] | 2496 | exe g:buf0 .. 'bwipe' |
| 2497 | set hidden& |
| 2498 | endfunc |
| 2499 | |