annotate src/testdir/test_clientserver.vim @ 19852:12518b40c161 v8.2.0482

patch 8.2.0482: channel and sandbox code not sufficiently tested Commit: https://github.com/vim/vim/commit/ca68ae13114619df3e4c195b41ad0575516f5ff6 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Mar 30 19:32:53 2020 +0200 patch 8.2.0482: channel and sandbox code not sufficiently tested Problem: Channel and sandbox code not sufficiently tested. Solution: Add more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5855)
author Bram Moolenaar <Bram@vim.org>
date Mon, 30 Mar 2020 19:45:05 +0200
parents 546bdeef35f1
children 031184ace7c5
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
17657
0da9bc55c31a patch 8.1.1826: tests use hand coded feature and option checks
Bram Moolenaar <Bram@vim.org>
parents: 16965
diff changeset
3 source check.vim
0da9bc55c31a patch 8.1.1826: tests use hand coded feature and option checks
Bram Moolenaar <Bram@vim.org>
parents: 16965
diff changeset
4 CheckFeature job
0da9bc55c31a patch 8.1.1826: tests use hand coded feature and option checks
Bram Moolenaar <Bram@vim.org>
parents: 16965
diff changeset
5 CheckFeature clientserver
11175
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
12765
c1347c968d31 patch 8.0.1260: using global variables for WaitFor()
Christian Brabandt <cb@256bit.org>
parents: 12746
diff changeset
30 let job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
13798
415185e2c970 patch 8.0.1771: in tests, when WaitFor() fails it doesn't say why
Christian Brabandt <cb@256bit.org>
parents: 13650
diff changeset
31 call WaitForAssert({-> assert_equal("run", job_status(job))})
11175
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 " 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
34 " When using valgrind it takes much longer.
13798
415185e2c970 patch 8.0.1771: in tests, when WaitFor() fails it doesn't say why
Christian Brabandt <cb@256bit.org>
parents: 13650
diff changeset
35 call WaitForAssert({-> assert_match(name, serverlist())})
11175
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36
17982
2029737e6a22 patch 8.1.1987: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17657
diff changeset
37 eval name->remote_foreground()
11175
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 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
40 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
41 call assert_equal('yes', remote_expr(name, "testvar", "", 2))
19852
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
42 call assert_fails("let x=remote_expr(name, '2+x')", 'E449:')
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
43 call assert_fails("let x=remote_expr('[], '2+2')", 'E116:')
11175
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44
11177
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
45 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
46 " 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
47 " 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
48 " 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
49 " 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
50 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
51 " 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
52 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
53 else
71311d899b42 patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents: 11185
diff changeset
54 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
55 endif
71311d899b42 patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents: 11185
diff changeset
56 " 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
57 sleep 100m
17982
2029737e6a22 patch 8.1.1987: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17657
diff changeset
58 call WaitForAssert({-> assert_true(name->remote_expr("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
59
11177
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
60 call remote_send(name, ":let testvar = 'maybe'\<CR>")
13798
415185e2c970 patch 8.0.1771: in tests, when WaitFor() fails it doesn't say why
Christian Brabandt <cb@256bit.org>
parents: 13650
diff changeset
61 call WaitForAssert({-> 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
62 endif
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
63
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
64 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
65
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
66 " 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
67 if v:servername == ''
17982
2029737e6a22 patch 8.1.1987: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17657
diff changeset
68 eval 'MYSELF'->remote_startserver()
11211
71311d899b42 patch 8.0.0492: a failing client-server request can make Vim hang
Christian Brabandt <cb@256bit.org>
parents: 11185
diff changeset
69 " 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
70 call assert_match('MYSELF', v:servername)
19852
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
71 call assert_fails("call remote_startserver('MYSELF')", 'E941:')
11177
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
72 endif
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
73 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
74 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
75
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
76 call remote_send(name, ":call server2client(expand('<client>'), 'got it')\<CR>", 'g:myserverid')
17982
2029737e6a22 patch 8.1.1987: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17657
diff changeset
77 call assert_equal('got it', g:myserverid->remote_read(2))
11177
76fb679a310e patch 8.0.0475: not enough testing for the client-server feature
Christian Brabandt <cb@256bit.org>
parents: 11175
diff changeset
78
17994
0dcc2ee838dd patch 8.1.1993: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17982
diff changeset
79 call remote_send(name, ":eval expand('<client>')->server2client('another')\<CR>", 'g:myserverid')
11185
eb050472e4b4 patch 8.0.0479: remote_peek() is not tested
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
80 let peek_result = 'nothing'
17982
2029737e6a22 patch 8.1.1987: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17657
diff changeset
81 let r = g:myserverid->remote_peek('peek_result')
12765
c1347c968d31 patch 8.0.1260: using global variables for WaitFor()
Christian Brabandt <cb@256bit.org>
parents: 12746
diff changeset
82 " unpredictable whether the result is already available.
11185
eb050472e4b4 patch 8.0.0479: remote_peek() is not tested
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
83 if r > 0
eb050472e4b4 patch 8.0.0479: remote_peek() is not tested
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
84 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
85 elseif r == 0
eb050472e4b4 patch 8.0.0479: remote_peek() is not tested
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
86 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
87 else
eb050472e4b4 patch 8.0.0479: remote_peek() is not tested
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
88 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
89 endif
eb050472e4b4 patch 8.0.0479: remote_peek() is not tested
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
90 let g:peek_result = 'empty'
eb050472e4b4 patch 8.0.0479: remote_peek() is not tested
Christian Brabandt <cb@256bit.org>
parents: 11181
diff changeset
91 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
92 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
93 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
94
17982
2029737e6a22 patch 8.1.1987: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17657
diff changeset
95 eval name->remote_send(":qa!\<CR>")
12765
c1347c968d31 patch 8.0.1260: using global variables for WaitFor()
Christian Brabandt <cb@256bit.org>
parents: 12746
diff changeset
96 try
13798
415185e2c970 patch 8.0.1771: in tests, when WaitFor() fails it doesn't say why
Christian Brabandt <cb@256bit.org>
parents: 13650
diff changeset
97 call WaitForAssert({-> assert_equal("dead", job_status(job))})
12765
c1347c968d31 patch 8.0.1260: using global variables for WaitFor()
Christian Brabandt <cb@256bit.org>
parents: 12746
diff changeset
98 finally
c1347c968d31 patch 8.0.1260: using global variables for WaitFor()
Christian Brabandt <cb@256bit.org>
parents: 12746
diff changeset
99 if job_status(job) != 'dead'
c1347c968d31 patch 8.0.1260: using global variables for WaitFor()
Christian Brabandt <cb@256bit.org>
parents: 12746
diff changeset
100 call assert_report('Server did not exit')
c1347c968d31 patch 8.0.1260: using global variables for WaitFor()
Christian Brabandt <cb@256bit.org>
parents: 12746
diff changeset
101 call job_stop(job, 'kill')
c1347c968d31 patch 8.0.1260: using global variables for WaitFor()
Christian Brabandt <cb@256bit.org>
parents: 12746
diff changeset
102 endif
c1347c968d31 patch 8.0.1260: using global variables for WaitFor()
Christian Brabandt <cb@256bit.org>
parents: 12746
diff changeset
103 endtry
19783
546bdeef35f1 patch 8.2.0448: various functions not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 17994
diff changeset
104
546bdeef35f1 patch 8.2.0448: various functions not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 17994
diff changeset
105 call assert_fails("let x=remote_peek([])", 'E730:')
19852
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
106 call assert_fails("let x=remote_read('vim10')", 'E277:')
11175
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107 endfunc
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108
9836b701afd9 patch 8.0.0474: the client-server feature is not tested
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109 " 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
110 " call ch_logfile('channellog', 'w')
19783
546bdeef35f1 patch 8.2.0448: various functions not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 17994
diff changeset
111
546bdeef35f1 patch 8.2.0448: various functions not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 17994
diff changeset
112 " vim: shiftwidth=2 sts=2 expandtab