blob: 0f403711d9b49bf2f8176f7e6863a858121f7552 [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 Moolenaara683ec42017-03-25 20:14:34 +010014 if has('x11')
15 if empty($DISPLAY)
16 throw 'Skipped: $DISPLAY is not set'
17 endif
Bram Moolenaara2845b82017-03-25 15:20:06 +010018 try
19 call remote_send('xxx', '')
20 catch
21 if v:exception =~ 'E240:'
Bram Moolenaara683ec42017-03-25 20:14:34 +010022 throw 'Skipped: no connection to the X server'
Bram Moolenaara2845b82017-03-25 15:20:06 +010023 endif
24 " ignore other errors
25 endtry
26 endif
Bram Moolenaar42205552017-03-18 19:42:22 +010027
Bram Moolenaar42205552017-03-18 19:42:22 +010028 let name = 'XVIMTEST'
Bram Moolenaar15bf76d2017-03-18 16:18:37 +010029 let cmd .= ' --servername ' . name
30 let g:job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
31 call WaitFor('job_status(g:job) == "run"')
32 if job_status(g:job) != 'run'
Bram Moolenaar42205552017-03-18 19:42:22 +010033 call assert_report('Cannot run the Vim server')
Bram Moolenaar15bf76d2017-03-18 16:18:37 +010034 return
35 endif
36
37 " Takes a short while for the server to be active.
38 call WaitFor('serverlist() =~ "' . name . '"')
39 call assert_match(name, serverlist())
40
41 call remote_foreground(name)
42
43 call remote_send(name, ":let testvar = 'yes'\<CR>")
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +010044 call WaitFor('remote_expr("' . name . '", "testvar", "", 1) == "yes"')
45 call assert_equal('yes', remote_expr(name, "testvar", "", 2))
Bram Moolenaar15bf76d2017-03-18 16:18:37 +010046
Bram Moolenaar7416f3e2017-03-18 18:10:13 +010047 if has('unix') && has('gui') && !has('gui_running')
Bram Moolenaar60964f62017-06-10 17:06:16 +020048 " Running in a terminal and the GUI is available: Tell the server to open
Bram Moolenaar7416f3e2017-03-18 18:10:13 +010049 " the GUI and check that the remote command still works.
50 " Need to wait for the GUI to start up, otherwise the send hangs in trying
51 " to send to the terminal window.
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +010052 if has('gui_athena') || has('gui_motif')
53 " For those GUIs, ignore the 'failed to create input context' error.
54 call remote_send(name, ":call test_ignore_error('E285') | gui -f\<CR>")
55 else
56 call remote_send(name, ":gui -f\<CR>")
57 endif
58 " Wait for the server to be up and answering requests.
Bram Moolenaar60964f62017-06-10 17:06:16 +020059 sleep 100m
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +010060 call WaitFor('remote_expr("' . name . '", "v:version", "", 1) != ""')
Bram Moolenaar60964f62017-06-10 17:06:16 +020061 call assert_true(remote_expr(name, "v:version", "", 1) != "")
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +010062
Bram Moolenaar7416f3e2017-03-18 18:10:13 +010063 call remote_send(name, ":let testvar = 'maybe'\<CR>")
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +010064 call WaitFor('remote_expr("' . name . '", "testvar", "", 1) == "maybe"')
65 call assert_equal('maybe', remote_expr(name, "testvar", "", 2))
Bram Moolenaar7416f3e2017-03-18 18:10:13 +010066 endif
67
68 call assert_fails('call remote_send("XXX", ":let testvar = ''yes''\<CR>")', 'E241')
69
70 " Expression evaluated locally.
71 if v:servername == ''
72 call remote_startserver('MYSELF')
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +010073 " May get MYSELF1 when running the test again.
74 call assert_match('MYSELF', v:servername)
Bram Moolenaar7416f3e2017-03-18 18:10:13 +010075 endif
76 let g:testvar = 'myself'
77 call assert_equal('myself', remote_expr(v:servername, 'testvar'))
78
79 call remote_send(name, ":call server2client(expand('<client>'), 'got it')\<CR>", 'g:myserverid')
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +010080 call assert_equal('got it', remote_read(g:myserverid, 2))
Bram Moolenaar7416f3e2017-03-18 18:10:13 +010081
Bram Moolenaar6caf6062017-03-18 20:45:05 +010082 call remote_send(name, ":call server2client(expand('<client>'), 'another')\<CR>", 'g:myserverid')
Bram Moolenaar6caf6062017-03-18 20:45:05 +010083 let peek_result = 'nothing'
84 let r = remote_peek(g:myserverid, 'peek_result')
Bram Moolenaar6caf6062017-03-18 20:45:05 +010085 " unpredictable whether the result is already avaialble.
86 if r > 0
87 call assert_equal('another', peek_result)
88 elseif r == 0
89 call assert_equal('nothing', peek_result)
90 else
91 call assert_report('remote_peek() failed')
92 endif
93 let g:peek_result = 'empty'
94 call WaitFor('remote_peek(g:myserverid, "g:peek_result") > 0')
Bram Moolenaar6caf6062017-03-18 20:45:05 +010095 call assert_equal('another', g:peek_result)
Bram Moolenaar81b9d0b2017-03-19 21:20:53 +010096 call assert_equal('another', remote_read(g:myserverid, 2))
Bram Moolenaar6caf6062017-03-18 20:45:05 +010097
Bram Moolenaar15bf76d2017-03-18 16:18:37 +010098 call remote_send(name, ":qa!\<CR>")
99 call WaitFor('job_status(g:job) == "dead"')
100 if job_status(g:job) != 'dead'
Bram Moolenaar42205552017-03-18 19:42:22 +0100101 call assert_report('Server did not exit')
Bram Moolenaar15bf76d2017-03-18 16:18:37 +0100102 call job_stop(g:job, 'kill')
103 endif
104endfunc
105
106" Uncomment this line to get a debugging log
107" call ch_logfile('channellog', 'w')