1" 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 if has('x11') 15 if empty($DISPLAY) 16 throw 'Skipped: $DISPLAY is not set' 17 endif 18 try 19 call remote_send('xxx', '') 20 catch 21 if v:exception =~ 'E240:' 22 throw 'Skipped: no connection to the X server' 23 endif 24 " ignore other errors 25 endtry 26 endif 27 28 let name = 'XVIMTEST' 29 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' 33 call assert_report('Cannot run the Vim server') 34 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>") 44 call WaitFor('remote_expr("' . name . '", "testvar", "", 1) == "yes"') 45 call assert_equal('yes', remote_expr(name, "testvar", "", 2)) 46 47 if has('unix') && has('gui') && !has('gui_running') 48 " Running in a terminal and the GUI is available: Tell the server to open 49 " 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. 52 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. 59 sleep 100m 60 call WaitFor('remote_expr("' . name . '", "v:version", "", 1) != ""') 61 call assert_true(remote_expr(name, "v:version", "", 1) != "") 62 63 call remote_send(name, ":let testvar = 'maybe'\<CR>") 64 call WaitFor('remote_expr("' . name . '", "testvar", "", 1) == "maybe"') 65 call assert_equal('maybe', remote_expr(name, "testvar", "", 2)) 66 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') 73 " May get MYSELF1 when running the test again. 74 call assert_match('MYSELF', v:servername) 75 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') 80 call assert_equal('got it', remote_read(g:myserverid, 2)) 81 82 call remote_send(name, ":call server2client(expand('<client>'), 'another')\<CR>", 'g:myserverid') 83 let peek_result = 'nothing' 84 let r = remote_peek(g:myserverid, 'peek_result') 85 " 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') 95 call assert_equal('another', g:peek_result) 96 call assert_equal('another', remote_read(g:myserverid, 2)) 97 98 call remote_send(name, ":qa!\<CR>") 99 call WaitFor('job_status(g:job) == "dead"') 100 if job_status(g:job) != 'dead' 101 call assert_report('Server did not exit') 102 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') 108