blob: 55f440ffc20f9361b3e81033f73fc3367aef1e63 [file] [log] [blame]
Bram Moolenaar15bf76d2017-03-18 16:18:37 +01001" Tests for the +clientserver feature.
2
3if !has('job') || !has('clientserver')
4 finish
5endif
6
7source shared.vim
8
9func 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
Bram Moolenaar7416f3e2017-03-18 18:10:13 +010033 if has('unix') && has('gui') && !has('gui_running')
34 " Running in a terminal and the GUI is avaiable: Tell the server to open
35 " the GUI and check that the remote command still works.
36 " Need to wait for the GUI to start up, otherwise the send hangs in trying
37 " to send to the terminal window.
38 call remote_send(name, ":gui -f\<CR>")
39 sleep 500m
40 call remote_send(name, ":let testvar = 'maybe'\<CR>")
41 call WaitFor('remote_expr("' . name . '", "testvar") == "maybe"')
42 call assert_equal('maybe', remote_expr(name, "testvar"))
43 endif
44
45 call assert_fails('call remote_send("XXX", ":let testvar = ''yes''\<CR>")', 'E241')
46
47 " Expression evaluated locally.
48 if v:servername == ''
49 call remote_startserver('MYSELF')
50 call assert_equal('MYSELF', v:servername)
51 endif
52 let g:testvar = 'myself'
53 call assert_equal('myself', remote_expr(v:servername, 'testvar'))
54
55 call remote_send(name, ":call server2client(expand('<client>'), 'got it')\<CR>", 'g:myserverid')
56 call assert_equal('got it', remote_read(g:myserverid))
57
Bram Moolenaar15bf76d2017-03-18 16:18:37 +010058 call remote_send(name, ":qa!\<CR>")
59 call WaitFor('job_status(g:job) == "dead"')
60 if job_status(g:job) != 'dead'
61 call assert_true(0, 'Server did not exit')
62 call job_stop(g:job, 'kill')
63 endif
64endfunc
65
66" Uncomment this line to get a debugging log
67" call ch_logfile('channellog', 'w')