annotate src/testdir/test_channel.vim @ 7965:646d5148fee2 v7.4.1278

commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Feb 7 16:53:13 2016 +0100 patch 7.4.1278 Problem: When jsonencode() fails it still returns something. Solution: Return an empty string on failure.
author Christian Brabandt <cb@256bit.org>
date Sun, 07 Feb 2016 17:00:05 +0100
parents b74549818500
children 5c30ba57aaea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Test for channel functions.
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 scriptencoding utf-8
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3
7922
14540239601d commit https://github.com/vim/vim/commit/e24692573a266f5060c06dd80bde264092c90dd5
Christian Brabandt <cb@256bit.org>
parents: 7918
diff changeset
4 if !has('channel')
14540239601d commit https://github.com/vim/vim/commit/e24692573a266f5060c06dd80bde264092c90dd5
Christian Brabandt <cb@256bit.org>
parents: 7918
diff changeset
5 finish
14540239601d commit https://github.com/vim/vim/commit/e24692573a266f5060c06dd80bde264092c90dd5
Christian Brabandt <cb@256bit.org>
parents: 7918
diff changeset
6 endif
14540239601d commit https://github.com/vim/vim/commit/e24692573a266f5060c06dd80bde264092c90dd5
Christian Brabandt <cb@256bit.org>
parents: 7918
diff changeset
7
14540239601d commit https://github.com/vim/vim/commit/e24692573a266f5060c06dd80bde264092c90dd5
Christian Brabandt <cb@256bit.org>
parents: 7918
diff changeset
8 " This test requires the Python command to run the test server.
7929
e44240b5a6da commit https://github.com/vim/vim/commit/a8343c1808f2f268282f3030ce4adaf22e8ade54
Christian Brabandt <cb@256bit.org>
parents: 7925
diff changeset
9 " This most likely only works on Unix and Windows.
7902
f12d6235a753 commit https://github.com/vim/vim/commit/a0f9cd148eaab23b2037d2f543f3b8f5a3a7ad3c
Christian Brabandt <cb@256bit.org>
parents: 7899
diff changeset
10 if has('unix')
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7939
diff changeset
11 " We also need the job feature or the pkill command to make sure the server
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7939
diff changeset
12 " can be stopped.
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7939
diff changeset
13 if !(executable('python') && (has('job') || executable('pkill')))
7902
f12d6235a753 commit https://github.com/vim/vim/commit/a0f9cd148eaab23b2037d2f543f3b8f5a3a7ad3c
Christian Brabandt <cb@256bit.org>
parents: 7899
diff changeset
14 finish
f12d6235a753 commit https://github.com/vim/vim/commit/a0f9cd148eaab23b2037d2f543f3b8f5a3a7ad3c
Christian Brabandt <cb@256bit.org>
parents: 7899
diff changeset
15 endif
7929
e44240b5a6da commit https://github.com/vim/vim/commit/a8343c1808f2f268282f3030ce4adaf22e8ade54
Christian Brabandt <cb@256bit.org>
parents: 7925
diff changeset
16 elseif has('win32')
7902
f12d6235a753 commit https://github.com/vim/vim/commit/a0f9cd148eaab23b2037d2f543f3b8f5a3a7ad3c
Christian Brabandt <cb@256bit.org>
parents: 7899
diff changeset
17 " Use Python Launcher for Windows (py.exe).
f12d6235a753 commit https://github.com/vim/vim/commit/a0f9cd148eaab23b2037d2f543f3b8f5a3a7ad3c
Christian Brabandt <cb@256bit.org>
parents: 7899
diff changeset
18 if !executable('py')
f12d6235a753 commit https://github.com/vim/vim/commit/a0f9cd148eaab23b2037d2f543f3b8f5a3a7ad3c
Christian Brabandt <cb@256bit.org>
parents: 7899
diff changeset
19 finish
f12d6235a753 commit https://github.com/vim/vim/commit/a0f9cd148eaab23b2037d2f543f3b8f5a3a7ad3c
Christian Brabandt <cb@256bit.org>
parents: 7899
diff changeset
20 endif
f12d6235a753 commit https://github.com/vim/vim/commit/a0f9cd148eaab23b2037d2f543f3b8f5a3a7ad3c
Christian Brabandt <cb@256bit.org>
parents: 7899
diff changeset
21 else
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 finish
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 endif
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24
7916
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
25 let s:port = -1
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
26
7902
f12d6235a753 commit https://github.com/vim/vim/commit/a0f9cd148eaab23b2037d2f543f3b8f5a3a7ad3c
Christian Brabandt <cb@256bit.org>
parents: 7899
diff changeset
27 func s:start_server()
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
28 " The Python program writes the port number in Xportnr.
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
29 call delete("Xportnr")
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
30
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7939
diff changeset
31 if has('job')
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7939
diff changeset
32 let s:job = job_start("python test_channel.py")
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7939
diff changeset
33 elseif has('win32')
7902
f12d6235a753 commit https://github.com/vim/vim/commit/a0f9cd148eaab23b2037d2f543f3b8f5a3a7ad3c
Christian Brabandt <cb@256bit.org>
parents: 7899
diff changeset
34 silent !start cmd /c start "test_channel" py test_channel.py
f12d6235a753 commit https://github.com/vim/vim/commit/a0f9cd148eaab23b2037d2f543f3b8f5a3a7ad3c
Christian Brabandt <cb@256bit.org>
parents: 7899
diff changeset
35 else
7904
14a5de0990a5 commit https://github.com/vim/vim/commit/f92591f7f9fc78d2aced99befe444cb423b26df8
Christian Brabandt <cb@256bit.org>
parents: 7902
diff changeset
36 silent !python test_channel.py&
7902
f12d6235a753 commit https://github.com/vim/vim/commit/a0f9cd148eaab23b2037d2f543f3b8f5a3a7ad3c
Christian Brabandt <cb@256bit.org>
parents: 7899
diff changeset
37 endif
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 " Wait for up to 2 seconds for the port number to be there.
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 let cnt = 20
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 let l = []
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 while cnt > 0
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 try
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 let l = readfile("Xportnr")
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 catch
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 endtry
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 if len(l) >= 1
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 break
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 endif
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 sleep 100m
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 let cnt -= 1
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 endwhile
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 call delete("Xportnr")
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 if len(l) == 0
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 " Can't make the connection, give up.
7902
f12d6235a753 commit https://github.com/vim/vim/commit/a0f9cd148eaab23b2037d2f543f3b8f5a3a7ad3c
Christian Brabandt <cb@256bit.org>
parents: 7899
diff changeset
57 call s:kill_server()
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
58 call assert_false(1, "Can't start test_channel.py")
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
59 return -1
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
60 endif
7916
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
61 let s:port = l[0]
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
62
7935
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
63 let handle = ch_open('localhost:' . s:port)
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
64 return handle
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
65 endfunc
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
66
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
67 func s:kill_server()
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7939
diff changeset
68 if has('job')
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7939
diff changeset
69 call job_stop(s:job)
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7939
diff changeset
70 elseif has('win32')
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
71 call system('taskkill /IM py.exe /T /F /FI "WINDOWTITLE eq test_channel"')
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
72 else
7914
35973ce58c84 commit https://github.com/vim/vim/commit/608a8919cae982cb38e38725a843df47b234dae6
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
73 call system("pkill -f test_channel.py")
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
74 endif
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
75 endfunc
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
76
7933
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
77 let s:responseHandle = -1
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
78 let s:responseMsg = ''
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
79 func s:RequestHandler(handle, msg)
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
80 let s:responseHandle = a:handle
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
81 let s:responseMsg = a:msg
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
82 endfunc
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
83
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
84 func Test_communicate()
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
85 let handle = s:start_server()
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
86 if handle < 0
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 return
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 endif
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90 " Simple string request and reply.
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 call assert_equal('got it', ch_sendexpr(handle, 'hello!'))
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 " Request that triggers sending two ex commands. These will usually be
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94 " handled before getting the response, but it's not guaranteed, thus wait a
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
95 " tiny bit for the commands to get executed.
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
96 call assert_equal('ok', ch_sendexpr(handle, 'make change'))
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
97 sleep 10m
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
98 call assert_equal('added1', getline(line('$') - 1))
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99 call assert_equal('added2', getline('$'))
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
101 call assert_equal('ok', ch_sendexpr(handle, 'do normal'))
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
102 sleep 10m
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
103 call assert_equal('added more', getline('$'))
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
104
7933
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
105 " Send a request with a specific handler.
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
106 call ch_sendexpr(handle, 'hello!', 's:RequestHandler')
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
107 sleep 10m
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
108 call assert_equal(handle, s:responseHandle)
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
109 call assert_equal('got it', s:responseMsg)
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
110
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
111 " Send an eval request that works.
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
112 call assert_equal('ok', ch_sendexpr(handle, 'eval-works'))
7925
b724dbb299d5 commit https://github.com/vim/vim/commit/a02b321686d9827ac806353ea8af780676da340d
Christian Brabandt <cb@256bit.org>
parents: 7922
diff changeset
113 sleep 10m
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
114 call assert_equal([-1, 'foo123'], ch_sendexpr(handle, 'eval-result'))
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
115
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
116 " Send an eval request that fails.
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
117 call assert_equal('ok', ch_sendexpr(handle, 'eval-fails'))
7925
b724dbb299d5 commit https://github.com/vim/vim/commit/a02b321686d9827ac806353ea8af780676da340d
Christian Brabandt <cb@256bit.org>
parents: 7922
diff changeset
118 sleep 10m
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
119 call assert_equal([-2, 'ERROR'], ch_sendexpr(handle, 'eval-result'))
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
120
7965
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7957
diff changeset
121 " Send an eval request that works but can't be encoded.
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7957
diff changeset
122 call assert_equal('ok', ch_sendexpr(handle, 'eval-error'))
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7957
diff changeset
123 sleep 10m
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7957
diff changeset
124 call assert_equal([-3, 'ERROR'], ch_sendexpr(handle, 'eval-result'))
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7957
diff changeset
125
7918
ce5a7a613867 commit https://github.com/vim/vim/commit/66624ff0d9e1de2fc5eb4f95f3a3a2ed70b10138
Christian Brabandt <cb@256bit.org>
parents: 7916
diff changeset
126 " Send a bad eval request. There will be no response.
ce5a7a613867 commit https://github.com/vim/vim/commit/66624ff0d9e1de2fc5eb4f95f3a3a2ed70b10138
Christian Brabandt <cb@256bit.org>
parents: 7916
diff changeset
127 call assert_equal('ok', ch_sendexpr(handle, 'eval-bad'))
7925
b724dbb299d5 commit https://github.com/vim/vim/commit/a02b321686d9827ac806353ea8af780676da340d
Christian Brabandt <cb@256bit.org>
parents: 7922
diff changeset
128 sleep 10m
7965
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7957
diff changeset
129 call assert_equal([-3, 'ERROR'], ch_sendexpr(handle, 'eval-result'))
7918
ce5a7a613867 commit https://github.com/vim/vim/commit/66624ff0d9e1de2fc5eb4f95f3a3a2ed70b10138
Christian Brabandt <cb@256bit.org>
parents: 7916
diff changeset
130
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
131 " Send an expr request
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
132 call assert_equal('ok', ch_sendexpr(handle, 'an expr'))
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
133 sleep 10m
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
134 call assert_equal('one', getline(line('$') - 2))
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
135 call assert_equal('two', getline(line('$') - 1))
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
136 call assert_equal('three', getline('$'))
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
137
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
138 " Request a redraw, we don't check for the effect.
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
139 call assert_equal('ok', ch_sendexpr(handle, 'redraw'))
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
140 call assert_equal('ok', ch_sendexpr(handle, 'redraw!'))
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
141
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
142 call assert_equal('ok', ch_sendexpr(handle, 'empty-request'))
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
143
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
144 " make the server quit, can't check if this works, should not hang.
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
145 call ch_sendexpr(handle, '!quit!', 0)
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
146
7902
f12d6235a753 commit https://github.com/vim/vim/commit/a0f9cd148eaab23b2037d2f543f3b8f5a3a7ad3c
Christian Brabandt <cb@256bit.org>
parents: 7899
diff changeset
147 call s:kill_server()
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
148 endfunc
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
149
7916
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
150 " Test that we can open two channels.
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
151 func Test_two_channels()
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
152 let handle = s:start_server()
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
153 if handle < 0
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
154 return
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
155 endif
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
156 call assert_equal('got it', ch_sendexpr(handle, 'hello!'))
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
157
7935
3f2e0b62003d commit https://github.com/vim/vim/commit/4d919d748e4e435edb135aa5ccf6ee7de9212023
Christian Brabandt <cb@256bit.org>
parents: 7933
diff changeset
158 let newhandle = ch_open('localhost:' . s:port)
7916
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
159 call assert_equal('got it', ch_sendexpr(newhandle, 'hello!'))
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
160 call assert_equal('got it', ch_sendexpr(handle, 'hello!'))
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
161
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
162 call ch_close(handle)
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
163 call assert_equal('got it', ch_sendexpr(newhandle, 'hello!'))
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
164
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
165 call s:kill_server()
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
166 endfunc
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
167
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
168 " Test that a server crash is handled gracefully.
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
169 func Test_server_crash()
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
170 let handle = s:start_server()
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
171 if handle < 0
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
172 return
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
173 endif
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
174 call ch_sendexpr(handle, '!crash!')
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
175
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
176 " kill the server in case if failed to crash
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
177 sleep 10m
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
178 call s:kill_server()
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
179 endfunc