annotate src/testdir/test_clientserver.vim @ 12746:27eee6528b3d v8.0.1251

patch 8.0.1251: invalid expressin passed to WaitFor() commit https://github.com/vim/vim/commit/d97fbf171ec0e63117813da045d2a1c51a9b6f62 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Nov 2 19:23:03 2017 +0100 patch 8.0.1251: invalid expressin passed to WaitFor() Problem: Invalid expressin passed to WaitFor(). Solution: Check if the variable exists.
author Christian Brabandt <cb@256bit.org>
date Thu, 02 Nov 2017 19:30:06 +0100
parents 6ef5e636f246
children c1347c968d31
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11175
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Tests for the +clientserver feature.
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 if !has('job') || !has('clientserver')
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 finish
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 endif
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 source shared.vim
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 func Test_client_server()
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 let cmd = GetVimCommand()
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 if cmd == ''
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 return
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 endif
11250
ca5550f66b27 patch 8.0.0511: message for skipping client-server tests is unclear
Christian Brabandt <cb@256bit.org>
parents: 11242
diff changeset
14 if has('x11')
ca5550f66b27 patch 8.0.0511: message for skipping client-server tests is unclear
Christian Brabandt <cb@256bit.org>
parents: 11242
diff changeset
15 if empty($DISPLAY)
ca5550f66b27 patch 8.0.0511: message for skipping client-server tests is unclear
Christian Brabandt <cb@256bit.org>
parents: 11242
diff changeset
16 throw 'Skipped: $DISPLAY is not set'
ca5550f66b27 patch 8.0.0511: message for skipping client-server tests is unclear
Christian Brabandt <cb@256bit.org>
parents: 11242
diff changeset
17 endif
11242
9612b93820a4 patch 8.0.0507: client-server tests fail when $DISPLAY is not set
Christian Brabandt <cb@256bit.org>
parents: 11211
diff changeset
18 try
9612b93820a4 patch 8.0.0507: client-server tests fail when $DISPLAY is not set
Christian Brabandt <cb@256bit.org>
parents: 11211
diff changeset
19 call remote_send('xxx', '')
9612b93820a4 patch 8.0.0507: client-server tests fail when $DISPLAY is not set
Christian Brabandt <cb@256bit.org>
parents: 11211
diff changeset
20 catch
9612b93820a4 patch 8.0.0507: client-server tests fail when $DISPLAY is not set
Christian Brabandt <cb@256bit.org>
parents: 11211
diff changeset
21 if v:exception =~ 'E240:'
11250
ca5550f66b27 patch 8.0.0511: message for skipping client-server tests is unclear
Christian Brabandt <cb@256bit.org>
parents: 11242
diff changeset
22 throw 'Skipped: no connection to the X server'
11242
9612b93820a4 patch 8.0.0507: client-server tests fail when $DISPLAY is not set
Christian Brabandt <cb@256bit.org>
parents: 11211
diff changeset
23 endif
9612b93820a4 patch 8.0.0507: client-server tests fail when $DISPLAY is not set
Christian Brabandt <cb@256bit.org>
parents: 11211
diff changeset
24 " ignore other errors
9612b93820a4 patch 8.0.0507: client-server tests fail when $DISPLAY is not set
Christian Brabandt <cb@256bit.org>
parents: 11211
diff changeset
25 endtry
9612b93820a4 patch 8.0.0507: client-server tests fail when $DISPLAY is not set
Christian Brabandt <cb@256bit.org>
parents: 11211
diff changeset
26 endif
11181
13544aa85dc0 patch 8.0.0477: the client-server test may hang when failing
Christian Brabandt <cb@256bit.org>
parents: 11177
diff changeset
27
13544aa85dc0 patch 8.0.0477: the client-server test may hang when failing
Christian Brabandt <cb@256bit.org>
parents: 11177
diff changeset
28 let name = 'XVIMTEST'
11175
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 let cmd .= ' --servername ' . name
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 let g:job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 call WaitFor('job_status(g:job) == "run"')
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 if job_status(g:job) != 'run'
11181
13544aa85dc0 patch 8.0.0477: the client-server test may hang when failing
Christian Brabandt <cb@256bit.org>
parents: 11177
diff changeset
33 call assert_report('Cannot run the Vim server')
11175
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 return
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 endif
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 " Takes a short while for the server to be active.
12405
6ef5e636f246 patch 8.0.1082: tests fail when run under valgrind
Christian Brabandt <cb@256bit.org>
parents: 11500
diff changeset
38 " When using valgrind it takes much longer.
6ef5e636f246 patch 8.0.1082: tests fail when run under valgrind
Christian Brabandt <cb@256bit.org>
parents: 11500
diff changeset
39 call WaitFor('serverlist() =~ "' . name . '"', 5000)
11175
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 call assert_match(name, serverlist())
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 call remote_foreground(name)
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 call remote_send(name, ":let testvar = 'yes'\<CR>")
12746
27eee6528b3d patch 8.0.1251: invalid expressin passed to WaitFor()
Christian Brabandt <cb@256bit.org>
parents: 12405
diff changeset
45 call WaitFor('remote_expr("' . name . '", "exists(\"testvar\") ? testvar : \"\"", "", 1) == "yes"')
11211
71311d899b42 patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents: 11185
diff changeset
46 call assert_equal('yes', remote_expr(name, "testvar", "", 2))
11175
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47
11177
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
48 if has('unix') && has('gui') && !has('gui_running')
11500
f0d050a452c5 patch 8.0.0633: the client-server test is still a bit flaky
Christian Brabandt <cb@256bit.org>
parents: 11250
diff changeset
49 " Running in a terminal and the GUI is available: Tell the server to open
11177
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
50 " the GUI and check that the remote command still works.
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
51 " Need to wait for the GUI to start up, otherwise the send hangs in trying
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
52 " to send to the terminal window.
11211
71311d899b42 patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents: 11185
diff changeset
53 if has('gui_athena') || has('gui_motif')
71311d899b42 patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents: 11185
diff changeset
54 " For those GUIs, ignore the 'failed to create input context' error.
71311d899b42 patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents: 11185
diff changeset
55 call remote_send(name, ":call test_ignore_error('E285') | gui -f\<CR>")
71311d899b42 patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents: 11185
diff changeset
56 else
71311d899b42 patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents: 11185
diff changeset
57 call remote_send(name, ":gui -f\<CR>")
71311d899b42 patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents: 11185
diff changeset
58 endif
71311d899b42 patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents: 11185
diff changeset
59 " Wait for the server to be up and answering requests.
11500
f0d050a452c5 patch 8.0.0633: the client-server test is still a bit flaky
Christian Brabandt <cb@256bit.org>
parents: 11250
diff changeset
60 sleep 100m
11211
71311d899b42 patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents: 11185
diff changeset
61 call WaitFor('remote_expr("' . name . '", "v:version", "", 1) != ""')
11500
f0d050a452c5 patch 8.0.0633: the client-server test is still a bit flaky
Christian Brabandt <cb@256bit.org>
parents: 11250
diff changeset
62 call assert_true(remote_expr(name, "v:version", "", 1) != "")
11211
71311d899b42 patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents: 11185
diff changeset
63
11177
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
64 call remote_send(name, ":let testvar = 'maybe'\<CR>")
11211
71311d899b42 patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents: 11185
diff changeset
65 call WaitFor('remote_expr("' . name . '", "testvar", "", 1) == "maybe"')
71311d899b42 patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents: 11185
diff changeset
66 call assert_equal('maybe', remote_expr(name, "testvar", "", 2))
11177
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
67 endif
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
68
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
69 call assert_fails('call remote_send("XXX", ":let testvar = ''yes''\<CR>")', 'E241')
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
70
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
71 " Expression evaluated locally.
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
72 if v:servername == ''
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
73 call remote_startserver('MYSELF')
11211
71311d899b42 patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents: 11185
diff changeset
74 " May get MYSELF1 when running the test again.
71311d899b42 patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents: 11185
diff changeset
75 call assert_match('MYSELF', v:servername)
11177
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
76 endif
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
77 let g:testvar = 'myself'
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
78 call assert_equal('myself', remote_expr(v:servername, 'testvar'))
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
79
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
80 call remote_send(name, ":call server2client(expand('<client>'), 'got it')\<CR>", 'g:myserverid')
11211
71311d899b42 patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents: 11185
diff changeset
81 call assert_equal('got it', remote_read(g:myserverid, 2))
11177
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
82
11185
eb050472e4b4 patch 8.0.0479: remote_peek() is not tested
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
83 call remote_send(name, ":call server2client(expand('<client>'), 'another')\<CR>", 'g:myserverid')
eb050472e4b4 patch 8.0.0479: remote_peek() is not tested
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
84 let peek_result = 'nothing'
eb050472e4b4 patch 8.0.0479: remote_peek() is not tested
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
85 let r = remote_peek(g:myserverid, 'peek_result')
eb050472e4b4 patch 8.0.0479: remote_peek() is not tested
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
86 " unpredictable whether the result is already avaialble.
eb050472e4b4 patch 8.0.0479: remote_peek() is not tested
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
87 if r > 0
eb050472e4b4 patch 8.0.0479: remote_peek() is not tested
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
88 call assert_equal('another', peek_result)
eb050472e4b4 patch 8.0.0479: remote_peek() is not tested
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
89 elseif r == 0
eb050472e4b4 patch 8.0.0479: remote_peek() is not tested
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
90 call assert_equal('nothing', peek_result)
eb050472e4b4 patch 8.0.0479: remote_peek() is not tested
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
91 else
eb050472e4b4 patch 8.0.0479: remote_peek() is not tested
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
92 call assert_report('remote_peek() failed')
eb050472e4b4 patch 8.0.0479: remote_peek() is not tested
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
93 endif
eb050472e4b4 patch 8.0.0479: remote_peek() is not tested
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
94 let g:peek_result = 'empty'
eb050472e4b4 patch 8.0.0479: remote_peek() is not tested
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
95 call WaitFor('remote_peek(g:myserverid, "g:peek_result") > 0')
eb050472e4b4 patch 8.0.0479: remote_peek() is not tested
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
96 call assert_equal('another', g:peek_result)
11211
71311d899b42 patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents: 11185
diff changeset
97 call assert_equal('another', remote_read(g:myserverid, 2))
11185
eb050472e4b4 patch 8.0.0479: remote_peek() is not tested
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
98
11175
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99 call remote_send(name, ":qa!\<CR>")
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100 call WaitFor('job_status(g:job) == "dead"')
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101 if job_status(g:job) != 'dead'
11181
13544aa85dc0 patch 8.0.0477: the client-server test may hang when failing
Christian Brabandt <cb@256bit.org>
parents: 11177
diff changeset
102 call assert_report('Server did not exit')
11175
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
103 call job_stop(g:job, 'kill')
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
104 endif
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
105 endfunc
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
106
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107 " Uncomment this line to get a debugging log
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108 " call ch_logfile('channellog', 'w')