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