annotate src/testdir/test_channel.vim @ 13740:f309afff6f25 v8.0.1742

patch 8.0.1742: cannot get a list of all the jobs commit https://github.com/vim/vim/commit/e1fc51558dc14906a8d9f6a6e7bb1ac2a6ba8f3d Author: Bram Moolenaar <Bram@vim.org> Date: Sat Apr 21 19:49:08 2018 +0200 patch 8.0.1742: cannot get a list of all the jobs Problem: Cannot get a list of all the jobs. Cannot get the command of the job. Solution: When job_info() is called without an argument return a list of jobs. Otherwise, include the command that the job is running. (Yegappan Lakshmanan)
author Christian Brabandt <cb@256bit.org>
date Sat, 21 Apr 2018 20:00:07 +0200
parents 87ffb7f85b28
children 5f6c61a71c02
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
7922
14540239601d commit https://github.com/vim/vim/commit/e24692573a266f5060c06dd80bde264092c90dd5
Christian Brabandt <cb@256bit.org>
parents: 7918
diff changeset
3 if !has('channel')
14540239601d commit https://github.com/vim/vim/commit/e24692573a266f5060c06dd80bde264092c90dd5
Christian Brabandt <cb@256bit.org>
parents: 7918
diff changeset
4 finish
14540239601d commit https://github.com/vim/vim/commit/e24692573a266f5060c06dd80bde264092c90dd5
Christian Brabandt <cb@256bit.org>
parents: 7918
diff changeset
5 endif
14540239601d commit https://github.com/vim/vim/commit/e24692573a266f5060c06dd80bde264092c90dd5
Christian Brabandt <cb@256bit.org>
parents: 7918
diff changeset
6
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
7 source shared.vim
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
8
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
9 let s:python = PythonProg()
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
10 if s:python == ''
11183
1c4ebbae41d2 patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors
Christian Brabandt <cb@256bit.org>
parents: 10845
diff changeset
11 " Can't run this test without Python.
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 finish
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 endif
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14
11183
1c4ebbae41d2 patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors
Christian Brabandt <cb@256bit.org>
parents: 10845
diff changeset
15 " Uncomment the next line to see what happens. Output is in
1c4ebbae41d2 patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors
Christian Brabandt <cb@256bit.org>
parents: 10845
diff changeset
16 " src/testdir/channellog.
1c4ebbae41d2 patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors
Christian Brabandt <cb@256bit.org>
parents: 10845
diff changeset
17 " call ch_logfile('channellog', 'w')
1c4ebbae41d2 patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors
Christian Brabandt <cb@256bit.org>
parents: 10845
diff changeset
18
8096
882ba5080c5c commit https://github.com/vim/vim/commit/e74e8e7d758e9312165a931f176185f07a64231a
Christian Brabandt <cb@256bit.org>
parents: 8094
diff changeset
19 let s:chopt = {}
7916
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
20
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
21 " 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
22 func s:run_server(testfunc, ...)
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
23 call RunServer('test_channel.py', a:testfunc, a:000)
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
24 endfunc
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
25
13357
179586a64f53 patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents: 13010
diff changeset
26 " Return a list of open files.
179586a64f53 patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents: 13010
diff changeset
27 " Can be used to make sure no resources leaked.
179586a64f53 patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents: 13010
diff changeset
28 " Returns an empty list on systems where this is not supported.
179586a64f53 patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents: 13010
diff changeset
29 func s:get_resources()
179586a64f53 patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents: 13010
diff changeset
30 let pid = getpid()
179586a64f53 patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents: 13010
diff changeset
31
179586a64f53 patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents: 13010
diff changeset
32 if has('mac')
179586a64f53 patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents: 13010
diff changeset
33 return systemlist('lsof -p ' . pid . ' | awk ''$4~/^[0-9]*[rwu]$/&&$5=="REG"{print$NF}''')
179586a64f53 patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents: 13010
diff changeset
34 elseif isdirectory('/proc/' . pid . '/fd/')
179586a64f53 patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents: 13010
diff changeset
35 return systemlist('readlink /proc/' . pid . '/fd/* | grep -v ''^/dev/''')
179586a64f53 patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents: 13010
diff changeset
36 else
179586a64f53 patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents: 13010
diff changeset
37 return []
179586a64f53 patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents: 13010
diff changeset
38 endif
179586a64f53 patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents: 13010
diff changeset
39 endfunc
179586a64f53 patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents: 13010
diff changeset
40
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
41 let g:Ch_responseMsg = ''
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
42 func Ch_requestHandler(handle, msg)
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
43 let g:Ch_responseHandle = a:handle
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
44 let g:Ch_responseMsg = a:msg
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
45 endfunc
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
46
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
47 func Ch_communicate(port)
10454
f5c7c76897fa commit https://github.com/vim/vim/commit/5643db84c6a9f15d14492cefd52647623aa2ac7c
Christian Brabandt <cb@256bit.org>
parents: 10428
diff changeset
48 " Avoid dropping messages, since we don't use a callback here.
f5c7c76897fa commit https://github.com/vim/vim/commit/5643db84c6a9f15d14492cefd52647623aa2ac7c
Christian Brabandt <cb@256bit.org>
parents: 10428
diff changeset
49 let s:chopt.drop = 'never'
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
50 let handle = ch_open('localhost:' . a:port, s:chopt)
10454
f5c7c76897fa commit https://github.com/vim/vim/commit/5643db84c6a9f15d14492cefd52647623aa2ac7c
Christian Brabandt <cb@256bit.org>
parents: 10428
diff changeset
51 unlet s:chopt.drop
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8037
diff changeset
52 if ch_status(handle) == "fail"
11183
1c4ebbae41d2 patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors
Christian Brabandt <cb@256bit.org>
parents: 10845
diff changeset
53 call assert_report("Can't open channel")
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 return
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 endif
8424
be45d4921f1f commit https://github.com/vim/vim/commit/839fd11d7ed1a96bace3159c4d1861658864aae3
Christian Brabandt <cb@256bit.org>
parents: 8420
diff changeset
56 if has('job')
8669
06848fe9c816 commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
57 " check that getjob without a job is handled correctly
8424
be45d4921f1f commit https://github.com/vim/vim/commit/839fd11d7ed1a96bace3159c4d1861658864aae3
Christian Brabandt <cb@256bit.org>
parents: 8420
diff changeset
58 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
59 endif
8669
06848fe9c816 commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
60 let dict = ch_info(handle)
06848fe9c816 commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
61 call assert_true(dict.id != 0)
06848fe9c816 commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
62 call assert_equal('open', dict.status)
06848fe9c816 commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
63 call assert_equal(a:port, string(dict.port))
06848fe9c816 commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
64 call assert_equal('open', dict.sock_status)
06848fe9c816 commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
65 call assert_equal('socket', dict.sock_io)
06848fe9c816 commit https://github.com/vim/vim/commit/03602ec28ed25739e88b2c835adb0662d3720bb2
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
66
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 " Simple string request and reply.
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
68 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
69
8653
d80edead9675 commit https://github.com/vim/vim/commit/ac74d5e86cd16b42e81ba48f58f3d45c72758248
Christian Brabandt <cb@256bit.org>
parents: 8540
diff changeset
70 " Malformed command should be ignored.
8655
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
71 call assert_equal('ok', ch_evalexpr(handle, 'malformed1'))
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
72 call assert_equal('ok', ch_evalexpr(handle, 'malformed2'))
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
73 call assert_equal('ok', ch_evalexpr(handle, 'malformed3'))
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
74
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
75 " split command should work
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
76 call assert_equal('ok', ch_evalexpr(handle, 'split'))
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
77 call WaitFor('exists("g:split")')
8655
1eb302bf2475 commit https://github.com/vim/vim/commit/ba61ac0d61f46de7d29c64bb0de6d25c2e378be0
Christian Brabandt <cb@256bit.org>
parents: 8653
diff changeset
78 call assert_equal(123, g:split)
8653
d80edead9675 commit https://github.com/vim/vim/commit/ac74d5e86cd16b42e81ba48f58f3d45c72758248
Christian Brabandt <cb@256bit.org>
parents: 8540
diff changeset
79
9969
176e34b0d678 commit https://github.com/vim/vim/commit/f1f0792e55e72cdc7c833b30f565a9b02f18bb1e
Christian Brabandt <cb@256bit.org>
parents: 9719
diff changeset
80 " string with ][ should work
176e34b0d678 commit https://github.com/vim/vim/commit/f1f0792e55e72cdc7c833b30f565a9b02f18bb1e
Christian Brabandt <cb@256bit.org>
parents: 9719
diff changeset
81 call assert_equal('this][that', ch_evalexpr(handle, 'echo this][that'))
176e34b0d678 commit https://github.com/vim/vim/commit/f1f0792e55e72cdc7c833b30f565a9b02f18bb1e
Christian Brabandt <cb@256bit.org>
parents: 9719
diff changeset
82
10422
e664ee056a84 commit https://github.com/vim/vim/commit/4b785f69c0616dba5d3f38e8ce4b5398cec89407
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
83 " nothing to read now
e664ee056a84 commit https://github.com/vim/vim/commit/4b785f69c0616dba5d3f38e8ce4b5398cec89407
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
84 call assert_equal(0, ch_canread(handle))
e664ee056a84 commit https://github.com/vim/vim/commit/4b785f69c0616dba5d3f38e8ce4b5398cec89407
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
85
9969
176e34b0d678 commit https://github.com/vim/vim/commit/f1f0792e55e72cdc7c833b30f565a9b02f18bb1e
Christian Brabandt <cb@256bit.org>
parents: 9719
diff changeset
86 " sending three messages quickly then reading should work
176e34b0d678 commit https://github.com/vim/vim/commit/f1f0792e55e72cdc7c833b30f565a9b02f18bb1e
Christian Brabandt <cb@256bit.org>
parents: 9719
diff changeset
87 for i in range(3)
176e34b0d678 commit https://github.com/vim/vim/commit/f1f0792e55e72cdc7c833b30f565a9b02f18bb1e
Christian Brabandt <cb@256bit.org>
parents: 9719
diff changeset
88 call ch_sendexpr(handle, 'echo hello ' . i)
176e34b0d678 commit https://github.com/vim/vim/commit/f1f0792e55e72cdc7c833b30f565a9b02f18bb1e
Christian Brabandt <cb@256bit.org>
parents: 9719
diff changeset
89 endfor
176e34b0d678 commit https://github.com/vim/vim/commit/f1f0792e55e72cdc7c833b30f565a9b02f18bb1e
Christian Brabandt <cb@256bit.org>
parents: 9719
diff changeset
90 call assert_equal('hello 0', ch_read(handle)[1])
176e34b0d678 commit https://github.com/vim/vim/commit/f1f0792e55e72cdc7c833b30f565a9b02f18bb1e
Christian Brabandt <cb@256bit.org>
parents: 9719
diff changeset
91 call assert_equal('hello 1', ch_read(handle)[1])
176e34b0d678 commit https://github.com/vim/vim/commit/f1f0792e55e72cdc7c833b30f565a9b02f18bb1e
Christian Brabandt <cb@256bit.org>
parents: 9719
diff changeset
92 call assert_equal('hello 2', ch_read(handle)[1])
176e34b0d678 commit https://github.com/vim/vim/commit/f1f0792e55e72cdc7c833b30f565a9b02f18bb1e
Christian Brabandt <cb@256bit.org>
parents: 9719
diff changeset
93
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94 " 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
95 " 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
96 " 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
97 call assert_equal('ok', ch_evalexpr(handle, 'make change'))
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
98 call WaitFor('"added2" == getline("$")')
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99 call assert_equal('added1', getline(line('$') - 1))
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100 call assert_equal('added2', getline('$'))
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101
8746
4c38a4733578 commit https://github.com/vim/vim/commit/c4dcd60c76666bf113719f929709ad6120eb6528
Christian Brabandt <cb@256bit.org>
parents: 8744
diff changeset
102 " Request command "foo bar", which fails silently.
4c38a4733578 commit https://github.com/vim/vim/commit/c4dcd60c76666bf113719f929709ad6120eb6528
Christian Brabandt <cb@256bit.org>
parents: 8744
diff changeset
103 call assert_equal('ok', ch_evalexpr(handle, 'bad command'))
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
104 call WaitFor('v:errmsg =~ "E492"')
8749
65a5a18d3acf commit https://github.com/vim/vim/commit/ea6553bec340920d8a09c7210cdc2d218e25ace2
Christian Brabandt <cb@256bit.org>
parents: 8746
diff changeset
105 call assert_match('E492:.*foo bar', v:errmsg)
8746
4c38a4733578 commit https://github.com/vim/vim/commit/c4dcd60c76666bf113719f929709ad6120eb6528
Christian Brabandt <cb@256bit.org>
parents: 8744
diff changeset
106
8380
892d7dcf17ec commit https://github.com/vim/vim/commit/da94fdf2588b3910d38e477a755748ce2c6d2e66
Christian Brabandt <cb@256bit.org>
parents: 8346
diff changeset
107 call assert_equal('ok', ch_evalexpr(handle, 'do normal', {'timeout': 100}))
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
108 call WaitFor('"added more" == getline("$")')
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
109 call assert_equal('added more', getline('$'))
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
110
7933
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
111 " Send a request with a specific handler.
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
112 call ch_sendexpr(handle, 'hello!', {'callback': 'Ch_requestHandler'})
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
113 call WaitFor('exists("g:Ch_responseHandle")')
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
114 if !exists('g:Ch_responseHandle')
11183
1c4ebbae41d2 patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors
Christian Brabandt <cb@256bit.org>
parents: 10845
diff changeset
115 call assert_report('g:Ch_responseHandle was not set')
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8037
diff changeset
116 else
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
117 call assert_equal(handle, g:Ch_responseHandle)
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
118 unlet g:Ch_responseHandle
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8037
diff changeset
119 endif
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
120 call assert_equal('got it', g:Ch_responseMsg)
7933
1f0743f4f88f commit https://github.com/vim/vim/commit/a07fec9c85d062acd9dd433a2e681770f459ba47
Christian Brabandt <cb@256bit.org>
parents: 7929
diff changeset
121
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
122 let g:Ch_responseMsg = ''
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
123 call ch_sendexpr(handle, 'hello!', {'callback': function('Ch_requestHandler')})
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
124 call WaitFor('exists("g:Ch_responseHandle")')
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
125 if !exists('g:Ch_responseHandle')
11183
1c4ebbae41d2 patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors
Christian Brabandt <cb@256bit.org>
parents: 10845
diff changeset
126 call assert_report('g:Ch_responseHandle was not set')
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8037
diff changeset
127 else
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
128 call assert_equal(handle, g:Ch_responseHandle)
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
129 unlet g:Ch_responseHandle
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8037
diff changeset
130 endif
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
131 call assert_equal('got it', g:Ch_responseMsg)
8017
c59a65524084 commit https://github.com/vim/vim/commit/b6a4fee37ebbb0c76f2fbda7d06cbf48a3a07e8d
Christian Brabandt <cb@256bit.org>
parents: 8013
diff changeset
132
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
133 " Using lambda.
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
134 let g:Ch_responseMsg = ''
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
135 call ch_sendexpr(handle, 'hello!', {'callback': {a, b -> Ch_requestHandler(a, b)}})
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
136 call WaitFor('exists("g:Ch_responseHandle")')
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
137 if !exists('g:Ch_responseHandle')
11183
1c4ebbae41d2 patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors
Christian Brabandt <cb@256bit.org>
parents: 10845
diff changeset
138 call assert_report('g:Ch_responseHandle was not set')
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
139 else
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
140 call assert_equal(handle, g:Ch_responseHandle)
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
141 unlet g:Ch_responseHandle
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
142 endif
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
143 call assert_equal('got it', g:Ch_responseMsg)
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
144
8420
f6d21a33d489 commit https://github.com/vim/vim/commit/38fd4bb2842df7634823b99c655b3896a7a2e988
Christian Brabandt <cb@256bit.org>
parents: 8404
diff changeset
145 " Collect garbage, tests that our handle isn't collected.
9108
d319453f62b3 commit https://github.com/vim/vim/commit/574860b5ee9da281c875dad07a607454e135eaee
Christian Brabandt <cb@256bit.org>
parents: 9050
diff changeset
146 call test_garbagecollect_now()
8420
f6d21a33d489 commit https://github.com/vim/vim/commit/38fd4bb2842df7634823b99c655b3896a7a2e988
Christian Brabandt <cb@256bit.org>
parents: 8404
diff changeset
147
8124
310dd635e8c9 commit https://github.com/vim/vim/commit/40ea1da14ba196a23309789852e1b663fd92e3a8
Christian Brabandt <cb@256bit.org>
parents: 8118
diff changeset
148 " 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
149 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
150 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
151 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
152 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
153 call ch_setoptions(handle, {'callback': ''})
10428
a963dce191cf commit https://github.com/vim/vim/commit/65e08ee1d26aa7bf341ac0e0400839d696d1ab64
Christian Brabandt <cb@256bit.org>
parents: 10422
diff changeset
154 call ch_setoptions(handle, {'drop': 'never'})
a963dce191cf commit https://github.com/vim/vim/commit/65e08ee1d26aa7bf341ac0e0400839d696d1ab64
Christian Brabandt <cb@256bit.org>
parents: 10422
diff changeset
155 call ch_setoptions(handle, {'drop': 'auto'})
a963dce191cf commit https://github.com/vim/vim/commit/65e08ee1d26aa7bf341ac0e0400839d696d1ab64
Christian Brabandt <cb@256bit.org>
parents: 10422
diff changeset
156 call assert_fails("call ch_setoptions(handle, {'drop': 'bad'})", "E475")
8124
310dd635e8c9 commit https://github.com/vim/vim/commit/40ea1da14ba196a23309789852e1b663fd92e3a8
Christian Brabandt <cb@256bit.org>
parents: 8118
diff changeset
157
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
158 " 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
159 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
160 sleep 10m
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
161 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
162
8744
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8692
diff changeset
163 " Send an eval request with special characters.
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8692
diff changeset
164 call assert_equal('ok', ch_evalexpr(handle, 'eval-special'))
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8692
diff changeset
165 sleep 10m
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8692
diff changeset
166 call assert_equal([-2, "foo\x7f\x10\x01bar"], ch_evalexpr(handle, 'eval-result'))
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8692
diff changeset
167
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8692
diff changeset
168 " Send an eval request to get a line with special characters.
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8692
diff changeset
169 call setline(3, "a\nb\<CR>c\x01d\x7fe")
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8692
diff changeset
170 call assert_equal('ok', ch_evalexpr(handle, 'eval-getline'))
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8692
diff changeset
171 sleep 10m
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8692
diff changeset
172 call assert_equal([-3, "a\nb\<CR>c\x01d\x7fe"], ch_evalexpr(handle, 'eval-result'))
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8692
diff changeset
173
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
174 " 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
175 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
176 sleep 10m
8744
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8692
diff changeset
177 call assert_equal([-4, '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
178
7965
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7957
diff changeset
179 " 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
180 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
181 sleep 10m
8744
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8692
diff changeset
182 call assert_equal([-5, '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
183
7918
ce5a7a613867 commit https://github.com/vim/vim/commit/66624ff0d9e1de2fc5eb4f95f3a3a2ed70b10138
Christian Brabandt <cb@256bit.org>
parents: 7916
diff changeset
184 " 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
185 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
186 sleep 10m
8744
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8692
diff changeset
187 call assert_equal([-5, '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
188
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
189 " Send an expr request
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
190 call assert_equal('ok', ch_evalexpr(handle, 'an expr'))
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
191 call WaitFor('"three" == getline("$")')
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
192 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
193 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
194 call assert_equal('three', getline('$'))
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
195
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7935
diff changeset
196 " 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
197 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
198 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
199
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
200 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
201
8157
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8132
diff changeset
202 " 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
203 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
204 let start = reltime()
4f0677020a43 commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
205 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
206 let elapsed = reltime(start)
4f0677020a43 commit https://github.com/vim/vim/commit/9186a276222ea8a7c88f4092ac5b4201381f4e20
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
207 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
208 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
209
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8132
diff changeset
210 " 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
211 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
212 let resp = ch_read(handle)
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8132
diff changeset
213 call assert_equal(type([]), type(resp))
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8132
diff changeset
214 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
215 call assert_equal('waited', resp[1])
74b44d06d3c7 commit https://github.com/vim/vim/commit/6f3a544228c1faf92211cbaf8bbedb1dff883f90
Christian Brabandt <cb@256bit.org>
parents: 8132
diff changeset
216
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
217 " 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
218 call ch_sendexpr(handle, '!quit!')
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
219 endfunc
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
220
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
221 func Test_communicate()
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
222 call ch_log('Test_communicate()')
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
223 call s:run_server('Ch_communicate')
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
224 endfunc
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
225
7916
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
226 " Test that we can open two channels.
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
227 func Ch_two_channels(port)
8013
dfae8bce5920 commit https://github.com/vim/vim/commit/39b21272d521512b6ecac6cc0f310944f21b7443
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
228 let handle = ch_open('localhost:' . a:port, s:chopt)
9587
05a56bbe34a1 commit https://github.com/vim/vim/commit/f562e72df726c6191fa305e1c0a113f1cfb87f76
Christian Brabandt <cb@256bit.org>
parents: 9527
diff changeset
229 call assert_equal(v:t_channel, type(handle))
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8037
diff changeset
230 if ch_status(handle) == "fail"
11183
1c4ebbae41d2 patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors
Christian Brabandt <cb@256bit.org>
parents: 10845
diff changeset
231 call assert_report("Can't open channel")
7916
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
232 return
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
233 endif
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
234
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(handle, 'hello!'))
7916
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
236
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
237 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
238 if ch_status(newhandle) == "fail"
11183
1c4ebbae41d2 patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors
Christian Brabandt <cb@256bit.org>
parents: 10845
diff changeset
239 call assert_report("Can't open second channel")
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
240 return
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
241 endif
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
242 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
243 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
244
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
245 call ch_close(handle)
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
246 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
247
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
248 call ch_close(newhandle)
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
249 endfunc
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
250
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
251 func Test_two_channels()
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
252 call ch_log('Test_two_channels()')
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
253 call s:run_server('Ch_two_channels')
7916
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
254 endfunc
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
255
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
256 " Test that a server crash is handled gracefully.
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
257 func Ch_server_crash(port)
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
258 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
259 if ch_status(handle) == "fail"
11183
1c4ebbae41d2 patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors
Christian Brabandt <cb@256bit.org>
parents: 10845
diff changeset
260 call assert_report("Can't open channel")
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
261 return
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
262 endif
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
263
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
264 call ch_evalexpr(handle, '!crash!')
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
265
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
266 sleep 10m
8007
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
267 endfunc
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
268
ac78cba9e72b commit https://github.com/vim/vim/commit/d6a8d48587b2ff43c343fa365898576cc1e235ea
Christian Brabandt <cb@256bit.org>
parents: 8005
diff changeset
269 func Test_server_crash()
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
270 call ch_log('Test_server_crash()')
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
271 call s:run_server('Ch_server_crash')
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7904
diff changeset
272 endfunc
7982
5c30ba57aaea commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
273
8382
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
274 """""""""
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
275
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
276 func Ch_handler(chan, msg)
10428
a963dce191cf commit https://github.com/vim/vim/commit/65e08ee1d26aa7bf341ac0e0400839d696d1ab64
Christian Brabandt <cb@256bit.org>
parents: 10422
diff changeset
277 call ch_log('Ch_handler()')
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
278 unlet g:Ch_reply
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
279 let g:Ch_reply = a:msg
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
280 endfunc
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
281
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
282 func Ch_channel_handler(port)
8017
c59a65524084 commit https://github.com/vim/vim/commit/b6a4fee37ebbb0c76f2fbda7d06cbf48a3a07e8d
Christian Brabandt <cb@256bit.org>
parents: 8013
diff changeset
283 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
284 if ch_status(handle) == "fail"
11183
1c4ebbae41d2 patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors
Christian Brabandt <cb@256bit.org>
parents: 10845
diff changeset
285 call assert_report("Can't open channel")
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
286 return
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
287 endif
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
288
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
289 " 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
290 call assert_equal('ok', ch_evalexpr(handle, 'call me'))
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
291 call WaitFor('"we called you" == g:Ch_reply')
8009
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 " 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
294 call ch_sendexpr(handle, 'call me again')
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
295 call WaitFor('"we did call you" == g:Ch_reply')
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
296 endfunc
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
297
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
298 func Test_channel_handler()
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
299 call ch_log('Test_channel_handler()')
10030
3b4b2ac811f0 commit https://github.com/vim/vim/commit/6fc8227ebfbdfbbb48b81b679db81f421dbce79b
Christian Brabandt <cb@256bit.org>
parents: 9994
diff changeset
300 let g:Ch_reply = ""
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
301 let s:chopt.callback = 'Ch_handler'
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
302 call s:run_server('Ch_channel_handler')
10030
3b4b2ac811f0 commit https://github.com/vim/vim/commit/6fc8227ebfbdfbbb48b81b679db81f421dbce79b
Christian Brabandt <cb@256bit.org>
parents: 9994
diff changeset
303 let g:Ch_reply = ""
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
304 let s:chopt.callback = function('Ch_handler')
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
305 call s:run_server('Ch_channel_handler')
8017
c59a65524084 commit https://github.com/vim/vim/commit/b6a4fee37ebbb0c76f2fbda7d06cbf48a3a07e8d
Christian Brabandt <cb@256bit.org>
parents: 8013
diff changeset
306 unlet s:chopt.callback
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
307 endfunc
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 8007
diff changeset
308
8382
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
309 """""""""
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
310
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
311 let g:Ch_reply = ''
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
312 func Ch_zeroHandler(chan, msg)
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
313 unlet g:Ch_reply
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
314 let g:Ch_reply = a:msg
8404
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
315 endfunc
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
316
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
317 let g:Ch_zero_reply = ''
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
318 func Ch_oneHandler(chan, msg)
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
319 unlet g:Ch_zero_reply
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
320 let g:Ch_zero_reply = a:msg
8404
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
321 endfunc
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
322
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
323 func Ch_channel_zero(port)
8404
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
324 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
325 if ch_status(handle) == "fail"
11183
1c4ebbae41d2 patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors
Christian Brabandt <cb@256bit.org>
parents: 10845
diff changeset
326 call assert_report("Can't open channel")
8404
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
327 return
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
328 endif
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
329
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
330 " Check that eval works.
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
331 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
332
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
333 " Check that eval works if a zero id message is sent back.
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
334 let g:Ch_reply = ''
8404
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
335 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
336 if s:has_handler
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
337 call WaitFor('"zero index" == g:Ch_reply')
8404
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
338 else
8449
3d567b5839c5 commit https://github.com/vim/vim/commit/9fe885e49ade94e6277db0dd18a5bbc1c94c60c4
Christian Brabandt <cb@256bit.org>
parents: 8447
diff changeset
339 sleep 20m
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
340 call assert_equal('', g:Ch_reply)
8404
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
341 endif
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
342
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
343 " Check that handler works if a zero id message is sent back.
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
344 let g:Ch_reply = ''
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
345 let g:Ch_zero_reply = ''
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
346 call ch_sendexpr(handle, 'send zero', {'callback': 'Ch_oneHandler'})
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
347 call WaitFor('"sent zero" == g:Ch_zero_reply')
8404
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
348 if s:has_handler
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
349 call assert_equal('zero index', g:Ch_reply)
8404
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
350 else
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
351 call assert_equal('', g:Ch_reply)
8404
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8386
diff changeset
352 endif
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
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
359 let s:chopt.callback = 'Ch_zeroHandler'
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
360 call s:run_server('Ch_channel_zero')
8404
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
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
365 call s:run_server('Ch_channel_zero')
8404
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
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
370 let g:Ch_reply1 = ""
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
371 func Ch_handleRaw1(chan, msg)
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
372 unlet g:Ch_reply1
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
373 let g:Ch_reply1 = a:msg
8382
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
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
376 let g:Ch_reply2 = ""
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
377 func Ch_handleRaw2(chan, msg)
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
378 unlet g:Ch_reply2
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
379 let g:Ch_reply2 = a:msg
8382
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
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
382 let g:Ch_reply3 = ""
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
383 func Ch_handleRaw3(chan, msg)
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
384 unlet g:Ch_reply3
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
385 let g:Ch_reply3 = a:msg
8382
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
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
388 func Ch_raw_one_time_callback(port)
8382
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"
11183
1c4ebbae41d2 patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors
Christian Brabandt <cb@256bit.org>
parents: 10845
diff changeset
391 call assert_report("Can't open channel")
8382
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
10422
e664ee056a84 commit https://github.com/vim/vim/commit/4b785f69c0616dba5d3f38e8ce4b5398cec89407
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
396 " The messages are sent raw, we do our own JSON strings here.
9973
01c3f981ce08 commit https://github.com/vim/vim/commit/dd74ab9b464f3d1a5f6f6395469b76f8e0e6dccd
Christian Brabandt <cb@256bit.org>
parents: 9969
diff changeset
397 call ch_sendraw(handle, "[1, \"hello!\"]\n", {'callback': 'Ch_handleRaw1'})
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
398 call WaitFor('g:Ch_reply1 != ""')
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
399 call assert_equal("[1, \"got it\"]", g:Ch_reply1)
9973
01c3f981ce08 commit https://github.com/vim/vim/commit/dd74ab9b464f3d1a5f6f6395469b76f8e0e6dccd
Christian Brabandt <cb@256bit.org>
parents: 9969
diff changeset
400 call ch_sendraw(handle, "[2, \"echo something\"]\n", {'callback': 'Ch_handleRaw2'})
01c3f981ce08 commit https://github.com/vim/vim/commit/dd74ab9b464f3d1a5f6f6395469b76f8e0e6dccd
Christian Brabandt <cb@256bit.org>
parents: 9969
diff changeset
401 call ch_sendraw(handle, "[3, \"wait a bit\"]\n", {'callback': 'Ch_handleRaw3'})
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
402 call WaitFor('g:Ch_reply2 != ""')
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
403 call assert_equal("[2, \"something\"]", g:Ch_reply2)
8449
3d567b5839c5 commit https://github.com/vim/vim/commit/9fe885e49ade94e6277db0dd18a5bbc1c94c60c4
Christian Brabandt <cb@256bit.org>
parents: 8447
diff changeset
404 " wait for the 200 msec delayed reply
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
405 call WaitFor('g:Ch_reply3 != ""')
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
406 call assert_equal("[3, \"waited\"]", g:Ch_reply3)
8382
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
407 endfunc
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
408
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
409 func Test_raw_one_time_callback()
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
410 call ch_log('Test_raw_one_time_callback()')
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
411 call s:run_server('Ch_raw_one_time_callback')
8382
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 """""""""
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
415
7982
5c30ba57aaea commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
416 " 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
417 func Test_connect_waittime()
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
418 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
419 let start = reltime()
8005
d65aa95725d3 commit https://github.com/vim/vim/commit/a483326e3b04215b86fe9c582ac96bb9679f0812
Christian Brabandt <cb@256bit.org>
parents: 7988
diff changeset
420 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
421 if ch_status(handle) != "fail"
7982
5c30ba57aaea commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
422 " Oops, port does exists.
5c30ba57aaea commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
423 call ch_close(handle)
5c30ba57aaea commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
424 else
5c30ba57aaea commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
425 let elapsed = reltime(start)
7984
c166ff6797cb commit https://github.com/vim/vim/commit/74f5e65bcc3d77ab879f56eb977f5038edccbcf8
Christian Brabandt <cb@256bit.org>
parents: 7982
diff changeset
426 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
427 endif
5c30ba57aaea commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
428
8168
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
429 " 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
430 " 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
431 " 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
432 let start = reltime()
8168
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
433 try
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
434 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
435 if ch_status(handle) != "fail"
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
436 " Oops, port does exists.
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
437 call ch_close(handle)
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
438 else
8500
1227dc21865b commit https://github.com/vim/vim/commit/ac42afd10b96424b89762871905e3e785cdfba3d
Christian Brabandt <cb@256bit.org>
parents: 8491
diff changeset
439 " Failed connection should wait about 500 msec. Can be longer if the
1227dc21865b commit https://github.com/vim/vim/commit/ac42afd10b96424b89762871905e3e785cdfba3d
Christian Brabandt <cb@256bit.org>
parents: 8491
diff changeset
440 " computer is busy with other things.
8168
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
441 let elapsed = reltime(start)
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
442 call assert_true(reltimefloat(elapsed) > 0.3)
8500
1227dc21865b commit https://github.com/vim/vim/commit/ac42afd10b96424b89762871905e3e785cdfba3d
Christian Brabandt <cb@256bit.org>
parents: 8491
diff changeset
443 call assert_true(reltimefloat(elapsed) < 1.5)
8168
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
444 endif
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
445 catch
454a30a7590e commit https://github.com/vim/vim/commit/08298fa1d3e32c2af476582792fc4f70cd57a59a
Christian Brabandt <cb@256bit.org>
parents: 8165
diff changeset
446 if v:exception !~ 'Connection reset by peer'
11183
1c4ebbae41d2 patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors
Christian Brabandt <cb@256bit.org>
parents: 10845
diff changeset
447 call assert_report("Caught exception: " . v:exception)
8168
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 endtry
7982
5c30ba57aaea commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
450 endfunc
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8027
diff changeset
451
8382
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
452 """""""""
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8380
diff changeset
453
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
454 func Test_raw_pipe()
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
455 if !has('job')
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
456 return
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
457 endif
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
458 call ch_log('Test_raw_pipe()')
10422
e664ee056a84 commit https://github.com/vim/vim/commit/4b785f69c0616dba5d3f38e8ce4b5398cec89407
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
459 " Add a dummy close callback to avoid that messages are dropped when calling
e664ee056a84 commit https://github.com/vim/vim/commit/4b785f69c0616dba5d3f38e8ce4b5398cec89407
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
460 " ch_canread().
e664ee056a84 commit https://github.com/vim/vim/commit/4b785f69c0616dba5d3f38e8ce4b5398cec89407
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
461 let job = job_start(s:python . " test_channel_pipe.py",
10428
a963dce191cf commit https://github.com/vim/vim/commit/65e08ee1d26aa7bf341ac0e0400839d696d1ab64
Christian Brabandt <cb@256bit.org>
parents: 10422
diff changeset
462 \ {'mode': 'raw', 'drop': 'never'})
9587
05a56bbe34a1 commit https://github.com/vim/vim/commit/f562e72df726c6191fa305e1c0a113f1cfb87f76
Christian Brabandt <cb@256bit.org>
parents: 9527
diff changeset
463 call assert_equal(v:t_job, type(job))
8084
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))
10233
d709622a18c9 commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents: 10147
diff changeset
465
d709622a18c9 commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents: 10147
diff changeset
466 call assert_equal("open", ch_status(job))
d709622a18c9 commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents: 10147
diff changeset
467 call assert_equal("open", ch_status(job), {"part": "out"})
d709622a18c9 commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents: 10147
diff changeset
468 call assert_equal("open", ch_status(job), {"part": "err"})
d709622a18c9 commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents: 10147
diff changeset
469 call assert_fails('call ch_status(job, {"in_mode": "raw"})', 'E475:')
d709622a18c9 commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents: 10147
diff changeset
470 call assert_fails('call ch_status(job, {"part": "in"})', 'E475:')
d709622a18c9 commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents: 10147
diff changeset
471
d709622a18c9 commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents: 10147
diff changeset
472 let dict = ch_info(job)
d709622a18c9 commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents: 10147
diff changeset
473 call assert_true(dict.id != 0)
d709622a18c9 commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents: 10147
diff changeset
474 call assert_equal('open', dict.status)
d709622a18c9 commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents: 10147
diff changeset
475 call assert_equal('open', dict.out_status)
d709622a18c9 commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents: 10147
diff changeset
476 call assert_equal('RAW', dict.out_mode)
d709622a18c9 commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents: 10147
diff changeset
477 call assert_equal('pipe', dict.out_io)
d709622a18c9 commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents: 10147
diff changeset
478 call assert_equal('open', dict.err_status)
d709622a18c9 commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents: 10147
diff changeset
479 call assert_equal('RAW', dict.err_mode)
d709622a18c9 commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents: 10147
diff changeset
480 call assert_equal('pipe', dict.err_io)
d709622a18c9 commit https://github.com/vim/vim/commit/7ef3810d28b7ab2edbfcafab3fe8ad8bc2c2f138
Christian Brabandt <cb@256bit.org>
parents: 10147
diff changeset
481
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
482 try
8436
0e6fd2f802b3 commit https://github.com/vim/vim/commit/151f656e171f6ffbb0cbeb343cbcf2ffac0c36b0
Christian Brabandt <cb@256bit.org>
parents: 8430
diff changeset
483 " For a change use the job where a channel is expected.
0e6fd2f802b3 commit https://github.com/vim/vim/commit/151f656e171f6ffbb0cbeb343cbcf2ffac0c36b0
Christian Brabandt <cb@256bit.org>
parents: 8430
diff changeset
484 call ch_sendraw(job, "echo something\n")
0e6fd2f802b3 commit https://github.com/vim/vim/commit/151f656e171f6ffbb0cbeb343cbcf2ffac0c36b0
Christian Brabandt <cb@256bit.org>
parents: 8430
diff changeset
485 let msg = ch_readraw(job)
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
486 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
487
8436
0e6fd2f802b3 commit https://github.com/vim/vim/commit/151f656e171f6ffbb0cbeb343cbcf2ffac0c36b0
Christian Brabandt <cb@256bit.org>
parents: 8430
diff changeset
488 call ch_sendraw(job, "double this\n")
10422
e664ee056a84 commit https://github.com/vim/vim/commit/4b785f69c0616dba5d3f38e8ce4b5398cec89407
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
489 let g:handle = job_getchannel(job)
e664ee056a84 commit https://github.com/vim/vim/commit/4b785f69c0616dba5d3f38e8ce4b5398cec89407
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
490 call WaitFor('ch_canread(g:handle)')
e664ee056a84 commit https://github.com/vim/vim/commit/4b785f69c0616dba5d3f38e8ce4b5398cec89407
Christian Brabandt <cb@256bit.org>
parents: 10386
diff changeset
491 unlet g:handle
8436
0e6fd2f802b3 commit https://github.com/vim/vim/commit/151f656e171f6ffbb0cbeb343cbcf2ffac0c36b0
Christian Brabandt <cb@256bit.org>
parents: 8430
diff changeset
492 let msg = ch_readraw(job)
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
493 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
494
10030
3b4b2ac811f0 commit https://github.com/vim/vim/commit/6fc8227ebfbdfbbb48b81b679db81f421dbce79b
Christian Brabandt <cb@256bit.org>
parents: 9994
diff changeset
495 let g:Ch_reply = ""
3b4b2ac811f0 commit https://github.com/vim/vim/commit/6fc8227ebfbdfbbb48b81b679db81f421dbce79b
Christian Brabandt <cb@256bit.org>
parents: 9994
diff changeset
496 call ch_sendraw(job, "double this\n", {'callback': 'Ch_handler'})
3b4b2ac811f0 commit https://github.com/vim/vim/commit/6fc8227ebfbdfbbb48b81b679db81f421dbce79b
Christian Brabandt <cb@256bit.org>
parents: 9994
diff changeset
497 call WaitFor('"" != g:Ch_reply')
3b4b2ac811f0 commit https://github.com/vim/vim/commit/6fc8227ebfbdfbbb48b81b679db81f421dbce79b
Christian Brabandt <cb@256bit.org>
parents: 9994
diff changeset
498 call assert_equal("this\nAND this\n", substitute(g:Ch_reply, "\r", "", 'g'))
3b4b2ac811f0 commit https://github.com/vim/vim/commit/6fc8227ebfbdfbbb48b81b679db81f421dbce79b
Christian Brabandt <cb@256bit.org>
parents: 9994
diff changeset
499
8436
0e6fd2f802b3 commit https://github.com/vim/vim/commit/151f656e171f6ffbb0cbeb343cbcf2ffac0c36b0
Christian Brabandt <cb@256bit.org>
parents: 8430
diff changeset
500 let reply = ch_evalraw(job, "quit\n", {'timeout': 100})
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
501 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
502 finally
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
503 call job_stop(job)
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
504 endtry
8502
ee5cb2e9ed5a commit https://github.com/vim/vim/commit/8950a563b306ce76f259573d91c2ddccdf52e32e
Christian Brabandt <cb@256bit.org>
parents: 8500
diff changeset
505
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
506 let g:Ch_job = job
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
507 call WaitFor('"dead" == job_status(g:Ch_job)')
8502
ee5cb2e9ed5a commit https://github.com/vim/vim/commit/8950a563b306ce76f259573d91c2ddccdf52e32e
Christian Brabandt <cb@256bit.org>
parents: 8500
diff changeset
508 let info = job_info(job)
ee5cb2e9ed5a commit https://github.com/vim/vim/commit/8950a563b306ce76f259573d91c2ddccdf52e32e
Christian Brabandt <cb@256bit.org>
parents: 8500
diff changeset
509 call assert_equal("dead", info.status)
ee5cb2e9ed5a commit https://github.com/vim/vim/commit/8950a563b306ce76f259573d91c2ddccdf52e32e
Christian Brabandt <cb@256bit.org>
parents: 8500
diff changeset
510 call assert_equal("term", info.stoponexit)
13740
f309afff6f25 patch 8.0.1742: cannot get a list of all the jobs
Christian Brabandt <cb@256bit.org>
parents: 13650
diff changeset
511 call assert_equal(2, len(info.cmd))
f309afff6f25 patch 8.0.1742: cannot get a list of all the jobs
Christian Brabandt <cb@256bit.org>
parents: 13650
diff changeset
512 call assert_equal("test_channel_pipe.py", info.cmd[1])
f309afff6f25 patch 8.0.1742: cannot get a list of all the jobs
Christian Brabandt <cb@256bit.org>
parents: 13650
diff changeset
513
f309afff6f25 patch 8.0.1742: cannot get a list of all the jobs
Christian Brabandt <cb@256bit.org>
parents: 13650
diff changeset
514 let found = 0
f309afff6f25 patch 8.0.1742: cannot get a list of all the jobs
Christian Brabandt <cb@256bit.org>
parents: 13650
diff changeset
515 for j in job_info()
f309afff6f25 patch 8.0.1742: cannot get a list of all the jobs
Christian Brabandt <cb@256bit.org>
parents: 13650
diff changeset
516 if j == job
f309afff6f25 patch 8.0.1742: cannot get a list of all the jobs
Christian Brabandt <cb@256bit.org>
parents: 13650
diff changeset
517 let found += 1
f309afff6f25 patch 8.0.1742: cannot get a list of all the jobs
Christian Brabandt <cb@256bit.org>
parents: 13650
diff changeset
518 endif
f309afff6f25 patch 8.0.1742: cannot get a list of all the jobs
Christian Brabandt <cb@256bit.org>
parents: 13650
diff changeset
519 endfor
f309afff6f25 patch 8.0.1742: cannot get a list of all the jobs
Christian Brabandt <cb@256bit.org>
parents: 13650
diff changeset
520 call assert_equal(1, found)
8084
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
521 endfunc
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
522
3ea56a74077f commit https://github.com/vim/vim/commit/9a6e33a19b18f20c25b73392cd2faa3ec4890c8c
Christian Brabandt <cb@256bit.org>
parents: 8078
diff changeset
523 func Test_nl_pipe()
8059
19304db153bc commit https://github.com/vim/vim/commit/d807036d10615b960c814ef3890ecad335b57f56
Christian Brabandt <cb@256bit.org>
parents: 8055
diff changeset
524 if !has('job')
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8027
diff changeset
525 return
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8027
diff changeset
526 endif
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
527 call ch_log('Test_nl_pipe()')
8504
0b31cc4b261e commit https://github.com/vim/vim/commit/1adda3403d80e96446248a92ceafee036053765c
Christian Brabandt <cb@256bit.org>
parents: 8502
diff changeset
528 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
529 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
530 try
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8027
diff changeset
531 let handle = job_getchannel(job)
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
532 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
533 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
534
8384
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
535 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
536 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
537
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
538 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
539 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
540 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
541
9238
7d13d180a6ae commit https://github.com/vim/vim/commit/bbe8d91e695184771d7e45315258fab8eb3e6b07
Christian Brabandt <cb@256bit.org>
parents: 9191
diff changeset
542 call ch_sendraw(handle, "split this line\n")
13010
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
543 call assert_equal("this linethis linethis line", ch_read(handle))
9238
7d13d180a6ae commit https://github.com/vim/vim/commit/bbe8d91e695184771d7e45315258fab8eb3e6b07
Christian Brabandt <cb@256bit.org>
parents: 9191
diff changeset
544
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
545 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
546 call assert_equal("Goodbye!", reply)
8031
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8027
diff changeset
547 finally
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8027
diff changeset
548 call job_stop(job)
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8027
diff changeset
549 endtry
ece323e2b57f commit https://github.com/vim/vim/commit/6463ca229cb9412581419497924c85fcbfc854ab
Christian Brabandt <cb@256bit.org>
parents: 8027
diff changeset
550 endfunc
8055
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
551
8384
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
552 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
553 if !has('job')
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
554 return
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
555 endif
8506
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
556 call ch_logfile('Xlog')
8384
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
557 call ch_log('Test_nl_err_to_out_pipe()')
8540
fec8655cf1bf commit https://github.com/vim/vim/commit/d6c2f0526064eef6f8917d2bad00df707d79ea16
Christian Brabandt <cb@256bit.org>
parents: 8506
diff changeset
558 let job = job_start(s:python . " test_channel_pipe.py", {'err_io': 'out'})
8384
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
559 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
560 try
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
561 let handle = job_getchannel(job)
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
562 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
563 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
564
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
565 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
566 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
567 finally
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
568 call job_stop(job)
8506
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
569 call ch_logfile('')
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
570 let loglines = readfile('Xlog')
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
571 call assert_true(len(loglines) > 10)
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
572 let found_test = 0
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
573 let found_send = 0
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
574 let found_recv = 0
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
575 let found_stop = 0
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
576 for l in loglines
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
577 if l =~ 'Test_nl_err_to_out_pipe'
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
578 let found_test = 1
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
579 endif
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
580 if l =~ 'SEND on.*echo something'
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
581 let found_send = 1
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
582 endif
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
583 if l =~ 'RECV on.*something'
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
584 let found_recv = 1
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
585 endif
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
586 if l =~ 'Stopping job with'
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
587 let found_stop = 1
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
588 endif
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
589 endfor
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
590 call assert_equal(1, found_test)
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
591 call assert_equal(1, found_send)
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
592 call assert_equal(1, found_recv)
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
593 call assert_equal(1, found_stop)
10060
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
594 " On MS-Windows need to sleep for a moment to be able to delete the file.
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
595 sleep 10m
8506
c93c352717b3 commit https://github.com/vim/vim/commit/5a6ec52392b78d41153660d0353d5b86a2dc583c
Christian Brabandt <cb@256bit.org>
parents: 8504
diff changeset
596 call delete('Xlog')
8384
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
597 endtry
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
598 endfunc
764dba33605c commit https://github.com/vim/vim/commit/c25558bff4ed10d2642e6f5c016701641c494916
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
599
10060
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
600 func Stop_g_job()
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
601 call job_stop(g:job)
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
602 if has('win32')
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
603 " On MS-Windows the server must close the file handle before we are able
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
604 " to delete the file.
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
605 call WaitFor('job_status(g:job) == "dead"')
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
606 sleep 10m
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
607 endif
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
608 endfunc
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
609
8430
800423dbc260 commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents: 8426
diff changeset
610 func Test_nl_read_file()
800423dbc260 commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents: 8426
diff changeset
611 if !has('job')
800423dbc260 commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents: 8426
diff changeset
612 return
800423dbc260 commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents: 8426
diff changeset
613 endif
800423dbc260 commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents: 8426
diff changeset
614 call ch_log('Test_nl_read_file()')
800423dbc260 commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents: 8426
diff changeset
615 call writefile(['echo something', 'echoerr wrong', 'double this'], 'Xinput')
10060
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
616 let g:job = job_start(s:python . " test_channel_pipe.py",
8540
fec8655cf1bf commit https://github.com/vim/vim/commit/d6c2f0526064eef6f8917d2bad00df707d79ea16
Christian Brabandt <cb@256bit.org>
parents: 8506
diff changeset
617 \ {'in_io': 'file', 'in_name': 'Xinput'})
10060
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
618 call assert_equal("run", job_status(g:job))
8430
800423dbc260 commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents: 8426
diff changeset
619 try
10060
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
620 let handle = job_getchannel(g:job)
8430
800423dbc260 commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents: 8426
diff changeset
621 call assert_equal("something", ch_readraw(handle))
800423dbc260 commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents: 8426
diff changeset
622 call assert_equal("wrong", ch_readraw(handle, {'part': 'err'}))
800423dbc260 commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents: 8426
diff changeset
623 call assert_equal("this", ch_readraw(handle))
800423dbc260 commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents: 8426
diff changeset
624 call assert_equal("AND this", ch_readraw(handle))
800423dbc260 commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents: 8426
diff changeset
625 finally
10060
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
626 call Stop_g_job()
8430
800423dbc260 commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents: 8426
diff changeset
627 call delete('Xinput')
800423dbc260 commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents: 8426
diff changeset
628 endtry
800423dbc260 commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents: 8426
diff changeset
629 endfunc
800423dbc260 commit https://github.com/vim/vim/commit/b69fccf377f43544b86817b0de6cc1498a4ff9ec
Christian Brabandt <cb@256bit.org>
parents: 8426
diff changeset
630
8447
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
631 func Test_nl_write_out_file()
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
632 if !has('job')
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
633 return
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
634 endif
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
635 call ch_log('Test_nl_write_out_file()')
10060
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
636 let g:job = job_start(s:python . " test_channel_pipe.py",
8540
fec8655cf1bf commit https://github.com/vim/vim/commit/d6c2f0526064eef6f8917d2bad00df707d79ea16
Christian Brabandt <cb@256bit.org>
parents: 8506
diff changeset
637 \ {'out_io': 'file', 'out_name': 'Xoutput'})
10060
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
638 call assert_equal("run", job_status(g:job))
8447
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
639 try
10060
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
640 let handle = job_getchannel(g:job)
8447
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
641 call ch_sendraw(handle, "echo line one\n")
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
642 call ch_sendraw(handle, "echo line two\n")
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
643 call ch_sendraw(handle, "double this\n")
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
644 call WaitFor('len(readfile("Xoutput")) > 2')
8447
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
645 call assert_equal(['line one', 'line two', 'this', 'AND this'], readfile('Xoutput'))
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
646 finally
10060
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
647 call Stop_g_job()
13357
179586a64f53 patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents: 13010
diff changeset
648 call assert_equal(-1, match(s:get_resources(), '\(^\|/\)Xoutput$'))
8447
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
649 call delete('Xoutput')
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
650 endtry
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
651 endfunc
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
652
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
653 func Test_nl_write_err_file()
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
654 if !has('job')
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
655 return
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
656 endif
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
657 call ch_log('Test_nl_write_err_file()')
10060
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
658 let g:job = job_start(s:python . " test_channel_pipe.py",
8540
fec8655cf1bf commit https://github.com/vim/vim/commit/d6c2f0526064eef6f8917d2bad00df707d79ea16
Christian Brabandt <cb@256bit.org>
parents: 8506
diff changeset
659 \ {'err_io': 'file', 'err_name': 'Xoutput'})
10060
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
660 call assert_equal("run", job_status(g:job))
8447
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
661 try
10060
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
662 let handle = job_getchannel(g:job)
8447
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
663 call ch_sendraw(handle, "echoerr line one\n")
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
664 call ch_sendraw(handle, "echoerr line two\n")
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
665 call ch_sendraw(handle, "doubleerr this\n")
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
666 call WaitFor('len(readfile("Xoutput")) > 2')
8447
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
667 call assert_equal(['line one', 'line two', 'this', 'AND this'], readfile('Xoutput'))
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
668 finally
10060
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
669 call Stop_g_job()
8447
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
670 call delete('Xoutput')
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
671 endtry
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
672 endfunc
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
673
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
674 func Test_nl_write_both_file()
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
675 if !has('job')
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
676 return
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
677 endif
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
678 call ch_log('Test_nl_write_both_file()')
10060
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
679 let g:job = job_start(s:python . " test_channel_pipe.py",
8540
fec8655cf1bf commit https://github.com/vim/vim/commit/d6c2f0526064eef6f8917d2bad00df707d79ea16
Christian Brabandt <cb@256bit.org>
parents: 8506
diff changeset
680 \ {'out_io': 'file', 'out_name': 'Xoutput', 'err_io': 'out'})
10060
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
681 call assert_equal("run", job_status(g:job))
8447
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
682 try
10060
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
683 let handle = job_getchannel(g:job)
8447
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
684 call ch_sendraw(handle, "echoerr line one\n")
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
685 call ch_sendraw(handle, "echo line two\n")
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
686 call ch_sendraw(handle, "double this\n")
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
687 call ch_sendraw(handle, "doubleerr that\n")
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
688 call WaitFor('len(readfile("Xoutput")) > 5')
8447
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
689 call assert_equal(['line one', 'line two', 'this', 'AND this', 'that', 'AND that'], readfile('Xoutput'))
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
690 finally
10060
cf9e550f17f6 commit https://github.com/vim/vim/commit/641ad6c7ac7367f95fd927b8efa4bf74ddb9ccf3
Christian Brabandt <cb@256bit.org>
parents: 10054
diff changeset
691 call Stop_g_job()
13357
179586a64f53 patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents: 13010
diff changeset
692 call assert_equal(-1, match(s:get_resources(), '\(^\|/\)Xoutput$'))
8447
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
693 call delete('Xoutput')
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
694 endtry
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
695 endfunc
6f26b680c243 commit https://github.com/vim/vim/commit/e98d12105213975f37b8d653bd909bd787a2cda9
Christian Brabandt <cb@256bit.org>
parents: 8443
diff changeset
696
9187
fb1a19011fbe commit https://github.com/vim/vim/commit/01d46e41ba4967ee534db4b94ad642007634841e
Christian Brabandt <cb@256bit.org>
parents: 9147
diff changeset
697 func BufCloseCb(ch)
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
698 let g:Ch_bufClosed = 'yes'
9187
fb1a19011fbe commit https://github.com/vim/vim/commit/01d46e41ba4967ee534db4b94ad642007634841e
Christian Brabandt <cb@256bit.org>
parents: 9147
diff changeset
699 endfunc
fb1a19011fbe commit https://github.com/vim/vim/commit/01d46e41ba4967ee534db4b94ad642007634841e
Christian Brabandt <cb@256bit.org>
parents: 9147
diff changeset
700
10147
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
701 func Run_test_pipe_to_buffer(use_name, nomod, do_msg)
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
702 if !has('job')
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
703 return
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
704 endif
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
705 call ch_log('Test_pipe_to_buffer()')
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
706 let g:Ch_bufClosed = 'no'
9187
fb1a19011fbe commit https://github.com/vim/vim/commit/01d46e41ba4967ee534db4b94ad642007634841e
Christian Brabandt <cb@256bit.org>
parents: 9147
diff changeset
707 let options = {'out_io': 'buffer', 'close_cb': 'BufCloseCb'}
10147
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
708 let expected = ['', 'line one', 'line two', 'this', 'AND this', 'Goodbye!']
8477
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
709 if a:use_name
8540
fec8655cf1bf commit https://github.com/vim/vim/commit/d6c2f0526064eef6f8917d2bad00df707d79ea16
Christian Brabandt <cb@256bit.org>
parents: 8506
diff changeset
710 let options['out_name'] = 'pipe-output'
10147
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
711 if a:do_msg
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
712 let expected[0] = 'Reading from channel output...'
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
713 else
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
714 let options['out_msg'] = 0
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
715 call remove(expected, 0)
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
716 endif
8477
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
717 else
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
718 sp pipe-output
8540
fec8655cf1bf commit https://github.com/vim/vim/commit/d6c2f0526064eef6f8917d2bad00df707d79ea16
Christian Brabandt <cb@256bit.org>
parents: 8506
diff changeset
719 let options['out_buf'] = bufnr('%')
8477
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
720 quit
10147
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
721 call remove(expected, 0)
8477
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
722 endif
9147
053bc64433ec commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
723 if a:nomod
053bc64433ec commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
724 let options['out_modifiable'] = 0
053bc64433ec commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
725 endif
8477
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
726 let job = job_start(s:python . " test_channel_pipe.py", options)
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
727 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
728 try
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
729 let handle = job_getchannel(job)
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
730 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
731 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
732 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
733 call ch_sendraw(handle, "quit\n")
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
734 sp pipe-output
12734
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
735 call WaitFor('line("$") == ' . len(expected) . ' && g:Ch_bufClosed == "yes"')
10147
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
736 call assert_equal(expected, getline(1, '$'))
9147
053bc64433ec commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
737 if a:nomod
053bc64433ec commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
738 call assert_equal(0, &modifiable)
053bc64433ec commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
739 else
053bc64433ec commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
740 call assert_equal(1, &modifiable)
053bc64433ec commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
741 endif
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
742 call assert_equal('yes', g:Ch_bufClosed)
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
743 bwipe!
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
744 finally
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
745 call job_stop(job)
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
746 endtry
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
747 endfunc
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
748
8477
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
749 func Test_pipe_to_buffer_name()
10147
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
750 call Run_test_pipe_to_buffer(1, 0, 1)
8477
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
751 endfunc
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
752
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
753 func Test_pipe_to_buffer_nr()
10147
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
754 call Run_test_pipe_to_buffer(0, 0, 1)
8477
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
755 endfunc
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
756
9147
053bc64433ec commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
757 func Test_pipe_to_buffer_name_nomod()
10147
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
758 call Run_test_pipe_to_buffer(1, 1, 1)
9147
053bc64433ec commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
759 endfunc
053bc64433ec commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
760
10147
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
761 func Test_pipe_to_buffer_name_nomsg()
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
762 call Run_test_pipe_to_buffer(1, 0, 1)
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
763 endfunc
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
764
11666
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
765 func Test_close_output_buffer()
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
766 if !has('job')
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
767 return
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
768 endif
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
769 enew!
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
770 let test_lines = ['one', 'two']
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
771 call setline(1, test_lines)
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
772 call ch_log('Test_close_output_buffer()')
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
773 let options = {'out_io': 'buffer'}
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
774 let options['out_name'] = 'buffer-output'
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
775 let options['out_msg'] = 0
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
776 split buffer-output
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
777 let job = job_start(s:python . " test_channel_write.py", options)
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
778 call assert_equal("run", job_status(job))
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
779 try
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
780 call WaitFor('line("$") == 3')
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
781 call assert_equal(3, line('$'))
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
782 quit!
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
783 sleep 100m
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
784 " Make sure the write didn't happen to the wrong buffer.
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
785 call assert_equal(test_lines, getline(1, line('$')))
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
786 call assert_equal(-1, bufwinnr('buffer-output'))
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
787 sbuf buffer-output
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
788 call assert_notequal(-1, bufwinnr('buffer-output'))
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
789 sleep 100m
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
790 close " no more writes
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
791 bwipe!
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
792 finally
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
793 call job_stop(job)
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
794 endtry
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
795 endfunc
5cd9ba96561d patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
796
10147
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
797 func Run_test_pipe_err_to_buffer(use_name, nomod, do_msg)
8463
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
798 if !has('job')
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
799 return
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
800 endif
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
801 call ch_log('Test_pipe_err_to_buffer()')
8540
fec8655cf1bf commit https://github.com/vim/vim/commit/d6c2f0526064eef6f8917d2bad00df707d79ea16
Christian Brabandt <cb@256bit.org>
parents: 8506
diff changeset
802 let options = {'err_io': 'buffer'}
10147
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
803 let expected = ['', 'line one', 'line two', 'this', 'AND this']
8477
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
804 if a:use_name
8540
fec8655cf1bf commit https://github.com/vim/vim/commit/d6c2f0526064eef6f8917d2bad00df707d79ea16
Christian Brabandt <cb@256bit.org>
parents: 8506
diff changeset
805 let options['err_name'] = 'pipe-err'
10147
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
806 if a:do_msg
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
807 let expected[0] = 'Reading from channel error...'
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
808 else
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
809 let options['err_msg'] = 0
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
810 call remove(expected, 0)
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
811 endif
8477
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
812 else
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
813 sp pipe-err
8540
fec8655cf1bf commit https://github.com/vim/vim/commit/d6c2f0526064eef6f8917d2bad00df707d79ea16
Christian Brabandt <cb@256bit.org>
parents: 8506
diff changeset
814 let options['err_buf'] = bufnr('%')
8477
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
815 quit
10147
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
816 call remove(expected, 0)
8477
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
817 endif
9147
053bc64433ec commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
818 if a:nomod
053bc64433ec commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
819 let options['err_modifiable'] = 0
053bc64433ec commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
820 endif
8477
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
821 let job = job_start(s:python . " test_channel_pipe.py", options)
8463
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
822 call assert_equal("run", job_status(job))
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
823 try
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
824 let handle = job_getchannel(job)
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
825 call ch_sendraw(handle, "echoerr line one\n")
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
826 call ch_sendraw(handle, "echoerr line two\n")
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
827 call ch_sendraw(handle, "doubleerr this\n")
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
828 call ch_sendraw(handle, "quit\n")
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
829 sp pipe-err
12734
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
830 call WaitFor('line("$") == ' . len(expected))
10147
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
831 call assert_equal(expected, getline(1, '$'))
9147
053bc64433ec commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
832 if a:nomod
053bc64433ec commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
833 call assert_equal(0, &modifiable)
053bc64433ec commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
834 else
053bc64433ec commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
835 call assert_equal(1, &modifiable)
053bc64433ec commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
836 endif
8463
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
837 bwipe!
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
838 finally
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
839 call job_stop(job)
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
840 endtry
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
841 endfunc
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
842
8477
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
843 func Test_pipe_err_to_buffer_name()
10147
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
844 call Run_test_pipe_err_to_buffer(1, 0, 1)
8477
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
845 endfunc
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
846
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
847 func Test_pipe_err_to_buffer_nr()
10147
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
848 call Run_test_pipe_err_to_buffer(0, 0, 1)
9147
053bc64433ec commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
849 endfunc
053bc64433ec commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
850
053bc64433ec commit https://github.com/vim/vim/commit/9f5842e63fc63d438cbffcec503e072a06f74dc2
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
851 func Test_pipe_err_to_buffer_name_nomod()
10147
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
852 call Run_test_pipe_err_to_buffer(1, 1, 1)
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
853 endfunc
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
854
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
855 func Test_pipe_err_to_buffer_name_nomsg()
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
856 call Run_test_pipe_err_to_buffer(1, 0, 0)
8477
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
857 endfunc
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
858
8463
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
859 func Test_pipe_both_to_buffer()
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
860 if !has('job')
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
861 return
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
862 endif
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
863 call ch_log('Test_pipe_both_to_buffer()')
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
864 let job = job_start(s:python . " test_channel_pipe.py",
8540
fec8655cf1bf commit https://github.com/vim/vim/commit/d6c2f0526064eef6f8917d2bad00df707d79ea16
Christian Brabandt <cb@256bit.org>
parents: 8506
diff changeset
865 \ {'out_io': 'buffer', 'out_name': 'pipe-err', 'err_io': 'out'})
8463
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
866 call assert_equal("run", job_status(job))
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
867 try
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
868 let handle = job_getchannel(job)
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
869 call ch_sendraw(handle, "echo line one\n")
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
870 call ch_sendraw(handle, "echoerr line two\n")
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
871 call ch_sendraw(handle, "double this\n")
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
872 call ch_sendraw(handle, "doubleerr that\n")
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
873 call ch_sendraw(handle, "quit\n")
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
874 sp pipe-err
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
875 call WaitFor('line("$") >= 7')
8463
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
876 call assert_equal(['Reading from channel output...', 'line one', 'line two', 'this', 'AND this', 'that', 'AND that', 'Goodbye!'], getline(1, '$'))
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
877 bwipe!
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
878 finally
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
879 call job_stop(job)
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
880 endtry
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
881 endfunc
508504ca52ac commit https://github.com/vim/vim/commit/6ff02c96519946716069f05c62849986a706033b
Christian Brabandt <cb@256bit.org>
parents: 8459
diff changeset
882
8477
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
883 func Run_test_pipe_from_buffer(use_name)
8386
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
884 if !has('job')
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
885 return
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
886 endif
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
887 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
888
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
889 sp pipe-input
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
890 call setline(1, ['echo one', 'echo two', 'echo three'])
8761
f8707ec9efe4 commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents: 8753
diff changeset
891 let options = {'in_io': 'buffer', 'block_write': 1}
8477
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
892 if a:use_name
8540
fec8655cf1bf commit https://github.com/vim/vim/commit/d6c2f0526064eef6f8917d2bad00df707d79ea16
Christian Brabandt <cb@256bit.org>
parents: 8506
diff changeset
893 let options['in_name'] = 'pipe-input'
8477
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
894 else
8540
fec8655cf1bf commit https://github.com/vim/vim/commit/d6c2f0526064eef6f8917d2bad00df707d79ea16
Christian Brabandt <cb@256bit.org>
parents: 8506
diff changeset
895 let options['in_buf'] = bufnr('%')
8477
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
896 endif
8386
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
897
8477
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
898 let job = job_start(s:python . " test_channel_pipe.py", options)
8386
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
899 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
900 try
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
901 let handle = job_getchannel(job)
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
902 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
903 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
904 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
905 bwipe!
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
906 finally
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
907 call job_stop(job)
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
908 endtry
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
909 endfunc
3b9a306724ec commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Christian Brabandt <cb@256bit.org>
parents: 8384
diff changeset
910
8477
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
911 func Test_pipe_from_buffer_name()
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
912 call Run_test_pipe_from_buffer(1)
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
913 endfunc
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
914
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
915 func Test_pipe_from_buffer_nr()
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
916 call Run_test_pipe_from_buffer(0)
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
917 endfunc
c08c6d19db4d commit https://github.com/vim/vim/commit/29fd03878c41526a586d77b3f3cd7938d26297af
Christian Brabandt <cb@256bit.org>
parents: 8471
diff changeset
918
10054
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
919 func Run_pipe_through_sort(all, use_buffer)
10052
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
920 if !executable('sort') || !has('job')
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
921 return
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
922 endif
10054
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
923 let options = {'out_io': 'buffer', 'out_name': 'sortout'}
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
924 if a:use_buffer
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
925 split sortin
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
926 call setline(1, ['ccc', 'aaa', 'ddd', 'bbb', 'eee'])
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
927 let options.in_io = 'buffer'
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
928 let options.in_name = 'sortin'
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
929 endif
10052
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
930 if !a:all
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
931 let options.in_top = 2
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
932 let options.in_bot = 4
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
933 endif
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
934 let g:job = job_start('sort', options)
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
935 call assert_equal("run", job_status(g:job))
10054
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
936
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
937 if !a:use_buffer
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
938 call ch_sendraw(g:job, "ccc\naaa\nddd\nbbb\neee\n")
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
939 call ch_close_in(g:job)
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
940 endif
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
941
10052
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
942 call WaitFor('job_status(g:job) == "dead"')
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
943 call assert_equal("dead", job_status(g:job))
10054
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
944
10052
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
945 sp sortout
10090
68303019acc9 commit https://github.com/vim/vim/commit/f7f3e32fcc4984d87f26337316379c2e2d90f7f1
Christian Brabandt <cb@256bit.org>
parents: 10060
diff changeset
946 call WaitFor('line("$") > 3')
10052
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
947 call assert_equal('Reading from channel output...', getline(1))
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
948 if a:all
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
949 call assert_equal(['aaa', 'bbb', 'ccc', 'ddd', 'eee'], getline(2, 6))
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
950 else
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
951 call assert_equal(['aaa', 'bbb', 'ddd'], getline(2, 4))
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
952 endif
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
953
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
954 call job_stop(g:job)
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
955 unlet g:job
10054
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
956 if a:use_buffer
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
957 bwipe! sortin
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
958 endif
10052
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
959 bwipe! sortout
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
960 endfunc
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
961
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
962 func Test_pipe_through_sort_all()
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
963 call ch_log('Test_pipe_through_sort_all()')
10054
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
964 call Run_pipe_through_sort(1, 1)
10052
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
965 endfunc
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
966
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
967 func Test_pipe_through_sort_some()
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
968 call ch_log('Test_pipe_through_sort_some()')
10054
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
969 call Run_pipe_through_sort(0, 1)
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
970 endfunc
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
971
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
972 func Test_pipe_through_sort_feed()
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
973 call ch_log('Test_pipe_through_sort_feed()')
d4b7232fc63a commit https://github.com/vim/vim/commit/0874a83e9be1b39fdb217f02b427bf1d6133a4d8
Christian Brabandt <cb@256bit.org>
parents: 10052
diff changeset
974 call Run_pipe_through_sort(1, 0)
10052
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
975 endfunc
c1ba49441c90 commit https://github.com/vim/vim/commit/d8b554904d18fe19bd9fa79dbda880845cb017d2
Christian Brabandt <cb@256bit.org>
parents: 10030
diff changeset
976
8291
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
977 func Test_pipe_to_nameless_buffer()
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
978 if !has('job')
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
979 return
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
980 endif
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
981 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
982 let job = job_start(s:python . " test_channel_pipe.py",
8540
fec8655cf1bf commit https://github.com/vim/vim/commit/d6c2f0526064eef6f8917d2bad00df707d79ea16
Christian Brabandt <cb@256bit.org>
parents: 8506
diff changeset
983 \ {'out_io': 'buffer'})
8291
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
984 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
985 try
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
986 let handle = job_getchannel(job)
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
987 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
988 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
989 exe ch_getbufnr(handle, "out") . 'sbuf'
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
990 call WaitFor('line("$") >= 3')
8291
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
991 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
992 bwipe!
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
993 finally
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
994 call job_stop(job)
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
995 endtry
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
996 endfunc
ac0c43e7af20 commit https://github.com/vim/vim/commit/c7f0ebc6d1e1cdaed816b88a0d6092c5ace615eb
Christian Brabandt <cb@256bit.org>
parents: 8285
diff changeset
997
8346
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
998 func Test_pipe_to_buffer_json()
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
999 if !has('job')
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
1000 return
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
1001 endif
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
1002 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
1003 let job = job_start(s:python . " test_channel_pipe.py",
8540
fec8655cf1bf commit https://github.com/vim/vim/commit/d6c2f0526064eef6f8917d2bad00df707d79ea16
Christian Brabandt <cb@256bit.org>
parents: 8506
diff changeset
1004 \ {'out_io': 'buffer', 'out_mode': 'json'})
8346
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
1005 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
1006 try
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
1007 let handle = job_getchannel(job)
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
1008 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
1009 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
1010 exe ch_getbufnr(handle, "out") . 'sbuf'
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1011 call WaitFor('line("$") >= 3')
8346
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
1012 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
1013 bwipe!
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
1014 finally
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
1015 call job_stop(job)
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
1016 endtry
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
1017 endfunc
8fa75a4c39bd commit https://github.com/vim/vim/commit/cc7f8be3e0e6c4d902b02052a862e21c3a3fbe22
Christian Brabandt <cb@256bit.org>
parents: 8324
diff changeset
1018
8426
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1019 " Wait a little while for the last line, minus "offset", to equal "line".
8449
3d567b5839c5 commit https://github.com/vim/vim/commit/9fe885e49ade94e6277db0dd18a5bbc1c94c60c4
Christian Brabandt <cb@256bit.org>
parents: 8447
diff changeset
1020 func s:wait_for_last_line(line, offset)
8426
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1021 for i in range(100)
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1022 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
1023 break
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1024 endif
8449
3d567b5839c5 commit https://github.com/vim/vim/commit/9fe885e49ade94e6277db0dd18a5bbc1c94c60c4
Christian Brabandt <cb@256bit.org>
parents: 8447
diff changeset
1025 sleep 10m
8426
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1026 endfor
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1027 endfunc
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1028
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1029 func Test_pipe_io_two_buffers()
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1030 if !has('job')
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1031 return
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1032 endif
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1033 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
1034
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1035 " 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
1036 split pipe-output
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1037 set buftype=nofile
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1038 split pipe-input
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1039 set buftype=nofile
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1040
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1041 let job = job_start(s:python . " test_channel_pipe.py",
8540
fec8655cf1bf commit https://github.com/vim/vim/commit/d6c2f0526064eef6f8917d2bad00df707d79ea16
Christian Brabandt <cb@256bit.org>
parents: 8506
diff changeset
1042 \ {'in_io': 'buffer', 'in_name': 'pipe-input', 'in_top': 0,
8761
f8707ec9efe4 commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents: 8753
diff changeset
1043 \ 'out_io': 'buffer', 'out_name': 'pipe-output',
f8707ec9efe4 commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents: 8753
diff changeset
1044 \ 'block_write': 1})
8426
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1045 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
1046 try
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1047 exe "normal Gaecho hello\<CR>"
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1048 exe bufwinnr('pipe-output') . "wincmd w"
8449
3d567b5839c5 commit https://github.com/vim/vim/commit/9fe885e49ade94e6277db0dd18a5bbc1c94c60c4
Christian Brabandt <cb@256bit.org>
parents: 8447
diff changeset
1049 call s:wait_for_last_line('hello', 0)
8426
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1050 call assert_equal('hello', getline('$'))
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1051
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1052 exe bufwinnr('pipe-input') . "wincmd w"
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1053 exe "normal Gadouble this\<CR>"
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1054 exe bufwinnr('pipe-output') . "wincmd w"
8449
3d567b5839c5 commit https://github.com/vim/vim/commit/9fe885e49ade94e6277db0dd18a5bbc1c94c60c4
Christian Brabandt <cb@256bit.org>
parents: 8447
diff changeset
1055 call s:wait_for_last_line('AND this', 0)
8426
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1056 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
1057 call assert_equal('AND this', getline('$'))
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1058
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1059 bwipe!
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1060 exe bufwinnr('pipe-input') . "wincmd w"
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1061 bwipe!
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1062 finally
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1063 call job_stop(job)
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1064 endtry
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1065 endfunc
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1066
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1067 func Test_pipe_io_one_buffer()
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1068 if !has('job')
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1069 return
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1070 endif
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1071 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
1072
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1073 " 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
1074 split pipe-io
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1075 set buftype=nofile
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1076
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1077 let job = job_start(s:python . " test_channel_pipe.py",
8540
fec8655cf1bf commit https://github.com/vim/vim/commit/d6c2f0526064eef6f8917d2bad00df707d79ea16
Christian Brabandt <cb@256bit.org>
parents: 8506
diff changeset
1078 \ {'in_io': 'buffer', 'in_name': 'pipe-io', 'in_top': 0,
8761
f8707ec9efe4 commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents: 8753
diff changeset
1079 \ 'out_io': 'buffer', 'out_name': 'pipe-io',
f8707ec9efe4 commit https://github.com/vim/vim/commit/8b877ac38e96424a08a8b8eb713ef4b3cf0064be
Christian Brabandt <cb@256bit.org>
parents: 8753
diff changeset
1080 \ 'block_write': 1})
8426
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1081 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
1082 try
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1083 exe "normal Goecho hello\<CR>"
8449
3d567b5839c5 commit https://github.com/vim/vim/commit/9fe885e49ade94e6277db0dd18a5bbc1c94c60c4
Christian Brabandt <cb@256bit.org>
parents: 8447
diff changeset
1084 call s:wait_for_last_line('hello', 1)
8426
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1085 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
1086
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1087 exe "normal Gadouble this\<CR>"
8449
3d567b5839c5 commit https://github.com/vim/vim/commit/9fe885e49ade94e6277db0dd18a5bbc1c94c60c4
Christian Brabandt <cb@256bit.org>
parents: 8447
diff changeset
1088 call s:wait_for_last_line('AND this', 1)
8426
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1089 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
1090 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
1091
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1092 bwipe!
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1093 finally
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1094 call job_stop(job)
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1095 endtry
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1096 endfunc
02ce040591c8 commit https://github.com/vim/vim/commit/3f39f648662bf8723f687d14694041779ed0780c
Christian Brabandt <cb@256bit.org>
parents: 8424
diff changeset
1097
8455
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1098 func Test_pipe_null()
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1099 if !has('job')
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1100 return
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1101 endif
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1102 call ch_log('Test_pipe_null()')
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1103
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1104 " We cannot check that no I/O works, we only check that the job starts
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1105 " properly.
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1106 let job = job_start(s:python . " test_channel_pipe.py something",
8540
fec8655cf1bf commit https://github.com/vim/vim/commit/d6c2f0526064eef6f8917d2bad00df707d79ea16
Christian Brabandt <cb@256bit.org>
parents: 8506
diff changeset
1107 \ {'in_io': 'null'})
8455
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1108 call assert_equal("run", job_status(job))
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1109 try
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1110 call assert_equal('something', ch_read(job))
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1111 finally
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1112 call job_stop(job)
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1113 endtry
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1114
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1115 let job = job_start(s:python . " test_channel_pipe.py err-out",
8540
fec8655cf1bf commit https://github.com/vim/vim/commit/d6c2f0526064eef6f8917d2bad00df707d79ea16
Christian Brabandt <cb@256bit.org>
parents: 8506
diff changeset
1116 \ {'out_io': 'null'})
8455
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1117 call assert_equal("run", job_status(job))
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1118 try
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1119 call assert_equal('err-out', ch_read(job, {"part": "err"}))
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1120 finally
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1121 call job_stop(job)
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1122 endtry
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1123
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1124 let job = job_start(s:python . " test_channel_pipe.py something",
8540
fec8655cf1bf commit https://github.com/vim/vim/commit/d6c2f0526064eef6f8917d2bad00df707d79ea16
Christian Brabandt <cb@256bit.org>
parents: 8506
diff changeset
1125 \ {'err_io': 'null'})
8455
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1126 call assert_equal("run", job_status(job))
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1127 try
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1128 call assert_equal('something', ch_read(job))
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1129 finally
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1130 call job_stop(job)
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1131 endtry
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1132
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1133 let job = job_start(s:python . " test_channel_pipe.py something",
8540
fec8655cf1bf commit https://github.com/vim/vim/commit/d6c2f0526064eef6f8917d2bad00df707d79ea16
Christian Brabandt <cb@256bit.org>
parents: 8506
diff changeset
1134 \ {'out_io': 'null', 'err_io': 'out'})
8455
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1135 call assert_equal("run", job_status(job))
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1136 call job_stop(job)
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1137
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1138 let job = job_start(s:python . " test_channel_pipe.py something",
8540
fec8655cf1bf commit https://github.com/vim/vim/commit/d6c2f0526064eef6f8917d2bad00df707d79ea16
Christian Brabandt <cb@256bit.org>
parents: 8506
diff changeset
1139 \ {'in_io': 'null', 'out_io': 'null', 'err_io': 'null'})
8455
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1140 call assert_equal("run", job_status(job))
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1141 call assert_equal('channel fail', string(job_getchannel(job)))
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1142 call assert_equal('fail', ch_status(job))
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1143 call job_stop(job)
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1144 endfunc
d0717262d802 commit https://github.com/vim/vim/commit/f65333c9b59654a70f2a07200f65c93dfcaa49b3
Christian Brabandt <cb@256bit.org>
parents: 8449
diff changeset
1145
9367
2465b6cda394 commit https://github.com/vim/vim/commit/adb78a77ebb47627bcf73bd16ac1119d970e17c8
Christian Brabandt <cb@256bit.org>
parents: 9266
diff changeset
1146 func Test_pipe_to_buffer_raw()
2465b6cda394 commit https://github.com/vim/vim/commit/adb78a77ebb47627bcf73bd16ac1119d970e17c8
Christian Brabandt <cb@256bit.org>
parents: 9266
diff changeset
1147 if !has('job')
2465b6cda394 commit https://github.com/vim/vim/commit/adb78a77ebb47627bcf73bd16ac1119d970e17c8
Christian Brabandt <cb@256bit.org>
parents: 9266
diff changeset
1148 return
2465b6cda394 commit https://github.com/vim/vim/commit/adb78a77ebb47627bcf73bd16ac1119d970e17c8
Christian Brabandt <cb@256bit.org>
parents: 9266
diff changeset
1149 endif
2465b6cda394 commit https://github.com/vim/vim/commit/adb78a77ebb47627bcf73bd16ac1119d970e17c8
Christian Brabandt <cb@256bit.org>
parents: 9266
diff changeset
1150 call ch_log('Test_raw_pipe_to_buffer()')
2465b6cda394 commit https://github.com/vim/vim/commit/adb78a77ebb47627bcf73bd16ac1119d970e17c8
Christian Brabandt <cb@256bit.org>
parents: 9266
diff changeset
1151 let options = {'out_mode': 'raw', 'out_io': 'buffer', 'out_name': 'testout'}
2465b6cda394 commit https://github.com/vim/vim/commit/adb78a77ebb47627bcf73bd16ac1119d970e17c8
Christian Brabandt <cb@256bit.org>
parents: 9266
diff changeset
1152 split testout
2465b6cda394 commit https://github.com/vim/vim/commit/adb78a77ebb47627bcf73bd16ac1119d970e17c8
Christian Brabandt <cb@256bit.org>
parents: 9266
diff changeset
1153 let job = job_start([s:python, '-c',
2465b6cda394 commit https://github.com/vim/vim/commit/adb78a77ebb47627bcf73bd16ac1119d970e17c8
Christian Brabandt <cb@256bit.org>
parents: 9266
diff changeset
1154 \ 'import sys; [sys.stdout.write(".") and sys.stdout.flush() for _ in range(10000)]'], options)
2465b6cda394 commit https://github.com/vim/vim/commit/adb78a77ebb47627bcf73bd16ac1119d970e17c8
Christian Brabandt <cb@256bit.org>
parents: 9266
diff changeset
1155 call assert_equal("run", job_status(job))
13650
87ffb7f85b28 patch 8.0.1697: various tests are still a bit flaky
Christian Brabandt <cb@256bit.org>
parents: 13598
diff changeset
1156 call WaitFor('len(join(getline(1, "$"), "")) >= 10000')
9367
2465b6cda394 commit https://github.com/vim/vim/commit/adb78a77ebb47627bcf73bd16ac1119d970e17c8
Christian Brabandt <cb@256bit.org>
parents: 9266
diff changeset
1157 try
12734
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
1158 let totlen = 0
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
1159 for line in getline(1, '$')
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
1160 call assert_equal('', substitute(line, '^\.*', '', ''))
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
1161 let totlen += len(line)
9367
2465b6cda394 commit https://github.com/vim/vim/commit/adb78a77ebb47627bcf73bd16ac1119d970e17c8
Christian Brabandt <cb@256bit.org>
parents: 9266
diff changeset
1162 endfor
12734
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
1163 call assert_equal(10000, totlen)
9367
2465b6cda394 commit https://github.com/vim/vim/commit/adb78a77ebb47627bcf73bd16ac1119d970e17c8
Christian Brabandt <cb@256bit.org>
parents: 9266
diff changeset
1164 finally
2465b6cda394 commit https://github.com/vim/vim/commit/adb78a77ebb47627bcf73bd16ac1119d970e17c8
Christian Brabandt <cb@256bit.org>
parents: 9266
diff changeset
1165 call job_stop(job)
2465b6cda394 commit https://github.com/vim/vim/commit/adb78a77ebb47627bcf73bd16ac1119d970e17c8
Christian Brabandt <cb@256bit.org>
parents: 9266
diff changeset
1166 bwipe!
2465b6cda394 commit https://github.com/vim/vim/commit/adb78a77ebb47627bcf73bd16ac1119d970e17c8
Christian Brabandt <cb@256bit.org>
parents: 9266
diff changeset
1167 endtry
2465b6cda394 commit https://github.com/vim/vim/commit/adb78a77ebb47627bcf73bd16ac1119d970e17c8
Christian Brabandt <cb@256bit.org>
parents: 9266
diff changeset
1168 endfunc
2465b6cda394 commit https://github.com/vim/vim/commit/adb78a77ebb47627bcf73bd16ac1119d970e17c8
Christian Brabandt <cb@256bit.org>
parents: 9266
diff changeset
1169
8491
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1170 func Test_reuse_channel()
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1171 if !has('job')
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1172 return
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1173 endif
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1174 call ch_log('Test_reuse_channel()')
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1175
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1176 let job = job_start(s:python . " test_channel_pipe.py")
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1177 call assert_equal("run", job_status(job))
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1178 let handle = job_getchannel(job)
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1179 try
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1180 call ch_sendraw(handle, "echo something\n")
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1181 call assert_equal("something", ch_readraw(handle))
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1182 finally
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1183 call job_stop(job)
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1184 endtry
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1185
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1186 let job = job_start(s:python . " test_channel_pipe.py", {'channel': handle})
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1187 call assert_equal("run", job_status(job))
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1188 let handle = job_getchannel(job)
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1189 try
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1190 call ch_sendraw(handle, "echo again\n")
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1191 call assert_equal("again", ch_readraw(handle))
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1192 finally
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1193 call job_stop(job)
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1194 endtry
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1195 endfunc
daebcbd87bd3 commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce
Christian Brabandt <cb@256bit.org>
parents: 8477
diff changeset
1196
8676
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1197 func Test_out_cb()
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1198 if !has('job')
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1199 return
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1200 endif
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1201 call ch_log('Test_out_cb()')
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1202
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1203 let dict = {'thisis': 'dict: '}
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1204 func dict.outHandler(chan, msg) dict
10845
c31782d57569 patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents: 10524
diff changeset
1205 if type(a:msg) == v:t_string
c31782d57569 patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents: 10524
diff changeset
1206 let g:Ch_outmsg = self.thisis . a:msg
c31782d57569 patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents: 10524
diff changeset
1207 else
c31782d57569 patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents: 10524
diff changeset
1208 let g:Ch_outobj = a:msg
c31782d57569 patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents: 10524
diff changeset
1209 endif
8676
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1210 endfunc
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1211 func dict.errHandler(chan, msg) dict
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1212 let g:Ch_errmsg = self.thisis . a:msg
8676
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1213 endfunc
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1214 let job = job_start(s:python . " test_channel_pipe.py",
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1215 \ {'out_cb': dict.outHandler,
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1216 \ 'out_mode': 'json',
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1217 \ 'err_cb': dict.errHandler,
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1218 \ 'err_mode': 'json'})
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1219 call assert_equal("run", job_status(job))
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1220 try
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1221 let g:Ch_outmsg = ''
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1222 let g:Ch_errmsg = ''
8676
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1223 call ch_sendraw(job, "echo [0, \"hello\"]\n")
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1224 call ch_sendraw(job, "echoerr [0, \"there\"]\n")
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1225 call WaitFor('g:Ch_outmsg != ""')
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1226 call assert_equal("dict: hello", g:Ch_outmsg)
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1227 call WaitFor('g:Ch_errmsg != ""')
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1228 call assert_equal("dict: there", g:Ch_errmsg)
10845
c31782d57569 patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents: 10524
diff changeset
1229
c31782d57569 patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents: 10524
diff changeset
1230 " Receive a json object split in pieces
c31782d57569 patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents: 10524
diff changeset
1231 unlet! g:Ch_outobj
c31782d57569 patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents: 10524
diff changeset
1232 call ch_sendraw(job, "echosplit [0, {\"one\": 1,| \"tw|o\": 2, \"three\": 3|}]\n")
c31782d57569 patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents: 10524
diff changeset
1233 call WaitFor('exists("g:Ch_outobj")')
c31782d57569 patch 8.0.0312: failure when a channel receives a split json message
Christian Brabandt <cb@256bit.org>
parents: 10524
diff changeset
1234 call assert_equal({'one': 1, 'two': 2, 'three': 3}, g:Ch_outobj)
8676
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1235 finally
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1236 call job_stop(job)
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1237 endtry
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1238 endfunc
289765409225 commit https://github.com/vim/vim/commit/75f7265dd402665b8600fdf21ba33f19db06ac0d
Christian Brabandt <cb@256bit.org>
parents: 8669
diff changeset
1239
9003
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1240 func Test_out_close_cb()
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1241 if !has('job')
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1242 return
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1243 endif
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1244 call ch_log('Test_out_close_cb()')
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1245
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1246 let s:counter = 1
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1247 let g:Ch_msg1 = ''
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1248 let g:Ch_closemsg = 0
9003
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1249 func! OutHandler(chan, msg)
9044
5abf6f38cbbb commit https://github.com/vim/vim/commit/d75263c020a5044fa73bc8cd57ce73ca5e23b360
Christian Brabandt <cb@256bit.org>
parents: 9007
diff changeset
1250 if s:counter == 1
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1251 let g:Ch_msg1 = a:msg
9044
5abf6f38cbbb commit https://github.com/vim/vim/commit/d75263c020a5044fa73bc8cd57ce73ca5e23b360
Christian Brabandt <cb@256bit.org>
parents: 9007
diff changeset
1252 endif
9003
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1253 let s:counter += 1
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1254 endfunc
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1255 func! CloseHandler(chan)
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1256 let g:Ch_closemsg = s:counter
9003
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1257 let s:counter += 1
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1258 endfunc
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1259 let job = job_start(s:python . " test_channel_pipe.py quit now",
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1260 \ {'out_cb': 'OutHandler',
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1261 \ 'close_cb': 'CloseHandler'})
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1262 call assert_equal("run", job_status(job))
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1263 try
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1264 call WaitFor('g:Ch_closemsg != 0 && g:Ch_msg1 != ""')
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1265 call assert_equal('quit', g:Ch_msg1)
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1266 call assert_equal(2, g:Ch_closemsg)
9003
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1267 finally
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1268 call job_stop(job)
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1269 delfunc OutHandler
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1270 delfunc CloseHandler
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1271 endtry
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1272 endfunc
072556995a8e commit https://github.com/vim/vim/commit/b2658a1ab02cd0ba848164f70c7c464fdc398162
Christian Brabandt <cb@256bit.org>
parents: 8881
diff changeset
1273
9007
d5c6f1c5cd28 commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents: 9003
diff changeset
1274 func Test_read_in_close_cb()
d5c6f1c5cd28 commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents: 9003
diff changeset
1275 if !has('job')
d5c6f1c5cd28 commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents: 9003
diff changeset
1276 return
d5c6f1c5cd28 commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents: 9003
diff changeset
1277 endif
d5c6f1c5cd28 commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents: 9003
diff changeset
1278 call ch_log('Test_read_in_close_cb()')
d5c6f1c5cd28 commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents: 9003
diff changeset
1279
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1280 let g:Ch_received = ''
9007
d5c6f1c5cd28 commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents: 9003
diff changeset
1281 func! CloseHandler(chan)
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1282 let g:Ch_received = ch_read(a:chan)
9007
d5c6f1c5cd28 commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents: 9003
diff changeset
1283 endfunc
d5c6f1c5cd28 commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents: 9003
diff changeset
1284 let job = job_start(s:python . " test_channel_pipe.py quit now",
d5c6f1c5cd28 commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents: 9003
diff changeset
1285 \ {'close_cb': 'CloseHandler'})
d5c6f1c5cd28 commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents: 9003
diff changeset
1286 call assert_equal("run", job_status(job))
d5c6f1c5cd28 commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents: 9003
diff changeset
1287 try
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1288 call WaitFor('g:Ch_received != ""')
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1289 call assert_equal('quit', g:Ch_received)
9007
d5c6f1c5cd28 commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents: 9003
diff changeset
1290 finally
d5c6f1c5cd28 commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents: 9003
diff changeset
1291 call job_stop(job)
d5c6f1c5cd28 commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents: 9003
diff changeset
1292 delfunc CloseHandler
d5c6f1c5cd28 commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents: 9003
diff changeset
1293 endtry
d5c6f1c5cd28 commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents: 9003
diff changeset
1294 endfunc
d5c6f1c5cd28 commit https://github.com/vim/vim/commit/437905c25d4cedfa16d0f87392e4a000d22362b7
Christian Brabandt <cb@256bit.org>
parents: 9003
diff changeset
1295
13010
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1296 " Use channel in NL mode but received text does not end in NL.
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1297 func Test_read_in_close_cb_incomplete()
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1298 if !has('job')
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1299 return
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1300 endif
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1301 call ch_log('Test_read_in_close_cb_incomplete()')
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1302
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1303 let g:Ch_received = ''
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1304 func! CloseHandler(chan)
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1305 while ch_status(a:chan, {'part': 'out'}) == 'buffered'
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1306 let g:Ch_received .= ch_read(a:chan)
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1307 endwhile
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1308 endfunc
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1309 let job = job_start(s:python . " test_channel_pipe.py incomplete",
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1310 \ {'close_cb': 'CloseHandler'})
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1311 call assert_equal("run", job_status(job))
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1312 try
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1313 call WaitFor('g:Ch_received != ""')
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1314 call assert_equal('incomplete', g:Ch_received)
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1315 finally
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1316 call job_stop(job)
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1317 delfunc CloseHandler
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1318 endtry
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1319 endfunc
c522585ce88d patch 8.0.1381: ch_readraw() waits for NL if channel mode is NL
Christian Brabandt <cb@256bit.org>
parents: 12979
diff changeset
1320
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1321 func Test_out_cb_lambda()
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1322 if !has('job')
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1323 return
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1324 endif
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1325 call ch_log('Test_out_cb_lambda()')
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1326
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1327 let job = job_start(s:python . " test_channel_pipe.py",
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1328 \ {'out_cb': {ch, msg -> execute("let g:Ch_outmsg = 'lambda: ' . msg")},
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1329 \ 'out_mode': 'json',
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1330 \ 'err_cb': {ch, msg -> execute(":let g:Ch_errmsg = 'lambda: ' . msg")},
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1331 \ 'err_mode': 'json'})
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1332 call assert_equal("run", job_status(job))
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1333 try
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1334 let g:Ch_outmsg = ''
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1335 let g:Ch_errmsg = ''
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1336 call ch_sendraw(job, "echo [0, \"hello\"]\n")
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1337 call ch_sendraw(job, "echoerr [0, \"there\"]\n")
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1338 call WaitFor('g:Ch_outmsg != ""')
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1339 call assert_equal("lambda: hello", g:Ch_outmsg)
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1340 call WaitFor('g:Ch_errmsg != ""')
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1341 call assert_equal("lambda: there", g:Ch_errmsg)
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1342 finally
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1343 call job_stop(job)
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1344 endtry
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1345 endfunc
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1346
10386
d3f0946b4a80 commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents: 10309
diff changeset
1347 func Test_close_and_exit_cb()
d3f0946b4a80 commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents: 10309
diff changeset
1348 if !has('job')
d3f0946b4a80 commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents: 10309
diff changeset
1349 return
d3f0946b4a80 commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents: 10309
diff changeset
1350 endif
d3f0946b4a80 commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents: 10309
diff changeset
1351 call ch_log('Test_close_and_exit_cb')
d3f0946b4a80 commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents: 10309
diff changeset
1352
12734
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
1353 let g:retdict = {'ret': {}}
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
1354 func g:retdict.close_cb(ch) dict
10386
d3f0946b4a80 commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents: 10309
diff changeset
1355 let self.ret['close_cb'] = job_status(ch_getjob(a:ch))
d3f0946b4a80 commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents: 10309
diff changeset
1356 endfunc
12734
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
1357 func g:retdict.exit_cb(job, status) dict
10386
d3f0946b4a80 commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents: 10309
diff changeset
1358 let self.ret['exit_cb'] = job_status(a:job)
d3f0946b4a80 commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents: 10309
diff changeset
1359 endfunc
d3f0946b4a80 commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents: 10309
diff changeset
1360
d3f0946b4a80 commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents: 10309
diff changeset
1361 let g:job = job_start('echo', {
12734
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
1362 \ 'close_cb': g:retdict.close_cb,
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
1363 \ 'exit_cb': g:retdict.exit_cb,
10386
d3f0946b4a80 commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents: 10309
diff changeset
1364 \ })
d3f0946b4a80 commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents: 10309
diff changeset
1365 call assert_equal('run', job_status(g:job))
d3f0946b4a80 commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents: 10309
diff changeset
1366 unlet g:job
12734
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
1367 call WaitFor('len(g:retdict.ret) >= 2')
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
1368 call assert_equal(2, len(g:retdict.ret))
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
1369 call assert_match('^\%(dead\|run\)', g:retdict.ret['close_cb'])
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
1370 call assert_equal('dead', g:retdict.ret['exit_cb'])
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
1371 unlet g:retdict
10386
d3f0946b4a80 commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents: 10309
diff changeset
1372 endfunc
d3f0946b4a80 commit https://github.com/vim/vim/commit/7df915d113ac1981792c50e8b000c9f5f784b78b
Christian Brabandt <cb@256bit.org>
parents: 10309
diff changeset
1373
8074
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
1374 """"""""""
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
1375
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1376 let g:Ch_unletResponse = ''
8055
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
1377 func s:UnletHandler(handle, msg)
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1378 let g:Ch_unletResponse = a:msg
8055
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
1379 unlet s:channelfd
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
1380 endfunc
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
1381
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
1382 " Test that "unlet handle" in a handler doesn't crash Vim.
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1383 func Ch_unlet_handle(port)
8055
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
1384 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
1385 call ch_sendexpr(s:channelfd, "test", {'callback': function('s:UnletHandler')})
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1386 call WaitFor('"what?" == g:Ch_unletResponse')
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1387 call assert_equal('what?', g:Ch_unletResponse)
8055
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
1388 endfunc
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
1389
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
1390 func Test_unlet_handle()
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
1391 call ch_log('Test_unlet_handle()')
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1392 call s:run_server('Ch_unlet_handle')
8055
6db4b1c863ec commit https://github.com/vim/vim/commit/3bece9fee9c02934d3e295b29d253e13d4ef26a7
Christian Brabandt <cb@256bit.org>
parents: 8045
diff changeset
1393 endfunc
8070
e4c3f6720b03 commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents: 8066
diff changeset
1394
8074
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
1395 """"""""""
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
1396
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1397 let g:Ch_unletResponse = ''
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1398 func Ch_CloseHandler(handle, msg)
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1399 let g:Ch_unletResponse = a:msg
8074
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
1400 call ch_close(s:channelfd)
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
1401 endfunc
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
1402
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
1403 " Test that "unlet handle" in a handler doesn't crash Vim.
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1404 func Ch_close_handle(port)
8074
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
1405 let s:channelfd = ch_open('localhost:' . a:port, s:chopt)
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1406 call ch_sendexpr(s:channelfd, "test", {'callback': function('Ch_CloseHandler')})
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1407 call WaitFor('"what?" == g:Ch_unletResponse')
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1408 call assert_equal('what?', g:Ch_unletResponse)
8074
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
1409 endfunc
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
1410
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
1411 func Test_close_handle()
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
1412 call ch_log('Test_close_handle()')
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1413 call s:run_server('Ch_close_handle')
8074
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
1414 endfunc
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
1415
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
1416 """"""""""
dc32c8026899 commit https://github.com/vim/vim/commit/d46ae142aa9452e99576b5e923de974704e3c896
Christian Brabandt <cb@256bit.org>
parents: 8070
diff changeset
1417
8070
e4c3f6720b03 commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents: 8066
diff changeset
1418 func Test_open_fail()
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
1419 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
1420 silent! let ch = ch_open("noserver")
e4c3f6720b03 commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents: 8066
diff changeset
1421 echo ch
e4c3f6720b03 commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents: 8066
diff changeset
1422 let d = ch
e4c3f6720b03 commit https://github.com/vim/vim/commit/5cefd4098204b4677387511b586673649f2fab48
Christian Brabandt <cb@256bit.org>
parents: 8066
diff changeset
1423 endfunc
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
1424
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
1425 """"""""""
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
1426
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1427 func Ch_open_delay(port)
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
1428 " 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
1429 let s:chopt.waittime = 1000
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
1430 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
1431 unlet s:chopt.waittime
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
1432 if ch_status(channel) == "fail"
11183
1c4ebbae41d2 patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors
Christian Brabandt <cb@256bit.org>
parents: 10845
diff changeset
1433 call assert_report("Can't open channel")
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
1434 return
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
1435 endif
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
1436 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
1437 call ch_close(channel)
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
1438 endfunc
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
1439
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
1440 func Test_open_delay()
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
1441 call ch_log('Test_open_delay()')
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
1442 " The server will wait half a second before creating the port.
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1443 call s:run_server('Ch_open_delay', 'delay')
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8096
diff changeset
1444 endfunc
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1445
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1446 """""""""
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1447
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1448 function MyFunction(a,b,c)
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1449 let g:Ch_call_ret = [a:a, a:b, a:c]
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1450 endfunc
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1451
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1452 function Ch_test_call(port)
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1453 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
1454 if ch_status(handle) == "fail"
11183
1c4ebbae41d2 patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors
Christian Brabandt <cb@256bit.org>
parents: 10845
diff changeset
1455 call assert_report("Can't open channel")
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1456 return
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1457 endif
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1458
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1459 let g:Ch_call_ret = []
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
1460 call assert_equal('ok', ch_evalexpr(handle, 'call-func'))
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1461 call WaitFor('len(g:Ch_call_ret) > 0')
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1462 call assert_equal([1, 2, 3], g:Ch_call_ret)
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1463 endfunc
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1464
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1465 func Test_call()
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1466 call ch_log('Test_call()')
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1467 call s:run_server('Ch_test_call')
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8157
diff changeset
1468 endfunc
8174
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
1469
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
1470 """""""""
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
1471
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1472 let g:Ch_job_exit_ret = 'not yet'
8174
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
1473 function MyExitCb(job, status)
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1474 let g:Ch_job_exit_ret = 'done'
8174
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
1475 endfunc
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
1476
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1477 function Ch_test_exit_callback(port)
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1478 call job_setoptions(g:currentJob, {'exit_cb': 'MyExitCb'})
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1479 let g:Ch_exit_job = g:currentJob
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1480 call assert_equal('MyExitCb', job_info(g:currentJob)['exit_cb'])
8174
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
1481 endfunc
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
1482
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
1483 func Test_exit_callback()
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
1484 if has('job')
8324
5e88bd55b789 commit https://github.com/vim/vim/commit/9730f74a0b2acb490943393a203a24ab8fab923a
Christian Brabandt <cb@256bit.org>
parents: 8291
diff changeset
1485 call ch_log('Test_exit_callback()')
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1486 call s:run_server('Ch_test_exit_callback')
8174
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
1487
8324
5e88bd55b789 commit https://github.com/vim/vim/commit/9730f74a0b2acb490943393a203a24ab8fab923a
Christian Brabandt <cb@256bit.org>
parents: 8291
diff changeset
1488 " 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
1489 for i in range(100)
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1490 if g:Ch_job_exit_ret == 'done'
8324
5e88bd55b789 commit https://github.com/vim/vim/commit/9730f74a0b2acb490943393a203a24ab8fab923a
Christian Brabandt <cb@256bit.org>
parents: 8291
diff changeset
1491 break
5e88bd55b789 commit https://github.com/vim/vim/commit/9730f74a0b2acb490943393a203a24ab8fab923a
Christian Brabandt <cb@256bit.org>
parents: 8291
diff changeset
1492 endif
5e88bd55b789 commit https://github.com/vim/vim/commit/9730f74a0b2acb490943393a203a24ab8fab923a
Christian Brabandt <cb@256bit.org>
parents: 8291
diff changeset
1493 sleep 10m
5e88bd55b789 commit https://github.com/vim/vim/commit/9730f74a0b2acb490943393a203a24ab8fab923a
Christian Brabandt <cb@256bit.org>
parents: 8291
diff changeset
1494 " calling job_status() triggers the callback
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1495 call job_status(g:Ch_exit_job)
8324
5e88bd55b789 commit https://github.com/vim/vim/commit/9730f74a0b2acb490943393a203a24ab8fab923a
Christian Brabandt <cb@256bit.org>
parents: 8291
diff changeset
1496 endfor
8174
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
1497
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1498 call assert_equal('done', g:Ch_job_exit_ret)
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1499 call assert_equal('dead', job_info(g:Ch_exit_job).status)
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1500 unlet g:Ch_exit_job
8174
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
1501 endif
f2286ff0c102 commit https://github.com/vim/vim/commit/ee1cffc07a42441924c5353af7fd7ab6e97e5aae
Christian Brabandt <cb@256bit.org>
parents: 8170
diff changeset
1502 endfunc
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
1503
10279
c5c15c818bda commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents: 10259
diff changeset
1504 function MyExitTimeCb(job, status)
10309
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1505 if job_info(a:job).process == g:exit_cb_val.process
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1506 let g:exit_cb_val.end = reltime(g:exit_cb_val.start)
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1507 endif
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1508 call Resume()
10279
c5c15c818bda commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents: 10259
diff changeset
1509 endfunction
c5c15c818bda commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents: 10259
diff changeset
1510
c5c15c818bda commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents: 10259
diff changeset
1511 func Test_exit_callback_interval()
c5c15c818bda commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents: 10259
diff changeset
1512 if !has('job')
c5c15c818bda commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents: 10259
diff changeset
1513 return
c5c15c818bda commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents: 10259
diff changeset
1514 endif
c5c15c818bda commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents: 10259
diff changeset
1515
10309
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1516 let g:exit_cb_val = {'start': reltime(), 'end': 0, 'process': 0}
10279
c5c15c818bda commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents: 10259
diff changeset
1517 let job = job_start([s:python, '-c', 'import time;time.sleep(0.5)'], {'exit_cb': 'MyExitTimeCb'})
10309
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1518 let g:exit_cb_val.process = job_info(job).process
13650
87ffb7f85b28 patch 8.0.1697: various tests are still a bit flaky
Christian Brabandt <cb@256bit.org>
parents: 13598
diff changeset
1519 call WaitFor('type(g:exit_cb_val.end) != v:t_number || g:exit_cb_val.end != 0')
10309
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1520 let elapsed = reltimefloat(g:exit_cb_val.end)
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1521 call assert_true(elapsed > 0.5)
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1522 call assert_true(elapsed < 1.0)
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1523
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1524 " case: unreferenced job, using timer
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1525 if !has('timers')
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1526 return
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1527 endif
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1528
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1529 let g:exit_cb_val = {'start': reltime(), 'end': 0, 'process': 0}
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1530 let g:job = job_start([s:python, '-c', 'import time;time.sleep(0.5)'], {'exit_cb': 'MyExitTimeCb'})
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1531 let g:exit_cb_val.process = job_info(g:job).process
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1532 unlet g:job
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1533 call Standby(1000)
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1534 if type(g:exit_cb_val.end) != v:t_number || g:exit_cb_val.end != 0
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1535 let elapsed = reltimefloat(g:exit_cb_val.end)
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1536 else
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1537 let elapsed = 1.0
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1538 endif
88331ee68367 commit https://github.com/vim/vim/commit/01688ad545ff0809ddad5c8fa6b149dc5d67312b
Christian Brabandt <cb@256bit.org>
parents: 10297
diff changeset
1539 call assert_true(elapsed > 0.5)
10279
c5c15c818bda commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents: 10259
diff changeset
1540 call assert_true(elapsed < 1.0)
c5c15c818bda commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents: 10259
diff changeset
1541 endfunc
c5c15c818bda commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577
Christian Brabandt <cb@256bit.org>
parents: 10259
diff changeset
1542
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
1543 """""""""
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
1544
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1545 let g:Ch_close_ret = 'alive'
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
1546 function MyCloseCb(ch)
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1547 let g:Ch_close_ret = 'closed'
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
1548 endfunc
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
1549
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1550 function Ch_test_close_callback(port)
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
1551 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
1552 if ch_status(handle) == "fail"
11183
1c4ebbae41d2 patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors
Christian Brabandt <cb@256bit.org>
parents: 10845
diff changeset
1553 call assert_report("Can't open channel")
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
1554 return
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
1555 endif
8540
fec8655cf1bf commit https://github.com/vim/vim/commit/d6c2f0526064eef6f8917d2bad00df707d79ea16
Christian Brabandt <cb@256bit.org>
parents: 8506
diff changeset
1556 call ch_setoptions(handle, {'close_cb': 'MyCloseCb'})
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
1557
8285
e05e28dcb590 commit https://github.com/vim/vim/commit/8b1862a31639becadcbbca5dc2eaa92db73e8e5f
Christian Brabandt <cb@256bit.org>
parents: 8222
diff changeset
1558 call assert_equal('', ch_evalexpr(handle, 'close me'))
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1559 call WaitFor('"closed" == g:Ch_close_ret')
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1560 call assert_equal('closed', g:Ch_close_ret)
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
1561 endfunc
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
1562
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
1563 func Test_close_callback()
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
1564 call ch_log('Test_close_callback()')
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1565 call s:run_server('Ch_test_close_callback')
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
1566 endfunc
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8174
diff changeset
1567
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1568 function Ch_test_close_partial(port)
8798
176647a751d7 commit https://github.com/vim/vim/commit/bdf0bda968a53a55149a4c83a10a60c28e431305
Christian Brabandt <cb@256bit.org>
parents: 8761
diff changeset
1569 let handle = ch_open('localhost:' . a:port, s:chopt)
176647a751d7 commit https://github.com/vim/vim/commit/bdf0bda968a53a55149a4c83a10a60c28e431305
Christian Brabandt <cb@256bit.org>
parents: 8761
diff changeset
1570 if ch_status(handle) == "fail"
11183
1c4ebbae41d2 patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors
Christian Brabandt <cb@256bit.org>
parents: 10845
diff changeset
1571 call assert_report("Can't open channel")
8798
176647a751d7 commit https://github.com/vim/vim/commit/bdf0bda968a53a55149a4c83a10a60c28e431305
Christian Brabandt <cb@256bit.org>
parents: 8761
diff changeset
1572 return
176647a751d7 commit https://github.com/vim/vim/commit/bdf0bda968a53a55149a4c83a10a60c28e431305
Christian Brabandt <cb@256bit.org>
parents: 8761
diff changeset
1573 endif
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1574 let g:Ch_d = {}
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1575 func g:Ch_d.closeCb(ch) dict
8798
176647a751d7 commit https://github.com/vim/vim/commit/bdf0bda968a53a55149a4c83a10a60c28e431305
Christian Brabandt <cb@256bit.org>
parents: 8761
diff changeset
1576 let self.close_ret = 'closed'
176647a751d7 commit https://github.com/vim/vim/commit/bdf0bda968a53a55149a4c83a10a60c28e431305
Christian Brabandt <cb@256bit.org>
parents: 8761
diff changeset
1577 endfunc
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1578 call ch_setoptions(handle, {'close_cb': g:Ch_d.closeCb})
8798
176647a751d7 commit https://github.com/vim/vim/commit/bdf0bda968a53a55149a4c83a10a60c28e431305
Christian Brabandt <cb@256bit.org>
parents: 8761
diff changeset
1579
176647a751d7 commit https://github.com/vim/vim/commit/bdf0bda968a53a55149a4c83a10a60c28e431305
Christian Brabandt <cb@256bit.org>
parents: 8761
diff changeset
1580 call assert_equal('', ch_evalexpr(handle, 'close me'))
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1581 call WaitFor('"closed" == g:Ch_d.close_ret')
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1582 call assert_equal('closed', g:Ch_d.close_ret)
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1583 unlet g:Ch_d
8798
176647a751d7 commit https://github.com/vim/vim/commit/bdf0bda968a53a55149a4c83a10a60c28e431305
Christian Brabandt <cb@256bit.org>
parents: 8761
diff changeset
1584 endfunc
176647a751d7 commit https://github.com/vim/vim/commit/bdf0bda968a53a55149a4c83a10a60c28e431305
Christian Brabandt <cb@256bit.org>
parents: 8761
diff changeset
1585
176647a751d7 commit https://github.com/vim/vim/commit/bdf0bda968a53a55149a4c83a10a60c28e431305
Christian Brabandt <cb@256bit.org>
parents: 8761
diff changeset
1586 func Test_close_partial()
176647a751d7 commit https://github.com/vim/vim/commit/bdf0bda968a53a55149a4c83a10a60c28e431305
Christian Brabandt <cb@256bit.org>
parents: 8761
diff changeset
1587 call ch_log('Test_close_partial()')
9517
9f8f03a44886 commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents: 9367
diff changeset
1588 call s:run_server('Ch_test_close_partial')
8798
176647a751d7 commit https://github.com/vim/vim/commit/bdf0bda968a53a55149a4c83a10a60c28e431305
Christian Brabandt <cb@256bit.org>
parents: 8761
diff changeset
1589 endfunc
176647a751d7 commit https://github.com/vim/vim/commit/bdf0bda968a53a55149a4c83a10a60c28e431305
Christian Brabandt <cb@256bit.org>
parents: 8761
diff changeset
1590
8753
df91c8263f04 commit https://github.com/vim/vim/commit/8038568722a0aad72d001edf4972c29abab57f8f
Christian Brabandt <cb@256bit.org>
parents: 8749
diff changeset
1591 func Test_job_start_invalid()
df91c8263f04 commit https://github.com/vim/vim/commit/8038568722a0aad72d001edf4972c29abab57f8f
Christian Brabandt <cb@256bit.org>
parents: 8749
diff changeset
1592 call assert_fails('call job_start($x)', 'E474:')
df91c8263f04 commit https://github.com/vim/vim/commit/8038568722a0aad72d001edf4972c29abab57f8f
Christian Brabandt <cb@256bit.org>
parents: 8749
diff changeset
1593 call assert_fails('call job_start("")', 'E474:')
df91c8263f04 commit https://github.com/vim/vim/commit/8038568722a0aad72d001edf4972c29abab57f8f
Christian Brabandt <cb@256bit.org>
parents: 8749
diff changeset
1594 endfunc
df91c8263f04 commit https://github.com/vim/vim/commit/8038568722a0aad72d001edf4972c29abab57f8f
Christian Brabandt <cb@256bit.org>
parents: 8749
diff changeset
1595
10297
c90f4cc9c3fe commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents: 10279
diff changeset
1596 func Test_job_stop_immediately()
c90f4cc9c3fe commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents: 10279
diff changeset
1597 if !has('job')
c90f4cc9c3fe commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents: 10279
diff changeset
1598 return
c90f4cc9c3fe commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents: 10279
diff changeset
1599 endif
c90f4cc9c3fe commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents: 10279
diff changeset
1600
12734
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
1601 let g:job = job_start([s:python, '-c', 'import time;time.sleep(10)'])
10297
c90f4cc9c3fe commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents: 10279
diff changeset
1602 try
12734
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
1603 call job_stop(g:job)
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
1604 call WaitFor('"dead" == job_status(g:job)')
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
1605 call assert_equal('dead', job_status(g:job))
10297
c90f4cc9c3fe commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents: 10279
diff changeset
1606 finally
12734
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
1607 call job_stop(g:job, 'kill')
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
1608 unlet g:job
10297
c90f4cc9c3fe commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents: 10279
diff changeset
1609 endtry
c90f4cc9c3fe commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents: 10279
diff changeset
1610 endfunc
c90f4cc9c3fe commit https://github.com/vim/vim/commit/bb09ceb95477ecc271854b3fdd8d2776eca66adf
Christian Brabandt <cb@256bit.org>
parents: 10279
diff changeset
1611
8881
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8859
diff changeset
1612 " This was leaking memory.
8859
03250bc0c63a commit https://github.com/vim/vim/commit/0e4c1de5560c7f8b4cae539ec8cff0949daba3fc
Christian Brabandt <cb@256bit.org>
parents: 8798
diff changeset
1613 func Test_partial_in_channel_cycle()
03250bc0c63a commit https://github.com/vim/vim/commit/0e4c1de5560c7f8b4cae539ec8cff0949daba3fc
Christian Brabandt <cb@256bit.org>
parents: 8798
diff changeset
1614 let d = {}
03250bc0c63a commit https://github.com/vim/vim/commit/0e4c1de5560c7f8b4cae539ec8cff0949daba3fc
Christian Brabandt <cb@256bit.org>
parents: 8798
diff changeset
1615 let d.a = function('string', [d])
03250bc0c63a commit https://github.com/vim/vim/commit/0e4c1de5560c7f8b4cae539ec8cff0949daba3fc
Christian Brabandt <cb@256bit.org>
parents: 8798
diff changeset
1616 try
03250bc0c63a commit https://github.com/vim/vim/commit/0e4c1de5560c7f8b4cae539ec8cff0949daba3fc
Christian Brabandt <cb@256bit.org>
parents: 8798
diff changeset
1617 let d.b = ch_open('nowhere:123', {'close_cb': d.a})
03250bc0c63a commit https://github.com/vim/vim/commit/0e4c1de5560c7f8b4cae539ec8cff0949daba3fc
Christian Brabandt <cb@256bit.org>
parents: 8798
diff changeset
1618 catch
03250bc0c63a commit https://github.com/vim/vim/commit/0e4c1de5560c7f8b4cae539ec8cff0949daba3fc
Christian Brabandt <cb@256bit.org>
parents: 8798
diff changeset
1619 call assert_exception('E901:')
03250bc0c63a commit https://github.com/vim/vim/commit/0e4c1de5560c7f8b4cae539ec8cff0949daba3fc
Christian Brabandt <cb@256bit.org>
parents: 8798
diff changeset
1620 endtry
03250bc0c63a commit https://github.com/vim/vim/commit/0e4c1de5560c7f8b4cae539ec8cff0949daba3fc
Christian Brabandt <cb@256bit.org>
parents: 8798
diff changeset
1621 unlet d
03250bc0c63a commit https://github.com/vim/vim/commit/0e4c1de5560c7f8b4cae539ec8cff0949daba3fc
Christian Brabandt <cb@256bit.org>
parents: 8798
diff changeset
1622 endfunc
03250bc0c63a commit https://github.com/vim/vim/commit/0e4c1de5560c7f8b4cae539ec8cff0949daba3fc
Christian Brabandt <cb@256bit.org>
parents: 8798
diff changeset
1623
8881
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8859
diff changeset
1624 func Test_using_freed_memory()
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8859
diff changeset
1625 let g:a = job_start(['ls'])
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8859
diff changeset
1626 sleep 10m
9108
d319453f62b3 commit https://github.com/vim/vim/commit/574860b5ee9da281c875dad07a607454e135eaee
Christian Brabandt <cb@256bit.org>
parents: 9050
diff changeset
1627 call test_garbagecollect_now()
8881
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8859
diff changeset
1628 endfunc
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8859
diff changeset
1629
9266
78fc4c84476e commit https://github.com/vim/vim/commit/b8aefa46adf5e825118716e142fab7ef32076475
Christian Brabandt <cb@256bit.org>
parents: 9238
diff changeset
1630 func Test_collapse_buffers()
9994
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1631 if !executable('cat') || !has('job')
9266
78fc4c84476e commit https://github.com/vim/vim/commit/b8aefa46adf5e825118716e142fab7ef32076475
Christian Brabandt <cb@256bit.org>
parents: 9238
diff changeset
1632 return
78fc4c84476e commit https://github.com/vim/vim/commit/b8aefa46adf5e825118716e142fab7ef32076475
Christian Brabandt <cb@256bit.org>
parents: 9238
diff changeset
1633 endif
78fc4c84476e commit https://github.com/vim/vim/commit/b8aefa46adf5e825118716e142fab7ef32076475
Christian Brabandt <cb@256bit.org>
parents: 9238
diff changeset
1634 sp test_channel.vim
78fc4c84476e commit https://github.com/vim/vim/commit/b8aefa46adf5e825118716e142fab7ef32076475
Christian Brabandt <cb@256bit.org>
parents: 9238
diff changeset
1635 let g:linecount = line('$')
78fc4c84476e commit https://github.com/vim/vim/commit/b8aefa46adf5e825118716e142fab7ef32076475
Christian Brabandt <cb@256bit.org>
parents: 9238
diff changeset
1636 close
78fc4c84476e commit https://github.com/vim/vim/commit/b8aefa46adf5e825118716e142fab7ef32076475
Christian Brabandt <cb@256bit.org>
parents: 9238
diff changeset
1637 split testout
78fc4c84476e commit https://github.com/vim/vim/commit/b8aefa46adf5e825118716e142fab7ef32076475
Christian Brabandt <cb@256bit.org>
parents: 9238
diff changeset
1638 1,$delete
78fc4c84476e commit https://github.com/vim/vim/commit/b8aefa46adf5e825118716e142fab7ef32076475
Christian Brabandt <cb@256bit.org>
parents: 9238
diff changeset
1639 call job_start('cat test_channel.vim', {'out_io': 'buffer', 'out_name': 'testout'})
12734
810a4c3d4f7e patch 8.0.1245: when WaitFor() has a wrong expression it just waits a second
Christian Brabandt <cb@256bit.org>
parents: 12596
diff changeset
1640 call WaitFor('line("$") >= g:linecount')
10147
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
1641 call assert_inrange(g:linecount, g:linecount + 1, line('$'))
9266
78fc4c84476e commit https://github.com/vim/vim/commit/b8aefa46adf5e825118716e142fab7ef32076475
Christian Brabandt <cb@256bit.org>
parents: 9238
diff changeset
1642 bwipe!
78fc4c84476e commit https://github.com/vim/vim/commit/b8aefa46adf5e825118716e142fab7ef32076475
Christian Brabandt <cb@256bit.org>
parents: 9238
diff changeset
1643 endfunc
8881
ed0b39dd7fd6 commit https://github.com/vim/vim/commit/ebf7dfa6f121c82f97d2adca3d45fbaba9ad8f7e
Christian Brabandt <cb@256bit.org>
parents: 8859
diff changeset
1644
12596
d177c142d086 patch 8.0.1176: job_start() does not handle quote and backslash correctly
Christian Brabandt <cb@256bit.org>
parents: 12096
diff changeset
1645 func Test_cmd_parsing()
d177c142d086 patch 8.0.1176: job_start() does not handle quote and backslash correctly
Christian Brabandt <cb@256bit.org>
parents: 12096
diff changeset
1646 if !has('unix')
d177c142d086 patch 8.0.1176: job_start() does not handle quote and backslash correctly
Christian Brabandt <cb@256bit.org>
parents: 12096
diff changeset
1647 return
d177c142d086 patch 8.0.1176: job_start() does not handle quote and backslash correctly
Christian Brabandt <cb@256bit.org>
parents: 12096
diff changeset
1648 endif
d177c142d086 patch 8.0.1176: job_start() does not handle quote and backslash correctly
Christian Brabandt <cb@256bit.org>
parents: 12096
diff changeset
1649 call assert_false(filereadable("file with space"))
d177c142d086 patch 8.0.1176: job_start() does not handle quote and backslash correctly
Christian Brabandt <cb@256bit.org>
parents: 12096
diff changeset
1650 let job = job_start('touch "file with space"')
d177c142d086 patch 8.0.1176: job_start() does not handle quote and backslash correctly
Christian Brabandt <cb@256bit.org>
parents: 12096
diff changeset
1651 call WaitFor('filereadable("file with space")')
d177c142d086 patch 8.0.1176: job_start() does not handle quote and backslash correctly
Christian Brabandt <cb@256bit.org>
parents: 12096
diff changeset
1652 call assert_true(filereadable("file with space"))
d177c142d086 patch 8.0.1176: job_start() does not handle quote and backslash correctly
Christian Brabandt <cb@256bit.org>
parents: 12096
diff changeset
1653 call delete("file with space")
d177c142d086 patch 8.0.1176: job_start() does not handle quote and backslash correctly
Christian Brabandt <cb@256bit.org>
parents: 12096
diff changeset
1654
d177c142d086 patch 8.0.1176: job_start() does not handle quote and backslash correctly
Christian Brabandt <cb@256bit.org>
parents: 12096
diff changeset
1655 let job = job_start('touch file\ with\ space')
d177c142d086 patch 8.0.1176: job_start() does not handle quote and backslash correctly
Christian Brabandt <cb@256bit.org>
parents: 12096
diff changeset
1656 call WaitFor('filereadable("file with space")')
d177c142d086 patch 8.0.1176: job_start() does not handle quote and backslash correctly
Christian Brabandt <cb@256bit.org>
parents: 12096
diff changeset
1657 call assert_true(filereadable("file with space"))
d177c142d086 patch 8.0.1176: job_start() does not handle quote and backslash correctly
Christian Brabandt <cb@256bit.org>
parents: 12096
diff changeset
1658 call delete("file with space")
d177c142d086 patch 8.0.1176: job_start() does not handle quote and backslash correctly
Christian Brabandt <cb@256bit.org>
parents: 12096
diff changeset
1659 endfunc
d177c142d086 patch 8.0.1176: job_start() does not handle quote and backslash correctly
Christian Brabandt <cb@256bit.org>
parents: 12096
diff changeset
1660
9994
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1661 func Test_raw_passes_nul()
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1662 if !executable('cat') || !has('job')
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1663 return
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1664 endif
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1665
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1666 " Test lines from the job containing NUL are stored correctly in a buffer.
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1667 new
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1668 call setline(1, ["asdf\nasdf", "xxx\n", "\nyyy"])
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1669 w! Xtestread
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1670 bwipe!
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1671 split testout
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1672 1,$delete
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1673 call job_start('cat Xtestread', {'out_io': 'buffer', 'out_name': 'testout'})
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1674 call WaitFor('line("$") > 2')
10147
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
1675 call assert_equal("asdf\nasdf", getline(1))
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
1676 call assert_equal("xxx\n", getline(2))
65afd399ffa7 commit https://github.com/vim/vim/commit/169ebb080454357279ad5ad21ac532deaec605e8
Christian Brabandt <cb@256bit.org>
parents: 10090
diff changeset
1677 call assert_equal("\nyyy", getline(3))
9994
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1678
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1679 call delete('Xtestread')
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1680 bwipe!
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1681
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1682 " Test lines from a buffer with NUL bytes are written correctly to the job.
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1683 new mybuffer
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1684 call setline(1, ["asdf\nasdf", "xxx\n", "\nyyy"])
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1685 let g:Ch_job = job_start('cat', {'in_io': 'buffer', 'in_name': 'mybuffer', 'out_io': 'file', 'out_name': 'Xtestwrite'})
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1686 call WaitFor('"dead" == job_status(g:Ch_job)')
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1687 bwipe!
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1688 split Xtestwrite
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1689 call assert_equal("asdf\nasdf", getline(1))
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1690 call assert_equal("xxx\n", getline(2))
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1691 call assert_equal("\nyyy", getline(3))
13357
179586a64f53 patch 8.0.1552: may leak file descriptors when executing job
Christian Brabandt <cb@256bit.org>
parents: 13010
diff changeset
1692 call assert_equal(-1, match(s:get_resources(), '\(^\|/\)Xtestwrite$'))
9994
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1693
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1694 call delete('Xtestwrite')
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1695 bwipe!
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1696 endfunc
ee8b8a670a5c commit https://github.com/vim/vim/commit/821179809d9b0f65177360b53584be2b4039dd46
Christian Brabandt <cb@256bit.org>
parents: 9973
diff changeset
1697
10249
920c73a27dda commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents: 10233
diff changeset
1698 func MyLineCountCb(ch, msg)
920c73a27dda commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents: 10233
diff changeset
1699 let g:linecount += 1
920c73a27dda commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents: 10233
diff changeset
1700 endfunc
920c73a27dda commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents: 10233
diff changeset
1701
920c73a27dda commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents: 10233
diff changeset
1702 func Test_read_nonl_line()
920c73a27dda commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents: 10233
diff changeset
1703 if !has('job')
920c73a27dda commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents: 10233
diff changeset
1704 return
920c73a27dda commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents: 10233
diff changeset
1705 endif
920c73a27dda commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents: 10233
diff changeset
1706
920c73a27dda commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents: 10233
diff changeset
1707 let g:linecount = 0
12096
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1708 let arg = 'import sys;sys.stdout.write("1\n2\n3")'
10249
920c73a27dda commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents: 10233
diff changeset
1709 call job_start([s:python, '-c', arg], {'callback': 'MyLineCountCb'})
920c73a27dda commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents: 10233
diff changeset
1710 call WaitFor('3 <= g:linecount')
920c73a27dda commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents: 10233
diff changeset
1711 call assert_equal(3, g:linecount)
920c73a27dda commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents: 10233
diff changeset
1712 endfunc
920c73a27dda commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c
Christian Brabandt <cb@256bit.org>
parents: 10233
diff changeset
1713
10259
a09db7a4afe0 commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents: 10249
diff changeset
1714 func Test_read_from_terminated_job()
a09db7a4afe0 commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents: 10249
diff changeset
1715 if !has('job')
a09db7a4afe0 commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents: 10249
diff changeset
1716 return
a09db7a4afe0 commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents: 10249
diff changeset
1717 endif
a09db7a4afe0 commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents: 10249
diff changeset
1718
a09db7a4afe0 commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents: 10249
diff changeset
1719 let g:linecount = 0
12096
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1720 let arg = 'import os,sys;os.close(1);sys.stderr.write("test\n")'
10259
a09db7a4afe0 commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents: 10249
diff changeset
1721 call job_start([s:python, '-c', arg], {'callback': 'MyLineCountCb'})
a09db7a4afe0 commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents: 10249
diff changeset
1722 call WaitFor('1 <= g:linecount')
a09db7a4afe0 commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents: 10249
diff changeset
1723 call assert_equal(1, g:linecount)
a09db7a4afe0 commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents: 10249
diff changeset
1724 endfunc
a09db7a4afe0 commit https://github.com/vim/vim/commit/dc0ccaee68ca24d10050117fbec757ad33590a17
Christian Brabandt <cb@256bit.org>
parents: 10249
diff changeset
1725
12043
2796a2c9fc17 patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents: 11666
diff changeset
1726 func Test_env()
2796a2c9fc17 patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents: 11666
diff changeset
1727 if !has('job')
2796a2c9fc17 patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents: 11666
diff changeset
1728 return
2796a2c9fc17 patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents: 11666
diff changeset
1729 endif
2796a2c9fc17 patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents: 11666
diff changeset
1730
12096
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1731 let g:envstr = ''
12043
2796a2c9fc17 patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents: 11666
diff changeset
1732 if has('win32')
13598
8723e4496dd1 patch 8.0.1671: crash when passing non-dict argument as env to job_start()
Christian Brabandt <cb@256bit.org>
parents: 13587
diff changeset
1733 let cmd = ['cmd', '/c', 'echo %FOO%']
12043
2796a2c9fc17 patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents: 11666
diff changeset
1734 else
13598
8723e4496dd1 patch 8.0.1671: crash when passing non-dict argument as env to job_start()
Christian Brabandt <cb@256bit.org>
parents: 13587
diff changeset
1735 let cmd = [&shell, &shellcmdflag, 'echo $FOO']
12043
2796a2c9fc17 patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents: 11666
diff changeset
1736 endif
13598
8723e4496dd1 patch 8.0.1671: crash when passing non-dict argument as env to job_start()
Christian Brabandt <cb@256bit.org>
parents: 13587
diff changeset
1737 call assert_fails('call job_start(cmd, {"env": 1})', 'E475:')
8723e4496dd1 patch 8.0.1671: crash when passing non-dict argument as env to job_start()
Christian Brabandt <cb@256bit.org>
parents: 13587
diff changeset
1738 call job_start(cmd, {'callback': {ch,msg -> execute(":let g:envstr .= msg")}, 'env': {'FOO': 'bar'}})
12096
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1739 call WaitFor('"" != g:envstr')
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1740 call assert_equal("bar", g:envstr)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1741 unlet g:envstr
12043
2796a2c9fc17 patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents: 11666
diff changeset
1742 endfunc
2796a2c9fc17 patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents: 11666
diff changeset
1743
2796a2c9fc17 patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents: 11666
diff changeset
1744 func Test_cwd()
2796a2c9fc17 patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents: 11666
diff changeset
1745 if !has('job')
2796a2c9fc17 patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents: 11666
diff changeset
1746 return
2796a2c9fc17 patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents: 11666
diff changeset
1747 endif
2796a2c9fc17 patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents: 11666
diff changeset
1748
12096
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1749 let g:envstr = ''
12043
2796a2c9fc17 patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents: 11666
diff changeset
1750 if has('win32')
2796a2c9fc17 patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents: 11666
diff changeset
1751 let expect = $TEMP
13598
8723e4496dd1 patch 8.0.1671: crash when passing non-dict argument as env to job_start()
Christian Brabandt <cb@256bit.org>
parents: 13587
diff changeset
1752 let cmd = ['cmd', '/c', 'echo %CD%']
12043
2796a2c9fc17 patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents: 11666
diff changeset
1753 else
2796a2c9fc17 patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents: 11666
diff changeset
1754 let expect = $HOME
13598
8723e4496dd1 patch 8.0.1671: crash when passing non-dict argument as env to job_start()
Christian Brabandt <cb@256bit.org>
parents: 13587
diff changeset
1755 let cmd = ['pwd']
12043
2796a2c9fc17 patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents: 11666
diff changeset
1756 endif
13598
8723e4496dd1 patch 8.0.1671: crash when passing non-dict argument as env to job_start()
Christian Brabandt <cb@256bit.org>
parents: 13587
diff changeset
1757 let job = job_start(cmd, {'callback': {ch,msg -> execute(":let g:envstr .= msg")}, 'cwd': expect})
12979
6cf6138b6484 patch 8.0.1365: when one channel test fails others fail as well
Christian Brabandt <cb@256bit.org>
parents: 12765
diff changeset
1758 try
6cf6138b6484 patch 8.0.1365: when one channel test fails others fail as well
Christian Brabandt <cb@256bit.org>
parents: 12765
diff changeset
1759 call WaitFor('"" != g:envstr')
6cf6138b6484 patch 8.0.1365: when one channel test fails others fail as well
Christian Brabandt <cb@256bit.org>
parents: 12765
diff changeset
1760 let expect = substitute(expect, '[/\\]$', '', '')
6cf6138b6484 patch 8.0.1365: when one channel test fails others fail as well
Christian Brabandt <cb@256bit.org>
parents: 12765
diff changeset
1761 let g:envstr = substitute(g:envstr, '[/\\]$', '', '')
6cf6138b6484 patch 8.0.1365: when one channel test fails others fail as well
Christian Brabandt <cb@256bit.org>
parents: 12765
diff changeset
1762 if $CI != '' && stridx(g:envstr, '/private/') == 0
6cf6138b6484 patch 8.0.1365: when one channel test fails others fail as well
Christian Brabandt <cb@256bit.org>
parents: 12765
diff changeset
1763 let g:envstr = g:envstr[8:]
6cf6138b6484 patch 8.0.1365: when one channel test fails others fail as well
Christian Brabandt <cb@256bit.org>
parents: 12765
diff changeset
1764 endif
6cf6138b6484 patch 8.0.1365: when one channel test fails others fail as well
Christian Brabandt <cb@256bit.org>
parents: 12765
diff changeset
1765 call assert_equal(expect, g:envstr)
6cf6138b6484 patch 8.0.1365: when one channel test fails others fail as well
Christian Brabandt <cb@256bit.org>
parents: 12765
diff changeset
1766 finally
6cf6138b6484 patch 8.0.1365: when one channel test fails others fail as well
Christian Brabandt <cb@256bit.org>
parents: 12765
diff changeset
1767 call job_stop(job)
6cf6138b6484 patch 8.0.1365: when one channel test fails others fail as well
Christian Brabandt <cb@256bit.org>
parents: 12765
diff changeset
1768 unlet g:envstr
6cf6138b6484 patch 8.0.1365: when one channel test fails others fail as well
Christian Brabandt <cb@256bit.org>
parents: 12765
diff changeset
1769 endtry
12043
2796a2c9fc17 patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents: 11666
diff changeset
1770 endfunc
2796a2c9fc17 patch 8.0.0902: cannot specify directory or environment for a job
Christian Brabandt <cb@256bit.org>
parents: 11666
diff changeset
1771
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1772 function Ch_test_close_lambda(port)
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1773 let handle = ch_open('localhost:' . a:port, s:chopt)
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1774 if ch_status(handle) == "fail"
11183
1c4ebbae41d2 patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors
Christian Brabandt <cb@256bit.org>
parents: 10845
diff changeset
1775 call assert_report("Can't open channel")
9527
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1776 return
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1777 endif
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1778 let g:Ch_close_ret = ''
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1779 call ch_setoptions(handle, {'close_cb': {ch -> execute("let g:Ch_close_ret = 'closed'")}})
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1780
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1781 call assert_equal('', ch_evalexpr(handle, 'close me'))
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1782 call WaitFor('"closed" == g:Ch_close_ret')
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1783 call assert_equal('closed', g:Ch_close_ret)
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1784 endfunc
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1785
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1786 func Test_close_lambda()
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1787 call ch_log('Test_close_lambda()')
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1788 call s:run_server('Ch_test_close_lambda')
e8b3db8e2d30 commit https://github.com/vim/vim/commit/069c1e7fa9f45a665064f7f2c17da84d6a48f544
Christian Brabandt <cb@256bit.org>
parents: 9517
diff changeset
1789 endfunc
12096
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1790
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1791 func s:test_list_args(cmd, out, remove_lf)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1792 try
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1793 let g:out = ''
12979
6cf6138b6484 patch 8.0.1365: when one channel test fails others fail as well
Christian Brabandt <cb@256bit.org>
parents: 12765
diff changeset
1794 let job = job_start([s:python, '-c', a:cmd], {'callback': {ch, msg -> execute('let g:out .= msg')}, 'out_mode': 'raw'})
12096
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1795 call WaitFor('"" != g:out')
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1796 if has('win32')
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1797 let g:out = substitute(g:out, '\r', '', 'g')
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1798 endif
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1799 if a:remove_lf
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1800 let g:out = substitute(g:out, '\n$', '', 'g')
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1801 endif
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1802 call assert_equal(a:out, g:out)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1803 finally
12979
6cf6138b6484 patch 8.0.1365: when one channel test fails others fail as well
Christian Brabandt <cb@256bit.org>
parents: 12765
diff changeset
1804 call job_stop(job)
12096
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1805 unlet g:out
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1806 endtry
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1807 endfunc
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1808
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1809 func Test_list_args()
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1810 if !has('job')
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1811 return
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1812 endif
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1813
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1814 call s:test_list_args('import sys;sys.stdout.write("hello world")', "hello world", 0)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1815 call s:test_list_args('import sys;sys.stdout.write("hello\nworld")', "hello\nworld", 0)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1816 call s:test_list_args('import sys;sys.stdout.write(''hello\nworld'')', "hello\nworld", 0)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1817 call s:test_list_args('import sys;sys.stdout.write(''hello"world'')', "hello\"world", 0)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1818 call s:test_list_args('import sys;sys.stdout.write(''hello^world'')', "hello^world", 0)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1819 call s:test_list_args('import sys;sys.stdout.write("hello&&world")', "hello&&world", 0)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1820 call s:test_list_args('import sys;sys.stdout.write(''hello\\world'')', "hello\\world", 0)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1821 call s:test_list_args('import sys;sys.stdout.write(''hello\\\\world'')', "hello\\\\world", 0)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1822 call s:test_list_args('import sys;sys.stdout.write("hello\"world\"")', 'hello"world"', 0)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1823 call s:test_list_args('import sys;sys.stdout.write("h\"ello worl\"d")', 'h"ello worl"d', 0)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1824 call s:test_list_args('import sys;sys.stdout.write("h\"e\\\"llo wor\\\"l\"d")', 'h"e\"llo wor\"l"d', 0)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1825 call s:test_list_args('import sys;sys.stdout.write("h\"e\\\"llo world")', 'h"e\"llo world', 0)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1826 call s:test_list_args('import sys;sys.stdout.write("hello\tworld")', "hello\tworld", 0)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1827
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1828 " tests which not contain spaces in the argument
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1829 call s:test_list_args('print("hello\nworld")', "hello\nworld", 1)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1830 call s:test_list_args('print(''hello\nworld'')', "hello\nworld", 1)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1831 call s:test_list_args('print(''hello"world'')', "hello\"world", 1)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1832 call s:test_list_args('print(''hello^world'')', "hello^world", 1)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1833 call s:test_list_args('print("hello&&world")', "hello&&world", 1)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1834 call s:test_list_args('print(''hello\\world'')', "hello\\world", 1)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1835 call s:test_list_args('print(''hello\\\\world'')', "hello\\\\world", 1)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1836 call s:test_list_args('print("hello\"world\"")', 'hello"world"', 1)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1837 call s:test_list_args('print("hello\tworld")', "hello\tworld", 1)
0a61213afdd2 patch 8.0.0928: MS-Windows: passing arglist to job has escaping problems
Christian Brabandt <cb@256bit.org>
parents: 12043
diff changeset
1838 endfunc
13587
c0ebd15a0908 patch 8.0.1666: % argument in ch_log() causes trouble
Christian Brabandt <cb@256bit.org>
parents: 13357
diff changeset
1839
c0ebd15a0908 patch 8.0.1666: % argument in ch_log() causes trouble
Christian Brabandt <cb@256bit.org>
parents: 13357
diff changeset
1840 " Do this last, it stops any channel log.
c0ebd15a0908 patch 8.0.1666: % argument in ch_log() causes trouble
Christian Brabandt <cb@256bit.org>
parents: 13357
diff changeset
1841 func Test_zz_ch_log()
c0ebd15a0908 patch 8.0.1666: % argument in ch_log() causes trouble
Christian Brabandt <cb@256bit.org>
parents: 13357
diff changeset
1842 call ch_logfile('Xlog', 'w')
c0ebd15a0908 patch 8.0.1666: % argument in ch_log() causes trouble
Christian Brabandt <cb@256bit.org>
parents: 13357
diff changeset
1843 call ch_log('hello there')
c0ebd15a0908 patch 8.0.1666: % argument in ch_log() causes trouble
Christian Brabandt <cb@256bit.org>
parents: 13357
diff changeset
1844 call ch_log('%s%s')
c0ebd15a0908 patch 8.0.1666: % argument in ch_log() causes trouble
Christian Brabandt <cb@256bit.org>
parents: 13357
diff changeset
1845 call ch_logfile('')
c0ebd15a0908 patch 8.0.1666: % argument in ch_log() causes trouble
Christian Brabandt <cb@256bit.org>
parents: 13357
diff changeset
1846 let text = readfile('Xlog')
c0ebd15a0908 patch 8.0.1666: % argument in ch_log() causes trouble
Christian Brabandt <cb@256bit.org>
parents: 13357
diff changeset
1847 call assert_match("hello there", text[1])
c0ebd15a0908 patch 8.0.1666: % argument in ch_log() causes trouble
Christian Brabandt <cb@256bit.org>
parents: 13357
diff changeset
1848 call assert_match("%s%s", text[2])
c0ebd15a0908 patch 8.0.1666: % argument in ch_log() causes trouble
Christian Brabandt <cb@256bit.org>
parents: 13357
diff changeset
1849 call delete('Xlog')
c0ebd15a0908 patch 8.0.1666: % argument in ch_log() causes trouble
Christian Brabandt <cb@256bit.org>
parents: 13357
diff changeset
1850 endfunc