2018-09-23 16:59:42 -07:00
|
|
|
" Test :suspend
|
|
|
|
|
|
|
|
source shared.vim
|
2020-04-28 20:13:23 -07:00
|
|
|
source term_util.vim
|
2018-09-23 16:59:42 -07:00
|
|
|
|
2019-07-11 03:20:36 -07:00
|
|
|
func CheckSuspended(buf, fileExists)
|
|
|
|
call WaitForAssert({-> assert_match('[$#] $', term_getline(a:buf, '.'))})
|
|
|
|
|
|
|
|
if a:fileExists
|
|
|
|
call assert_equal(['foo'], readfile('Xfoo'))
|
|
|
|
else
|
|
|
|
" Without 'autowrite', buffer should not be written.
|
|
|
|
call assert_equal(0, filereadable('Xfoo'))
|
|
|
|
endif
|
|
|
|
|
|
|
|
call term_sendkeys(a:buf, "fg\<CR>\<C-L>")
|
|
|
|
call WaitForAssert({-> assert_equal(' 1 foo', term_getline(a:buf, '.'))})
|
|
|
|
endfunc
|
|
|
|
|
2018-09-23 16:59:42 -07:00
|
|
|
func Test_suspend()
|
|
|
|
if !has('terminal') || !executable('/bin/sh')
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
let buf = term_start('/bin/sh')
|
|
|
|
" Wait for shell prompt.
|
2018-11-04 03:58:22 -07:00
|
|
|
call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))})
|
2018-09-23 16:59:42 -07:00
|
|
|
|
2022-02-14 03:56:30 -07:00
|
|
|
call term_sendkeys(buf, GetVimCommandClean()
|
|
|
|
\ . " -X"
|
2018-09-23 16:59:42 -07:00
|
|
|
\ . " -c 'set nu'"
|
|
|
|
\ . " -c 'call setline(1, \"foo\")'"
|
|
|
|
\ . " Xfoo\<CR>")
|
|
|
|
" Cursor in terminal buffer should be on first line in spawned vim.
|
|
|
|
call WaitForAssert({-> assert_equal(' 1 foo', term_getline(buf, '.'))})
|
|
|
|
|
|
|
|
for suspend_cmd in [":suspend\<CR>",
|
|
|
|
\ ":stop\<CR>",
|
|
|
|
\ ":suspend!\<CR>",
|
|
|
|
\ ":stop!\<CR>",
|
|
|
|
\ "\<C-Z>"]
|
|
|
|
" Suspend and wait for shell prompt.
|
|
|
|
call term_sendkeys(buf, suspend_cmd)
|
2019-07-11 03:20:36 -07:00
|
|
|
call CheckSuspended(buf, 0)
|
2018-09-23 16:59:42 -07:00
|
|
|
endfor
|
|
|
|
|
|
|
|
" Test that :suspend! with 'autowrite' writes content of buffers if modified.
|
|
|
|
call term_sendkeys(buf, ":set autowrite\<CR>")
|
|
|
|
call assert_equal(0, filereadable('Xfoo'))
|
|
|
|
call term_sendkeys(buf, ":suspend\<CR>")
|
|
|
|
" Wait for shell prompt.
|
2019-07-11 03:20:36 -07:00
|
|
|
call CheckSuspended(buf, 1)
|
2018-09-23 16:59:42 -07:00
|
|
|
|
2019-06-08 15:09:35 -07:00
|
|
|
" Quit gracefully to dump coverage information.
|
|
|
|
call term_sendkeys(buf, ":qall!\<CR>")
|
|
|
|
call term_wait(buf)
|
2019-07-08 18:05:35 -07:00
|
|
|
" Wait until Vim actually exited and shell shows a prompt
|
|
|
|
call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))})
|
2020-04-28 20:13:23 -07:00
|
|
|
call StopShellInTerminal(buf)
|
2019-06-08 15:09:35 -07:00
|
|
|
|
2018-09-23 16:59:42 -07:00
|
|
|
exe buf . 'bwipe!'
|
|
|
|
call delete('Xfoo')
|
|
|
|
endfunc
|