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