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