annotate src/testdir/test_terminal.vim @ 11912:22658e33203f v8.0.0836

patch 8.0.0836: can abandon a terminal buffer after making a change commit https://github.com/vim/vim/commit/20e6cd07baed8992e7a509ccef7f111ffcded44d Author: Bram Moolenaar <Bram@vim.org> Date: Tue Aug 1 20:25:22 2017 +0200 patch 8.0.0836: can abandon a terminal buffer after making a change Problem: When a terminal buffer is changed it can still be accidentally abandoned. Solution: When making a change reset the 'buftype' option.
author Christian Brabandt <cb@256bit.org>
date Tue, 01 Aug 2017 20:30:04 +0200
parents 7df4afab67c7
children 00836eb177cb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Tests for the terminal window.
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 if !exists('*term_start')
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 finish
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 endif
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 source shared.vim
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8
11912
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
9 func Run_shell_in_terminal()
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 let buf = term_start(&shell)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 let termlist = term_list()
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 call assert_equal(1, len(termlist))
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 call assert_equal(buf, termlist[0])
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 let g:job = term_getjob(buf)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 call assert_equal(v:t_job, type(g:job))
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 call term_sendkeys(buf, "exit\r")
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 call WaitFor('job_status(g:job) == "dead"')
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 call assert_equal('dead', job_status(g:job))
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22
11912
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
23 return buf
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
24 endfunc
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
25
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
26 func Test_terminal_basic()
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
27 let buf = Run_shell_in_terminal()
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
28
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
29 exe buf . 'bwipe'
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
30 unlet g:job
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
31 endfunc
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
32
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
33 func Test_terminal_make_change()
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
34 let buf = Run_shell_in_terminal()
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
35 call term_wait(buf)
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
36
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
37 setlocal modifiable
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
38 exe "normal Axxx\<Esc>"
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
39 call assert_fails(buf . 'bwipe', 'E517')
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
40 undo
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
41
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 exe buf . 'bwipe'
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 unlet g:job
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 endfunc
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 func Check_123(buf)
11906
7df4afab67c7 patch 8.0.0833: terminal test fails
Christian Brabandt <cb@256bit.org>
parents: 11872
diff changeset
47 let l = term_scrape(a:buf, 1)
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 call assert_true(len(l) > 0)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 call assert_equal('1', l[0].chars)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 call assert_equal('2', l[1].chars)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 call assert_equal('3', l[2].chars)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 call assert_equal('#00e000', l[0].fg)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 if &background == 'light'
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 call assert_equal('#ffffff', l[0].bg)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 else
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 call assert_equal('#000000', l[0].bg)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 endif
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58
11906
7df4afab67c7 patch 8.0.0833: terminal test fails
Christian Brabandt <cb@256bit.org>
parents: 11872
diff changeset
59 let l = term_getline(a:buf, 1)
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 call assert_equal('123', l)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 endfunc
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 func Test_terminal_scrape()
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 if has('win32')
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 let cmd = 'cmd /c "cls && color 2 && echo 123"'
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 else
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 call writefile(["\<Esc>[32m123"], 'Xtext')
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 let cmd = "cat Xtext"
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 endif
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 let buf = term_start(cmd)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 let termlist = term_list()
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 call assert_equal(1, len(termlist))
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 call assert_equal(buf, termlist[0])
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75
11872
ff8122091ec6 patch 8.0.0816: crash when using invalid buffer number
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
76 " Nothing happens with invalid buffer number
ff8122091ec6 patch 8.0.0816: crash when using invalid buffer number
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
77 call term_wait(1234)
ff8122091ec6 patch 8.0.0816: crash when using invalid buffer number
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
78
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 call term_wait(buf)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 call Check_123(buf)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 " Must still work after the job ended.
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 let g:job = term_getjob(buf)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 call WaitFor('job_status(g:job) == "dead"')
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85 call term_wait(buf)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86 call Check_123(buf)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 exe buf . 'bwipe'
11872
ff8122091ec6 patch 8.0.0816: crash when using invalid buffer number
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
89 call delete('Xtext')
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90 endfunc