annotate src/testdir/test_channel.py @ 35167:6dddafdbe6f9 default tip

Added tag v9.1.0409 for changeset 0b259135fb3a4ce87fc1ff0673ae9b61cb7ed555
author Christian Brabandt <cb@256bit.org>
date Sun, 12 May 2024 00:15:05 +0200
parents 8492bbc9f533
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20003
e373843e2980 patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents: 13351
diff changeset
1 #!/usr/bin/env python
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 #
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 # Server that will accept connections from a Vim channel.
8041
c6443e78cf2d commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b
Christian Brabandt <cb@256bit.org>
parents: 8009
diff changeset
4 # Used by test_channel.vim.
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 #
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 # This requires Python 2.6 or later.
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 from __future__ import print_function
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 import json
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 import socket
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 import sys
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
12 import time
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 import threading
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 try:
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 # Python 3
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 import socketserver
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 except ImportError:
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 # Python 2
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 import SocketServer as socketserver
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21
28329
cdd13ed3e5cb patch 8.2.4690: channel tests fail on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 28317
diff changeset
22 class TestingRequestHandler(socketserver.BaseRequestHandler):
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 def handle(self):
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 print("=== socket opened ===")
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 while True:
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 try:
7914
35973ce58c84 commit https://github.com/vim/vim/commit/608a8919cae982cb38e38725a843df47b234dae6
Christian Brabandt <cb@256bit.org>
parents: 7912
diff changeset
27 received = self.request.recv(4096).decode('utf-8')
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 except socket.error:
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 print("=== socket error ===")
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 break
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 except IOError:
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 print("=== socket closed ===")
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 break
7914
35973ce58c84 commit https://github.com/vim/vim/commit/608a8919cae982cb38e38725a843df47b234dae6
Christian Brabandt <cb@256bit.org>
parents: 7912
diff changeset
34 if received == '':
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 print("=== socket closed ===")
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 break
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
37 print("received: {0}".format(received))
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
38
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
39 # We may receive two messages at once. Take the part up to the
9969
176e34b0d678 commit https://github.com/vim/vim/commit/f1f0792e55e72cdc7c833b30f565a9b02f18bb1e
Christian Brabandt <cb@256bit.org>
parents: 8746
diff changeset
40 # newline, which should be after the matching "]".
7914
35973ce58c84 commit https://github.com/vim/vim/commit/608a8919cae982cb38e38725a843df47b234dae6
Christian Brabandt <cb@256bit.org>
parents: 7912
diff changeset
41 todo = received
35973ce58c84 commit https://github.com/vim/vim/commit/608a8919cae982cb38e38725a843df47b234dae6
Christian Brabandt <cb@256bit.org>
parents: 7912
diff changeset
42 while todo != '':
9969
176e34b0d678 commit https://github.com/vim/vim/commit/f1f0792e55e72cdc7c833b30f565a9b02f18bb1e
Christian Brabandt <cb@256bit.org>
parents: 8746
diff changeset
43 splitidx = todo.find('\n')
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
44 if splitidx < 0:
7914
35973ce58c84 commit https://github.com/vim/vim/commit/608a8919cae982cb38e38725a843df47b234dae6
Christian Brabandt <cb@256bit.org>
parents: 7912
diff changeset
45 used = todo
35973ce58c84 commit https://github.com/vim/vim/commit/608a8919cae982cb38e38725a843df47b234dae6
Christian Brabandt <cb@256bit.org>
parents: 7912
diff changeset
46 todo = ''
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
47 else:
9969
176e34b0d678 commit https://github.com/vim/vim/commit/f1f0792e55e72cdc7c833b30f565a9b02f18bb1e
Christian Brabandt <cb@256bit.org>
parents: 8746
diff changeset
48 used = todo[:splitidx]
7914
35973ce58c84 commit https://github.com/vim/vim/commit/608a8919cae982cb38e38725a843df47b234dae6
Christian Brabandt <cb@256bit.org>
parents: 7912
diff changeset
49 todo = todo[splitidx + 1:]
35973ce58c84 commit https://github.com/vim/vim/commit/608a8919cae982cb38e38725a843df47b234dae6
Christian Brabandt <cb@256bit.org>
parents: 7912
diff changeset
50 if used != received:
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
51 print("using: {0}".format(used))
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
52
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
53 try:
7914
35973ce58c84 commit https://github.com/vim/vim/commit/608a8919cae982cb38e38725a843df47b234dae6
Christian Brabandt <cb@256bit.org>
parents: 7912
diff changeset
54 decoded = json.loads(used)
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
55 except ValueError:
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
56 print("json decoding failed")
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
57 decoded = [-1, '']
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
59 # Send a response if the sequence number is positive.
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
60 if decoded[0] >= 0:
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
61 if decoded[1] == 'hello!':
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
62 # simply send back a string
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
63 response = "got it"
13351
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
64 elif decoded[1] == 'malformed1':
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
65 cmd = '["ex",":"]wrong!["ex","smi"]'
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
66 print("sending: {0}".format(cmd))
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
67 self.request.sendall(cmd.encode('utf-8'))
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
68 response = "ok"
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
69 # Need to wait for Vim to give up, otherwise it
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
70 # sometimes fails on OS X.
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
71 time.sleep(0.2)
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
72 elif decoded[1] == 'malformed2':
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
73 cmd = '"unterminated string'
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
74 print("sending: {0}".format(cmd))
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
75 self.request.sendall(cmd.encode('utf-8'))
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
76 response = "ok"
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
77 # Need to wait for Vim to give up, otherwise the double
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
78 # quote in the "ok" response terminates the string.
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
79 time.sleep(0.2)
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
80 elif decoded[1] == 'malformed3':
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
81 cmd = '["ex","missing ]"'
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
82 print("sending: {0}".format(cmd))
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
83 self.request.sendall(cmd.encode('utf-8'))
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
84 response = "ok"
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
85 # Need to wait for Vim to give up, otherwise the ]
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
86 # in the "ok" response terminates the list.
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
87 time.sleep(0.2)
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
88 elif decoded[1] == 'split':
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
89 cmd = '["ex","let '
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
90 print("sending: {0}".format(cmd))
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
91 self.request.sendall(cmd.encode('utf-8'))
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
92 time.sleep(0.01)
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
93 cmd = 'g:split = 123"]'
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
94 print("sending: {0}".format(cmd))
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
95 self.request.sendall(cmd.encode('utf-8'))
33a2277b8d4d patch 8.0.1549: various small problems in test files
Christian Brabandt <cb@256bit.org>
parents: 10458
diff changeset
96 response = "ok"
8382
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
97 elif decoded[1].startswith("echo "):
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
98 # send back the argument
3dbe93a240d8 commit https://github.com/vim/vim/commit/d6547fc6471d9084f942bdc4ae3aedb39361751d
Christian Brabandt <cb@256bit.org>
parents: 8210
diff changeset
99 response = decoded[1][5:]
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
100 elif decoded[1] == 'make change':
7918
ce5a7a613867 commit https://github.com/vim/vim/commit/66624ff0d9e1de2fc5eb4f95f3a3a2ed70b10138
Christian Brabandt <cb@256bit.org>
parents: 7916
diff changeset
101 # Send two ex commands at the same time, before
ce5a7a613867 commit https://github.com/vim/vim/commit/66624ff0d9e1de2fc5eb4f95f3a3a2ed70b10138
Christian Brabandt <cb@256bit.org>
parents: 7916
diff changeset
102 # replying to the request.
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
103 cmd = '["ex","call append(\\"$\\",\\"added1\\")"]'
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
104 cmd += '["ex","call append(\\"$\\",\\"added2\\")"]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
105 print("sending: {0}".format(cmd))
7916
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
106 self.request.sendall(cmd.encode('utf-8'))
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
107 response = "ok"
25090
73503bafb3bf patch 8.2.3082: a channel command "echoerr" does not show anything
Bram Moolenaar <Bram@vim.org>
parents: 20464
diff changeset
108 elif decoded[1] == 'echoerr':
73503bafb3bf patch 8.2.3082: a channel command "echoerr" does not show anything
Bram Moolenaar <Bram@vim.org>
parents: 20464
diff changeset
109 cmd = '["ex","echoerr \\\"this is an error\\\""]'
73503bafb3bf patch 8.2.3082: a channel command "echoerr" does not show anything
Bram Moolenaar <Bram@vim.org>
parents: 20464
diff changeset
110 print("sending: {0}".format(cmd))
73503bafb3bf patch 8.2.3082: a channel command "echoerr" does not show anything
Bram Moolenaar <Bram@vim.org>
parents: 20464
diff changeset
111 self.request.sendall(cmd.encode('utf-8'))
73503bafb3bf patch 8.2.3082: a channel command "echoerr" does not show anything
Bram Moolenaar <Bram@vim.org>
parents: 20464
diff changeset
112 response = "ok"
25433
42c9386eebf4 patch 8.2.3253: channel test fails randomly
Bram Moolenaar <Bram@vim.org>
parents: 25090
diff changeset
113 # Wait a bit, so that the "ex" command is handled
42c9386eebf4 patch 8.2.3253: channel test fails randomly
Bram Moolenaar <Bram@vim.org>
parents: 25090
diff changeset
114 # before the "ch_evalexpr() returns. Otherwise we are
42c9386eebf4 patch 8.2.3253: channel test fails randomly
Bram Moolenaar <Bram@vim.org>
parents: 25090
diff changeset
115 # outside the try/catch when the "ex" command is
42c9386eebf4 patch 8.2.3253: channel test fails randomly
Bram Moolenaar <Bram@vim.org>
parents: 25090
diff changeset
116 # handled.
42c9386eebf4 patch 8.2.3253: channel test fails randomly
Bram Moolenaar <Bram@vim.org>
parents: 25090
diff changeset
117 time.sleep(0.02)
8746
4c38a4733578 commit https://github.com/vim/vim/commit/c4dcd60c76666bf113719f929709ad6120eb6528
Christian Brabandt <cb@256bit.org>
parents: 8744
diff changeset
118 elif decoded[1] == 'bad command':
4c38a4733578 commit https://github.com/vim/vim/commit/c4dcd60c76666bf113719f929709ad6120eb6528
Christian Brabandt <cb@256bit.org>
parents: 8744
diff changeset
119 cmd = '["ex","foo bar"]'
4c38a4733578 commit https://github.com/vim/vim/commit/c4dcd60c76666bf113719f929709ad6120eb6528
Christian Brabandt <cb@256bit.org>
parents: 8744
diff changeset
120 print("sending: {0}".format(cmd))
4c38a4733578 commit https://github.com/vim/vim/commit/c4dcd60c76666bf113719f929709ad6120eb6528
Christian Brabandt <cb@256bit.org>
parents: 8744
diff changeset
121 self.request.sendall(cmd.encode('utf-8'))
4c38a4733578 commit https://github.com/vim/vim/commit/c4dcd60c76666bf113719f929709ad6120eb6528
Christian Brabandt <cb@256bit.org>
parents: 8744
diff changeset
122 response = "ok"
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
123 elif decoded[1] == 'do normal':
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
124 # Send a normal command.
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
125 cmd = '["normal","G$s more\u001b"]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
126 print("sending: {0}".format(cmd))
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
127 self.request.sendall(cmd.encode('utf-8'))
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
128 response = "ok"
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
129 elif decoded[1] == 'eval-works':
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
130 # Send an eval request. We ignore the response.
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
131 cmd = '["expr","\\"foo\\" . 123", -1]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
132 print("sending: {0}".format(cmd))
7916
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
133 self.request.sendall(cmd.encode('utf-8'))
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
134 response = "ok"
8744
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
135 elif decoded[1] == 'eval-special':
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
136 # Send an eval request. We ignore the response.
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
137 cmd = '["expr","\\"foo\x7f\x10\x01bar\\"", -2]'
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
138 print("sending: {0}".format(cmd))
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
139 self.request.sendall(cmd.encode('utf-8'))
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
140 response = "ok"
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
141 elif decoded[1] == 'eval-getline':
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
142 # Send an eval request. We ignore the response.
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
143 cmd = '["expr","getline(3)", -3]'
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
144 print("sending: {0}".format(cmd))
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
145 self.request.sendall(cmd.encode('utf-8'))
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
146 response = "ok"
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
147 elif decoded[1] == 'eval-fails':
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
148 # Send an eval request that will fail.
8744
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
149 cmd = '["expr","xxx", -4]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
150 print("sending: {0}".format(cmd))
7916
54602dcac207 commit https://github.com/vim/vim/commit/3b05b135e3ee4cfd59983fd63461e8f7642c1713
Christian Brabandt <cb@256bit.org>
parents: 7914
diff changeset
151 self.request.sendall(cmd.encode('utf-8'))
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
152 response = "ok"
7965
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7939
diff changeset
153 elif decoded[1] == 'eval-error':
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7939
diff changeset
154 # Send an eval request that works but the result can't
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7939
diff changeset
155 # be encoded.
8744
ff9973bbbfcb commit https://github.com/vim/vim/commit/fa8b2e173dd5f6c4a5cfd326abdcf68b8eebf90d
Christian Brabandt <cb@256bit.org>
parents: 8663
diff changeset
156 cmd = '["expr","function(\\"tr\\")", -5]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
157 print("sending: {0}".format(cmd))
7965
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7939
diff changeset
158 self.request.sendall(cmd.encode('utf-8'))
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7939
diff changeset
159 response = "ok"
7918
ce5a7a613867 commit https://github.com/vim/vim/commit/66624ff0d9e1de2fc5eb4f95f3a3a2ed70b10138
Christian Brabandt <cb@256bit.org>
parents: 7916
diff changeset
160 elif decoded[1] == 'eval-bad':
ce5a7a613867 commit https://github.com/vim/vim/commit/66624ff0d9e1de2fc5eb4f95f3a3a2ed70b10138
Christian Brabandt <cb@256bit.org>
parents: 7916
diff changeset
161 # Send an eval request missing the third argument.
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
162 cmd = '["expr","xxx"]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
163 print("sending: {0}".format(cmd))
7918
ce5a7a613867 commit https://github.com/vim/vim/commit/66624ff0d9e1de2fc5eb4f95f3a3a2ed70b10138
Christian Brabandt <cb@256bit.org>
parents: 7916
diff changeset
164 self.request.sendall(cmd.encode('utf-8'))
ce5a7a613867 commit https://github.com/vim/vim/commit/66624ff0d9e1de2fc5eb4f95f3a3a2ed70b10138
Christian Brabandt <cb@256bit.org>
parents: 7916
diff changeset
165 response = "ok"
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
166 elif decoded[1] == 'an expr':
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
167 # Send an expr request.
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
168 cmd = '["expr","setline(\\"$\\", [\\"one\\",\\"two\\",\\"three\\"])"]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
169 print("sending: {0}".format(cmd))
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
170 self.request.sendall(cmd.encode('utf-8'))
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
171 response = "ok"
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
172 elif decoded[1] == 'call-func':
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
173 cmd = '["call","MyFunction",[1,2,3], 0]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
174 print("sending: {0}".format(cmd))
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
175 self.request.sendall(cmd.encode('utf-8'))
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
176 response = "ok"
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
177 elif decoded[1] == 'redraw':
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
178 cmd = '["redraw",""]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
179 print("sending: {0}".format(cmd))
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
180 self.request.sendall(cmd.encode('utf-8'))
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
181 response = "ok"
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
182 elif decoded[1] == 'redraw!':
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
183 cmd = '["redraw","force"]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
184 print("sending: {0}".format(cmd))
7939
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
185 self.request.sendall(cmd.encode('utf-8'))
dcc0bd6b1574 commit https://github.com/vim/vim/commit/f416086f264c1d998863b2e600f4c14f799d0d99
Christian Brabandt <cb@256bit.org>
parents: 7937
diff changeset
186 response = "ok"
7937
2e905dfc6999 commit https://github.com/vim/vim/commit/6076fe1986255d32b7a078a28bf9e7bea19d6f30
Christian Brabandt <cb@256bit.org>
parents: 7920
diff changeset
187 elif decoded[1] == 'empty-request':
2e905dfc6999 commit https://github.com/vim/vim/commit/6076fe1986255d32b7a078a28bf9e7bea19d6f30
Christian Brabandt <cb@256bit.org>
parents: 7920
diff changeset
188 cmd = '[]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
189 print("sending: {0}".format(cmd))
7937
2e905dfc6999 commit https://github.com/vim/vim/commit/6076fe1986255d32b7a078a28bf9e7bea19d6f30
Christian Brabandt <cb@256bit.org>
parents: 7920
diff changeset
190 self.request.sendall(cmd.encode('utf-8'))
2e905dfc6999 commit https://github.com/vim/vim/commit/6076fe1986255d32b7a078a28bf9e7bea19d6f30
Christian Brabandt <cb@256bit.org>
parents: 7920
diff changeset
191 response = "ok"
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
192 elif decoded[1] == 'eval-result':
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
193 # Send back the last received eval result.
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
194 response = last_eval
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
195 elif decoded[1] == 'call me':
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
196 cmd = '[0,"we called you"]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
197 print("sending: {0}".format(cmd))
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
198 self.request.sendall(cmd.encode('utf-8'))
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
199 response = "ok"
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
200 elif decoded[1] == 'call me again':
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
201 cmd = '[0,"we did call you"]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
202 print("sending: {0}".format(cmd))
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
203 self.request.sendall(cmd.encode('utf-8'))
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
204 response = ""
8404
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
205 elif decoded[1] == 'send zero':
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
206 cmd = '[0,"zero index"]'
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
207 print("sending: {0}".format(cmd))
8404
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
208 self.request.sendall(cmd.encode('utf-8'))
8894d595b786 commit https://github.com/vim/vim/commit/5983ad0b038fa689653246cb304fd43e8ae39a78
Christian Brabandt <cb@256bit.org>
parents: 8382
diff changeset
209 response = "sent zero"
8210
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
210 elif decoded[1] == 'close me':
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
211 print("closing")
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
212 self.request.close()
b717dae2f26d commit https://github.com/vim/vim/commit/4e221c99e85ed40c98892068a01270b9e7492d98
Christian Brabandt <cb@256bit.org>
parents: 8159
diff changeset
213 response = ""
8159
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
214 elif decoded[1] == 'wait a bit':
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
215 time.sleep(0.2)
d0958e22d9ff commit https://github.com/vim/vim/commit/ece61b06ef4726515177c9b293e1c20d2122a73f
Christian Brabandt <cb@256bit.org>
parents: 8153
diff changeset
216 response = "waited"
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
217 elif decoded[1] == '!quit!':
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
218 # we're done
7920
1ebc7be4dbbf commit https://github.com/vim/vim/commit/b3e2f00f39d6edafda6e5508a926ebd244997a0f
Christian Brabandt <cb@256bit.org>
parents: 7918
diff changeset
219 self.server.shutdown()
7993
0756eab66b71 commit https://github.com/vim/vim/commit/b92abad0c58de36d0b0afdcd4ec05261fa1fa84c
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
220 return
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
221 elif decoded[1] == '!crash!':
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
222 # Crash!
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
223 42 / 0
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
224 else:
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
225 response = "what?"
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
226
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
227 if response == "":
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
228 print("no response")
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
229 else:
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
230 encoded = json.dumps([decoded[0], response])
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
231 print("sending: {0}".format(encoded))
8009
b2cfa3416ba0 commit https://github.com/vim/vim/commit/f6157284de71d8881f3b89fbd79d1ecbf842929f
Christian Brabandt <cb@256bit.org>
parents: 7993
diff changeset
232 self.request.sendall(encoded.encode('utf-8'))
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
233
7912
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
234 # Negative numbers are used for "eval" responses.
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
235 elif decoded[0] < 0:
1c6ef9113556 commit https://github.com/vim/vim/commit/e7bed627c89ed80bc4b2d96f542819029adf6e76
Christian Brabandt <cb@256bit.org>
parents: 7906
diff changeset
236 last_eval = decoded
7906
ea1fd8d750a6 commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Christian Brabandt <cb@256bit.org>
parents: 7902
diff changeset
237
28329
cdd13ed3e5cb patch 8.2.4690: channel tests fail on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 28317
diff changeset
238 class ThreadedTCPRequestHandler(TestingRequestHandler):
cdd13ed3e5cb patch 8.2.4690: channel tests fail on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 28317
diff changeset
239 def setup(self):
cdd13ed3e5cb patch 8.2.4690: channel tests fail on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 28317
diff changeset
240 self.request.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
cdd13ed3e5cb patch 8.2.4690: channel tests fail on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 28317
diff changeset
241
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
242 class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
243 pass
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
244
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
245 def writePortInFile(port):
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
246 # Write the port number in Xportnr, so that the test knows it.
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
247 f = open("Xportnr", "w")
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
248 f.write("{0}".format(port))
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
249 f.close()
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
250
20003
e373843e2980 patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents: 13351
diff changeset
251 def main(host, port, server_class=ThreadedTCPServer):
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
252 # Wait half a second before opening the port to test waittime in ch_open().
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
253 # We do want to get the port number, get that first. We cannot open the
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
254 # socket, guess a port is free.
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
255 if len(sys.argv) >= 2 and sys.argv[1] == 'delay':
20003
e373843e2980 patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents: 13351
diff changeset
256 port = 13684
e373843e2980 patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents: 13351
diff changeset
257 writePortInFile(port)
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
258
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
259 print("Wait for it...")
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
260 time.sleep(0.5)
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
261
31665
8492bbc9f533 patch 9.0.1165: tests using IPv6 sometimes fail
Bram Moolenaar <Bram@vim.org>
parents: 28329
diff changeset
262 addrs = socket.getaddrinfo(host, port, 0, 0, socket.IPPROTO_TCP)
8492bbc9f533 patch 9.0.1165: tests using IPv6 sometimes fail
Bram Moolenaar <Bram@vim.org>
parents: 28329
diff changeset
263 # Each addr is a (family, type, proto, canonname, sockaddr) tuple
8492bbc9f533 patch 9.0.1165: tests using IPv6 sometimes fail
Bram Moolenaar <Bram@vim.org>
parents: 28329
diff changeset
264 sockaddr = addrs[0][4]
8492bbc9f533 patch 9.0.1165: tests using IPv6 sometimes fail
Bram Moolenaar <Bram@vim.org>
parents: 28329
diff changeset
265 server_class.address_family = addrs[0][0]
8492bbc9f533 patch 9.0.1165: tests using IPv6 sometimes fail
Bram Moolenaar <Bram@vim.org>
parents: 28329
diff changeset
266
8492bbc9f533 patch 9.0.1165: tests using IPv6 sometimes fail
Bram Moolenaar <Bram@vim.org>
parents: 28329
diff changeset
267 server = server_class(sockaddr[0:2], ThreadedTCPRequestHandler)
20003
e373843e2980 patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents: 13351
diff changeset
268 ip, port = server.server_address[0:2]
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
269
7937
2e905dfc6999 commit https://github.com/vim/vim/commit/6076fe1986255d32b7a078a28bf9e7bea19d6f30
Christian Brabandt <cb@256bit.org>
parents: 7920
diff changeset
270 # Start a thread with the server. That thread will then start a new thread
2e905dfc6999 commit https://github.com/vim/vim/commit/6076fe1986255d32b7a078a28bf9e7bea19d6f30
Christian Brabandt <cb@256bit.org>
parents: 7920
diff changeset
271 # for each connection.
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
272 server_thread = threading.Thread(target=server.serve_forever)
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
273 server_thread.start()
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
274
8114
4aea0b0aa714 commit https://github.com/vim/vim/commit/81661fb86801e6d6e5194b43dfd27d73fcc016ec
Christian Brabandt <cb@256bit.org>
parents: 8041
diff changeset
275 writePortInFile(port)
7899
93c61501c2cf commit https://github.com/vim/vim/commit/d7ece1008ee6173afda6d173bed486ae79c1c38a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
276
8663
b2a48aabe21f commit https://github.com/vim/vim/commit/a63cdb5ed685181c377ee89f1d1de6a97dfeb151
Christian Brabandt <cb@256bit.org>
parents: 8655
diff changeset
277 print("Listening on port {0}".format(port))
7920
1ebc7be4dbbf commit https://github.com/vim/vim/commit/b3e2f00f39d6edafda6e5508a926ebd244997a0f
Christian Brabandt <cb@256bit.org>
parents: 7918
diff changeset
278
1ebc7be4dbbf commit https://github.com/vim/vim/commit/b3e2f00f39d6edafda6e5508a926ebd244997a0f
Christian Brabandt <cb@256bit.org>
parents: 7918
diff changeset
279 # Main thread terminates, but the server continues running
1ebc7be4dbbf commit https://github.com/vim/vim/commit/b3e2f00f39d6edafda6e5508a926ebd244997a0f
Christian Brabandt <cb@256bit.org>
parents: 7918
diff changeset
280 # until server.shutdown() is called.
8153
240deebfadde commit https://github.com/vim/vim/commit/ddbe7d26b10c4374f406b807ae161826cf2096e1
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
281 try:
20003
e373843e2980 patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents: 13351
diff changeset
282 while server_thread.is_alive():
8153
240deebfadde commit https://github.com/vim/vim/commit/ddbe7d26b10c4374f406b807ae161826cf2096e1
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
283 server_thread.join(1)
240deebfadde commit https://github.com/vim/vim/commit/ddbe7d26b10c4374f406b807ae161826cf2096e1
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
284 except (KeyboardInterrupt, SystemExit):
240deebfadde commit https://github.com/vim/vim/commit/ddbe7d26b10c4374f406b807ae161826cf2096e1
Christian Brabandt <cb@256bit.org>
parents: 8114
diff changeset
285 server.shutdown()
20003
e373843e2980 patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents: 13351
diff changeset
286
e373843e2980 patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents: 13351
diff changeset
287 if __name__ == "__main__":
e373843e2980 patch 8.2.0557: no IPv6 support for channels
Bram Moolenaar <Bram@vim.org>
parents: 13351
diff changeset
288 main("localhost", 0)