comparison src/testdir/test_channel.vim @ 7899:93c61501c2cf v7.4.1246

commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a Author: Bram Moolenaar <Bram@vim.org> Date: Tue Feb 2 23:23:02 2016 +0100 patch 7.4.1246 Problem: The channel functionality isn't tested. Solution: Add a test using a Python test server.
author Christian Brabandt <cb@256bit.org>
date Tue, 02 Feb 2016 23:30:04 +0100
parents
children f12d6235a753
comparison
equal deleted inserted replaced
7898:3990e89cec64 7899:93c61501c2cf
1 " Test for channel functions.
2 scriptencoding utf-8
3
4 " This requires the Python command to run the test server.
5 " This most likely only works on Unix.
6 if !has('unix') || !executable('python')
7 finish
8 endif
9
10 func Test_communicate()
11 " The Python program writes the port number in Xportnr.
12 silent !./test_channel.py&
13
14 " Wait for up to 2 seconds for the port number to be there.
15 let cnt = 20
16 let l = []
17 while cnt > 0
18 try
19 let l = readfile("Xportnr")
20 catch
21 endtry
22 if len(l) >= 1
23 break
24 endif
25 sleep 100m
26 let cnt -= 1
27 endwhile
28 call delete("Xportnr")
29
30 if len(l) == 0
31 " Can't make the connection, give up.
32 call system("killall test_channel.py")
33 return
34 endif
35 let port = l[0]
36 let handle = ch_open('localhost:' . port, 'json')
37
38 " Simple string request and reply.
39 call assert_equal('got it', ch_sendexpr(handle, 'hello!'))
40
41 " Request that triggers sending two ex commands. These will usually be
42 " handled before getting the response, but it's not guaranteed, thus wait a
43 " tiny bit for the commands to get executed.
44 call assert_equal('ok', ch_sendexpr(handle, 'make change'))
45 sleep 10m
46 call assert_equal('added1', getline(line('$') - 1))
47 call assert_equal('added2', getline('$'))
48
49 " make the server quit, can't check if this works, should not hang.
50 call ch_sendexpr(handle, '!quit!', 0)
51
52 call system("killall test_channel.py")
53 endfunc