Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 1 | " Tests for the terminal window. |
| 2 | |
Bram Moolenaar | ea5d6fa | 2017-08-18 21:07:11 +0200 | [diff] [blame] | 3 | if !has('terminal') |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 4 | finish |
| 5 | endif |
| 6 | |
| 7 | source shared.vim |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 8 | source screendump.vim |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 9 | |
Bram Moolenaar | b81bc77 | 2017-08-11 22:45:01 +0200 | [diff] [blame] | 10 | let s:python = PythonProg() |
| 11 | |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 12 | " Open a terminal with a shell, assign the job to g:job and return the buffer |
| 13 | " number. |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 14 | func Run_shell_in_terminal(options) |
Bram Moolenaar | ba6febd | 2017-10-30 21:56:23 +0100 | [diff] [blame] | 15 | if has('win32') |
| 16 | let buf = term_start([&shell,'/k'], a:options) |
| 17 | else |
| 18 | let buf = term_start(&shell, a:options) |
| 19 | endif |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 20 | |
| 21 | let termlist = term_list() |
| 22 | call assert_equal(1, len(termlist)) |
| 23 | call assert_equal(buf, termlist[0]) |
| 24 | |
| 25 | let g:job = term_getjob(buf) |
| 26 | call assert_equal(v:t_job, type(g:job)) |
| 27 | |
Bram Moolenaar | 35422f4 | 2017-08-05 16:33:56 +0200 | [diff] [blame] | 28 | let string = string({'job': term_getjob(buf)}) |
| 29 | call assert_match("{'job': 'process \\d\\+ run'}", string) |
| 30 | |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 31 | return buf |
| 32 | endfunc |
| 33 | |
Bram Moolenaar | 20e6cd0 | 2017-08-01 20:25:22 +0200 | [diff] [blame] | 34 | func Test_terminal_basic() |
Bram Moolenaar | 606cb8b | 2018-05-03 20:40:20 +0200 | [diff] [blame] | 35 | au TerminalOpen * let b:done = 'yes' |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 36 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | b00fdf6 | 2017-09-21 22:16:21 +0200 | [diff] [blame] | 37 | |
Bram Moolenaar | 7c9aec4 | 2017-08-03 13:51:25 +0200 | [diff] [blame] | 38 | if has("unix") |
Bram Moolenaar | 2dc9d26 | 2017-09-08 14:39:30 +0200 | [diff] [blame] | 39 | call assert_match('^/dev/', job_info(g:job).tty_out) |
| 40 | call assert_match('^/dev/', term_gettty('')) |
Bram Moolenaar | 7c9aec4 | 2017-08-03 13:51:25 +0200 | [diff] [blame] | 41 | else |
Bram Moolenaar | 2dc9d26 | 2017-09-08 14:39:30 +0200 | [diff] [blame] | 42 | call assert_match('^\\\\.\\pipe\\', job_info(g:job).tty_out) |
| 43 | call assert_match('^\\\\.\\pipe\\', term_gettty('')) |
Bram Moolenaar | 7c9aec4 | 2017-08-03 13:51:25 +0200 | [diff] [blame] | 44 | endif |
Bram Moolenaar | 2bb7b6b | 2017-08-13 20:58:33 +0200 | [diff] [blame] | 45 | call assert_equal('t', mode()) |
Bram Moolenaar | b00fdf6 | 2017-09-21 22:16:21 +0200 | [diff] [blame] | 46 | call assert_equal('yes', b:done) |
Bram Moolenaar | 2bb7b6b | 2017-08-13 20:58:33 +0200 | [diff] [blame] | 47 | call assert_match('%aR[^\n]*running]', execute('ls')) |
Bram Moolenaar | 0751f51 | 2018-03-29 16:37:16 +0200 | [diff] [blame] | 48 | call assert_match('%aR[^\n]*running]', execute('ls R')) |
| 49 | call assert_notmatch('%[^\n]*running]', execute('ls F')) |
| 50 | call assert_notmatch('%[^\n]*running]', execute('ls ?')) |
Bram Moolenaar | 2bb7b6b | 2017-08-13 20:58:33 +0200 | [diff] [blame] | 51 | |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 52 | call Stop_shell_in_terminal(buf) |
| 53 | call term_wait(buf) |
Bram Moolenaar | 2bb7b6b | 2017-08-13 20:58:33 +0200 | [diff] [blame] | 54 | call assert_equal('n', mode()) |
| 55 | call assert_match('%aF[^\n]*finished]', execute('ls')) |
Bram Moolenaar | 0751f51 | 2018-03-29 16:37:16 +0200 | [diff] [blame] | 56 | call assert_match('%aF[^\n]*finished]', execute('ls F')) |
| 57 | call assert_notmatch('%[^\n]*finished]', execute('ls R')) |
| 58 | call assert_notmatch('%[^\n]*finished]', execute('ls ?')) |
Bram Moolenaar | 20e6cd0 | 2017-08-01 20:25:22 +0200 | [diff] [blame] | 59 | |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 60 | " closing window wipes out the terminal buffer a with finished job |
| 61 | close |
| 62 | call assert_equal("", bufname(buf)) |
| 63 | |
Bram Moolenaar | 606cb8b | 2018-05-03 20:40:20 +0200 | [diff] [blame] | 64 | au! TerminalOpen |
Bram Moolenaar | 20e6cd0 | 2017-08-01 20:25:22 +0200 | [diff] [blame] | 65 | unlet g:job |
| 66 | endfunc |
| 67 | |
| 68 | func Test_terminal_make_change() |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 69 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 70 | call Stop_shell_in_terminal(buf) |
Bram Moolenaar | 20e6cd0 | 2017-08-01 20:25:22 +0200 | [diff] [blame] | 71 | call term_wait(buf) |
| 72 | |
| 73 | setlocal modifiable |
| 74 | exe "normal Axxx\<Esc>" |
| 75 | call assert_fails(buf . 'bwipe', 'E517') |
| 76 | undo |
| 77 | |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 78 | exe buf . 'bwipe' |
| 79 | unlet g:job |
| 80 | endfunc |
| 81 | |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 82 | func Test_terminal_wipe_buffer() |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 83 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | eb44a68 | 2017-08-03 22:44:55 +0200 | [diff] [blame] | 84 | call assert_fails(buf . 'bwipe', 'E517') |
| 85 | exe buf . 'bwipe!' |
Bram Moolenaar | 50182fa | 2018-04-28 21:34:40 +0200 | [diff] [blame] | 86 | call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 87 | call assert_equal("", bufname(buf)) |
| 88 | |
| 89 | unlet g:job |
| 90 | endfunc |
| 91 | |
Bram Moolenaar | 8adb0d0 | 2017-09-17 19:08:02 +0200 | [diff] [blame] | 92 | func Test_terminal_split_quit() |
| 93 | let buf = Run_shell_in_terminal({}) |
| 94 | call term_wait(buf) |
| 95 | split |
| 96 | quit! |
| 97 | call term_wait(buf) |
| 98 | sleep 50m |
| 99 | call assert_equal('run', job_status(g:job)) |
| 100 | |
| 101 | quit! |
Bram Moolenaar | 50182fa | 2018-04-28 21:34:40 +0200 | [diff] [blame] | 102 | call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) |
Bram Moolenaar | 8adb0d0 | 2017-09-17 19:08:02 +0200 | [diff] [blame] | 103 | |
| 104 | exe buf . 'bwipe' |
| 105 | unlet g:job |
| 106 | endfunc |
| 107 | |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 108 | func Test_terminal_hide_buffer() |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 109 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | 97a80e4 | 2017-08-30 13:31:49 +0200 | [diff] [blame] | 110 | setlocal bufhidden=hide |
Bram Moolenaar | 94053a5 | 2017-08-01 21:44:33 +0200 | [diff] [blame] | 111 | quit |
| 112 | for nr in range(1, winnr('$')) |
| 113 | call assert_notequal(winbufnr(nr), buf) |
| 114 | endfor |
| 115 | call assert_true(bufloaded(buf)) |
| 116 | call assert_true(buflisted(buf)) |
| 117 | |
| 118 | exe 'split ' . buf . 'buf' |
| 119 | call Stop_shell_in_terminal(buf) |
| 120 | exe buf . 'bwipe' |
| 121 | |
| 122 | unlet g:job |
| 123 | endfunc |
| 124 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 125 | func s:Nasty_exit_cb(job, st) |
Bram Moolenaar | 3c3a80d | 2017-08-03 17:06:45 +0200 | [diff] [blame] | 126 | exe g:buf . 'bwipe!' |
| 127 | let g:buf = 0 |
| 128 | endfunc |
| 129 | |
Bram Moolenaar | 9d18961 | 2017-09-09 18:11:00 +0200 | [diff] [blame] | 130 | func Get_cat_123_cmd() |
| 131 | if has('win32') |
| 132 | return 'cmd /c "cls && color 2 && echo 123"' |
| 133 | else |
| 134 | call writefile(["\<Esc>[32m123"], 'Xtext') |
| 135 | return "cat Xtext" |
| 136 | endif |
| 137 | endfunc |
| 138 | |
Bram Moolenaar | 3c3a80d | 2017-08-03 17:06:45 +0200 | [diff] [blame] | 139 | func Test_terminal_nasty_cb() |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 140 | let cmd = Get_cat_123_cmd() |
Bram Moolenaar | 3c3a80d | 2017-08-03 17:06:45 +0200 | [diff] [blame] | 141 | let g:buf = term_start(cmd, {'exit_cb': function('s:Nasty_exit_cb')}) |
| 142 | let g:job = term_getjob(g:buf) |
| 143 | |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 144 | call WaitForAssert({-> assert_equal("dead", job_status(g:job))}) |
| 145 | call WaitForAssert({-> assert_equal(0, g:buf)}) |
Bram Moolenaar | 3c3a80d | 2017-08-03 17:06:45 +0200 | [diff] [blame] | 146 | unlet g:buf |
| 147 | unlet g:job |
| 148 | call delete('Xtext') |
| 149 | endfunc |
| 150 | |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 151 | func Check_123(buf) |
Bram Moolenaar | 5c838a3 | 2017-08-02 22:10:34 +0200 | [diff] [blame] | 152 | let l = term_scrape(a:buf, 0) |
| 153 | call assert_true(len(l) == 0) |
| 154 | let l = term_scrape(a:buf, 999) |
| 155 | call assert_true(len(l) == 0) |
Bram Moolenaar | 9c84484 | 2017-08-01 18:41:21 +0200 | [diff] [blame] | 156 | let l = term_scrape(a:buf, 1) |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 157 | call assert_true(len(l) > 0) |
| 158 | call assert_equal('1', l[0].chars) |
| 159 | call assert_equal('2', l[1].chars) |
| 160 | call assert_equal('3', l[2].chars) |
| 161 | call assert_equal('#00e000', l[0].fg) |
Bram Moolenaar | 81df635 | 2018-12-22 18:25:30 +0100 | [diff] [blame] | 162 | if has('win32') |
| 163 | " On Windows 'background' always defaults to dark, even though the terminal |
| 164 | " may use a light background. Therefore accept both white and black. |
| 165 | call assert_match('#ffffff\|#000000', l[0].bg) |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 166 | else |
Bram Moolenaar | 81df635 | 2018-12-22 18:25:30 +0100 | [diff] [blame] | 167 | if &background == 'light' |
| 168 | call assert_equal('#ffffff', l[0].bg) |
| 169 | else |
| 170 | call assert_equal('#000000', l[0].bg) |
| 171 | endif |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 172 | endif |
| 173 | |
Bram Moolenaar | 5c838a3 | 2017-08-02 22:10:34 +0200 | [diff] [blame] | 174 | let l = term_getline(a:buf, -1) |
| 175 | call assert_equal('', l) |
| 176 | let l = term_getline(a:buf, 0) |
| 177 | call assert_equal('', l) |
| 178 | let l = term_getline(a:buf, 999) |
| 179 | call assert_equal('', l) |
Bram Moolenaar | 9c84484 | 2017-08-01 18:41:21 +0200 | [diff] [blame] | 180 | let l = term_getline(a:buf, 1) |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 181 | call assert_equal('123', l) |
| 182 | endfunc |
| 183 | |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 184 | func Test_terminal_scrape_123() |
| 185 | let cmd = Get_cat_123_cmd() |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 186 | let buf = term_start(cmd) |
| 187 | |
| 188 | let termlist = term_list() |
| 189 | call assert_equal(1, len(termlist)) |
| 190 | call assert_equal(buf, termlist[0]) |
| 191 | |
Bram Moolenaar | f144a3f | 2017-07-30 18:02:12 +0200 | [diff] [blame] | 192 | " Nothing happens with invalid buffer number |
| 193 | call term_wait(1234) |
| 194 | |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 195 | call term_wait(buf) |
Bram Moolenaar | 1783337 | 2017-09-04 22:23:19 +0200 | [diff] [blame] | 196 | " 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] | 197 | " "cls" to happen, after that we have one line with three characters. |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 198 | call WaitForAssert({-> assert_equal(3, len(term_scrape(buf, 1)))}) |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 199 | call Check_123(buf) |
| 200 | |
| 201 | " Must still work after the job ended. |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 202 | let job = term_getjob(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 203 | call WaitForAssert({-> assert_equal("dead", job_status(job))}) |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 204 | call term_wait(buf) |
| 205 | call Check_123(buf) |
| 206 | |
| 207 | exe buf . 'bwipe' |
Bram Moolenaar | f144a3f | 2017-07-30 18:02:12 +0200 | [diff] [blame] | 208 | call delete('Xtext') |
Bram Moolenaar | c6df10e | 2017-07-29 20:15:08 +0200 | [diff] [blame] | 209 | endfunc |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 210 | |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 211 | func Test_terminal_scrape_multibyte() |
| 212 | if !has('multi_byte') |
| 213 | return |
| 214 | endif |
| 215 | call writefile(["léttまrs"], 'Xtext') |
| 216 | if has('win32') |
Bram Moolenaar | 3678393 | 2017-08-14 23:07:30 +0200 | [diff] [blame] | 217 | " Run cmd with UTF-8 codepage to make the type command print the expected |
| 218 | " multibyte characters. |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 219 | let buf = term_start("cmd /K chcp 65001") |
| 220 | call term_sendkeys(buf, "type Xtext\<CR>") |
| 221 | call term_sendkeys(buf, "exit\<CR>") |
| 222 | let line = 4 |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 223 | else |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 224 | let buf = term_start("cat Xtext") |
| 225 | let line = 1 |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 226 | endif |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 227 | |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 228 | call WaitFor({-> len(term_scrape(buf, line)) >= 7 && term_scrape(buf, line)[0].chars == "l"}) |
| 229 | let l = term_scrape(buf, line) |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 230 | call assert_true(len(l) >= 7) |
| 231 | call assert_equal('l', l[0].chars) |
| 232 | call assert_equal('é', l[1].chars) |
| 233 | call assert_equal(1, l[1].width) |
| 234 | call assert_equal('t', l[2].chars) |
| 235 | call assert_equal('t', l[3].chars) |
| 236 | call assert_equal('ま', l[4].chars) |
| 237 | call assert_equal(2, l[4].width) |
| 238 | call assert_equal('r', l[5].chars) |
| 239 | call assert_equal('s', l[6].chars) |
| 240 | |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 241 | let job = term_getjob(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 242 | call WaitForAssert({-> assert_equal("dead", job_status(job))}) |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 243 | call term_wait(buf) |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 244 | |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 245 | exe buf . 'bwipe' |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 246 | call delete('Xtext') |
| 247 | endfunc |
| 248 | |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 249 | func Test_terminal_scroll() |
| 250 | call writefile(range(1, 200), 'Xtext') |
| 251 | if has('win32') |
| 252 | let cmd = 'cmd /c "type Xtext"' |
| 253 | else |
| 254 | let cmd = "cat Xtext" |
| 255 | endif |
| 256 | let buf = term_start(cmd) |
| 257 | |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 258 | let job = term_getjob(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 259 | call WaitForAssert({-> assert_equal("dead", job_status(job))}) |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 260 | call term_wait(buf) |
| 261 | if has('win32') |
| 262 | " TODO: this should not be needed |
| 263 | sleep 100m |
| 264 | endif |
| 265 | |
Bram Moolenaar | 82b9ca0 | 2017-08-08 23:06:46 +0200 | [diff] [blame] | 266 | let scrolled = term_getscrolled(buf) |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 267 | call assert_equal('1', getline(1)) |
Bram Moolenaar | 82b9ca0 | 2017-08-08 23:06:46 +0200 | [diff] [blame] | 268 | call assert_equal('1', term_getline(buf, 1 - scrolled)) |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 269 | call assert_equal('49', getline(49)) |
Bram Moolenaar | 82b9ca0 | 2017-08-08 23:06:46 +0200 | [diff] [blame] | 270 | call assert_equal('49', term_getline(buf, 49 - scrolled)) |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 271 | call assert_equal('200', getline(200)) |
Bram Moolenaar | 82b9ca0 | 2017-08-08 23:06:46 +0200 | [diff] [blame] | 272 | call assert_equal('200', term_getline(buf, 200 - scrolled)) |
Bram Moolenaar | f8d57a5 | 2017-08-07 20:38:42 +0200 | [diff] [blame] | 273 | |
| 274 | exe buf . 'bwipe' |
| 275 | call delete('Xtext') |
| 276 | endfunc |
| 277 | |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 278 | func Test_terminal_scrollback() |
Bram Moolenaar | 33c5e9f | 2018-05-26 18:58:51 +0200 | [diff] [blame] | 279 | let buf = Run_shell_in_terminal({'term_rows': 15}) |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 280 | set termwinscroll=100 |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 281 | call writefile(range(150), 'Xtext') |
| 282 | if has('win32') |
| 283 | call term_sendkeys(buf, "type Xtext\<CR>") |
| 284 | else |
| 285 | call term_sendkeys(buf, "cat Xtext\<CR>") |
| 286 | endif |
| 287 | let rows = term_getsize(buf)[0] |
Bram Moolenaar | 6c67219 | 2018-04-15 13:28:42 +0200 | [diff] [blame] | 288 | " 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] | 289 | 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] | 290 | let lines = line('$') |
Bram Moolenaar | ac3e830 | 2018-04-15 13:10:44 +0200 | [diff] [blame] | 291 | call assert_inrange(91, 100, lines) |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 292 | |
| 293 | call Stop_shell_in_terminal(buf) |
| 294 | call term_wait(buf) |
| 295 | exe buf . 'bwipe' |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 296 | set termwinscroll& |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 297 | endfunc |
| 298 | |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 299 | func Test_terminal_size() |
Bram Moolenaar | 33a43be | 2017-08-06 21:36:22 +0200 | [diff] [blame] | 300 | let cmd = Get_cat_123_cmd() |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 301 | |
Bram Moolenaar | b241208 | 2017-08-20 18:09:14 +0200 | [diff] [blame] | 302 | exe 'terminal ++rows=5 ' . cmd |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 303 | let size = term_getsize('') |
| 304 | bwipe! |
| 305 | call assert_equal(5, size[0]) |
| 306 | |
Bram Moolenaar | 08d384f | 2017-08-11 21:51:23 +0200 | [diff] [blame] | 307 | call term_start(cmd, {'term_rows': 6}) |
| 308 | let size = term_getsize('') |
| 309 | bwipe! |
| 310 | call assert_equal(6, size[0]) |
| 311 | |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 312 | vsplit |
Bram Moolenaar | b241208 | 2017-08-20 18:09:14 +0200 | [diff] [blame] | 313 | exe 'terminal ++rows=5 ++cols=33 ' . cmd |
Bram Moolenaar | a42d363 | 2018-04-14 17:05:38 +0200 | [diff] [blame] | 314 | call assert_equal([5, 33], term_getsize('')) |
| 315 | |
| 316 | call term_setsize('', 6, 0) |
| 317 | call assert_equal([6, 33], term_getsize('')) |
| 318 | |
| 319 | call term_setsize('', 0, 35) |
| 320 | call assert_equal([6, 35], term_getsize('')) |
| 321 | |
| 322 | call term_setsize('', 7, 30) |
| 323 | call assert_equal([7, 30], term_getsize('')) |
| 324 | |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 325 | bwipe! |
Bram Moolenaar | 6e72cd0 | 2018-04-14 21:31:35 +0200 | [diff] [blame] | 326 | call assert_fails("call term_setsize('', 7, 30)", "E955:") |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 327 | |
Bram Moolenaar | 08d384f | 2017-08-11 21:51:23 +0200 | [diff] [blame] | 328 | call term_start(cmd, {'term_rows': 6, 'term_cols': 36}) |
| 329 | let size = term_getsize('') |
| 330 | bwipe! |
| 331 | call assert_equal([6, 36], size) |
| 332 | |
Bram Moolenaar | b241208 | 2017-08-20 18:09:14 +0200 | [diff] [blame] | 333 | exe 'vertical terminal ++cols=20 ' . cmd |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 334 | let size = term_getsize('') |
| 335 | bwipe! |
| 336 | call assert_equal(20, size[1]) |
| 337 | |
Bram Moolenaar | 08d384f | 2017-08-11 21:51:23 +0200 | [diff] [blame] | 338 | call term_start(cmd, {'vertical': 1, 'term_cols': 26}) |
| 339 | let size = term_getsize('') |
| 340 | bwipe! |
| 341 | call assert_equal(26, size[1]) |
| 342 | |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 343 | split |
Bram Moolenaar | b241208 | 2017-08-20 18:09:14 +0200 | [diff] [blame] | 344 | exe 'vertical terminal ++rows=6 ++cols=20 ' . cmd |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 345 | let size = term_getsize('') |
| 346 | bwipe! |
| 347 | call assert_equal([6, 20], size) |
Bram Moolenaar | 08d384f | 2017-08-11 21:51:23 +0200 | [diff] [blame] | 348 | |
| 349 | call term_start(cmd, {'vertical': 1, 'term_rows': 7, 'term_cols': 27}) |
| 350 | let size = term_getsize('') |
| 351 | bwipe! |
| 352 | call assert_equal([7, 27], size) |
Bram Moolenaar | 9d654a8 | 2017-09-03 19:52:17 +0200 | [diff] [blame] | 353 | |
| 354 | call delete('Xtext') |
Bram Moolenaar | da43b61 | 2017-08-11 22:27:50 +0200 | [diff] [blame] | 355 | endfunc |
| 356 | |
| 357 | func Test_terminal_curwin() |
| 358 | let cmd = Get_cat_123_cmd() |
| 359 | call assert_equal(1, winnr('$')) |
| 360 | |
| 361 | split dummy |
| 362 | exe 'terminal ++curwin ' . cmd |
| 363 | call assert_equal(2, winnr('$')) |
| 364 | bwipe! |
| 365 | |
| 366 | split dummy |
| 367 | call term_start(cmd, {'curwin': 1}) |
| 368 | call assert_equal(2, winnr('$')) |
| 369 | bwipe! |
| 370 | |
| 371 | split dummy |
| 372 | call setline(1, 'change') |
| 373 | call assert_fails('terminal ++curwin ' . cmd, 'E37:') |
| 374 | call assert_equal(2, winnr('$')) |
| 375 | exe 'terminal! ++curwin ' . cmd |
| 376 | call assert_equal(2, winnr('$')) |
| 377 | bwipe! |
| 378 | |
| 379 | split dummy |
| 380 | call setline(1, 'change') |
| 381 | call assert_fails("call term_start(cmd, {'curwin': 1})", 'E37:') |
| 382 | call assert_equal(2, winnr('$')) |
| 383 | bwipe! |
| 384 | |
| 385 | split dummy |
| 386 | bwipe! |
Bram Moolenaar | 9d654a8 | 2017-09-03 19:52:17 +0200 | [diff] [blame] | 387 | call delete('Xtext') |
Bram Moolenaar | cfcc022 | 2017-08-05 17:13:48 +0200 | [diff] [blame] | 388 | endfunc |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 389 | |
Bram Moolenaar | ff54679 | 2017-11-21 14:47:57 +0100 | [diff] [blame] | 390 | func s:get_sleep_cmd() |
Bram Moolenaar | b81bc77 | 2017-08-11 22:45:01 +0200 | [diff] [blame] | 391 | if s:python != '' |
| 392 | let cmd = s:python . " test_short_sleep.py" |
Bram Moolenaar | c8523e2 | 2018-06-03 18:22:02 +0200 | [diff] [blame] | 393 | " 500 was not enough for Travis |
| 394 | let waittime = 900 |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 395 | else |
Bram Moolenaar | b81bc77 | 2017-08-11 22:45:01 +0200 | [diff] [blame] | 396 | echo 'This will take five seconds...' |
| 397 | let waittime = 2000 |
| 398 | if has('win32') |
| 399 | let cmd = $windir . '\system32\timeout.exe 1' |
| 400 | else |
| 401 | let cmd = 'sleep 1' |
| 402 | endif |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 403 | endif |
Bram Moolenaar | ff54679 | 2017-11-21 14:47:57 +0100 | [diff] [blame] | 404 | return [cmd, waittime] |
| 405 | endfunc |
| 406 | |
| 407 | func Test_terminal_finish_open_close() |
| 408 | call assert_equal(1, winnr('$')) |
| 409 | |
| 410 | let [cmd, waittime] = s:get_sleep_cmd() |
Bram Moolenaar | b81bc77 | 2017-08-11 22:45:01 +0200 | [diff] [blame] | 411 | |
Bram Moolenaar | 1dd9833 | 2018-03-16 22:54:53 +0100 | [diff] [blame] | 412 | " shell terminal closes automatically |
| 413 | terminal |
| 414 | let buf = bufnr('%') |
| 415 | call assert_equal(2, winnr('$')) |
| 416 | " Wait for the shell to display a prompt |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 417 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
Bram Moolenaar | 1dd9833 | 2018-03-16 22:54:53 +0100 | [diff] [blame] | 418 | call Stop_shell_in_terminal(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 419 | call WaitForAssert({-> assert_equal(1, winnr('$'))}, waittime) |
Bram Moolenaar | 1dd9833 | 2018-03-16 22:54:53 +0100 | [diff] [blame] | 420 | |
| 421 | " shell terminal that does not close automatically |
| 422 | terminal ++noclose |
| 423 | let buf = bufnr('%') |
| 424 | call assert_equal(2, winnr('$')) |
| 425 | " Wait for the shell to display a prompt |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 426 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
Bram Moolenaar | 1dd9833 | 2018-03-16 22:54:53 +0100 | [diff] [blame] | 427 | call Stop_shell_in_terminal(buf) |
| 428 | call assert_equal(2, winnr('$')) |
| 429 | quit |
| 430 | call assert_equal(1, winnr('$')) |
| 431 | |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 432 | exe 'terminal ++close ' . cmd |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 433 | call assert_equal(2, winnr('$')) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 434 | wincmd p |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 435 | call WaitForAssert({-> assert_equal(1, winnr('$'))}, waittime) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 436 | |
| 437 | call term_start(cmd, {'term_finish': 'close'}) |
| 438 | call assert_equal(2, winnr('$')) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 439 | wincmd p |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 440 | call WaitForAssert({-> assert_equal(1, winnr('$'))}, waittime) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 441 | call assert_equal(1, winnr('$')) |
| 442 | |
| 443 | exe 'terminal ++open ' . cmd |
Bram Moolenaar | 97a80e4 | 2017-08-30 13:31:49 +0200 | [diff] [blame] | 444 | close! |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 445 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 446 | bwipe |
| 447 | |
| 448 | call term_start(cmd, {'term_finish': 'open'}) |
Bram Moolenaar | 97a80e4 | 2017-08-30 13:31:49 +0200 | [diff] [blame] | 449 | close! |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 450 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | 8cad930 | 2017-08-12 14:32:32 +0200 | [diff] [blame] | 451 | bwipe |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 452 | |
Bram Moolenaar | 8cad930 | 2017-08-12 14:32:32 +0200 | [diff] [blame] | 453 | exe 'terminal ++hidden ++open ' . cmd |
| 454 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 455 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | 8cad930 | 2017-08-12 14:32:32 +0200 | [diff] [blame] | 456 | bwipe |
| 457 | |
| 458 | call term_start(cmd, {'term_finish': 'open', 'hidden': 1}) |
| 459 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 460 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 461 | bwipe |
Bram Moolenaar | 37c4583 | 2017-08-12 16:01:04 +0200 | [diff] [blame] | 462 | |
| 463 | call assert_fails("call term_start(cmd, {'term_opencmd': 'open'})", 'E475:') |
| 464 | call assert_fails("call term_start(cmd, {'term_opencmd': 'split %x'})", 'E475:') |
| 465 | call assert_fails("call term_start(cmd, {'term_opencmd': 'split %d and %s'})", 'E475:') |
| 466 | call assert_fails("call term_start(cmd, {'term_opencmd': 'split % and %d'})", 'E475:') |
| 467 | |
| 468 | call term_start(cmd, {'term_finish': 'open', 'term_opencmd': '4split | buffer %d'}) |
Bram Moolenaar | 97a80e4 | 2017-08-30 13:31:49 +0200 | [diff] [blame] | 469 | close! |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 470 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | 37c4583 | 2017-08-12 16:01:04 +0200 | [diff] [blame] | 471 | call assert_equal(4, winheight(0)) |
| 472 | bwipe |
Bram Moolenaar | dd693ce | 2017-08-10 23:15:19 +0200 | [diff] [blame] | 473 | endfunc |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 474 | |
| 475 | func Test_terminal_cwd() |
Bram Moolenaar | e9f6fd2 | 2017-09-10 14:25:49 +0200 | [diff] [blame] | 476 | if !executable('pwd') |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 477 | return |
| 478 | endif |
| 479 | call mkdir('Xdir') |
| 480 | let buf = term_start('pwd', {'cwd': 'Xdir'}) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 481 | call WaitForAssert({-> assert_equal('Xdir', fnamemodify(getline(1), ":t"))}) |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 482 | |
| 483 | exe buf . 'bwipe' |
| 484 | call delete('Xdir', 'rf') |
| 485 | endfunc |
| 486 | |
Bram Moolenaar | 839e81e | 2018-10-19 16:53:39 +0200 | [diff] [blame] | 487 | func Test_terminal_cwd_failure() |
| 488 | " Case 1: Provided directory is not actually a directory. Attempt to make |
| 489 | " the file executable as well. |
| 490 | call writefile([], 'Xfile') |
| 491 | call setfperm('Xfile', 'rwx------') |
| 492 | call assert_fails("call term_start(&shell, {'cwd': 'Xfile'})", 'E475:') |
| 493 | call delete('Xfile') |
| 494 | |
| 495 | " Case 2: Directory does not exist. |
| 496 | call assert_fails("call term_start(&shell, {'cwd': 'Xdir'})", 'E475:') |
| 497 | |
| 498 | " Case 3: Directory exists but is not accessible. |
Bram Moolenaar | 0b38f54 | 2018-11-03 21:47:16 +0100 | [diff] [blame] | 499 | " Skip this for root, it will be accessible anyway. |
| 500 | if $USER != 'root' |
| 501 | call mkdir('XdirNoAccess', '', '0600') |
| 502 | " return early if the directory permissions could not be set properly |
| 503 | if getfperm('XdirNoAccess')[2] == 'x' |
| 504 | call delete('XdirNoAccess', 'rf') |
| 505 | return |
| 506 | endif |
| 507 | call assert_fails("call term_start(&shell, {'cwd': 'XdirNoAccess'})", 'E475:') |
| 508 | call delete('XdirNoAccess', 'rf') |
Bram Moolenaar | 839e81e | 2018-10-19 16:53:39 +0200 | [diff] [blame] | 509 | endif |
Bram Moolenaar | 839e81e | 2018-10-19 16:53:39 +0200 | [diff] [blame] | 510 | endfunc |
| 511 | |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 512 | func Test_terminal_servername() |
| 513 | if !has('clientserver') |
| 514 | return |
| 515 | endif |
Bram Moolenaar | d7a137f | 2018-06-12 18:05:24 +0200 | [diff] [blame] | 516 | call s:test_environment("VIM_SERVERNAME", v:servername) |
| 517 | endfunc |
| 518 | |
| 519 | func Test_terminal_version() |
| 520 | call s:test_environment("VIM_TERMINAL", string(v:version)) |
| 521 | endfunc |
| 522 | |
| 523 | func s:test_environment(name, value) |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 524 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 525 | " Wait for the shell to display a prompt |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 526 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 527 | if has('win32') |
Bram Moolenaar | d7a137f | 2018-06-12 18:05:24 +0200 | [diff] [blame] | 528 | call term_sendkeys(buf, "echo %" . a:name . "%\r") |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 529 | else |
Bram Moolenaar | d7a137f | 2018-06-12 18:05:24 +0200 | [diff] [blame] | 530 | call term_sendkeys(buf, "echo $" . a:name . "\r") |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 531 | endif |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 532 | call term_wait(buf) |
| 533 | call Stop_shell_in_terminal(buf) |
Bram Moolenaar | d7a137f | 2018-06-12 18:05:24 +0200 | [diff] [blame] | 534 | call WaitForAssert({-> assert_equal(a:value, getline(2))}) |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 535 | |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 536 | exe buf . 'bwipe' |
| 537 | unlet buf |
Bram Moolenaar | 52dbb5e | 2017-11-21 18:11:27 +0100 | [diff] [blame] | 538 | endfunc |
| 539 | |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 540 | func Test_terminal_env() |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 541 | let buf = Run_shell_in_terminal({'env': {'TESTENV': 'correct'}}) |
Bram Moolenaar | 51c2368 | 2017-08-14 21:45:00 +0200 | [diff] [blame] | 542 | " Wait for the shell to display a prompt |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 543 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
Bram Moolenaar | ba6febd | 2017-10-30 21:56:23 +0100 | [diff] [blame] | 544 | if has('win32') |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 545 | call term_sendkeys(buf, "echo %TESTENV%\r") |
Bram Moolenaar | ba6febd | 2017-10-30 21:56:23 +0100 | [diff] [blame] | 546 | else |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 547 | call term_sendkeys(buf, "echo $TESTENV\r") |
Bram Moolenaar | ba6febd | 2017-10-30 21:56:23 +0100 | [diff] [blame] | 548 | endif |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 549 | call term_wait(buf) |
| 550 | call Stop_shell_in_terminal(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 551 | call WaitForAssert({-> assert_equal('correct', getline(2))}) |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 552 | |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 553 | exe buf . 'bwipe' |
Bram Moolenaar | 05aafed | 2017-08-11 19:12:11 +0200 | [diff] [blame] | 554 | endfunc |
Bram Moolenaar | 679653e | 2017-08-13 14:13:19 +0200 | [diff] [blame] | 555 | |
Bram Moolenaar | dcaa613 | 2017-08-13 17:13:09 +0200 | [diff] [blame] | 556 | func Test_terminal_list_args() |
| 557 | let buf = term_start([&shell, &shellcmdflag, 'echo "123"']) |
| 558 | call assert_fails(buf . 'bwipe', 'E517') |
| 559 | exe buf . 'bwipe!' |
| 560 | call assert_equal("", bufname(buf)) |
| 561 | endfunction |
Bram Moolenaar | 97bd5e6 | 2017-08-18 20:50:30 +0200 | [diff] [blame] | 562 | |
| 563 | func Test_terminal_noblock() |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 564 | let buf = term_start(&shell) |
Bram Moolenaar | d8d85bf | 2017-09-03 18:08:00 +0200 | [diff] [blame] | 565 | if has('mac') |
| 566 | " The shell or something else has a problem dealing with more than 1000 |
| 567 | " characters at the same time. |
| 568 | let len = 1000 |
| 569 | else |
| 570 | let len = 5000 |
| 571 | endif |
Bram Moolenaar | 97bd5e6 | 2017-08-18 20:50:30 +0200 | [diff] [blame] | 572 | |
| 573 | for c in ['a','b','c','d','e','f','g','h','i','j','k'] |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 574 | call term_sendkeys(buf, 'echo ' . repeat(c, len) . "\<cr>") |
Bram Moolenaar | 97bd5e6 | 2017-08-18 20:50:30 +0200 | [diff] [blame] | 575 | endfor |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 576 | call term_sendkeys(buf, "echo done\<cr>") |
Bram Moolenaar | eef0531 | 2017-08-20 20:21:23 +0200 | [diff] [blame] | 577 | |
| 578 | " On MS-Windows there is an extra empty line below "done". Find "done" in |
| 579 | " the last-but-one or the last-but-two line. |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 580 | let lnum = term_getsize(buf)[0] - 1 |
Bram Moolenaar | 2181014 | 2018-02-02 18:30:36 +0100 | [diff] [blame] | 581 | call WaitFor({-> term_getline(buf, lnum) =~ "done" || term_getline(buf, lnum - 1) =~ "done"}, 10000) |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 582 | let line = term_getline(buf, lnum) |
Bram Moolenaar | eef0531 | 2017-08-20 20:21:23 +0200 | [diff] [blame] | 583 | if line !~ 'done' |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 584 | let line = term_getline(buf, lnum - 1) |
Bram Moolenaar | eef0531 | 2017-08-20 20:21:23 +0200 | [diff] [blame] | 585 | endif |
| 586 | call assert_match('done', line) |
Bram Moolenaar | 97bd5e6 | 2017-08-18 20:50:30 +0200 | [diff] [blame] | 587 | |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 588 | let g:job = term_getjob(buf) |
| 589 | call Stop_shell_in_terminal(buf) |
| 590 | call term_wait(buf) |
Bram Moolenaar | d21f8b5 | 2017-08-19 15:40:01 +0200 | [diff] [blame] | 591 | unlet g:job |
Bram Moolenaar | 97bd5e6 | 2017-08-18 20:50:30 +0200 | [diff] [blame] | 592 | bwipe |
| 593 | endfunc |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 594 | |
| 595 | func Test_terminal_write_stdin() |
Bram Moolenaar | 3346cc4 | 2017-09-02 14:54:21 +0200 | [diff] [blame] | 596 | if !executable('wc') |
Bram Moolenaar | dada6d2 | 2017-09-02 17:18:35 +0200 | [diff] [blame] | 597 | throw 'skipped: wc command not available' |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 598 | endif |
Bram Moolenaar | 1580f75 | 2018-06-03 15:26:36 +0200 | [diff] [blame] | 599 | if has('win32') |
| 600 | " TODO: enable once writing to stdin works on MS-Windows |
| 601 | return |
| 602 | endif |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 603 | new |
| 604 | call setline(1, ['one', 'two', 'three']) |
| 605 | %term wc |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 606 | call WaitForAssert({-> assert_match('3', getline("$"))}) |
Bram Moolenaar | 3346cc4 | 2017-09-02 14:54:21 +0200 | [diff] [blame] | 607 | let nrs = split(getline('$')) |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 608 | call assert_equal(['3', '3', '14'], nrs) |
| 609 | bwipe |
| 610 | |
Bram Moolenaar | dada6d2 | 2017-09-02 17:18:35 +0200 | [diff] [blame] | 611 | new |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 612 | call setline(1, ['one', 'two', 'three', 'four']) |
| 613 | 2,3term wc |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 614 | call WaitForAssert({-> assert_match('2', getline("$"))}) |
Bram Moolenaar | 3346cc4 | 2017-09-02 14:54:21 +0200 | [diff] [blame] | 615 | let nrs = split(getline('$')) |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 616 | call assert_equal(['2', '2', '10'], nrs) |
| 617 | bwipe |
| 618 | |
Bram Moolenaar | dada6d2 | 2017-09-02 17:18:35 +0200 | [diff] [blame] | 619 | if executable('python') |
| 620 | new |
| 621 | call setline(1, ['print("hello")']) |
| 622 | 1term ++eof=exit() python |
| 623 | " MS-Windows echoes the input, Unix doesn't. |
| 624 | call WaitFor('getline("$") =~ "exit" || getline(1) =~ "hello"') |
| 625 | if getline(1) =~ 'hello' |
| 626 | call assert_equal('hello', getline(1)) |
| 627 | else |
| 628 | call assert_equal('hello', getline(line('$') - 1)) |
| 629 | endif |
| 630 | bwipe |
| 631 | |
| 632 | if has('win32') |
| 633 | new |
| 634 | call setline(1, ['print("hello")']) |
| 635 | 1term ++eof=<C-Z> python |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 636 | call WaitForAssert({-> assert_match('Z', getline("$"))}) |
Bram Moolenaar | dada6d2 | 2017-09-02 17:18:35 +0200 | [diff] [blame] | 637 | call assert_equal('hello', getline(line('$') - 1)) |
| 638 | bwipe |
| 639 | endif |
| 640 | endif |
| 641 | |
Bram Moolenaar | 37819ed | 2017-08-20 19:33:47 +0200 | [diff] [blame] | 642 | bwipe! |
| 643 | endfunc |
Bram Moolenaar | 13ebb03 | 2017-08-26 22:02:51 +0200 | [diff] [blame] | 644 | |
| 645 | func Test_terminal_no_cmd() |
Bram Moolenaar | e25bbc3 | 2019-01-19 18:20:45 +0100 | [diff] [blame] | 646 | " Does not work on Mac. |
Bram Moolenaar | d383c92 | 2019-01-19 15:27:08 +0100 | [diff] [blame] | 647 | " Todo: make this work on Win32 again |
Bram Moolenaar | e25bbc3 | 2019-01-19 18:20:45 +0100 | [diff] [blame] | 648 | if has('mac') || has('win32') |
Bram Moolenaar | 13ebb03 | 2017-08-26 22:02:51 +0200 | [diff] [blame] | 649 | return |
| 650 | endif |
| 651 | let buf = term_start('NONE', {}) |
| 652 | call assert_notequal(0, buf) |
| 653 | |
Bram Moolenaar | 2dc9d26 | 2017-09-08 14:39:30 +0200 | [diff] [blame] | 654 | let pty = job_info(term_getjob(buf))['tty_out'] |
Bram Moolenaar | 13ebb03 | 2017-08-26 22:02:51 +0200 | [diff] [blame] | 655 | call assert_notequal('', pty) |
Bram Moolenaar | 2dc9d26 | 2017-09-08 14:39:30 +0200 | [diff] [blame] | 656 | if has('win32') |
Bram Moolenaar | e738a1a | 2017-09-16 17:42:41 +0200 | [diff] [blame] | 657 | silent exe '!start cmd /c "echo look here > ' . pty . '"' |
Bram Moolenaar | 2dc9d26 | 2017-09-08 14:39:30 +0200 | [diff] [blame] | 658 | else |
| 659 | call system('echo "look here" > ' . pty) |
| 660 | endif |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 661 | call WaitForAssert({-> assert_match('look here', term_getline(buf, 1))}) |
Bram Moolenaar | 2dc9d26 | 2017-09-08 14:39:30 +0200 | [diff] [blame] | 662 | |
Bram Moolenaar | 13ebb03 | 2017-08-26 22:02:51 +0200 | [diff] [blame] | 663 | bwipe! |
| 664 | endfunc |
Bram Moolenaar | 9d654a8 | 2017-09-03 19:52:17 +0200 | [diff] [blame] | 665 | |
| 666 | func Test_terminal_special_chars() |
| 667 | " this file name only works on Unix |
| 668 | if !has('unix') |
| 669 | return |
| 670 | endif |
| 671 | call mkdir('Xdir with spaces') |
| 672 | call writefile(['x'], 'Xdir with spaces/quoted"file') |
| 673 | term ls Xdir\ with\ spaces/quoted\"file |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 674 | call WaitForAssert({-> assert_match('quoted"file', term_getline('', 1))}) |
Bram Moolenaar | 9d654a8 | 2017-09-03 19:52:17 +0200 | [diff] [blame] | 675 | call term_wait('') |
| 676 | |
| 677 | call delete('Xdir with spaces', 'rf') |
| 678 | bwipe |
| 679 | endfunc |
Bram Moolenaar | e88fc7a | 2017-09-03 20:59:40 +0200 | [diff] [blame] | 680 | |
| 681 | func Test_terminal_wrong_options() |
| 682 | call assert_fails('call term_start(&shell, { |
| 683 | \ "in_io": "file", |
| 684 | \ "in_name": "xxx", |
| 685 | \ "out_io": "file", |
| 686 | \ "out_name": "xxx", |
| 687 | \ "err_io": "file", |
| 688 | \ "err_name": "xxx" |
| 689 | \ })', 'E474:') |
| 690 | call assert_fails('call term_start(&shell, { |
| 691 | \ "out_buf": bufnr("%") |
| 692 | \ })', 'E474:') |
| 693 | call assert_fails('call term_start(&shell, { |
| 694 | \ "err_buf": bufnr("%") |
| 695 | \ })', 'E474:') |
| 696 | endfunc |
| 697 | |
| 698 | func Test_terminal_redir_file() |
Bram Moolenaar | f25329c | 2018-05-06 21:49:32 +0200 | [diff] [blame] | 699 | let cmd = Get_cat_123_cmd() |
| 700 | let buf = term_start(cmd, {'out_io': 'file', 'out_name': 'Xfile'}) |
| 701 | call term_wait(buf) |
| 702 | call WaitForAssert({-> assert_notequal(0, len(readfile("Xfile")))}) |
| 703 | call assert_match('123', readfile('Xfile')[0]) |
| 704 | let g:job = term_getjob(buf) |
| 705 | call WaitForAssert({-> assert_equal("dead", job_status(g:job))}) |
| 706 | call delete('Xfile') |
| 707 | bwipe |
Bram Moolenaar | e88fc7a | 2017-09-03 20:59:40 +0200 | [diff] [blame] | 708 | |
| 709 | if has('unix') |
Bram Moolenaar | e88fc7a | 2017-09-03 20:59:40 +0200 | [diff] [blame] | 710 | call writefile(['one line'], 'Xfile') |
| 711 | let buf = term_start('cat', {'in_io': 'file', 'in_name': 'Xfile'}) |
| 712 | call term_wait(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 713 | call WaitForAssert({-> assert_equal('one line', term_getline(buf, 1))}) |
Bram Moolenaar | 8b53b79 | 2017-09-05 20:29:25 +0200 | [diff] [blame] | 714 | let g:job = term_getjob(buf) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 715 | call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) |
Bram Moolenaar | e88fc7a | 2017-09-03 20:59:40 +0200 | [diff] [blame] | 716 | bwipe |
| 717 | call delete('Xfile') |
| 718 | endif |
| 719 | endfunc |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 720 | |
| 721 | func TerminalTmap(remap) |
| 722 | let buf = Run_shell_in_terminal({}) |
| 723 | call assert_equal('t', mode()) |
| 724 | |
| 725 | if a:remap |
| 726 | tmap 123 456 |
| 727 | else |
| 728 | tnoremap 123 456 |
| 729 | endif |
Bram Moolenaar | 461fe50 | 2017-12-05 12:30:03 +0100 | [diff] [blame] | 730 | " don't use abcde, it's an existing command |
| 731 | tmap 456 abxde |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 732 | call assert_equal('456', maparg('123', 't')) |
Bram Moolenaar | 461fe50 | 2017-12-05 12:30:03 +0100 | [diff] [blame] | 733 | call assert_equal('abxde', maparg('456', 't')) |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 734 | call feedkeys("123", 'tx') |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 735 | 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] | 736 | let lnum = term_getcursor(buf)[0] |
| 737 | if a:remap |
Bram Moolenaar | 461fe50 | 2017-12-05 12:30:03 +0100 | [diff] [blame] | 738 | call assert_match('abxde', term_getline(buf, lnum)) |
Bram Moolenaar | 69fbc9e | 2017-09-14 20:37:57 +0200 | [diff] [blame] | 739 | else |
| 740 | call assert_match('456', term_getline(buf, lnum)) |
| 741 | endif |
| 742 | |
| 743 | call term_sendkeys(buf, "\r") |
| 744 | call Stop_shell_in_terminal(buf) |
| 745 | call term_wait(buf) |
| 746 | |
| 747 | tunmap 123 |
| 748 | tunmap 456 |
| 749 | call assert_equal('', maparg('123', 't')) |
| 750 | close |
| 751 | unlet g:job |
| 752 | endfunc |
| 753 | |
| 754 | func Test_terminal_tmap() |
| 755 | call TerminalTmap(1) |
| 756 | call TerminalTmap(0) |
| 757 | endfunc |
Bram Moolenaar | 059db5c | 2017-10-15 22:42:23 +0200 | [diff] [blame] | 758 | |
| 759 | func Test_terminal_wall() |
| 760 | let buf = Run_shell_in_terminal({}) |
| 761 | wall |
| 762 | call Stop_shell_in_terminal(buf) |
| 763 | call term_wait(buf) |
| 764 | exe buf . 'bwipe' |
| 765 | unlet g:job |
| 766 | endfunc |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 767 | |
Bram Moolenaar | 7a76092 | 2018-02-19 23:10:02 +0100 | [diff] [blame] | 768 | func Test_terminal_wqall() |
| 769 | let buf = Run_shell_in_terminal({}) |
| 770 | call assert_fails('wqall', 'E948') |
| 771 | call Stop_shell_in_terminal(buf) |
| 772 | call term_wait(buf) |
| 773 | exe buf . 'bwipe' |
| 774 | unlet g:job |
| 775 | endfunc |
| 776 | |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 777 | func Test_terminal_composing_unicode() |
| 778 | let save_enc = &encoding |
| 779 | set encoding=utf-8 |
| 780 | |
| 781 | if has('win32') |
| 782 | let cmd = "cmd /K chcp 65001" |
| 783 | let lnum = [3, 6, 9] |
| 784 | else |
| 785 | let cmd = &shell |
| 786 | let lnum = [1, 3, 5] |
| 787 | endif |
| 788 | |
| 789 | enew |
| 790 | let buf = term_start(cmd, {'curwin': bufnr('')}) |
Bram Moolenaar | 3e1c617 | 2017-11-02 16:58:00 +0100 | [diff] [blame] | 791 | let g:job = term_getjob(buf) |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 792 | call term_wait(buf, 50) |
| 793 | |
Bram Moolenaar | ebe74b7 | 2018-04-21 23:34:43 +0200 | [diff] [blame] | 794 | if has('win32') |
| 795 | call assert_equal('cmd', job_info(g:job).cmd[0]) |
| 796 | else |
| 797 | call assert_equal(&shell, job_info(g:job).cmd[0]) |
| 798 | endif |
| 799 | |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 800 | " ascii + composing |
| 801 | let txt = "a\u0308bc" |
| 802 | call term_sendkeys(buf, "echo " . txt . "\r") |
| 803 | call term_wait(buf, 50) |
| 804 | call assert_match("echo " . txt, term_getline(buf, lnum[0])) |
| 805 | call assert_equal(txt, term_getline(buf, lnum[0] + 1)) |
| 806 | let l = term_scrape(buf, lnum[0] + 1) |
| 807 | call assert_equal("a\u0308", l[0].chars) |
| 808 | call assert_equal("b", l[1].chars) |
| 809 | call assert_equal("c", l[2].chars) |
| 810 | |
| 811 | " multibyte + composing |
| 812 | let txt = "\u304b\u3099\u304e\u304f\u3099\u3052\u3053\u3099" |
| 813 | call term_sendkeys(buf, "echo " . txt . "\r") |
| 814 | call term_wait(buf, 50) |
| 815 | call assert_match("echo " . txt, term_getline(buf, lnum[1])) |
| 816 | call assert_equal(txt, term_getline(buf, lnum[1] + 1)) |
| 817 | let l = term_scrape(buf, lnum[1] + 1) |
| 818 | call assert_equal("\u304b\u3099", l[0].chars) |
| 819 | call assert_equal("\u304e", l[1].chars) |
| 820 | call assert_equal("\u304f\u3099", l[2].chars) |
| 821 | call assert_equal("\u3052", l[3].chars) |
| 822 | call assert_equal("\u3053\u3099", l[4].chars) |
| 823 | |
| 824 | " \u00a0 + composing |
| 825 | let txt = "abc\u00a0\u0308" |
| 826 | call term_sendkeys(buf, "echo " . txt . "\r") |
| 827 | call term_wait(buf, 50) |
| 828 | call assert_match("echo " . txt, term_getline(buf, lnum[2])) |
| 829 | call assert_equal(txt, term_getline(buf, lnum[2] + 1)) |
| 830 | let l = term_scrape(buf, lnum[2] + 1) |
| 831 | call assert_equal("\u00a0\u0308", l[3].chars) |
| 832 | |
| 833 | call term_sendkeys(buf, "exit\r") |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 834 | call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 835 | bwipe! |
Bram Moolenaar | 3e1c617 | 2017-11-02 16:58:00 +0100 | [diff] [blame] | 836 | unlet g:job |
Bram Moolenaar | 6daeef1 | 2017-10-15 22:56:49 +0200 | [diff] [blame] | 837 | let &encoding = save_enc |
| 838 | endfunc |
Bram Moolenaar | ff54679 | 2017-11-21 14:47:57 +0100 | [diff] [blame] | 839 | |
| 840 | func Test_terminal_aucmd_on_close() |
| 841 | fun Nop() |
| 842 | let s:called = 1 |
| 843 | endfun |
| 844 | |
| 845 | aug repro |
| 846 | au! |
| 847 | au BufWinLeave * call Nop() |
| 848 | aug END |
| 849 | |
| 850 | let [cmd, waittime] = s:get_sleep_cmd() |
| 851 | |
| 852 | call assert_equal(1, winnr('$')) |
| 853 | new |
| 854 | call setline(1, ['one', 'two']) |
| 855 | exe 'term ++close ' . cmd |
| 856 | wincmd p |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 857 | call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) |
Bram Moolenaar | ff54679 | 2017-11-21 14:47:57 +0100 | [diff] [blame] | 858 | call assert_equal(1, s:called) |
| 859 | bwipe! |
| 860 | |
| 861 | unlet s:called |
| 862 | au! repro |
| 863 | delfunc Nop |
| 864 | endfunc |
Bram Moolenaar | ede35bb | 2018-01-26 20:05:18 +0100 | [diff] [blame] | 865 | |
| 866 | func Test_terminal_term_start_empty_command() |
| 867 | let cmd = "call term_start('', {'curwin' : 1, 'term_finish' : 'close'})" |
| 868 | call assert_fails(cmd, 'E474') |
| 869 | let cmd = "call term_start('', {'curwin' : 1, 'term_finish' : 'close'})" |
| 870 | call assert_fails(cmd, 'E474') |
| 871 | let cmd = "call term_start({}, {'curwin' : 1, 'term_finish' : 'close'})" |
| 872 | call assert_fails(cmd, 'E474') |
| 873 | let cmd = "call term_start(0, {'curwin' : 1, 'term_finish' : 'close'})" |
| 874 | call assert_fails(cmd, 'E474') |
| 875 | endfunc |
Bram Moolenaar | b50773c | 2018-01-30 22:31:19 +0100 | [diff] [blame] | 876 | |
| 877 | func Test_terminal_response_to_control_sequence() |
| 878 | if !has('unix') |
| 879 | return |
| 880 | endif |
| 881 | |
| 882 | let buf = Run_shell_in_terminal({}) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 883 | call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) |
Bram Moolenaar | b50773c | 2018-01-30 22:31:19 +0100 | [diff] [blame] | 884 | |
Bram Moolenaar | 086eb87 | 2018-03-25 21:24:12 +0200 | [diff] [blame] | 885 | call term_sendkeys(buf, "cat\<CR>") |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 886 | call WaitForAssert({-> assert_match('cat', term_getline(buf, 1))}) |
Bram Moolenaar | d4a282f | 2018-02-02 18:22:31 +0100 | [diff] [blame] | 887 | |
Bram Moolenaar | 086eb87 | 2018-03-25 21:24:12 +0200 | [diff] [blame] | 888 | " Request the cursor position. |
| 889 | call term_sendkeys(buf, "\x1b[6n\<CR>") |
Bram Moolenaar | d4a282f | 2018-02-02 18:22:31 +0100 | [diff] [blame] | 890 | |
| 891 | " Wait for output from tty to display, below an empty line. |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 892 | call WaitForAssert({-> assert_match('3;1R', term_getline(buf, 4))}) |
Bram Moolenaar | b50773c | 2018-01-30 22:31:19 +0100 | [diff] [blame] | 893 | |
Bram Moolenaar | 086eb87 | 2018-03-25 21:24:12 +0200 | [diff] [blame] | 894 | " End "cat" gently. |
| 895 | call term_sendkeys(buf, "\<CR>\<C-D>") |
| 896 | |
Bram Moolenaar | b50773c | 2018-01-30 22:31:19 +0100 | [diff] [blame] | 897 | call Stop_shell_in_terminal(buf) |
Bram Moolenaar | b50773c | 2018-01-30 22:31:19 +0100 | [diff] [blame] | 898 | exe buf . 'bwipe' |
| 899 | unlet g:job |
| 900 | endfunc |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 901 | |
Bram Moolenaar | 3e8d385 | 2018-03-20 17:43:01 +0100 | [diff] [blame] | 902 | " Run Vim, start a terminal in that Vim with the kill argument, |
| 903 | " :qall works. |
| 904 | func Run_terminal_qall_kill(line1, line2) |
| 905 | " 1. Open a terminal window and wait for the prompt to appear |
| 906 | " 2. set kill using term_setkill() |
| 907 | " 3. make Vim exit, it will kill the shell |
| 908 | let after = [ |
| 909 | \ a:line1, |
| 910 | \ 'let buf = bufnr("%")', |
| 911 | \ 'while term_getline(buf, 1) =~ "^\\s*$"', |
| 912 | \ ' sleep 10m', |
| 913 | \ 'endwhile', |
| 914 | \ a:line2, |
| 915 | \ 'au VimLeavePre * call writefile(["done"], "Xdone")', |
| 916 | \ 'qall', |
| 917 | \ ] |
| 918 | if !RunVim([], after, '') |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 919 | return |
| 920 | endif |
Bram Moolenaar | 3e8d385 | 2018-03-20 17:43:01 +0100 | [diff] [blame] | 921 | call assert_equal("done", readfile("Xdone")[0]) |
| 922 | call delete("Xdone") |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 923 | endfunc |
| 924 | |
| 925 | " Run Vim in a terminal, then start a terminal in that Vim with a kill |
| 926 | " argument, check that :qall works. |
Bram Moolenaar | 3e8d385 | 2018-03-20 17:43:01 +0100 | [diff] [blame] | 927 | func Test_terminal_qall_kill_arg() |
| 928 | call Run_terminal_qall_kill('term ++kill=kill', '') |
| 929 | endfunc |
| 930 | |
| 931 | " Run Vim, start a terminal in that Vim, set the kill argument with |
| 932 | " term_setkill(), check that :qall works. |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 933 | func Test_terminal_qall_kill_func() |
Bram Moolenaar | 3e8d385 | 2018-03-20 17:43:01 +0100 | [diff] [blame] | 934 | call Run_terminal_qall_kill('term', 'call term_setkill(buf, "kill")') |
| 935 | endfunc |
| 936 | |
| 937 | " Run Vim, start a terminal in that Vim without the kill argument, |
| 938 | " check that :qall does not exit, :qall! does. |
| 939 | func Test_terminal_qall_exit() |
| 940 | let after = [ |
| 941 | \ 'term', |
| 942 | \ 'let buf = bufnr("%")', |
| 943 | \ 'while term_getline(buf, 1) =~ "^\\s*$"', |
| 944 | \ ' sleep 10m', |
| 945 | \ 'endwhile', |
| 946 | \ 'set nomore', |
| 947 | \ 'au VimLeavePre * call writefile(["too early"], "Xdone")', |
| 948 | \ 'qall', |
| 949 | \ 'au! VimLeavePre * exe buf . "bwipe!" | call writefile(["done"], "Xdone")', |
| 950 | \ 'cquit', |
| 951 | \ ] |
| 952 | if !RunVim([], after, '') |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 953 | return |
| 954 | endif |
Bram Moolenaar | 3e8d385 | 2018-03-20 17:43:01 +0100 | [diff] [blame] | 955 | call assert_equal("done", readfile("Xdone")[0]) |
| 956 | call delete("Xdone") |
Bram Moolenaar | 25cdd9c | 2018-03-10 20:28:12 +0100 | [diff] [blame] | 957 | endfunc |
Bram Moolenaar | 435acdb | 2018-03-10 20:51:25 +0100 | [diff] [blame] | 958 | |
| 959 | " Run Vim in a terminal, then start a terminal in that Vim without a kill |
| 960 | " argument, check that :confirm qall works. |
| 961 | func Test_terminal_qall_prompt() |
| 962 | if !CanRunVimInTerminal() |
| 963 | return |
| 964 | endif |
| 965 | let buf = RunVimInTerminal('', {}) |
| 966 | |
| 967 | " Open a terminal window and wait for the prompt to appear |
| 968 | call term_sendkeys(buf, ":term\<CR>") |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 969 | call WaitForAssert({-> assert_match('\[running]', term_getline(buf, 10))}) |
| 970 | call WaitForAssert({-> assert_notmatch('^\s*$', term_getline(buf, 1))}) |
Bram Moolenaar | 435acdb | 2018-03-10 20:51:25 +0100 | [diff] [blame] | 971 | |
| 972 | " make Vim exit, it will prompt to kill the shell |
| 973 | call term_sendkeys(buf, "\<C-W>:confirm qall\<CR>") |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 974 | call WaitForAssert({-> assert_match('ancel:', term_getline(buf, 20))}) |
Bram Moolenaar | 435acdb | 2018-03-10 20:51:25 +0100 | [diff] [blame] | 975 | call term_sendkeys(buf, "y") |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 976 | call WaitForAssert({-> assert_equal('finished', term_getstatus(buf))}) |
Bram Moolenaar | 435acdb | 2018-03-10 20:51:25 +0100 | [diff] [blame] | 977 | |
| 978 | " close the terminal window where Vim was running |
| 979 | quit |
| 980 | endfunc |
Bram Moolenaar | b852c3e | 2018-03-11 16:55:36 +0100 | [diff] [blame] | 981 | |
Bram Moolenaar | 012eb66 | 2018-03-13 17:55:27 +0100 | [diff] [blame] | 982 | func Test_terminal_open_autocmd() |
Bram Moolenaar | b852c3e | 2018-03-11 16:55:36 +0100 | [diff] [blame] | 983 | augroup repro |
| 984 | au! |
| 985 | au TerminalOpen * let s:called += 1 |
| 986 | augroup END |
| 987 | |
| 988 | let s:called = 0 |
| 989 | |
| 990 | " Open a terminal window with :terminal |
| 991 | terminal |
| 992 | call assert_equal(1, s:called) |
| 993 | bwipe! |
| 994 | |
| 995 | " Open a terminal window with term_start() |
| 996 | call term_start(&shell) |
| 997 | call assert_equal(2, s:called) |
| 998 | bwipe! |
| 999 | |
| 1000 | " Open a hidden terminal buffer with :terminal |
| 1001 | terminal ++hidden |
| 1002 | call assert_equal(3, s:called) |
| 1003 | for buf in term_list() |
| 1004 | exe buf . "bwipe!" |
| 1005 | endfor |
| 1006 | |
| 1007 | " Open a hidden terminal buffer with term_start() |
| 1008 | let buf = term_start(&shell, {'hidden': 1}) |
| 1009 | call assert_equal(4, s:called) |
| 1010 | exe buf . "bwipe!" |
| 1011 | |
| 1012 | unlet s:called |
| 1013 | au! repro |
| 1014 | endfunction |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1015 | |
| 1016 | func Check_dump01(off) |
| 1017 | call assert_equal('one two three four five', trim(getline(a:off + 1))) |
| 1018 | call assert_equal('~ Select Word', trim(getline(a:off + 7))) |
Bram Moolenaar | 1834d37 | 2018-03-29 17:40:46 +0200 | [diff] [blame] | 1019 | call assert_equal(':popup PopUp', trim(getline(a:off + 20))) |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1020 | endfunc |
| 1021 | |
Bram Moolenaar | f06b0b6 | 2018-03-29 17:22:24 +0200 | [diff] [blame] | 1022 | func Test_terminal_dumpwrite_composing() |
| 1023 | if !CanRunVimInTerminal() |
| 1024 | return |
| 1025 | endif |
| 1026 | let save_enc = &encoding |
| 1027 | set encoding=utf-8 |
| 1028 | call assert_equal(1, winnr('$')) |
| 1029 | |
| 1030 | let text = " a\u0300 e\u0302 o\u0308" |
| 1031 | call writefile([text], 'Xcomposing') |
Bram Moolenaar | 77bfd75 | 2018-04-30 18:03:10 +0200 | [diff] [blame] | 1032 | let buf = RunVimInTerminal('--cmd "set encoding=utf-8" Xcomposing', {}) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1033 | call WaitForAssert({-> assert_match(text, term_getline(buf, 1))}) |
Bram Moolenaar | f06b0b6 | 2018-03-29 17:22:24 +0200 | [diff] [blame] | 1034 | call term_dumpwrite(buf, 'Xdump') |
| 1035 | let dumpline = readfile('Xdump')[0] |
| 1036 | call assert_match('|à| |ê| |ö', dumpline) |
| 1037 | |
| 1038 | call StopVimInTerminal(buf) |
| 1039 | call delete('Xcomposing') |
| 1040 | call delete('Xdump') |
| 1041 | let &encoding = save_enc |
| 1042 | endfunc |
| 1043 | |
Bram Moolenaar | 45d2a64 | 2018-03-24 14:30:32 +0100 | [diff] [blame] | 1044 | " just testing basic functionality. |
| 1045 | func Test_terminal_dumpload() |
| 1046 | call assert_equal(1, winnr('$')) |
| 1047 | call term_dumpload('dumps/Test_popup_command_01.dump') |
| 1048 | call assert_equal(2, winnr('$')) |
| 1049 | call assert_equal(20, line('$')) |
| 1050 | call Check_dump01(0) |
| 1051 | quit |
| 1052 | endfunc |
| 1053 | |
| 1054 | func Test_terminal_dumpdiff() |
| 1055 | call assert_equal(1, winnr('$')) |
| 1056 | call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_02.dump') |
| 1057 | call assert_equal(2, winnr('$')) |
| 1058 | call assert_equal(62, line('$')) |
| 1059 | call Check_dump01(0) |
| 1060 | call Check_dump01(42) |
| 1061 | call assert_equal(' bbbbbbbbbbbbbbbbbb ', getline(26)[0:29]) |
| 1062 | quit |
| 1063 | endfunc |
Bram Moolenaar | 897e63c | 2018-03-24 17:16:33 +0100 | [diff] [blame] | 1064 | |
| 1065 | func Test_terminal_dumpdiff_options() |
| 1066 | set laststatus=0 |
| 1067 | call assert_equal(1, winnr('$')) |
| 1068 | let height = winheight(0) |
| 1069 | call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_02.dump', {'vertical': 1, 'term_cols': 33}) |
| 1070 | call assert_equal(2, winnr('$')) |
| 1071 | call assert_equal(height, winheight(winnr())) |
| 1072 | call assert_equal(33, winwidth(winnr())) |
| 1073 | call assert_equal('dump diff dumps/Test_popup_command_01.dump', bufname('%')) |
| 1074 | quit |
| 1075 | |
| 1076 | call assert_equal(1, winnr('$')) |
| 1077 | let width = winwidth(0) |
| 1078 | call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_02.dump', {'vertical': 0, 'term_rows': 13, 'term_name': 'something else'}) |
| 1079 | call assert_equal(2, winnr('$')) |
| 1080 | call assert_equal(width, winwidth(winnr())) |
| 1081 | call assert_equal(13, winheight(winnr())) |
| 1082 | call assert_equal('something else', bufname('%')) |
| 1083 | quit |
| 1084 | |
| 1085 | call assert_equal(1, winnr('$')) |
| 1086 | call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_02.dump', {'curwin': 1}) |
| 1087 | call assert_equal(1, winnr('$')) |
| 1088 | bwipe |
| 1089 | |
| 1090 | set laststatus& |
| 1091 | endfunc |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1092 | |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1093 | func Api_drop_common(options) |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1094 | call assert_equal(1, winnr('$')) |
| 1095 | |
| 1096 | " Use the title termcap entries to output the escape sequence. |
| 1097 | call writefile([ |
Bram Moolenaar | cf67a50 | 2018-03-25 20:31:32 +0200 | [diff] [blame] | 1098 | \ 'set title', |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1099 | \ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"', |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1100 | \ 'let &titlestring = ''["drop","Xtextfile"' . a:options . ']''', |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1101 | \ 'redraw', |
| 1102 | \ "set t_ts=", |
| 1103 | \ ], 'Xscript') |
| 1104 | let buf = RunVimInTerminal('-S Xscript', {}) |
Bram Moolenaar | 769e9d2 | 2018-04-11 20:53:49 +0200 | [diff] [blame] | 1105 | call WaitFor({-> bufnr('Xtextfile') > 0}) |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1106 | call assert_equal('Xtextfile', expand('%:t')) |
| 1107 | call assert_true(winnr('$') >= 3) |
Bram Moolenaar | 333b80a | 2018-04-04 22:57:29 +0200 | [diff] [blame] | 1108 | return buf |
| 1109 | endfunc |
| 1110 | |
| 1111 | func Test_terminal_api_drop_newwin() |
| 1112 | if !CanRunVimInTerminal() |
| 1113 | return |
| 1114 | endif |
| 1115 | let buf = Api_drop_common('') |
| 1116 | call assert_equal(0, &bin) |
| 1117 | call assert_equal('', &fenc) |
| 1118 | |
| 1119 | call StopVimInTerminal(buf) |
| 1120 | call delete('Xscript') |
| 1121 | bwipe Xtextfile |
| 1122 | endfunc |
| 1123 | |
| 1124 | func Test_terminal_api_drop_newwin_bin() |
| 1125 | if !CanRunVimInTerminal() |
| 1126 | return |
| 1127 | endif |
| 1128 | let buf = Api_drop_common(',{"bin":1}') |
| 1129 | call assert_equal(1, &bin) |
| 1130 | |
| 1131 | call StopVimInTerminal(buf) |
| 1132 | call delete('Xscript') |
| 1133 | bwipe Xtextfile |
| 1134 | endfunc |
| 1135 | |
| 1136 | func Test_terminal_api_drop_newwin_binary() |
| 1137 | if !CanRunVimInTerminal() |
| 1138 | return |
| 1139 | endif |
| 1140 | let buf = Api_drop_common(',{"binary":1}') |
| 1141 | call assert_equal(1, &bin) |
| 1142 | |
| 1143 | call StopVimInTerminal(buf) |
| 1144 | call delete('Xscript') |
| 1145 | bwipe Xtextfile |
| 1146 | endfunc |
| 1147 | |
| 1148 | func Test_terminal_api_drop_newwin_nobin() |
| 1149 | if !CanRunVimInTerminal() |
| 1150 | return |
| 1151 | endif |
| 1152 | set binary |
| 1153 | let buf = Api_drop_common(',{"nobin":1}') |
| 1154 | call assert_equal(0, &bin) |
| 1155 | |
| 1156 | call StopVimInTerminal(buf) |
| 1157 | call delete('Xscript') |
| 1158 | bwipe Xtextfile |
| 1159 | set nobinary |
| 1160 | endfunc |
| 1161 | |
| 1162 | func Test_terminal_api_drop_newwin_nobinary() |
| 1163 | if !CanRunVimInTerminal() |
| 1164 | return |
| 1165 | endif |
| 1166 | set binary |
| 1167 | let buf = Api_drop_common(',{"nobinary":1}') |
| 1168 | call assert_equal(0, &bin) |
| 1169 | |
| 1170 | call StopVimInTerminal(buf) |
| 1171 | call delete('Xscript') |
| 1172 | bwipe Xtextfile |
| 1173 | set nobinary |
| 1174 | endfunc |
| 1175 | |
| 1176 | func Test_terminal_api_drop_newwin_ff() |
| 1177 | if !CanRunVimInTerminal() |
| 1178 | return |
| 1179 | endif |
| 1180 | let buf = Api_drop_common(',{"ff":"dos"}') |
| 1181 | call assert_equal("dos", &ff) |
| 1182 | |
| 1183 | call StopVimInTerminal(buf) |
| 1184 | call delete('Xscript') |
| 1185 | bwipe Xtextfile |
| 1186 | endfunc |
| 1187 | |
| 1188 | func Test_terminal_api_drop_newwin_fileformat() |
| 1189 | if !CanRunVimInTerminal() |
| 1190 | return |
| 1191 | endif |
| 1192 | let buf = Api_drop_common(',{"fileformat":"dos"}') |
| 1193 | call assert_equal("dos", &ff) |
| 1194 | |
| 1195 | call StopVimInTerminal(buf) |
| 1196 | call delete('Xscript') |
| 1197 | bwipe Xtextfile |
| 1198 | endfunc |
| 1199 | |
| 1200 | func Test_terminal_api_drop_newwin_enc() |
| 1201 | if !CanRunVimInTerminal() |
| 1202 | return |
| 1203 | endif |
| 1204 | let buf = Api_drop_common(',{"enc":"utf-16"}') |
| 1205 | call assert_equal("utf-16", &fenc) |
| 1206 | |
| 1207 | call StopVimInTerminal(buf) |
| 1208 | call delete('Xscript') |
| 1209 | bwipe Xtextfile |
| 1210 | endfunc |
| 1211 | |
| 1212 | func Test_terminal_api_drop_newwin_encoding() |
| 1213 | if !CanRunVimInTerminal() |
| 1214 | return |
| 1215 | endif |
| 1216 | let buf = Api_drop_common(',{"encoding":"utf-16"}') |
| 1217 | call assert_equal("utf-16", &fenc) |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1218 | |
| 1219 | call StopVimInTerminal(buf) |
| 1220 | call delete('Xscript') |
| 1221 | bwipe Xtextfile |
| 1222 | endfunc |
| 1223 | |
| 1224 | func Test_terminal_api_drop_oldwin() |
| 1225 | if !CanRunVimInTerminal() |
| 1226 | return |
| 1227 | endif |
| 1228 | let firstwinid = win_getid() |
| 1229 | split Xtextfile |
| 1230 | let textfile_winid = win_getid() |
| 1231 | call assert_equal(2, winnr('$')) |
| 1232 | call win_gotoid(firstwinid) |
| 1233 | |
| 1234 | " Use the title termcap entries to output the escape sequence. |
| 1235 | call writefile([ |
Bram Moolenaar | cf67a50 | 2018-03-25 20:31:32 +0200 | [diff] [blame] | 1236 | \ 'set title', |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1237 | \ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"', |
| 1238 | \ 'let &titlestring = ''["drop","Xtextfile"]''', |
| 1239 | \ 'redraw', |
| 1240 | \ "set t_ts=", |
| 1241 | \ ], 'Xscript') |
Bram Moolenaar | 15a1c3f | 2018-03-25 18:56:25 +0200 | [diff] [blame] | 1242 | let buf = RunVimInTerminal('-S Xscript', {'rows': 10}) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1243 | call WaitForAssert({-> assert_equal('Xtextfile', expand('%:t'))}) |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1244 | call assert_equal(textfile_winid, win_getid()) |
| 1245 | |
| 1246 | call StopVimInTerminal(buf) |
| 1247 | call delete('Xscript') |
| 1248 | bwipe Xtextfile |
| 1249 | endfunc |
| 1250 | |
Bram Moolenaar | 2a77d21 | 2018-03-26 21:38:52 +0200 | [diff] [blame] | 1251 | func Tapi_TryThis(bufnum, arg) |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1252 | let g:called_bufnum = a:bufnum |
| 1253 | let g:called_arg = a:arg |
| 1254 | endfunc |
| 1255 | |
Bram Moolenaar | 2a77d21 | 2018-03-26 21:38:52 +0200 | [diff] [blame] | 1256 | func WriteApiCall(funcname) |
| 1257 | " Use the title termcap entries to output the escape sequence. |
| 1258 | call writefile([ |
| 1259 | \ 'set title', |
| 1260 | \ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"', |
| 1261 | \ 'let &titlestring = ''["call","' . a:funcname . '",["hello",123]]''', |
| 1262 | \ 'redraw', |
| 1263 | \ "set t_ts=", |
| 1264 | \ ], 'Xscript') |
| 1265 | endfunc |
| 1266 | |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1267 | func Test_terminal_api_call() |
| 1268 | if !CanRunVimInTerminal() |
| 1269 | return |
| 1270 | endif |
Bram Moolenaar | 2de50f8 | 2018-03-25 19:09:56 +0200 | [diff] [blame] | 1271 | |
Bram Moolenaar | 2a77d21 | 2018-03-26 21:38:52 +0200 | [diff] [blame] | 1272 | call WriteApiCall('Tapi_TryThis') |
Bram Moolenaar | 8fbaeb1 | 2018-03-25 18:20:17 +0200 | [diff] [blame] | 1273 | let buf = RunVimInTerminal('-S Xscript', {}) |
| 1274 | call WaitFor({-> exists('g:called_bufnum')}) |
| 1275 | call assert_equal(buf, g:called_bufnum) |
| 1276 | call assert_equal(['hello', 123], g:called_arg) |
| 1277 | |
| 1278 | call StopVimInTerminal(buf) |
| 1279 | call delete('Xscript') |
| 1280 | unlet g:called_bufnum |
| 1281 | unlet g:called_arg |
| 1282 | endfunc |
Bram Moolenaar | 2a77d21 | 2018-03-26 21:38:52 +0200 | [diff] [blame] | 1283 | |
| 1284 | func Test_terminal_api_call_fails() |
| 1285 | if !CanRunVimInTerminal() |
| 1286 | return |
| 1287 | endif |
| 1288 | |
| 1289 | call WriteApiCall('TryThis') |
| 1290 | call ch_logfile('Xlog', 'w') |
| 1291 | let buf = RunVimInTerminal('-S Xscript', {}) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1292 | call WaitForAssert({-> assert_match('Invalid function name: TryThis', string(readfile('Xlog')))}) |
Bram Moolenaar | 2a77d21 | 2018-03-26 21:38:52 +0200 | [diff] [blame] | 1293 | |
| 1294 | call StopVimInTerminal(buf) |
| 1295 | call delete('Xscript') |
| 1296 | call ch_logfile('', '') |
| 1297 | call delete('Xlog') |
| 1298 | endfunc |
Bram Moolenaar | f59c6e8 | 2018-04-10 15:59:11 +0200 | [diff] [blame] | 1299 | |
Bram Moolenaar | a997b45 | 2018-04-17 23:24:06 +0200 | [diff] [blame] | 1300 | let s:caught_e937 = 0 |
| 1301 | |
| 1302 | func Tapi_Delete(bufnum, arg) |
| 1303 | try |
| 1304 | execute 'bdelete!' a:bufnum |
| 1305 | catch /E937:/ |
| 1306 | let s:caught_e937 = 1 |
| 1307 | endtry |
| 1308 | endfunc |
| 1309 | |
| 1310 | func Test_terminal_api_call_fail_delete() |
| 1311 | if !CanRunVimInTerminal() |
| 1312 | return |
| 1313 | endif |
| 1314 | |
| 1315 | call WriteApiCall('Tapi_Delete') |
| 1316 | let buf = RunVimInTerminal('-S Xscript', {}) |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 1317 | call WaitForAssert({-> assert_equal(1, s:caught_e937)}) |
Bram Moolenaar | a997b45 | 2018-04-17 23:24:06 +0200 | [diff] [blame] | 1318 | |
| 1319 | call StopVimInTerminal(buf) |
| 1320 | call delete('Xscript') |
| 1321 | call ch_logfile('', '') |
| 1322 | endfunc |
| 1323 | |
Bram Moolenaar | f59c6e8 | 2018-04-10 15:59:11 +0200 | [diff] [blame] | 1324 | func Test_terminal_ansicolors_default() |
| 1325 | let colors = [ |
| 1326 | \ '#000000', '#e00000', |
| 1327 | \ '#00e000', '#e0e000', |
| 1328 | \ '#0000e0', '#e000e0', |
| 1329 | \ '#00e0e0', '#e0e0e0', |
| 1330 | \ '#808080', '#ff4040', |
| 1331 | \ '#40ff40', '#ffff40', |
| 1332 | \ '#4040ff', '#ff40ff', |
| 1333 | \ '#40ffff', '#ffffff', |
| 1334 | \] |
| 1335 | |
| 1336 | let buf = Run_shell_in_terminal({}) |
| 1337 | call assert_equal(colors, term_getansicolors(buf)) |
| 1338 | call Stop_shell_in_terminal(buf) |
| 1339 | call term_wait(buf) |
| 1340 | |
| 1341 | exe buf . 'bwipe' |
| 1342 | endfunc |
| 1343 | |
| 1344 | let s:test_colors = [ |
| 1345 | \ '#616e64', '#0d0a79', |
| 1346 | \ '#6d610d', '#0a7373', |
| 1347 | \ '#690d0a', '#6d696e', |
| 1348 | \ '#0d0a6f', '#616e0d', |
| 1349 | \ '#0a6479', '#6d0d0a', |
| 1350 | \ '#617373', '#0d0a69', |
| 1351 | \ '#6d690d', '#0a6e6f', |
| 1352 | \ '#610d0a', '#6e6479', |
| 1353 | \] |
| 1354 | |
| 1355 | func Test_terminal_ansicolors_global() |
| 1356 | let g:terminal_ansi_colors = reverse(copy(s:test_colors)) |
| 1357 | let buf = Run_shell_in_terminal({}) |
| 1358 | call assert_equal(g:terminal_ansi_colors, term_getansicolors(buf)) |
| 1359 | call Stop_shell_in_terminal(buf) |
| 1360 | call term_wait(buf) |
| 1361 | |
| 1362 | exe buf . 'bwipe' |
| 1363 | unlet g:terminal_ansi_colors |
| 1364 | endfunc |
| 1365 | |
| 1366 | func Test_terminal_ansicolors_func() |
| 1367 | let g:terminal_ansi_colors = reverse(copy(s:test_colors)) |
| 1368 | let buf = Run_shell_in_terminal({'ansi_colors': s:test_colors}) |
| 1369 | call assert_equal(s:test_colors, term_getansicolors(buf)) |
| 1370 | |
| 1371 | call term_setansicolors(buf, g:terminal_ansi_colors) |
| 1372 | call assert_equal(g:terminal_ansi_colors, term_getansicolors(buf)) |
| 1373 | |
| 1374 | let colors = [ |
| 1375 | \ 'ivory', 'AliceBlue', |
| 1376 | \ 'grey67', 'dark goldenrod', |
| 1377 | \ 'SteelBlue3', 'PaleVioletRed4', |
| 1378 | \ 'MediumPurple2', 'yellow2', |
| 1379 | \ 'RosyBrown3', 'OrangeRed2', |
| 1380 | \ 'white smoke', 'navy blue', |
| 1381 | \ 'grey47', 'gray97', |
| 1382 | \ 'MistyRose2', 'DodgerBlue4', |
| 1383 | \] |
| 1384 | call term_setansicolors(buf, colors) |
| 1385 | |
| 1386 | let colors[4] = 'Invalid' |
| 1387 | call assert_fails('call term_setansicolors(buf, colors)', 'E474:') |
| 1388 | |
| 1389 | call Stop_shell_in_terminal(buf) |
| 1390 | call term_wait(buf) |
| 1391 | exe buf . 'bwipe' |
| 1392 | endfunc |
Bram Moolenaar | a7eef3d | 2018-04-15 22:25:54 +0200 | [diff] [blame] | 1393 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1394 | func Test_terminal_termwinsize_option_fixed() |
Bram Moolenaar | a7eef3d | 2018-04-15 22:25:54 +0200 | [diff] [blame] | 1395 | if !CanRunVimInTerminal() |
| 1396 | return |
| 1397 | endif |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1398 | set termwinsize=6x40 |
Bram Moolenaar | a7eef3d | 2018-04-15 22:25:54 +0200 | [diff] [blame] | 1399 | let text = [] |
| 1400 | for n in range(10) |
| 1401 | call add(text, repeat(n, 50)) |
| 1402 | endfor |
| 1403 | call writefile(text, 'Xwinsize') |
| 1404 | let buf = RunVimInTerminal('Xwinsize', {}) |
| 1405 | let win = bufwinid(buf) |
| 1406 | call assert_equal([6, 40], term_getsize(buf)) |
| 1407 | call assert_equal(6, winheight(win)) |
| 1408 | call assert_equal(40, winwidth(win)) |
| 1409 | |
| 1410 | " resizing the window doesn't resize the terminal. |
| 1411 | resize 10 |
| 1412 | vertical resize 60 |
| 1413 | call assert_equal([6, 40], term_getsize(buf)) |
| 1414 | call assert_equal(10, winheight(win)) |
| 1415 | call assert_equal(60, winwidth(win)) |
| 1416 | |
| 1417 | call StopVimInTerminal(buf) |
| 1418 | call delete('Xwinsize') |
| 1419 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1420 | call assert_fails('set termwinsize=40', 'E474') |
| 1421 | call assert_fails('set termwinsize=10+40', 'E474') |
| 1422 | call assert_fails('set termwinsize=abc', 'E474') |
Bram Moolenaar | a7eef3d | 2018-04-15 22:25:54 +0200 | [diff] [blame] | 1423 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1424 | set termwinsize= |
Bram Moolenaar | a7eef3d | 2018-04-15 22:25:54 +0200 | [diff] [blame] | 1425 | endfunc |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1426 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1427 | func Test_terminal_termwinsize_option_zero() |
| 1428 | set termwinsize=0x0 |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1429 | let buf = Run_shell_in_terminal({}) |
| 1430 | let win = bufwinid(buf) |
| 1431 | call assert_equal([winheight(win), winwidth(win)], term_getsize(buf)) |
| 1432 | call Stop_shell_in_terminal(buf) |
| 1433 | call term_wait(buf) |
| 1434 | exe buf . 'bwipe' |
| 1435 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1436 | set termwinsize=7x0 |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1437 | let buf = Run_shell_in_terminal({}) |
| 1438 | let win = bufwinid(buf) |
| 1439 | call assert_equal([7, winwidth(win)], term_getsize(buf)) |
| 1440 | call Stop_shell_in_terminal(buf) |
| 1441 | call term_wait(buf) |
| 1442 | exe buf . 'bwipe' |
| 1443 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1444 | set termwinsize=0x33 |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1445 | let buf = Run_shell_in_terminal({}) |
| 1446 | let win = bufwinid(buf) |
| 1447 | call assert_equal([winheight(win), 33], term_getsize(buf)) |
| 1448 | call Stop_shell_in_terminal(buf) |
| 1449 | call term_wait(buf) |
| 1450 | exe buf . 'bwipe' |
| 1451 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1452 | set termwinsize= |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1453 | endfunc |
| 1454 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1455 | func Test_terminal_termwinsize_mininmum() |
| 1456 | set termwinsize=10*50 |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1457 | vsplit |
| 1458 | let buf = Run_shell_in_terminal({}) |
| 1459 | let win = bufwinid(buf) |
| 1460 | call assert_inrange(10, 1000, winheight(win)) |
| 1461 | call assert_inrange(50, 1000, winwidth(win)) |
| 1462 | call assert_equal([winheight(win), winwidth(win)], term_getsize(buf)) |
| 1463 | |
| 1464 | resize 15 |
| 1465 | vertical resize 60 |
| 1466 | redraw |
| 1467 | call assert_equal([15, 60], term_getsize(buf)) |
| 1468 | call assert_equal(15, winheight(win)) |
| 1469 | call assert_equal(60, winwidth(win)) |
| 1470 | |
| 1471 | resize 7 |
| 1472 | vertical resize 30 |
| 1473 | redraw |
| 1474 | call assert_equal([10, 50], term_getsize(buf)) |
| 1475 | call assert_equal(7, winheight(win)) |
| 1476 | call assert_equal(30, winwidth(win)) |
| 1477 | |
| 1478 | call Stop_shell_in_terminal(buf) |
| 1479 | call term_wait(buf) |
| 1480 | exe buf . 'bwipe' |
| 1481 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1482 | set termwinsize=0*0 |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1483 | let buf = Run_shell_in_terminal({}) |
| 1484 | let win = bufwinid(buf) |
| 1485 | call assert_equal([winheight(win), winwidth(win)], term_getsize(buf)) |
| 1486 | call Stop_shell_in_terminal(buf) |
| 1487 | call term_wait(buf) |
| 1488 | exe buf . 'bwipe' |
| 1489 | |
Bram Moolenaar | 6d150f7 | 2018-04-21 20:03:20 +0200 | [diff] [blame] | 1490 | set termwinsize= |
Bram Moolenaar | 498c256 | 2018-04-15 23:45:15 +0200 | [diff] [blame] | 1491 | endfunc |
Bram Moolenaar | b2ac14c | 2018-05-01 18:47:59 +0200 | [diff] [blame] | 1492 | |
| 1493 | func Test_terminal_termwinkey() |
| 1494 | call assert_equal(1, winnr('$')) |
| 1495 | let thiswin = win_getid() |
| 1496 | |
| 1497 | let buf = Run_shell_in_terminal({}) |
| 1498 | let termwin = bufwinid(buf) |
| 1499 | set termwinkey=<C-L> |
| 1500 | call feedkeys("\<C-L>w", 'tx') |
| 1501 | call assert_equal(thiswin, win_getid()) |
| 1502 | call feedkeys("\<C-W>w", 'tx') |
| 1503 | |
| 1504 | let job = term_getjob(buf) |
| 1505 | call feedkeys("\<C-L>\<C-C>", 'tx') |
| 1506 | call WaitForAssert({-> assert_equal("dead", job_status(job))}) |
| 1507 | endfunc |
Bram Moolenaar | cd8fb44 | 2018-05-12 17:42:42 +0200 | [diff] [blame] | 1508 | |
| 1509 | func Test_terminal_out_err() |
| 1510 | if !has('unix') |
| 1511 | return |
| 1512 | endif |
| 1513 | call writefile([ |
| 1514 | \ '#!/bin/sh', |
| 1515 | \ 'echo "this is standard error" >&2', |
| 1516 | \ 'echo "this is standard out" >&1', |
| 1517 | \ ], 'Xechoerrout.sh') |
| 1518 | call setfperm('Xechoerrout.sh', 'rwxrwx---') |
| 1519 | |
| 1520 | let outfile = 'Xtermstdout' |
| 1521 | let buf = term_start(['./Xechoerrout.sh'], {'out_io': 'file', 'out_name': outfile}) |
Bram Moolenaar | 5319191 | 2018-06-19 20:08:14 +0200 | [diff] [blame] | 1522 | |
| 1523 | call WaitFor({-> !empty(readfile(outfile)) && !empty(term_getline(buf, 1))}) |
| 1524 | call assert_equal(['this is standard out'], readfile(outfile)) |
Bram Moolenaar | cd8fb44 | 2018-05-12 17:42:42 +0200 | [diff] [blame] | 1525 | call assert_equal('this is standard error', term_getline(buf, 1)) |
| 1526 | |
Bram Moolenaar | 54c6baf | 2018-05-12 21:12:12 +0200 | [diff] [blame] | 1527 | call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))}) |
Bram Moolenaar | cd8fb44 | 2018-05-12 17:42:42 +0200 | [diff] [blame] | 1528 | exe buf . 'bwipe' |
| 1529 | call delete('Xechoerrout.sh') |
| 1530 | call delete(outfile) |
| 1531 | endfunc |
Bram Moolenaar | 4d6cd29 | 2018-05-15 23:53:26 +0200 | [diff] [blame] | 1532 | |
| 1533 | func Test_terminwinscroll() |
| 1534 | if !has('unix') |
| 1535 | return |
| 1536 | endif |
| 1537 | |
| 1538 | " Let the terminal output more than 'termwinscroll' lines, some at the start |
| 1539 | " will be dropped. |
| 1540 | exe 'set termwinscroll=' . &lines |
| 1541 | let buf = term_start('/bin/sh') |
| 1542 | for i in range(1, &lines) |
| 1543 | call feedkeys("echo " . i . "\<CR>", 'xt') |
| 1544 | call WaitForAssert({-> assert_match(string(i), term_getline(buf, term_getcursor(buf)[0] - 1))}) |
| 1545 | endfor |
| 1546 | " Go to Terminal-Normal mode to update the buffer. |
| 1547 | call feedkeys("\<C-W>N", 'xt') |
| 1548 | call assert_inrange(&lines, &lines * 110 / 100 + winheight(0), line('$')) |
| 1549 | |
| 1550 | " Every "echo nr" must only appear once |
| 1551 | let lines = getline(1, line('$')) |
| 1552 | for i in range(&lines - len(lines) / 2 + 2, &lines) |
| 1553 | let filtered = filter(copy(lines), {idx, val -> val =~ 'echo ' . i . '\>'}) |
| 1554 | call assert_equal(1, len(filtered), 'for "echo ' . i . '"') |
| 1555 | endfor |
| 1556 | |
| 1557 | exe buf . 'bwipe!' |
| 1558 | endfunc |
Bram Moolenaar | f9c3883 | 2018-06-19 19:59:20 +0200 | [diff] [blame] | 1559 | |
Bram Moolenaar | 875cf87 | 2018-07-08 20:49:07 +0200 | [diff] [blame] | 1560 | " Resizing the terminal window caused an ml_get error. |
| 1561 | " TODO: This does not reproduce the original problem. |
| 1562 | func Test_terminal_resize() |
| 1563 | set statusline=x |
| 1564 | terminal |
| 1565 | call assert_equal(2, winnr('$')) |
| 1566 | |
| 1567 | " Fill the terminal with text. |
| 1568 | if has('win32') |
| 1569 | call feedkeys("dir\<CR>", 'xt') |
| 1570 | else |
| 1571 | call feedkeys("ls\<CR>", 'xt') |
| 1572 | endif |
| 1573 | " Go to Terminal-Normal mode for a moment. |
| 1574 | call feedkeys("\<C-W>N", 'xt') |
| 1575 | " Open a new window |
| 1576 | call feedkeys("i\<C-W>n", 'xt') |
| 1577 | call assert_equal(3, winnr('$')) |
| 1578 | redraw |
| 1579 | |
| 1580 | close |
| 1581 | call assert_equal(2, winnr('$')) |
| 1582 | call feedkeys("exit\<CR>", 'xt') |
| 1583 | set statusline& |
| 1584 | endfunc |
| 1585 | |
Bram Moolenaar | f9c3883 | 2018-06-19 19:59:20 +0200 | [diff] [blame] | 1586 | " must be nearly the last, we can't go back from GUI to terminal |
| 1587 | func Test_zz1_terminal_in_gui() |
| 1588 | if !CanRunGui() |
| 1589 | return |
| 1590 | endif |
| 1591 | |
| 1592 | " Ignore the "failed to create input context" error. |
| 1593 | call test_ignore_error('E285:') |
| 1594 | |
| 1595 | gui -f |
| 1596 | |
| 1597 | call assert_equal(1, winnr('$')) |
| 1598 | let buf = Run_shell_in_terminal({'term_finish': 'close'}) |
| 1599 | call Stop_shell_in_terminal(buf) |
| 1600 | call term_wait(buf) |
| 1601 | |
| 1602 | " closing window wipes out the terminal buffer a with finished job |
| 1603 | call WaitForAssert({-> assert_equal(1, winnr('$'))}) |
| 1604 | call assert_equal("", bufname(buf)) |
| 1605 | |
| 1606 | unlet g:job |
| 1607 | endfunc |
| 1608 | |
| 1609 | func Test_zz2_terminal_guioptions_bang() |
| 1610 | if !has('gui_running') |
| 1611 | return |
| 1612 | endif |
| 1613 | set guioptions+=! |
| 1614 | |
| 1615 | let filename = 'Xtestscript' |
| 1616 | if has('win32') |
| 1617 | let filename .= '.bat' |
| 1618 | let prefix = '' |
| 1619 | let contents = ['@echo off', 'exit %1'] |
| 1620 | else |
| 1621 | let filename .= '.sh' |
| 1622 | let prefix = './' |
| 1623 | let contents = ['#!/bin/sh', 'exit $1'] |
| 1624 | endif |
| 1625 | call writefile(contents, filename) |
| 1626 | call setfperm(filename, 'rwxrwx---') |
| 1627 | |
| 1628 | " Check if v:shell_error is equal to the exit status. |
| 1629 | let exitval = 0 |
| 1630 | execute printf(':!%s%s %d', prefix, filename, exitval) |
| 1631 | call assert_equal(exitval, v:shell_error) |
| 1632 | |
| 1633 | let exitval = 9 |
| 1634 | execute printf(':!%s%s %d', prefix, filename, exitval) |
| 1635 | call assert_equal(exitval, v:shell_error) |
| 1636 | |
| 1637 | set guioptions& |
| 1638 | call delete(filename) |
| 1639 | endfunc |
Bram Moolenaar | 7da1fb5 | 2018-08-04 16:54:11 +0200 | [diff] [blame] | 1640 | |
| 1641 | func Test_terminal_hidden() |
| 1642 | if !has('unix') |
| 1643 | return |
| 1644 | endif |
| 1645 | term ++hidden cat |
| 1646 | let bnr = bufnr('$') |
| 1647 | call assert_equal('terminal', getbufvar(bnr, '&buftype')) |
| 1648 | exe 'sbuf ' . bnr |
| 1649 | call assert_equal('terminal', &buftype) |
| 1650 | call term_sendkeys(bnr, "asdf\<CR>") |
| 1651 | call WaitForAssert({-> assert_match('asdf', term_getline(bnr, 2))}) |
| 1652 | call term_sendkeys(bnr, "\<C-D>") |
| 1653 | call WaitForAssert({-> assert_equal('finished', term_getstatus(bnr))}) |
| 1654 | bwipe! |
| 1655 | endfunc |
Bram Moolenaar | 5db7eec | 2018-08-07 16:33:18 +0200 | [diff] [blame] | 1656 | |
| 1657 | func Test_terminal_hidden_and_close() |
| 1658 | if !has('unix') |
| 1659 | return |
| 1660 | endif |
| 1661 | call assert_equal(1, winnr('$')) |
| 1662 | term ++hidden ++close ls |
| 1663 | let bnr = bufnr('$') |
| 1664 | call assert_equal('terminal', getbufvar(bnr, '&buftype')) |
| 1665 | call WaitForAssert({-> assert_false(bufexists(bnr))}) |
| 1666 | call assert_equal(1, winnr('$')) |
| 1667 | endfunc |
Bram Moolenaar | f3aea59 | 2018-11-11 22:18:21 +0100 | [diff] [blame] | 1668 | |
| 1669 | func Test_terminal_does_not_truncate_last_newlines() |
Bram Moolenaar | f3aea59 | 2018-11-11 22:18:21 +0100 | [diff] [blame] | 1670 | let contents = [ |
| 1671 | \ [ 'One', '', 'X' ], |
| 1672 | \ [ 'Two', '', '' ], |
| 1673 | \ [ 'Three' ] + repeat([''], 30) |
| 1674 | \ ] |
| 1675 | |
| 1676 | for c in contents |
| 1677 | call writefile(c, 'Xfile') |
Bram Moolenaar | d3471e5 | 2018-11-12 21:42:24 +0100 | [diff] [blame] | 1678 | if has('win32') |
| 1679 | term cmd /c type Xfile |
| 1680 | else |
| 1681 | term cat Xfile |
| 1682 | endif |
Bram Moolenaar | f3aea59 | 2018-11-11 22:18:21 +0100 | [diff] [blame] | 1683 | let bnr = bufnr('$') |
| 1684 | call assert_equal('terminal', getbufvar(bnr, '&buftype')) |
| 1685 | call WaitForAssert({-> assert_equal('finished', term_getstatus(bnr))}) |
Bram Moolenaar | d3471e5 | 2018-11-12 21:42:24 +0100 | [diff] [blame] | 1686 | sleep 100m |
Bram Moolenaar | f3aea59 | 2018-11-11 22:18:21 +0100 | [diff] [blame] | 1687 | call assert_equal(c, getline(1, line('$'))) |
| 1688 | quit |
| 1689 | endfor |
| 1690 | |
| 1691 | call delete('Xfile') |
| 1692 | endfunc |
Bram Moolenaar | e751a5f | 2018-12-16 16:16:10 +0100 | [diff] [blame] | 1693 | |
Bram Moolenaar | 528ccfb | 2018-12-21 20:55:22 +0100 | [diff] [blame] | 1694 | func Test_terminal_no_job() |
| 1695 | let term = term_start('false', {'term_finish': 'close'}) |
| 1696 | call WaitForAssert({-> assert_equal(v:null, term_getjob(term)) }) |
| 1697 | endfunc |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1698 | |
| 1699 | func Test_term_gettitle() |
| 1700 | if !has('title') || empty(&t_ts) |
| 1701 | return |
| 1702 | endif |
| 1703 | " TODO: this fails on Travis |
| 1704 | return |
| 1705 | |
| 1706 | " term_gettitle() returns an empty string for a non-terminal buffer |
| 1707 | " or for a non-existing buffer. |
| 1708 | call assert_equal('', term_gettitle(bufnr('%'))) |
| 1709 | call assert_equal('', term_gettitle(bufnr('$') + 1)) |
| 1710 | |
| 1711 | let term = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile']) |
| 1712 | call WaitForAssert({-> assert_equal('[No Name] - VIM', term_gettitle(term)) }) |
| 1713 | |
| 1714 | call term_sendkeys(term, ":e Xfoo\r") |
| 1715 | call WaitForAssert({-> assert_match('Xfoo (.*[/\\]testdir) - VIM', term_gettitle(term)) }) |
| 1716 | |
| 1717 | call term_sendkeys(term, ":set titlestring=foo\r") |
| 1718 | call WaitForAssert({-> assert_equal('foo', term_gettitle(term)) }) |
| 1719 | |
| 1720 | exe term . 'bwipe!' |
| 1721 | endfunc |