1
0
forked from aniani/vim

patch 8.2.0808: not enough testing for the terminal window

Problem:    Not enough testing for the terminal window.
Solution:   Add more tests. (Yegappan Lakshmanan, closes #6069)  Fix memory
            leak.
This commit is contained in:
Bram Moolenaar
2020-05-22 13:34:01 +02:00
parent 4c9243f9fb
commit 98f1671cc0
4 changed files with 41 additions and 19 deletions

View File

@@ -3047,7 +3047,7 @@ handle_settermprop(
#endif
else
{
term->tl_title = vim_strsave(strval);
term->tl_title = strval;
strval = NULL;
}
VIM_CLEAR(term->tl_status_text);

View File

@@ -850,8 +850,7 @@ func Test_gui_run_cmd_in_terminal()
" assume all the other systems have a cat command
let cmd = 'cat'
endif
let cmd = ':silent !' . cmd . " test_gui.vim\<CR>\<CR>"
call feedkeys(cmd, 'xt')
exe "silent !" . cmd . " test_gui.vim"
" TODO: how to check that the command ran in a separate terminal?
" Maybe check for $TERM (dumb vs xterm) in the spawned shell?
let &guioptions = save_guioptions

View File

@@ -1220,6 +1220,7 @@ func Test_terminal_dumpwrite_errors()
call delete('Xtest.dump')
call assert_fails("call term_dumpwrite(buf, '')", 'E482:')
call assert_fails("call term_dumpwrite(buf, test_null_string())", 'E482:')
call test_garbagecollect_now()
call StopVimInTerminal(buf)
call term_wait(buf)
call assert_fails("call term_dumpwrite(buf, 'Xtest.dump')", 'E958:')
@@ -1305,6 +1306,16 @@ func Test_terminal_dumpdiff_swap()
call assert_match('three four five', getline(3))
call assert_match('Undo', getline(45))
quit
" Diff two terminal dump files with different number of rows
" Swap the diffs
call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_winline_rnu.dump')
call assert_match('Test_popup_command_01.dump', getline(21))
call assert_match('Test_winline_rnu.dump', getline(42))
normal s
call assert_match('Test_winline_rnu.dump', getline(6))
call assert_match('Test_popup_command_01.dump', getline(27))
quit
endfunc
func Test_terminal_dumpdiff_options()
@@ -1619,6 +1630,7 @@ func Test_terminal_ansicolors_default()
call assert_equal(colors, term_getansicolors(buf))
call StopShellInTerminal(buf)
call TermWait(buf)
call assert_equal([], term_getansicolors(buf))
exe buf . 'bwipe'
endfunc
@@ -1673,9 +1685,11 @@ func Test_terminal_ansicolors_func()
let colors[4] = 'Invalid'
call assert_fails('call term_setansicolors(buf, colors)', 'E474:')
call assert_fails('call term_setansicolors(buf, {})', 'E714:')
call StopShellInTerminal(buf)
call TermWait(buf)
call assert_equal(0, term_setansicolors(buf, []))
exe buf . 'bwipe'
endfunc
@@ -2029,7 +2043,7 @@ func Test_terminal_switch_mode()
call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))})
call feedkeys("A", 'xt')
call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))})
call feedkeys("\<C-W>N", 'xt')
call feedkeys("\<C-\>\<C-N>", 'xt')
call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))})
call feedkeys("I", 'xt')
call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))})
@@ -2066,6 +2080,7 @@ func Test_terminal_normal_mode()
call term_sendkeys(buf, ":set culopt=line\r")
call VerifyScreenDump(buf, 'Test_terminal_normal_3', {})
call assert_fails('call term_sendkeys(buf, [])', 'E730:')
call term_sendkeys(buf, "a:q!\<CR>:q\<CR>:q\<CR>")
call StopVimInTerminal(buf)
call delete('XtermNormal')
@@ -2178,17 +2193,18 @@ func Test_term_getcursor()
call StopShellInTerminal(buf)
endfunc
" Test for term_gettitle()
func Test_term_gettitle()
" term_gettitle() returns an empty string for a non-terminal buffer
" and for a non-existing buffer.
call assert_equal('', bufnr('%')->term_gettitle())
call assert_equal('', term_gettitle(bufnr('$') + 1))
if !has('title') || &title == 0 || empty(&t_ts)
if !has('title') || empty(&t_ts)
throw "Skipped: can't get/set title"
endif
let term = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile'])
let term = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', '-c', 'set title'])
if has('autoservername')
call WaitForAssert({-> assert_match('^\[No Name\] - VIM\d\+$', term_gettitle(term)) })
call term_sendkeys(term, ":e Xfoo\r")
@@ -2692,15 +2708,6 @@ func Test_term_keycode_translation()
call assert_equal(output[i], term_getline(buf, 1))
endfor
"call term_sendkeys(buf, "\<K0>\<K1>\<K2>\<K3>\<K4>\<K5>\<K6>\<K7>\<K8>\<K9>")
"call term_sendkeys(buf, "\<kEnter>\<kPoint>\<kPlus>")
"call term_sendkeys(buf, "\<kMinus>\<kMultiply>\<kDivide>")
"call term_sendkeys(buf, "\<Esc>")
"call term_sendkeys(buf, "\<Home>\<Ins>\<Tab>\<S-Tab>")
"call term_sendkeys(buf, "\<Esc>")
"call term_sendkeys(buf, ":write Xkeycodes\<CR>")
let keypad_keys = ["\<k0>", "\<k1>", "\<k2>", "\<k3>", "\<k4>", "\<k5>",
\ "\<k6>", "\<k7>", "\<k8>", "\<k9>", "\<kPoint>", "\<kPlus>",
\ "\<kMinus>", "\<kMultiply>", "\<kDivide>"]
@@ -2733,7 +2740,6 @@ func Test_term_mouse()
let save_term = &term
let save_ttymouse = &ttymouse
let save_clipboard = &clipboard
call test_override('no_query_mouse', 1)
set mouse=a term=xterm ttymouse=sgr mousetime=200 clipboard=
let lines =<< trim END
@@ -2743,6 +2749,8 @@ func Test_term_mouse()
END
call writefile(lines, 'Xtest_mouse')
" Create a terminal window running Vim for the test with mouse enabled
let prev_win = win_getid()
let buf = RunVimInTerminal('Xtest_mouse -n', {})
call term_sendkeys(buf, ":set nocompatible\<CR>")
call term_sendkeys(buf, ":set mouse=a term=xterm ttymouse=sgr\<CR>")
@@ -2751,6 +2759,12 @@ func Test_term_mouse()
call term_wait(buf)
redraw!
" Use the mouse to enter the terminal window
call win_gotoid(prev_win)
call feedkeys(MouseLeftClickCode(1, 1), 'x')
call feedkeys(MouseLeftReleaseCode(1, 1), 'x')
call assert_equal(1, getwininfo(win_getid())[0].terminal)
" Test for <LeftMouse> click/release
call test_setmouse(2, 5)
call feedkeys("\<LeftMouse>\<LeftRelease>", 'xt')
@@ -2833,7 +2847,6 @@ func Test_term_mouse()
let &ttymouse = save_ttymouse
let &clipboard = save_clipboard
set mousetime&
call test_override('no_query_mouse', 0)
call delete('Xtest_mouse')
call delete('Xbuf')
endfunc
@@ -2848,7 +2861,6 @@ func Test_term_modeless_selection()
let save_mouse = &mouse
let save_term = &term
let save_ttymouse = &ttymouse
call test_override('no_query_mouse', 1)
set mouse=a term=xterm ttymouse=sgr mousetime=200
set clipboard=autoselectml
@@ -2859,12 +2871,21 @@ func Test_term_modeless_selection()
END
call writefile(lines, 'Xtest_modeless')
" Create a terminal window running Vim for the test with mouse disabled
let prev_win = win_getid()
let buf = RunVimInTerminal('Xtest_modeless -n', {})
call term_sendkeys(buf, ":set nocompatible\<CR>")
call term_sendkeys(buf, ":set mouse=\<CR>")
call term_wait(buf)
redraw!
" Use the mouse to enter the terminal window
call win_gotoid(prev_win)
call feedkeys(MouseLeftClickCode(1, 1), 'x')
call feedkeys(MouseLeftReleaseCode(1, 1), 'x')
call term_wait(buf)
call assert_equal(1, getwininfo(win_getid())[0].terminal)
" Test for copying a modeless selection to clipboard
let @* = 'clean'
" communicating with X server may take a little time
@@ -2881,8 +2902,8 @@ func Test_term_modeless_selection()
let &term = save_term
let &ttymouse = save_ttymouse
set mousetime& clipboard&
call test_override('no_query_mouse', 0)
call delete('Xtest_modeless')
new | only!
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -746,6 +746,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
808,
/**/
807,
/**/