blob: c98fc026ae1e0e21ec2ffbe88f67ecc768600be0 [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
Bram Moolenaar42205552017-03-18 19:42:22 +010014
Bram Moolenaar42205552017-03-18 19:42:22 +010015 let name = 'XVIMTEST'
Bram Moolenaar15bf76d2017-03-18 16:18:37 +010016 let cmd .= ' --servername ' . name
17 let g:job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
18 call WaitFor('job_status(g:job) == "run"')
19 if job_status(g:job) != 'run'
Bram Moolenaar42205552017-03-18 19:42:22 +010020 call assert_report('Cannot run the Vim server')
Bram Moolenaar15bf76d2017-03-18 16:18:37 +010021 return
22 endif
23
24 " Takes a short while for the server to be active.
25 call WaitFor('serverlist() =~ "' . name . '"')
26 call assert_match(name, serverlist())
27
28 call remote_foreground(name)
29
30 call remote_send(name, ":let testvar = 'yes'\<CR>")
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +010031 call WaitFor('remote_expr("' . name . '", "testvar", "", 1) == "yes"')
32 call assert_equal('yes', remote_expr(name, "testvar", "", 2))
Bram Moolenaar15bf76d2017-03-18 16:18:37 +010033
Bram Moolenaar7416f3e2017-03-18 18:10:13 +010034 if has('unix') && has('gui') && !has('gui_running')
35 " Running in a terminal and the GUI is avaiable: Tell the server to open
36 " the GUI and check that the remote command still works.
37 " Need to wait for the GUI to start up, otherwise the send hangs in trying
38 " to send to the terminal window.
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +010039 if has('gui_athena') || has('gui_motif')
40 " For those GUIs, ignore the 'failed to create input context' error.
41 call remote_send(name, ":call test_ignore_error('E285') | gui -f\<CR>")
42 else
43 call remote_send(name, ":gui -f\<CR>")
44 endif
45 " Wait for the server to be up and answering requests.
46 call WaitFor('remote_expr("' . name . '", "v:version", "", 1) != ""')
47
Bram Moolenaar7416f3e2017-03-18 18:10:13 +010048 call remote_send(name, ":let testvar = 'maybe'\<CR>")
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +010049 call WaitFor('remote_expr("' . name . '", "testvar", "", 1) == "maybe"')
50 call assert_equal('maybe', remote_expr(name, "testvar", "", 2))
Bram Moolenaar7416f3e2017-03-18 18:10:13 +010051 endif
52
53 call assert_fails('call remote_send("XXX", ":let testvar = ''yes''\<CR>")', 'E241')
54
55 " Expression evaluated locally.
56 if v:servername == ''
57 call remote_startserver('MYSELF')
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +010058 " May get MYSELF1 when running the test again.
59 call assert_match('MYSELF', v:servername)
Bram Moolenaar7416f3e2017-03-18 18:10:13 +010060 endif
61 let g:testvar = 'myself'
62 call assert_equal('myself', remote_expr(v:servername, 'testvar'))
63
64 call remote_send(name, ":call server2client(expand('<client>'), 'got it')\<CR>", 'g:myserverid')
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +010065 call assert_equal('got it', remote_read(g:myserverid, 2))
Bram Moolenaar7416f3e2017-03-18 18:10:13 +010066
Bram Moolenaar6caf6062017-03-18 20:45:05 +010067 call remote_send(name, ":call server2client(expand('<client>'), 'another')\<CR>", 'g:myserverid')
Bram Moolenaar6caf6062017-03-18 20:45:05 +010068 let peek_result = 'nothing'
69 let r = remote_peek(g:myserverid, 'peek_result')
Bram Moolenaar6caf6062017-03-18 20:45:05 +010070 " unpredictable whether the result is already avaialble.
71 if r > 0
72 call assert_equal('another', peek_result)
73 elseif r == 0
74 call assert_equal('nothing', peek_result)
75 else
76 call assert_report('remote_peek() failed')
77 endif
78 let g:peek_result = 'empty'
79 call WaitFor('remote_peek(g:myserverid, "g:peek_result") > 0')
Bram Moolenaar6caf6062017-03-18 20:45:05 +010080 call assert_equal('another', g:peek_result)
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +010081 call assert_equal('another', remote_read(g:myserverid, 2))
Bram Moolenaar6caf6062017-03-18 20:45:05 +010082
Bram Moolenaar15bf76d2017-03-18 16:18:37 +010083 call remote_send(name, ":qa!\<CR>")
84 call WaitFor('job_status(g:job) == "dead"')
85 if job_status(g:job) != 'dead'
Bram Moolenaar42205552017-03-18 19:42:22 +010086 call assert_report('Server did not exit')
Bram Moolenaar15bf76d2017-03-18 16:18:37 +010087 call job_stop(g:job, 'kill')
88 endif
89endfunc
90
91" Uncomment this line to get a debugging log
92" call ch_logfile('channellog', 'w')