summaryrefslogtreecommitdiffstats
path: root/src/testdir/test_clientserver.vim
blob: 55f440ffc20f9361b3e81033f73fc3367aef1e63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
" Tests for the +clientserver feature.

if !has('job') || !has('clientserver')
  finish
endif

source shared.vim

func Test_client_server()
  let cmd = GetVimCommand()
  if cmd == ''
    return
  endif
  let name = 'XVIMTEXT'
  let cmd .= ' --servername ' . name
  let g:job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
  call WaitFor('job_status(g:job) == "run"')
  if job_status(g:job) != 'run'
    call assert_true(0, 'Cannot run the Vim server')
    return
  endif

  " Takes a short while for the server to be active.
  call WaitFor('serverlist() =~ "' . name . '"')
  call assert_match(name, serverlist())

  call remote_foreground(name)

  call remote_send(name, ":let testvar = 'yes'\<CR>")
  call WaitFor('remote_expr("' . name . '", "testvar") == "yes"')
  call assert_equal('yes', remote_expr(name, "testvar"))

  if has('unix') && has('gui') && !has('gui_running')
    " Running in a terminal and the GUI is avaiable: Tell the server to open
    " the GUI and check that the remote command still works.
    " Need to wait for the GUI to start up, otherwise the send hangs in trying
    " to send to the terminal window.
    call remote_send(name, ":gui -f\<CR>")
    sleep 500m
    call remote_send(name, ":let testvar = 'maybe'\<CR>")
    call WaitFor('remote_expr("' . name . '", "testvar") == "maybe"')
    call assert_equal('maybe', remote_expr(name, "testvar"))
  endif

  call assert_fails('call remote_send("XXX", ":let testvar = ''yes''\<CR>")', 'E241')

  " Expression evaluated locally.
  if v:servername == ''
    call remote_startserver('MYSELF')
    call assert_equal('MYSELF', v:servername)
  endif
  let g:testvar = 'myself'
  call assert_equal('myself', remote_expr(v:servername, 'testvar'))

  call remote_send(name, ":call server2client(expand('<client>'), 'got it')\<CR>", 'g:myserverid')
  call assert_equal('got it', remote_read(g:myserverid))

  call remote_send(name, ":qa!\<CR>")
  call WaitFor('job_status(g:job) == "dead"')
  if job_status(g:job) != 'dead'
    call assert_true(0, 'Server did not exit')
    call job_stop(g:job, 'kill')
  endif
endfunc

" Uncomment this line to get a debugging log
" call ch_logfile('channellog', 'w')