comparison src/testdir/test_clientserver.vim @ 19906:031184ace7c5 v8.2.0509

patch 8.2.0509: various code is not properly tested. Commit: https://github.com/vim/vim/commit/cde0ff39da2459b16007fef701ebaa449fb6fe9d Author: Bram Moolenaar <Bram@vim.org> Date: Sat Apr 4 14:00:39 2020 +0200 patch 8.2.0509: various code is not properly tested. Problem: various code is not properly tested. Solution: Add more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5871)
author Bram Moolenaar <Bram@vim.org>
date Sat, 04 Apr 2020 14:15:05 +0200
parents 12518b40c161
children 2c4d9ca33769
comparison
equal deleted inserted replaced
19905:a1a00030eedc 19906:031184ace7c5
4 CheckFeature job 4 CheckFeature job
5 CheckFeature clientserver 5 CheckFeature clientserver
6 6
7 source shared.vim 7 source shared.vim
8 8
9 func Test_client_server() 9 func Check_X11_Connection()
10 let cmd = GetVimCommand()
11 if cmd == ''
12 return
13 endif
14 if has('x11') 10 if has('x11')
15 if empty($DISPLAY) 11 if empty($DISPLAY)
16 throw 'Skipped: $DISPLAY is not set' 12 throw 'Skipped: $DISPLAY is not set'
17 endif 13 endif
18 try 14 try
19 call remote_send('xxx', '') 15 call remote_send('xxx', '')
20 catch 16 catch
21 if v:exception =~ 'E240:' 17 if v:exception =~ 'E240:'
22 throw 'Skipped: no connection to the X server' 18 throw 'Skipped: no connection to the X server'
23 endif 19 endif
24 " ignore other errors 20 " ignore other errors
25 endtry 21 endtry
26 endif 22 endif
23 endfunc
24
25 func Test_client_server()
26 let cmd = GetVimCommand()
27 if cmd == ''
28 return
29 endif
30 call Check_X11_Connection()
27 31
28 let name = 'XVIMTEST' 32 let name = 'XVIMTEST'
29 let cmd .= ' --servername ' . name 33 let cmd .= ' --servername ' . name
30 let job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'}) 34 let job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
31 call WaitForAssert({-> assert_equal("run", job_status(job))}) 35 call WaitForAssert({-> assert_equal("run", job_status(job))})
70 call assert_match('MYSELF', v:servername) 74 call assert_match('MYSELF', v:servername)
71 call assert_fails("call remote_startserver('MYSELF')", 'E941:') 75 call assert_fails("call remote_startserver('MYSELF')", 'E941:')
72 endif 76 endif
73 let g:testvar = 'myself' 77 let g:testvar = 'myself'
74 call assert_equal('myself', remote_expr(v:servername, 'testvar')) 78 call assert_equal('myself', remote_expr(v:servername, 'testvar'))
79 call remote_send(v:servername, ":let g:testvar2 = 75\<CR>")
80 call feedkeys('', 'x')
81 call assert_equal(75, g:testvar2)
82 call assert_fails('let v = remote_expr(v:servername, "/2")', 'E449:')
75 83
76 call remote_send(name, ":call server2client(expand('<client>'), 'got it')\<CR>", 'g:myserverid') 84 call remote_send(name, ":call server2client(expand('<client>'), 'got it')\<CR>", 'g:myserverid')
77 call assert_equal('got it', g:myserverid->remote_read(2)) 85 call assert_equal('got it', g:myserverid->remote_read(2))
78 86
79 call remote_send(name, ":eval expand('<client>')->server2client('another')\<CR>", 'g:myserverid') 87 call remote_send(name, ":eval expand('<client>')->server2client('another')\<CR>", 'g:myserverid')
90 let g:peek_result = 'empty' 98 let g:peek_result = 'empty'
91 call WaitFor('remote_peek(g:myserverid, "g:peek_result") > 0') 99 call WaitFor('remote_peek(g:myserverid, "g:peek_result") > 0')
92 call assert_equal('another', g:peek_result) 100 call assert_equal('another', g:peek_result)
93 call assert_equal('another', remote_read(g:myserverid, 2)) 101 call assert_equal('another', remote_read(g:myserverid, 2))
94 102
103 if !has('gui_running')
104 " In GUI vim, the following tests display a dialog box
105
106 let cmd = GetVimProg() .. ' --servername ' .. name
107
108 " Run a separate instance to send a command to the server
109 call remote_expr(name, 'execute("only")')
110 call system(cmd .. ' --remote-send ":new Xfile<CR>"')
111 call assert_equal('2', remote_expr(name, 'winnr("$")'))
112 call assert_equal('Xfile', remote_expr(name, 'winbufnr(1)->bufname()'))
113 call remote_expr(name, 'execute("only")')
114
115 " Invoke a remote-expr. On MS-Windows, the returned value has a carriage
116 " return.
117 let l = system(cmd .. ' --remote-expr "2 + 2"')
118 call assert_equal(['4'], split(l, "\n"))
119
120 " Edit multiple files using --remote
121 call system(cmd .. ' --remote Xfile1 Xfile2 Xfile3')
122 call assert_equal("Xfile1\nXfile2\nXfile3\n", remote_expr(name, 'argv()'))
123 eval name->remote_send(":%bw!\<CR>")
124
125 " Edit files in separate tab pages
126 call system(cmd .. ' --remote-tab Xfile1 Xfile2 Xfile3')
127 call assert_equal('3', remote_expr(name, 'tabpagenr("$")'))
128 call assert_equal('Xfile2', remote_expr(name, 'bufname(tabpagebuflist(2)[0])'))
129 eval name->remote_send(":%bw!\<CR>")
130
131 " Edit a file using --remote-wait
132 eval name->remote_send(":source $VIMRUNTIME/plugin/rrhelper.vim\<CR>")
133 call system(cmd .. ' --remote-wait +enew Xfile1')
134 call assert_equal("Xfile1", remote_expr(name, 'bufname("#")'))
135 eval name->remote_send(":%bw!\<CR>")
136
137 " Edit files using --remote-tab-wait
138 call system(cmd .. ' --remote-tabwait +tabonly\|enew Xfile1 Xfile2')
139 call assert_equal('1', remote_expr(name, 'tabpagenr("$")'))
140 eval name->remote_send(":%bw!\<CR>")
141
142 " Error cases
143 if v:lang == "C" || v:lang =~ '^[Ee]n'
144 let l = split(system(cmd .. ' --remote +pwd'), "\n")
145 call assert_equal("Argument missing after: \"+pwd\"", l[1])
146 endif
147 let l = system(cmd .. ' --remote-expr "abcd"')
148 call assert_match('^E449: ', l)
149 endif
150
151 eval name->remote_send(":%bw!\<CR>")
95 eval name->remote_send(":qa!\<CR>") 152 eval name->remote_send(":qa!\<CR>")
96 try 153 try
97 call WaitForAssert({-> assert_equal("dead", job_status(job))}) 154 call WaitForAssert({-> assert_equal("dead", job_status(job))})
98 finally 155 finally
99 if job_status(job) != 'dead' 156 if job_status(job) != 'dead'
100 call assert_report('Server did not exit') 157 call assert_report('Server did not exit')
101 call job_stop(job, 'kill') 158 call job_stop(job, 'kill')
102 endif 159 endif
103 endtry 160 endtry
104 161
105 call assert_fails("let x=remote_peek([])", 'E730:') 162 call assert_fails("let x = remote_peek([])", 'E730:')
106 call assert_fails("let x=remote_read('vim10')", 'E277:') 163 call assert_fails("let x = remote_read('vim10')", 'E277:')
107 endfunc 164 endfunc
108 165
109 " Uncomment this line to get a debugging log 166 " Uncomment this line to get a debugging log
110 " call ch_logfile('channellog', 'w') 167 " call ch_logfile('channellog', 'w')
111 168