1" Test :suspend 2 3source shared.vim 4 5func Test_suspend() 6 if !has('terminal') || !executable('/bin/sh') 7 return 8 endif 9 10 let buf = term_start('/bin/sh') 11 " Wait for shell prompt. 12 call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))}) 13 14 call term_sendkeys(buf, v:progpath 15 \ . " --clean -X" 16 \ . " -c 'set nu'" 17 \ . " -c 'call setline(1, \"foo\")'" 18 \ . " Xfoo\<CR>") 19 " Cursor in terminal buffer should be on first line in spawned vim. 20 call WaitForAssert({-> assert_equal(' 1 foo', term_getline(buf, '.'))}) 21 22 for suspend_cmd in [":suspend\<CR>", 23 \ ":stop\<CR>", 24 \ ":suspend!\<CR>", 25 \ ":stop!\<CR>", 26 \ "\<C-Z>"] 27 " Suspend and wait for shell prompt. 28 call term_sendkeys(buf, suspend_cmd) 29 call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))}) 30 31 " Without 'autowrite', buffer should not be written. 32 call assert_equal(0, filereadable('Xfoo')) 33 34 call term_sendkeys(buf, "fg\<CR>") 35 call WaitForAssert({-> assert_equal(' 1 foo', term_getline(buf, '.'))}) 36 endfor 37 38 " Test that :suspend! with 'autowrite' writes content of buffers if modified. 39 call term_sendkeys(buf, ":set autowrite\<CR>") 40 call assert_equal(0, filereadable('Xfoo')) 41 call term_sendkeys(buf, ":suspend\<CR>") 42 " Wait for shell prompt. 43 call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))}) 44 call assert_equal(['foo'], readfile('Xfoo')) 45 call term_sendkeys(buf, "fg\<CR>") 46 call WaitForAssert({-> assert_equal(' 1 foo', term_getline(buf, '.'))}) 47 48 " Quit gracefully to dump coverage information. 49 call term_sendkeys(buf, ":qall!\<CR>") 50 call term_wait(buf) 51 call Stop_shell_in_terminal(buf) 52 53 exe buf . 'bwipe!' 54 call delete('Xfoo') 55endfunc 56