blob: a9964b04000ad251357e6b5f0ee7d282e60d0a62 [file] [log] [blame]
Bram Moolenaar3b301682018-09-22 21:37:39 +02001" 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.
Bram Moolenaar0f62cf52018-11-03 21:09:15 +010012 call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))})
Bram Moolenaar3b301682018-09-22 21:37:39 +020013
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)
Bram Moolenaar0f62cf52018-11-03 21:09:15 +010029 call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))})
Bram Moolenaar3b301682018-09-22 21:37:39 +020030
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.
Bram Moolenaar0f62cf52018-11-03 21:09:15 +010043 call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))})
Bram Moolenaar3b301682018-09-22 21:37:39 +020044 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 exe buf . 'bwipe!'
49 call delete('Xfoo')
50 set autowrite&
51endfunc