Skip to content

Commit 15bf76d

Browse files
committed
patch 8.0.0474: the client-server feature is not tested
Problem: The client-server feature is not tested. Solution: Add a test.
1 parent 8c34aa0 commit 15bf76d

File tree

6 files changed

+72
-16
lines changed

6 files changed

+72
-16
lines changed

src/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2097,11 +2097,12 @@ test_arglist \
20972097
test_breakindent \
20982098
test_bufwintabinfo \
20992099
test_cdo \
2100+
test_changedtick \
21002101
test_channel \
21012102
test_charsearch \
21022103
test_charsearch_utf8 \
2103-
test_changedtick \
21042104
test_cindent \
2105+
test_clientserver \
21052106
test_cmdline \
21062107
test_command_count \
21072108
test_crypt \

src/os_mswin.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,11 +2105,15 @@ Messaging_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
21052105

21062106
str = serverConvert(client_enc, (char_u *)data->lpData, &tofree);
21072107
res = eval_client_expr_to_string(str);
2108-
vim_free(tofree);
21092108

21102109
if (res == NULL)
21112110
{
2112-
res = vim_strsave((char_u *)_(e_invexprmsg));
2111+
char *err = _(e_invexprmsg);
2112+
size_t len = STRLEN(str) + STRLEN(err) + 5;
2113+
2114+
res = alloc(len);
2115+
if (res != NULL)
2116+
vim_snprintf((char *)res, len, "%s: \"%s\"", err, str);
21132117
reply.dwData = COPYDATA_ERROR_RESULT;
21142118
}
21152119
else
@@ -2120,6 +2124,7 @@ Messaging_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
21202124
serverSendEnc(sender);
21212125
retval = (int)SendMessage(sender, WM_COPYDATA,
21222126
(WPARAM)message_window, (LPARAM)(&reply));
2127+
vim_free(tofree);
21232128
vim_free(res);
21242129
return retval;
21252130

src/testdir/Make_all.mak

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ NEW_TESTS = test_arabic.res \
144144
test_channel.res \
145145
test_charsearch.res \
146146
test_cindent.res \
147+
test_clientserver.res \
147148
test_cmdline.res \
148149
test_command_count.res \
149150
test_crypt.res \

src/testdir/shared.vim

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,22 @@ func s:feedkeys(timer)
164164
call feedkeys('x', 'nt')
165165
endfunc
166166

167+
" Get the command to run Vim, with -u NONE and --not-a-term arguments.
168+
" Returns an empty string on error.
169+
func GetVimCommand()
170+
if !filereadable('vimcmd')
171+
return ''
172+
endif
173+
let cmd = readfile('vimcmd')[0]
174+
let cmd = substitute(cmd, '-u \f\+', '-u NONE', '')
175+
if cmd !~ '-u NONE'
176+
let cmd = cmd . ' -u NONE'
177+
endif
178+
let cmd .= ' --not-a-term'
179+
let cmd = substitute(cmd, 'VIMRUNTIME=.*VIMRUNTIME;', '', '')
180+
return cmd
181+
endfunc
182+
167183
" Run Vim, using the "vimcmd" file and "-u NORC".
168184
" "before" is a list of Vim commands to be executed before loading plugins.
169185
" "after" is a list of Vim commands to be executed after loading plugins.
@@ -174,7 +190,8 @@ func RunVim(before, after, arguments)
174190
endfunc
175191

176192
func RunVimPiped(before, after, arguments, pipecmd)
177-
if !filereadable('vimcmd')
193+
let cmd = GetVimCommand()
194+
if cmd == ''
178195
return 0
179196
endif
180197
let args = ''
@@ -187,18 +204,6 @@ func RunVimPiped(before, after, arguments, pipecmd)
187204
let args .= ' -S Xafter.vim'
188205
endif
189206

190-
let cmd = readfile('vimcmd')[0]
191-
let cmd = substitute(cmd, '-u \f\+', '-u NONE', '')
192-
if cmd !~ '-u NONE'
193-
let cmd = cmd . ' -u NONE'
194-
endif
195-
let cmd .= ' --not-a-term'
196-
197-
" With pipecmd we can't set VIMRUNTIME.
198-
if a:pipecmd != ''
199-
let cmd = substitute(cmd, 'VIMRUNTIME=.*VIMRUNTIME;', '', '')
200-
endif
201-
202207
exe "silent !" . a:pipecmd . cmd . args . ' ' . a:arguments
203208

204209
if len(a:before) > 0

src/testdir/test_clientserver.vim

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
" Tests for the +clientserver feature.
2+
3+
if !has('job') || !has('clientserver')
4+
finish
5+
endif
6+
7+
source shared.vim
8+
9+
func Test_client_server()
10+
let cmd = GetVimCommand()
11+
if cmd == ''
12+
return
13+
endif
14+
let name = 'XVIMTEXT'
15+
let cmd .= ' --servername ' . name
16+
let g:job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
17+
call WaitFor('job_status(g:job) == "run"')
18+
if job_status(g:job) != 'run'
19+
call assert_true(0, 'Cannot run the Vim server')
20+
return
21+
endif
22+
23+
" Takes a short while for the server to be active.
24+
call WaitFor('serverlist() =~ "' . name . '"')
25+
call assert_match(name, serverlist())
26+
27+
call remote_foreground(name)
28+
29+
call remote_send(name, ":let testvar = 'yes'\<CR>")
30+
call WaitFor('remote_expr("' . name . '", "testvar") == "yes"')
31+
call assert_equal('yes', remote_expr(name, "testvar"))
32+
33+
call remote_send(name, ":qa!\<CR>")
34+
call WaitFor('job_status(g:job) == "dead"')
35+
if job_status(g:job) != 'dead'
36+
call assert_true(0, 'Server did not exit')
37+
call job_stop(g:job, 'kill')
38+
endif
39+
endfunc
40+
41+
" Uncomment this line to get a debugging log
42+
" call ch_logfile('channellog', 'w')

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
474,
767769
/**/
768770
473,
769771
/**/

0 commit comments

Comments
 (0)