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