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