annotate src/testdir/test_terminal.vim @ 11917:00836eb177cb v8.0.0838

patch 8.0.0838: buffer hangs around whem terminal window is closed commit https://github.com/vim/vim/commit/94053a51255121713f51c122eb0dbb46c120e6d4 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Aug 1 21:44:33 2017 +0200 patch 8.0.0838: buffer hangs around whem terminal window is closed Problem: Buffer hangs around whem terminal window is closed. Solution: When the job has ended wipe out a terminal buffer when the window is closed.
author Christian Brabandt <cb@256bit.org>
date Tue, 01 Aug 2017 21:45:04 +0200
parents 22658e33203f
children c9da7b42fdf5
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
11917
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
9 " Open a terminal with a shell, assign the job to g:job and return the buffer
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
10 " number.
11912
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
11 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
12 let buf = term_start(&shell)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 let termlist = term_list()
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 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
16 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
17
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 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
19 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
20
11917
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
21 return buf
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
22 endfunc
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
23
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
24 " Stops the shell started by Run_shell_in_terminal().
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
25 func Stop_shell_in_terminal(buf)
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
26 call term_sendkeys(a:buf, "exit\r")
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 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
28 call assert_equal('dead', job_status(g:job))
11912
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
29 endfunc
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
30
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
31 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
32 let buf = Run_shell_in_terminal()
11917
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
33 call Stop_shell_in_terminal(buf)
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
34 call term_wait(buf)
11912
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
35
11917
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
36 " closing window wipes out the terminal buffer a with finished job
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
37 close
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
38 call assert_equal("", bufname(buf))
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
39
11912
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
40 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
41 endfunc
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
42
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
43 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
44 let buf = Run_shell_in_terminal()
11917
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
45 call Stop_shell_in_terminal(buf)
11912
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
46 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
47
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
48 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
49 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
50 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
51 undo
22658e33203f patch 8.0.0836: can abandon a terminal buffer after making a change
Christian Brabandt <cb@256bit.org>
parents: 11906
diff changeset
52
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 exe buf . 'bwipe'
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 unlet g:job
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 endfunc
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56
11917
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
57 func Test_terminal_wipe_buffer()
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
58 let buf = Run_shell_in_terminal()
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
59 exe buf . 'bwipe'
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
60 call WaitFor('job_status(g:job) == "dead"')
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
61 call assert_equal('dead', job_status(g:job))
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
62 call assert_equal("", bufname(buf))
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
63
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
64 unlet g:job
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
65 endfunc
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
66
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
67 func Test_terminal_hide_buffer()
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
68 let buf = Run_shell_in_terminal()
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
69 quit
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
70 for nr in range(1, winnr('$'))
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
71 call assert_notequal(winbufnr(nr), buf)
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
72 endfor
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
73 call assert_true(bufloaded(buf))
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
74 call assert_true(buflisted(buf))
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
75
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
76 exe 'split ' . buf . 'buf'
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
77 call Stop_shell_in_terminal(buf)
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
78 exe buf . 'bwipe'
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
79
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
80 unlet g:job
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
81 endfunc
00836eb177cb patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents: 11912
diff changeset
82
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 func Check_123(buf)
11906
7df4afab67c7 patch 8.0.0833: terminal test fails
Christian Brabandt <cb@256bit.org>
parents: 11872
diff changeset
84 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
85 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
86 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
87 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
88 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
89 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
90 if &background == 'light'
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 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
92 else
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 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
94 endif
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
95
11906
7df4afab67c7 patch 8.0.0833: terminal test fails
Christian Brabandt <cb@256bit.org>
parents: 11872
diff changeset
96 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
97 call assert_equal('123', l)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
98 endfunc
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100 func Test_terminal_scrape()
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101 if has('win32')
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
102 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
103 else
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
104 call writefile(["\<Esc>[32m123"], 'Xtext')
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
105 let cmd = "cat Xtext"
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
106 endif
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107 let buf = term_start(cmd)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109 let termlist = term_list()
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
110 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
111 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
112
11872
ff8122091ec6 patch 8.0.0816: crash when using invalid buffer number
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
113 " 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
114 call term_wait(1234)
ff8122091ec6 patch 8.0.0816: crash when using invalid buffer number
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
115
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
116 call term_wait(buf)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
117 call Check_123(buf)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
118
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
119 " 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
120 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
121 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
122 call term_wait(buf)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
123 call Check_123(buf)
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
124
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
125 exe buf . 'bwipe'
11872
ff8122091ec6 patch 8.0.0816: crash when using invalid buffer number
Christian Brabandt <cb@256bit.org>
parents: 11846
diff changeset
126 call delete('Xtext')
11846
1c65cad8b967 patch 8.0.0804: terminal window functions not yet implemented
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
127 endfunc