annotate src/testdir/test_channel.vim @ 8426:02ce040591c8 v7.4.1504

commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c Author: Bram Moolenaar <Bram@vim.org> Date: Sun Mar 6 21:35:57 2016 +0100 patch 7.4.1504 Problem: No test for reading last-but-one line. Solution: Add a test.
author Christian Brabandt <cb@256bit.org>
date Sun, 06 Mar 2016 21:45:05 +0100
parents be45d4921f1f
children 800423dbc260
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
8066
1aa8ed4ee48b commit https://github.com/vim/vim/commit/b6a7737938e7e7b34f862f58aa5498e6f652e33d
Christian Brabandt <cb@256bit.org>
parents: 8059
diff changeset
16 let s:python = 'python'
7929
e44240b5a6da commit https://github.com/vim/vim/commit/a8343c1808f2f268282f3030ce4adaf22e8ade54
Christian Brabandt <cb@256bit.org>
parents: 7925
diff changeset
17 elseif has('win32')
8066
1aa8ed4ee48b commit https://github.com/vim/vim/commit/b6a7737938e7e7b34f862f58aa5498e6f652e33d
Christian Brabandt <cb@256bit.org>
parents: 8059
diff changeset
18 " Use Python Launcher for Windows (py.exe) if available.
1aa8ed4ee48b commit https://github.com/vim/vim/commit/b6a7737938e7e7b34f862f58aa5498e6f652e33d
Christian Brabandt <cb@256bit.org>
parents: 8059
diff changeset
19 if executable('py.exe')
1aa8ed4ee48b commit https://github.com/vim/vim/commit/b6a7737938e7e7b34f862f58aa5498e6f652e33d
Christian Brabandt <cb@256bit.org>
parents: 8059
diff changeset
20 let s:python = 'py.exe'
1aa8ed4ee48b commit https://github.com/vim/vim/commit/b6a7737938e7e7b34f862f58aa5498e6f652e33d
Christian Brabandt <cb@256bit.org>
parents: 8059
diff changeset
21 elseif executable('python.exe')
1aa8ed4ee48b commit https://github.com/vim/vim/commit/b6a7737938e7e7b34f862f58aa5498e6f652e33d
Christian Brabandt <cb@256bit.org>
parents: 8059
diff changeset
22 let s:python = 'python.exe'
1aa8ed4ee48b commit https://github.com/vim/vim/commit/b6a7737938e7e7b34f862f58aa5498e6f652e33d
Christian Brabandt <cb@256bit.org>
parents: 8059
diff changeset
23 else
7902
f12d6235a753 commit https://github.com/vim/vim/commit/a0f9cd148eaab23b2037d2f543f3b8f5a3a7ad3c
Christian Brabandt <cb@256bit.org>
parents: 7899
diff changeset
24 finish
f12d6235a753 commit https://github.com/vim/vim/commit/a0f9cd148eaab23b2037d2f543f3b8f5a3a7ad3c
Christian Brabandt <cb@256bit.org>
parents: 7899
diff changeset
25 endif
f12d6235a753 commit https://github.com/vim/vim/commit/a0f9cd148eaab23b2037d2f543f3b8f5a3a7ad3c
Christian Brabandt <cb@256bit.org>
parents: 7899
diff changeset
26 else
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
27 " Can't run this test.
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 finish
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 endif
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30
8096
882ba5080c5c commit https://github.com/vim/vim/commit/e74e8e7d758e9312165a931f176185f07a64231a
Christian Brabandt <cb@256bit.org>
parents: 8094
diff changeset
31 let s:chopt = {}
7916
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
32
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
33 " Run "testfunc" after sarting the server and stop the server afterwards.
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
34 func s:run_server(testfunc, ...)
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
35 " 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
36 call delete("Xportnr")
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
37
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
38 if a:0 == 1
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
39 let arg = ' ' . a:1
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
40 else
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
41 let arg = ''
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
42 endif
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
43 let cmd = s:python . " test_channel.py" . arg
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
44
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
45 try
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
46 if has('job')
8170
a0ffb1f3dedc commit https://github.com/vim/vim/commit/65edff8f51e9e54f85407bdb9156ae8e3e1b76a1
Christian Brabandt <cb@256bit.org>
parents: 8168
diff changeset
47 let s:job = job_start(cmd, {"stoponexit": "hup"})
a0ffb1f3dedc commit https://github.com/vim/vim/commit/65edff8f51e9e54f85407bdb9156ae8e3e1b76a1
Christian Brabandt <cb@256bit.org>
parents: 8168
diff changeset
48 call job_setoptions(s:job, {"stoponexit": "kill"})
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
49 elseif has('win32')
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
50 exe 'silent !start cmd /c start "test_channel" ' . cmd
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
51 else
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
52 exe 'silent !' . cmd . '&'
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
53 endif
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
55 " Wait for up to 2 seconds for the port number to be there.
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
56 let cnt = 20
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
57 let l = []
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
58 while cnt > 0
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
59 try
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
60 let l = readfile("Xportnr")
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
61 catch
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
62 endtry
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
63 if len(l) >= 1
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
64 break
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
65 endif
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
66 sleep 100m
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
67 let cnt -= 1
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
68 endwhile
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
69 call delete("Xportnr")
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
70
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
71 if len(l) == 0
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
72 " Can't make the connection, give up.
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
73 call assert_false(1, "Can't start test_channel.py")
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
74 return -1
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75 endif
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
76 let port = l[0]
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
78 call call(function(a:testfunc), [port])
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
79 catch
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
80 call assert_false(1, "Caught exception: " . v:exception)
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
81 finally
7902
f12d6235a753 commit https://github.com/vim/vim/commit/a0f9cd148eaab23b2037d2f543f3b8f5a3a7ad3c
Christian Brabandt <cb@256bit.org>
parents: 7899
diff changeset
82 call s:kill_server()
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
83 endtry
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
84 endfunc
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
85
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
86 func s:kill_server()
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7939
diff changeset
87 if has('job')
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
88 if exists('s:job')
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
89 call job_stop(s:job)
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
90 unlet s:job
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
91 endif
7957
b74549818500 commit https://github.com/vim/vim/commit/835dc636a5350f610b62f110227d2363b5b2880a
Christian Brabandt <cb@256bit.org>
parents: 7939
diff changeset
92 elseif has('win32')
8066
1aa8ed4ee48b commit https://github.com/vim/vim/commit/b6a7737938e7e7b34f862f58aa5498e6f652e33d
Christian Brabandt <cb@256bit.org>
parents: 8059
diff changeset
93 call system('taskkill /IM ' . s:python . ' /T /F /FI "WINDOWTITLE eq test_channel"')
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
94 else
7914
35973ce58c84 commit https://github.com/vim/vim/commit/608a8919cae982cb38e38725a843df47b234dae6
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
95 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
96 endif
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
97 endfunc
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
98
7933
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
99 let s:responseMsg = ''
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
100 func s:RequestHandler(handle, msg)
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
101 let s:responseHandle = a:handle
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
102 let s:responseMsg = a:msg
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
103 endfunc
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
104
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
105 func s:communicate(port)
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
106 let handle = ch_open('localhost:' . a:port, s:chopt)
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8037
diff changeset
107 if ch_status(handle) == "fail"
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
108 call assert_false(1, "Can't open channel")
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109 return
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
110 endif
8424
be45d4921f1f commit https://github.com/vim/vim/commit/839fd11d7ed1a96bace3159c4d1861658864aae3
Christian Brabandt <cb@256bit.org>
parents: 8420
diff changeset
111 if has('job')
be45d4921f1f commit https://github.com/vim/vim/commit/839fd11d7ed1a96bace3159c4d1861658864aae3
Christian Brabandt <cb@256bit.org>
parents: 8420
diff changeset
112 " check that no job is handled correctly
be45d4921f1f commit https://github.com/vim/vim/commit/839fd11d7ed1a96bace3159c4d1861658864aae3
Christian Brabandt <cb@256bit.org>
parents: 8420
diff changeset
113 call assert_equal('no process', string(ch_getjob(handle)))
be45d4921f1f commit https://github.com/vim/vim/commit/839fd11d7ed1a96bace3159c4d1861658864aae3
Christian Brabandt <cb@256bit.org>
parents: 8420
diff changeset
114 endif
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
115
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
116 " Simple string request and reply.
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
117 call assert_equal('got it', ch_evalexpr(handle, 'hello!'))
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
118
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
119 " 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
120 " 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
121 " tiny bit for the commands to get executed.
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
122 call assert_equal('ok', ch_evalexpr(handle, 'make change'))
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
123 sleep 10m
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
124 call assert_equal('added1', getline(line('$') - 1))
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
125 call assert_equal('added2', getline('$'))
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
126
8380
892d7dcf17ec commit https://github.com/vim/vim/commit/da94fdf2588b3910d38e477a755748ce2c6d2e66
Christian Brabandt <cb@256bit.org>
parents: 8346
diff changeset
127 call assert_equal('ok', ch_evalexpr(handle, 'do normal', {'timeout': 100}))
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
128 sleep 10m
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
129 call assert_equal('added more', getline('$'))
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
130
7933
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
131 " Send a request with a specific handler.
8094
18a3f0f05244 commit https://github.com/vim/vim/commit/910b8aac5dc4693c4508b7acd2cef0bbfac04242
Christian Brabandt <cb@256bit.org>
parents: 8084
diff changeset
132 call ch_sendexpr(handle, 'hello!', {'callback': 's:RequestHandler'})
7933
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
133 sleep 10m
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8037
diff changeset
134 if !exists('s:responseHandle')
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8037
diff changeset
135 call assert_false(1, 's:responseHandle was not set')
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8037
diff changeset
136 else
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8037
diff changeset
137 call assert_equal(handle, s:responseHandle)
8222
4f0677020a43 commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
138 unlet s:responseHandle
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8037
diff changeset
139 endif
7933
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
140 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
141
8017
c59a65524084 commit https://github.com/vim/vim/commit/b6a4fee37ebbb0c76f2fbda7d06cbf48a3a07e8d
Christian Brabandt <cb@256bit.org>
parents: 8013
diff changeset
142 let s:responseMsg = ''
8094
18a3f0f05244 commit https://github.com/vim/vim/commit/910b8aac5dc4693c4508b7acd2cef0bbfac04242
Christian Brabandt <cb@256bit.org>
parents: 8084
diff changeset
143 call ch_sendexpr(handle, 'hello!', {'callback': function('s:RequestHandler')})
8017
c59a65524084 commit https://github.com/vim/vim/commit/b6a4fee37ebbb0c76f2fbda7d06cbf48a3a07e8d
Christian Brabandt <cb@256bit.org>
parents: 8013
diff changeset
144 sleep 10m
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8037
diff changeset
145 if !exists('s:responseHandle')
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8037
diff changeset
146 call assert_false(1, 's:responseHandle was not set')
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8037
diff changeset
147 else
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8037
diff changeset
148 call assert_equal(handle, s:responseHandle)
8222
4f0677020a43 commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
149 unlet s:responseHandle
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8037
diff changeset
150 endif
8017
c59a65524084 commit https://github.com/vim/vim/commit/b6a4fee37ebbb0c76f2fbda7d06cbf48a3a07e8d
Christian Brabandt <cb@256bit.org>
parents: 8013
diff changeset
151 call assert_equal('got it', s:responseMsg)
c59a65524084 commit https://github.com/vim/vim/commit/b6a4fee37ebbb0c76f2fbda7d06cbf48a3a07e8d
Christian Brabandt <cb@256bit.org>
parents: 8013
diff changeset
152
8420
f6d21a33d489 commit https://github.com/vim/vim/commit/38fd4bb2842df7634823b99c655b3896a7a2e988
Christian Brabandt <cb@256bit.org>
parents: 8404
diff changeset
153 " Collect garbage, tests that our handle isn't collected.
f6d21a33d489 commit https://github.com/vim/vim/commit/38fd4bb2842df7634823b99c655b3896a7a2e988
Christian Brabandt <cb@256bit.org>
parents: 8404
diff changeset
154 call garbagecollect()
f6d21a33d489 commit https://github.com/vim/vim/commit/38fd4bb2842df7634823b99c655b3896a7a2e988
Christian Brabandt <cb@256bit.org>
parents: 8404
diff changeset
155
8124
310dd635e8c9 commit https://github.com/vim/vim/commit/40ea1da14ba196a23309789852e1b663fd92e3a8
Christian Brabandt <cb@256bit.org>
parents: 8118
diff changeset
156 " check setting options (without testing the effect)
310dd635e8c9 commit https://github.com/vim/vim/commit/40ea1da14ba196a23309789852e1b663fd92e3a8
Christian Brabandt <cb@256bit.org>
parents: 8118
diff changeset
157 call ch_setoptions(handle, {'callback': 's:NotUsed'})
8130
3462f9cfedf8 commit https://github.com/vim/vim/commit/1f6ef66254c1e25ef1c7972aa9a0ba119ebc17e4
Christian Brabandt <cb@256bit.org>
parents: 8124
diff changeset
158 call ch_setoptions(handle, {'timeout': 1111})
8165
973686665238 commit https://github.com/vim/vim/commit/b6b5252bcde68b296858bc090cb424493635dfec
Christian Brabandt <cb@256bit.org>
parents: 8161
diff changeset
159 call ch_setoptions(handle, {'mode': 'json'})
8124
310dd635e8c9 commit https://github.com/vim/vim/commit/40ea1da14ba196a23309789852e1b663fd92e3a8
Christian Brabandt <cb@256bit.org>
parents: 8118
diff changeset
160 call assert_fails("call ch_setoptions(handle, {'waittime': 111})", "E475")
8132
f96536c291d8 commit https://github.com/vim/vim/commit/0ba75a9714884895b2ac09733158c47544a8dfb9
Christian Brabandt <cb@256bit.org>
parents: 8130
diff changeset
161 call ch_setoptions(handle, {'callback': ''})
8124
310dd635e8c9 commit https://github.com/vim/vim/commit/40ea1da14ba196a23309789852e1b663fd92e3a8
Christian Brabandt <cb@256bit.org>
parents: 8118
diff changeset
162
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
163 " Send an eval request that works.
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
164 call assert_equal('ok', ch_evalexpr(handle, 'eval-works'))
7925
b724dbb299d5 commit https://github.com/vim/vim/commit/a02b321686d9827ac806353ea8af780676da340d
Christian Brabandt <cb@256bit.org>
parents: 7922
diff changeset
165 sleep 10m
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
166 call assert_equal([-1, 'foo123'], ch_evalexpr(handle, 'eval-result'))
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
167
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
168 " Send an eval request that fails.
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
169 call assert_equal('ok', ch_evalexpr(handle, 'eval-fails'))
7925
b724dbb299d5 commit https://github.com/vim/vim/commit/a02b321686d9827ac806353ea8af780676da340d
Christian Brabandt <cb@256bit.org>
parents: 7922
diff changeset
170 sleep 10m
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
171 call assert_equal([-2, 'ERROR'], ch_evalexpr(handle, 'eval-result'))
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
172
7965
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7957
diff changeset
173 " Send an eval request that works but can't be encoded.
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
174 call assert_equal('ok', ch_evalexpr(handle, 'eval-error'))
7965
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7957
diff changeset
175 sleep 10m
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
176 call assert_equal([-3, 'ERROR'], ch_evalexpr(handle, 'eval-result'))
7965
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7957
diff changeset
177
7918
ce5a7a613867 commit https://github.com/vim/vim/commit/66624ff0d9e1de2fc5eb4f95f3a3a2ed70b10138
Christian Brabandt <cb@256bit.org>
parents: 7916
diff changeset
178 " Send a bad eval request. There will be no response.
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
179 call assert_equal('ok', ch_evalexpr(handle, 'eval-bad'))
7925
b724dbb299d5 commit https://github.com/vim/vim/commit/a02b321686d9827ac806353ea8af780676da340d
Christian Brabandt <cb@256bit.org>
parents: 7922
diff changeset
180 sleep 10m
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
181 call assert_equal([-3, 'ERROR'], ch_evalexpr(handle, 'eval-result'))
7918
ce5a7a613867 commit https://github.com/vim/vim/commit/66624ff0d9e1de2fc5eb4f95f3a3a2ed70b10138
Christian Brabandt <cb@256bit.org>
parents: 7916
diff changeset
182
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
183 " Send an expr request
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
184 call assert_equal('ok', ch_evalexpr(handle, 'an expr'))
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
185 sleep 10m
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
186 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
187 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
188 call assert_equal('three', getline('$'))
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
189
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
190 " Request a redraw, we don't check for the effect.
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
191 call assert_equal('ok', ch_evalexpr(handle, 'redraw'))
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
192 call assert_equal('ok', ch_evalexpr(handle, 'redraw!'))
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
193
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
194 call assert_equal('ok', ch_evalexpr(handle, 'empty-request'))
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
195
8157
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8132
diff changeset
196 " Reading while there is nothing available.
8222
4f0677020a43 commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
197 call assert_equal(v:none, ch_read(handle, {'timeout': 0}))
4f0677020a43 commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
198 let start = reltime()
4f0677020a43 commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
199 call assert_equal(v:none, ch_read(handle, {'timeout': 333}))
4f0677020a43 commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
200 let elapsed = reltime(start)
4f0677020a43 commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
201 call assert_true(reltimefloat(elapsed) > 0.3)
4f0677020a43 commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
202 call assert_true(reltimefloat(elapsed) < 0.6)
8157
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8132
diff changeset
203
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8132
diff changeset
204 " Send without waiting for a response, then wait for a response.
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
205 call ch_sendexpr(handle, 'wait a bit')
8157
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8132
diff changeset
206 let resp = ch_read(handle)
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8132
diff changeset
207 call assert_equal(type([]), type(resp))
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8132
diff changeset
208 call assert_equal(type(11), type(resp[0]))
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8132
diff changeset
209 call assert_equal('waited', resp[1])
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8132
diff changeset
210
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
211 " make the server quit, can't check if this works, should not hang.
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
212 call ch_sendexpr(handle, '!quit!')
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
213 endfunc
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
214
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
215 func Test_communicate()
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
216 call ch_log('Test_communicate()')
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
217 call s:run_server('s:communicate')
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
218 endfunc
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
219
7916
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
220 " Test that we can open two channels.
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
221 func s:two_channels(port)
8013
dfae8bce5920 commit https://github.com/vim/vim/commit/39b21272d521512b6ecac6cc0f310944f21b7443
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
222 let handle = ch_open('localhost:' . a:port, s:chopt)
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8037
diff changeset
223 if ch_status(handle) == "fail"
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
224 call assert_false(1, "Can't open channel")
7916
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
225 return
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
226 endif
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
227
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
228 call assert_equal('got it', ch_evalexpr(handle, 'hello!'))
7916
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
229
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
230 let newhandle = ch_open('localhost:' . a:port, s:chopt)
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8037
diff changeset
231 if ch_status(newhandle) == "fail"
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
232 call assert_false(1, "Can't open second channel")
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
233 return
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
234 endif
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
235 call assert_equal('got it', ch_evalexpr(newhandle, 'hello!'))
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
236 call assert_equal('got it', ch_evalexpr(handle, 'hello!'))
7916
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
237
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
238 call ch_close(handle)
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
239 call assert_equal('got it', ch_evalexpr(newhandle, 'hello!'))
7916
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
240
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
241 call ch_close(newhandle)
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
242 endfunc
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
243
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
244 func Test_two_channels()
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
245 call ch_log('Test_two_channels()')
8037
9dea1571b352 commit https://github.com/vim/vim/commit/bfa1ffca8bcce92c030d8366036a316954f1ee69
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
246 call s:run_server('s:two_channels')
7916
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
247 endfunc
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
248
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
249 " Test that a server crash is handled gracefully.
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
250 func s:server_crash(port)
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
251 let handle = ch_open('localhost:' . a:port, s:chopt)
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8037
diff changeset
252 if ch_status(handle) == "fail"
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
253 call assert_false(1, "Can't open channel")
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
254 return
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
255 endif
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
256
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
257 call ch_evalexpr(handle, '!crash!')
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
258
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
259 sleep 10m
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
260 endfunc
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
261
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
262 func Test_server_crash()
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
263 call ch_log('Test_server_crash()')
8037
9dea1571b352 commit https://github.com/vim/vim/commit/bfa1ffca8bcce92c030d8366036a316954f1ee69
Christian Brabandt <cb@256bit.org>
parents: 8031
diff changeset
264 call s:run_server('s:server_crash')
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
265 endfunc
7982
5c30ba57aaea commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
266
8382
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
267 """""""""
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
268
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
269 let s:reply = ""
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
270 func s:Handler(chan, msg)
8017
c59a65524084 commit https://github.com/vim/vim/commit/b6a4fee37ebbb0c76f2fbda7d06cbf48a3a07e8d
Christian Brabandt <cb@256bit.org>
parents: 8013
diff changeset
271 unlet s:reply
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
272 let s:reply = a:msg
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
273 endfunc
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
274
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
275 func s:channel_handler(port)
8017
c59a65524084 commit https://github.com/vim/vim/commit/b6a4fee37ebbb0c76f2fbda7d06cbf48a3a07e8d
Christian Brabandt <cb@256bit.org>
parents: 8013
diff changeset
276 let handle = ch_open('localhost:' . a:port, s:chopt)
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8037
diff changeset
277 if ch_status(handle) == "fail"
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
278 call assert_false(1, "Can't open channel")
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
279 return
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
280 endif
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
281
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
282 " Test that it works while waiting on a numbered message.
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
283 call assert_equal('ok', ch_evalexpr(handle, 'call me'))
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
284 sleep 10m
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
285 call assert_equal('we called you', s:reply)
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
286
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
287 " Test that it works while not waiting on a numbered message.
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
288 call ch_sendexpr(handle, 'call me again')
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
289 sleep 10m
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
290 call assert_equal('we did call you', s:reply)
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
291 endfunc
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
292
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
293 func Test_channel_handler()
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
294 call ch_log('Test_channel_handler()')
8017
c59a65524084 commit https://github.com/vim/vim/commit/b6a4fee37ebbb0c76f2fbda7d06cbf48a3a07e8d
Christian Brabandt <cb@256bit.org>
parents: 8013
diff changeset
295 let s:chopt.callback = 's:Handler'
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
296 call s:run_server('s:channel_handler')
8017
c59a65524084 commit https://github.com/vim/vim/commit/b6a4fee37ebbb0c76f2fbda7d06cbf48a3a07e8d
Christian Brabandt <cb@256bit.org>
parents: 8013
diff changeset
297 let s:chopt.callback = function('s:Handler')
c59a65524084 commit https://github.com/vim/vim/commit/b6a4fee37ebbb0c76f2fbda7d06cbf48a3a07e8d
Christian Brabandt <cb@256bit.org>
parents: 8013
diff changeset
298 call s:run_server('s:channel_handler')
c59a65524084 commit https://github.com/vim/vim/commit/b6a4fee37ebbb0c76f2fbda7d06cbf48a3a07e8d
Christian Brabandt <cb@256bit.org>
parents: 8013
diff changeset
299 unlet s:chopt.callback
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
300 endfunc
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
301
8382
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
302 """""""""
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
303
8404
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
304 let s:ch_reply = ''
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
305 func s:ChHandler(chan, msg)
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
306 unlet s:ch_reply
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
307 let s:ch_reply = a:msg
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
308 endfunc
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
309
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
310 let s:zero_reply = ''
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
311 func s:OneHandler(chan, msg)
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
312 unlet s:zero_reply
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
313 let s:zero_reply = a:msg
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
314 endfunc
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
315
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
316 func s:channel_zero(port)
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
317 let handle = ch_open('localhost:' . a:port, s:chopt)
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
318 if ch_status(handle) == "fail"
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
319 call assert_false(1, "Can't open channel")
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
320 return
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
321 endif
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
322
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
323 " Check that eval works.
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
324 call assert_equal('got it', ch_evalexpr(handle, 'hello!'))
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
325
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
326 " Check that eval works if a zero id message is sent back.
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
327 let s:ch_reply = ''
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
328 call assert_equal('sent zero', ch_evalexpr(handle, 'send zero'))
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
329 sleep 10m
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
330 if s:has_handler
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
331 call assert_equal('zero index', s:ch_reply)
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
332 else
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
333 call assert_equal('', s:ch_reply)
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
334 endif
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
335
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
336 " Check that handler works if a zero id message is sent back.
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
337 let s:ch_reply = ''
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
338 let s:zero_reply = ''
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
339 call ch_sendexpr(handle, 'send zero', {'callback': 's:OneHandler'})
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
340 " Somehow the second message takes a bit of time.
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
341 for i in range(50)
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
342 if s:zero_reply == 'sent zero'
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
343 break
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
344 endif
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
345 sleep 10m
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
346 endfor
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
347 if s:has_handler
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
348 call assert_equal('zero index', s:ch_reply)
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
349 else
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
350 call assert_equal('', s:ch_reply)
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
351 endif
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
352 call assert_equal('sent zero', s:zero_reply)
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
353 endfunc
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
354
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
355 func Test_zero_reply()
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
356 call ch_log('Test_zero_reply()')
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
357 " Run with channel handler
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
358 let s:has_handler = 1
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
359 let s:chopt.callback = 's:ChHandler'
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
360 call s:run_server('s:channel_zero')
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
361 unlet s:chopt.callback
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
362
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
363 " Run without channel handler
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
364 let s:has_handler = 0
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
365 call s:run_server('s:channel_zero')
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
366 endfunc
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
367
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
368 """""""""
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
369
8382
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
370 let s:reply1 = ""
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
371 func s:HandleRaw1(chan, msg)
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
372 unlet s:reply1
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
373 let s:reply1 = a:msg
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
374 endfunc
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
375
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
376 let s:reply2 = ""
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
377 func s:HandleRaw2(chan, msg)
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
378 unlet s:reply2
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
379 let s:reply2 = a:msg
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
380 endfunc
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
381
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
382 let s:reply3 = ""
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
383 func s:HandleRaw3(chan, msg)
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
384 unlet s:reply3
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
385 let s:reply3 = a:msg
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
386 endfunc
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
387
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
388 func s:raw_one_time_callback(port)
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
389 let handle = ch_open('localhost:' . a:port, s:chopt)
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
390 if ch_status(handle) == "fail"
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
391 call assert_false(1, "Can't open channel")
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
392 return
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
393 endif
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
394 call ch_setoptions(handle, {'mode': 'raw'})
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
395
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
396 " The message are sent raw, we do our own JSON strings here.
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
397 call ch_sendraw(handle, "[1, \"hello!\"]", {'callback': 's:HandleRaw1'})
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
398 sleep 10m
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
399 call assert_equal("[1, \"got it\"]", s:reply1)
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
400 call ch_sendraw(handle, "[2, \"echo something\"]", {'callback': 's:HandleRaw2'})
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
401 call ch_sendraw(handle, "[3, \"wait a bit\"]", {'callback': 's:HandleRaw3'})
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
402 sleep 10m
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
403 call assert_equal("[2, \"something\"]", s:reply2)
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
404 " wait for up to 500 msec for the 200 msec delayed reply
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
405 for i in range(50)
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
406 sleep 10m
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
407 if s:reply3 != ''
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
408 break
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
409 endif
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
410 endfor
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
411 call assert_equal("[3, \"waited\"]", s:reply3)
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
412 endfunc
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
413
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
414 func Test_raw_one_time_callback()
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
415 call ch_log('Test_raw_one_time_callback()')
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
416 call s:run_server('s:raw_one_time_callback')
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
417 endfunc
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
418
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
419 """""""""
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
420
7982
5c30ba57aaea commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
421 " Test that trying to connect to a non-existing port fails quickly.
5c30ba57aaea commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
422 func Test_connect_waittime()
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
423 call ch_log('Test_connect_waittime()')
7982
5c30ba57aaea commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
424 let start = reltime()
8005
d65aa95725d3 commit https://github.com/vim/vim/commit/a483326e3b04215b86fe9c582ac96bb9679f0812
Christian Brabandt <cb@256bit.org>
parents: 7988
diff changeset
425 let handle = ch_open('localhost:9876', s:chopt)
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
426 if ch_status(handle) != "fail"
7982
5c30ba57aaea commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
427 " Oops, port does exists.
5c30ba57aaea commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
428 call ch_close(handle)
5c30ba57aaea commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
429 else
5c30ba57aaea commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
430 let elapsed = reltime(start)
7984
c166ff6797cb commit https://github.com/vim/vim/commit/74f5e65bcc3d77ab879f56eb977f5038edccbcf8
Christian Brabandt <cb@256bit.org>
parents: 7982
diff changeset
431 call assert_true(reltimefloat(elapsed) < 1.0)
7982
5c30ba57aaea commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
432 endif
5c30ba57aaea commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
433
8168
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
434 " We intend to use a socket that doesn't exist and wait for half a second
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
435 " before giving up. If the socket does exist it can fail in various ways.
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
436 " Check for "Connection reset by peer" to avoid flakyness.
7982
5c30ba57aaea commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
437 let start = reltime()
8168
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
438 try
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
439 let handle = ch_open('localhost:9867', {'waittime': 500})
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
440 if ch_status(handle) != "fail"
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
441 " Oops, port does exists.
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
442 call ch_close(handle)
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
443 else
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
444 " Failed connection should wait about 500 msec.
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
445 let elapsed = reltime(start)
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
446 call assert_true(reltimefloat(elapsed) > 0.3)
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
447 call assert_true(reltimefloat(elapsed) < 1.0)
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
448 endif
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
449 catch
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
450 if v:exception !~ 'Connection reset by peer'
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
451 call assert_false(1, "Caught exception: " . v:exception)
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
452 endif
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
453 endtry
7982
5c30ba57aaea commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
454 endfunc
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8027
diff changeset
455
8382
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
456 """""""""
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
457
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
458 func Test_raw_pipe()
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
459 if !has('job')
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
460 return
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
461 endif
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
462 call ch_log('Test_raw_pipe()')
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
463 let job = job_start(s:python . " test_channel_pipe.py", {'mode': 'raw'})
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
464 call assert_equal("run", job_status(job))
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
465 try
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
466 let handle = job_getchannel(job)
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
467 call ch_sendraw(handle, "echo something\n")
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
468 let msg = ch_readraw(handle)
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
469 call assert_equal("something\n", substitute(msg, "\r", "", 'g'))
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
470
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
471 call ch_sendraw(handle, "double this\n")
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
472 let msg = ch_readraw(handle)
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
473 call assert_equal("this\nAND this\n", substitute(msg, "\r", "", 'g'))
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
474
8380
892d7dcf17ec commit https://github.com/vim/vim/commit/da94fdf2588b3910d38e477a755748ce2c6d2e66
Christian Brabandt <cb@256bit.org>
parents: 8346
diff changeset
475 let reply = ch_evalraw(handle, "quit\n", {'timeout': 100})
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
476 call assert_equal("Goodbye!\n", substitute(reply, "\r", "", 'g'))
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
477 finally
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
478 call job_stop(job)
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
479 endtry
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
480 endfunc
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
481
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
482 func Test_nl_pipe()
8059
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
483 if !has('job')
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8027
diff changeset
484 return
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8027
diff changeset
485 endif
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
486 call ch_log('Test_nl_pipe()')
8066
1aa8ed4ee48b commit https://github.com/vim/vim/commit/b6a7737938e7e7b34f862f58aa5498e6f652e33d
Christian Brabandt <cb@256bit.org>
parents: 8059
diff changeset
487 let job = job_start(s:python . " test_channel_pipe.py")
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8027
diff changeset
488 call assert_equal("run", job_status(job))
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8027
diff changeset
489 try
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8027
diff changeset
490 let handle = job_getchannel(job)
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
491 call ch_sendraw(handle, "echo something\n")
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
492 call assert_equal("something", ch_readraw(handle))
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
493
8384
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
494 call ch_sendraw(handle, "echoerr wrong\n")
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
495 call assert_equal("wrong", ch_readraw(handle, {'part': 'err'}))
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
496
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
497 call ch_sendraw(handle, "double this\n")
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
498 call assert_equal("this", ch_readraw(handle))
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
499 call assert_equal("AND this", ch_readraw(handle))
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
500
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
501 let reply = ch_evalraw(handle, "quit\n")
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
502 call assert_equal("Goodbye!", reply)
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8027
diff changeset
503 finally
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8027
diff changeset
504 call job_stop(job)
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8027
diff changeset
505 endtry
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8027
diff changeset
506 endfunc
8055
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
507
8384
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
508 func Test_nl_err_to_out_pipe()
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
509 if !has('job')
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
510 return
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
511 endif
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
512 call ch_log('Test_nl_err_to_out_pipe()')
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
513 let job = job_start(s:python . " test_channel_pipe.py", {'err-io': 'out'})
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
514 call assert_equal("run", job_status(job))
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
515 try
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
516 let handle = job_getchannel(job)
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
517 call ch_sendraw(handle, "echo something\n")
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
518 call assert_equal("something", ch_readraw(handle))
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
519
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
520 call ch_sendraw(handle, "echoerr wrong\n")
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
521 call assert_equal("wrong", ch_readraw(handle))
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
522 finally
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
523 call job_stop(job)
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
524 endtry
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
525 endfunc
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
526
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
527 func Test_pipe_to_buffer()
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
528 if !has('job')
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
529 return
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
530 endif
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
531 call ch_log('Test_pipe_to_buffer()')
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
532 let job = job_start(s:python . " test_channel_pipe.py",
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
533 \ {'out-io': 'buffer', 'out-name': 'pipe-output'})
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
534 call assert_equal("run", job_status(job))
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
535 try
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
536 let handle = job_getchannel(job)
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
537 call ch_sendraw(handle, "echo line one\n")
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
538 call ch_sendraw(handle, "echo line two\n")
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
539 call ch_sendraw(handle, "double this\n")
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
540 call ch_sendraw(handle, "quit\n")
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
541 sp pipe-output
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
542 for i in range(100)
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
543 sleep 10m
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
544 if line('$') >= 6
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
545 break
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
546 endif
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
547 endfor
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
548 call assert_equal(['Reading from channel output...', 'line one', 'line two', 'this', 'AND this', 'Goodbye!'], getline(1, '$'))
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
549 bwipe!
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
550 finally
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
551 call job_stop(job)
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
552 endtry
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
553 endfunc
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
554
8386
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
555 func Test_pipe_from_buffer()
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
556 if !has('job')
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
557 return
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
558 endif
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
559 call ch_logfile('channellog', 'w')
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
560 call ch_log('Test_pipe_from_buffer()')
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
561
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
562 sp pipe-input
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
563 call setline(1, ['echo one', 'echo two', 'echo three'])
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
564
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
565 let job = job_start(s:python . " test_channel_pipe.py",
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
566 \ {'in-io': 'buffer', 'in-name': 'pipe-input'})
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
567 call assert_equal("run", job_status(job))
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
568 try
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
569 let handle = job_getchannel(job)
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
570 call assert_equal('one', ch_read(handle))
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
571 call assert_equal('two', ch_read(handle))
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
572 call assert_equal('three', ch_read(handle))
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
573 bwipe!
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
574 finally
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
575 call job_stop(job)
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
576 endtry
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
577 call ch_logfile('')
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
578 endfunc
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
579
8291
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
580 func Test_pipe_to_nameless_buffer()
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
581 if !has('job')
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
582 return
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
583 endif
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
584 call ch_log('Test_pipe_to_nameless_buffer()')
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
585 let job = job_start(s:python . " test_channel_pipe.py",
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
586 \ {'out-io': 'buffer'})
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
587 call assert_equal("run", job_status(job))
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
588 try
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
589 let handle = job_getchannel(job)
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
590 call ch_sendraw(handle, "echo line one\n")
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
591 call ch_sendraw(handle, "echo line two\n")
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
592 exe ch_getbufnr(handle, "out") . 'sbuf'
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
593 for i in range(100)
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
594 sleep 10m
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
595 if line('$') >= 3
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
596 break
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
597 endif
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
598 endfor
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
599 call assert_equal(['Reading from channel output...', 'line one', 'line two'], getline(1, '$'))
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
600 bwipe!
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
601 finally
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
602 call job_stop(job)
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
603 endtry
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
604 endfunc
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
605
8346
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
606 func Test_pipe_to_buffer_json()
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
607 if !has('job')
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
608 return
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
609 endif
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
610 call ch_log('Test_pipe_to_buffer_json()')
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
611 let job = job_start(s:python . " test_channel_pipe.py",
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
612 \ {'out-io': 'buffer', 'out-mode': 'json'})
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
613 call assert_equal("run", job_status(job))
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
614 try
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
615 let handle = job_getchannel(job)
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
616 call ch_sendraw(handle, "echo [0, \"hello\"]\n")
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
617 call ch_sendraw(handle, "echo [-2, 12.34]\n")
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
618 exe ch_getbufnr(handle, "out") . 'sbuf'
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
619 for i in range(100)
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
620 sleep 10m
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
621 if line('$') >= 3
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
622 break
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
623 endif
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
624 endfor
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
625 call assert_equal(['Reading from channel output...', '[0,"hello"]', '[-2,12.34]'], getline(1, '$'))
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
626 bwipe!
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
627 finally
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
628 call job_stop(job)
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
629 endtry
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
630 endfunc
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
631
8426
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
632 " Wait a little while for the last line, minus "offset", to equal "line".
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
633 func Wait_for_last_line(line, offset)
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
634 for i in range(100)
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
635 sleep 10m
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
636 if getline(line('$') - a:offset) == a:line
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
637 break
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
638 endif
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
639 endfor
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
640 endfunc
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
641
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
642 func Test_pipe_io_two_buffers()
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
643 if !has('job')
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
644 return
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
645 endif
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
646 call ch_log('Test_pipe_io_two_buffers()')
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
647
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
648 " Create two buffers, one to read from and one to write to.
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
649 split pipe-output
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
650 set buftype=nofile
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
651 split pipe-input
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
652 set buftype=nofile
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
653
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
654 let job = job_start(s:python . " test_channel_pipe.py",
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
655 \ {'in-io': 'buffer', 'in-name': 'pipe-input', 'in-top': 0,
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
656 \ 'out-io': 'buffer', 'out-name': 'pipe-output'})
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
657 call assert_equal("run", job_status(job))
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
658 try
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
659 exe "normal Gaecho hello\<CR>"
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
660 exe bufwinnr('pipe-output') . "wincmd w"
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
661 call Wait_for_last_line('hello', 0)
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
662 call assert_equal('hello', getline('$'))
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
663
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
664 exe bufwinnr('pipe-input') . "wincmd w"
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
665 exe "normal Gadouble this\<CR>"
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
666 exe bufwinnr('pipe-output') . "wincmd w"
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
667 call Wait_for_last_line('AND this', 0)
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
668 call assert_equal('this', getline(line('$') - 1))
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
669 call assert_equal('AND this', getline('$'))
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
670
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
671 bwipe!
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
672 exe bufwinnr('pipe-input') . "wincmd w"
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
673 bwipe!
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
674 finally
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
675 call job_stop(job)
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
676 endtry
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
677 endfunc
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
678
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
679 func Test_pipe_io_one_buffer()
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
680 if !has('job')
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
681 return
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
682 endif
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
683 call ch_log('Test_pipe_io_one_buffer()')
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
684
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
685 " Create one buffer to read from and to write to.
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
686 split pipe-io
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
687 set buftype=nofile
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
688
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
689 let job = job_start(s:python . " test_channel_pipe.py",
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
690 \ {'in-io': 'buffer', 'in-name': 'pipe-io', 'in-top': 0,
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
691 \ 'out-io': 'buffer', 'out-name': 'pipe-io'})
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
692 call assert_equal("run", job_status(job))
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
693 try
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
694 exe "normal Goecho hello\<CR>"
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
695 call Wait_for_last_line('hello', 1)
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
696 call assert_equal('hello', getline(line('$') - 1))
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
697
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
698 exe "normal Gadouble this\<CR>"
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
699 call Wait_for_last_line('AND this', 1)
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
700 call assert_equal('this', getline(line('$') - 2))
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
701 call assert_equal('AND this', getline(line('$') - 1))
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
702
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
703 bwipe!
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
704 finally
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
705 call job_stop(job)
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
706 endtry
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
707 endfunc
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
708
8074
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
709 """"""""""
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
710
8055
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
711 let s:unletResponse = ''
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
712 func s:UnletHandler(handle, msg)
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
713 let s:unletResponse = a:msg
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
714 unlet s:channelfd
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
715 endfunc
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
716
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
717 " Test that "unlet handle" in a handler doesn't crash Vim.
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
718 func s:unlet_handle(port)
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
719 let s:channelfd = ch_open('localhost:' . a:port, s:chopt)
8094
18a3f0f05244 commit https://github.com/vim/vim/commit/910b8aac5dc4693c4508b7acd2cef0bbfac04242
Christian Brabandt <cb@256bit.org>
parents: 8084
diff changeset
720 call ch_sendexpr(s:channelfd, "test", {'callback': function('s:UnletHandler')})
8055
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
721 sleep 10m
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
722 call assert_equal('what?', s:unletResponse)
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
723 endfunc
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
724
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
725 func Test_unlet_handle()
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
726 call ch_log('Test_unlet_handle()')
8055
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
727 call s:run_server('s:unlet_handle')
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
728 endfunc
8070
e4c3f6720b03 commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents: 8066
diff changeset
729
8074
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
730 """"""""""
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
731
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
732 let s:unletResponse = ''
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
733 func s:CloseHandler(handle, msg)
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
734 let s:unletResponse = a:msg
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
735 call ch_close(s:channelfd)
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
736 endfunc
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
737
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
738 " Test that "unlet handle" in a handler doesn't crash Vim.
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
739 func s:close_handle(port)
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
740 let s:channelfd = ch_open('localhost:' . a:port, s:chopt)
8094
18a3f0f05244 commit https://github.com/vim/vim/commit/910b8aac5dc4693c4508b7acd2cef0bbfac04242
Christian Brabandt <cb@256bit.org>
parents: 8084
diff changeset
741 call ch_sendexpr(s:channelfd, "test", {'callback': function('s:CloseHandler')})
8074
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
742 sleep 10m
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
743 call assert_equal('what?', s:unletResponse)
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
744 endfunc
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
745
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
746 func Test_close_handle()
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
747 call ch_log('Test_close_handle()')
8074
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
748 call s:run_server('s:close_handle')
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
749 endfunc
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
750
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
751 """"""""""
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
752
8070
e4c3f6720b03 commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents: 8066
diff changeset
753 func Test_open_fail()
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
754 call ch_log('Test_open_fail()')
8070
e4c3f6720b03 commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents: 8066
diff changeset
755 silent! let ch = ch_open("noserver")
e4c3f6720b03 commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents: 8066
diff changeset
756 echo ch
e4c3f6720b03 commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents: 8066
diff changeset
757 let d = ch
e4c3f6720b03 commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents: 8066
diff changeset
758 endfunc
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
759
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
760 """"""""""
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
761
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
762 func s:open_delay(port)
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
763 " Wait up to a second for the port to open.
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
764 let s:chopt.waittime = 1000
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
765 let channel = ch_open('localhost:' . a:port, s:chopt)
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
766 unlet s:chopt.waittime
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
767 if ch_status(channel) == "fail"
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
768 call assert_false(1, "Can't open channel")
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
769 return
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
770 endif
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
771 call assert_equal('got it', ch_evalexpr(channel, 'hello!'))
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
772 call ch_close(channel)
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
773 endfunc
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
774
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
775 func Test_open_delay()
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
776 call ch_log('Test_open_delay()')
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
777 " The server will wait half a second before creating the port.
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
778 call s:run_server('s:open_delay', 'delay')
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
779 endfunc
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
780
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
781 """""""""
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
782
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
783 function MyFunction(a,b,c)
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
784 let s:call_ret = [a:a, a:b, a:c]
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
785 endfunc
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
786
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
787 function s:test_call(port)
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
788 let handle = ch_open('localhost:' . a:port, s:chopt)
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
789 if ch_status(handle) == "fail"
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
790 call assert_false(1, "Can't open channel")
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
791 return
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
792 endif
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
793
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
794 call assert_equal('ok', ch_evalexpr(handle, 'call-func'))
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
795 sleep 20m
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
796 call assert_equal([1, 2, 3], s:call_ret)
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
797 endfunc
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
798
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
799 func Test_call()
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
800 call ch_log('Test_call()')
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
801 call s:run_server('s:test_call')
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
802 endfunc
8174
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
803
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
804 """""""""
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
805
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
806 let s:job_exit_ret = 'not yet'
8174
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
807 function MyExitCb(job, status)
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
808 let s:job_exit_ret = 'done'
8174
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
809 endfunc
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
810
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
811 function s:test_exit_callback(port)
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
812 call job_setoptions(s:job, {'exit-cb': 'MyExitCb'})
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
813 let s:exit_job = s:job
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
814 endfunc
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
815
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
816 func Test_exit_callback()
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
817 if has('job')
8324
5e88bd55b789 commit https://github.com/vim/vim/commit/9730f74a0b2acb490943393a203a24ab8fab923a
Christian Brabandt <cb@256bit.org>
parents: 8291
diff changeset
818 call ch_log('Test_exit_callback()')
8174
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
819 call s:run_server('s:test_exit_callback')
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
820
8324
5e88bd55b789 commit https://github.com/vim/vim/commit/9730f74a0b2acb490943393a203a24ab8fab923a
Christian Brabandt <cb@256bit.org>
parents: 8291
diff changeset
821 " wait up to a second for the job to exit
5e88bd55b789 commit https://github.com/vim/vim/commit/9730f74a0b2acb490943393a203a24ab8fab923a
Christian Brabandt <cb@256bit.org>
parents: 8291
diff changeset
822 for i in range(100)
5e88bd55b789 commit https://github.com/vim/vim/commit/9730f74a0b2acb490943393a203a24ab8fab923a
Christian Brabandt <cb@256bit.org>
parents: 8291
diff changeset
823 if s:job_exit_ret == 'done'
5e88bd55b789 commit https://github.com/vim/vim/commit/9730f74a0b2acb490943393a203a24ab8fab923a
Christian Brabandt <cb@256bit.org>
parents: 8291
diff changeset
824 break
5e88bd55b789 commit https://github.com/vim/vim/commit/9730f74a0b2acb490943393a203a24ab8fab923a
Christian Brabandt <cb@256bit.org>
parents: 8291
diff changeset
825 endif
5e88bd55b789 commit https://github.com/vim/vim/commit/9730f74a0b2acb490943393a203a24ab8fab923a
Christian Brabandt <cb@256bit.org>
parents: 8291
diff changeset
826 sleep 10m
5e88bd55b789 commit https://github.com/vim/vim/commit/9730f74a0b2acb490943393a203a24ab8fab923a
Christian Brabandt <cb@256bit.org>
parents: 8291
diff changeset
827 " calling job_status() triggers the callback
5e88bd55b789 commit https://github.com/vim/vim/commit/9730f74a0b2acb490943393a203a24ab8fab923a
Christian Brabandt <cb@256bit.org>
parents: 8291
diff changeset
828 call job_status(s:exit_job)
5e88bd55b789 commit https://github.com/vim/vim/commit/9730f74a0b2acb490943393a203a24ab8fab923a
Christian Brabandt <cb@256bit.org>
parents: 8291
diff changeset
829 endfor
8174
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
830
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
831 call assert_equal('done', s:job_exit_ret)
8324
5e88bd55b789 commit https://github.com/vim/vim/commit/9730f74a0b2acb490943393a203a24ab8fab923a
Christian Brabandt <cb@256bit.org>
parents: 8291
diff changeset
832 unlet s:exit_job
8174
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
833 endif
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
834 endfunc
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
835
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
836 """""""""
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
837
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
838 let s:ch_close_ret = 'alive'
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
839 function MyCloseCb(ch)
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
840 let s:ch_close_ret = 'closed'
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
841 endfunc
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
842
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
843 function s:test_close_callback(port)
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
844 let handle = ch_open('localhost:' . a:port, s:chopt)
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
845 if ch_status(handle) == "fail"
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
846 call assert_false(1, "Can't open channel")
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
847 return
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
848 endif
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
849 call ch_setoptions(handle, {'close-cb': 'MyCloseCb'})
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
850
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
851 call assert_equal('', ch_evalexpr(handle, 'close me'))
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
852 sleep 20m
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
853 call assert_equal('closed', s:ch_close_ret)
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
854 endfunc
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
855
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
856 func Test_close_callback()
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
857 call ch_log('Test_close_callback()')
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
858 call s:run_server('s:test_close_callback')
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
859 endfunc
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
860
8324
5e88bd55b789 commit https://github.com/vim/vim/commit/9730f74a0b2acb490943393a203a24ab8fab923a
Christian Brabandt <cb@256bit.org>
parents: 8291
diff changeset
861 " Uncomment this to see what happens, output is in src/testdir/channellog.
5e88bd55b789 commit https://github.com/vim/vim/commit/9730f74a0b2acb490943393a203a24ab8fab923a
Christian Brabandt <cb@256bit.org>
parents: 8291
diff changeset
862 " call ch_logfile('channellog', 'w')