Mercurial > vim
comparison src/testdir/test_channel.py @ 7906:ea1fd8d750a6 v7.4.1249
commit https://github.com/vim/vim/commit/fcb1e3d16832ce06da0dc38ecb7ab9aaa3ee4383
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Feb 3 21:32:46 2016 +0100
patch 7.4.1249
Problem: Crash when the process a channel is connected to exits.
Solution: Use the file descriptor properly. Add a test. (Damien)
Also add a test for eval().
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 03 Feb 2016 21:45:04 +0100 |
parents | f12d6235a753 |
children | 1c6ef9113556 |
comparison
equal
deleted
inserted
replaced
7905:dfdf2ee817fa | 7906:ea1fd8d750a6 |
---|---|
50 except ValueError: | 50 except ValueError: |
51 print("json decoding failed") | 51 print("json decoding failed") |
52 decoded = [-1, ''] | 52 decoded = [-1, ''] |
53 | 53 |
54 # Send a response if the sequence number is positive. | 54 # Send a response if the sequence number is positive. |
55 # Negative numbers are used for "eval" responses. | |
56 if decoded[0] >= 0: | 55 if decoded[0] >= 0: |
57 if decoded[1] == 'hello!': | 56 if decoded[1] == 'hello!': |
58 # simply send back a string | 57 # simply send back a string |
59 response = "got it" | 58 response = "got it" |
60 elif decoded[1] == 'make change': | 59 elif decoded[1] == 'make change': |
63 cmd = '["ex","call append(\\"$\\",\\"added1\\")"]' | 62 cmd = '["ex","call append(\\"$\\",\\"added1\\")"]' |
64 cmd += '["ex","call append(\\"$\\",\\"added2\\")"]' | 63 cmd += '["ex","call append(\\"$\\",\\"added2\\")"]' |
65 print("sending: {}".format(cmd)) | 64 print("sending: {}".format(cmd)) |
66 thesocket.sendall(cmd.encode('utf-8')) | 65 thesocket.sendall(cmd.encode('utf-8')) |
67 response = "ok" | 66 response = "ok" |
67 elif decoded[1] == 'eval-works': | |
68 # Send an eval request. We ignore the response. | |
69 cmd = '["eval","\\"foo\\" . 123", -1]' | |
70 print("sending: {}".format(cmd)) | |
71 thesocket.sendall(cmd.encode('utf-8')) | |
72 response = "ok" | |
73 elif decoded[1] == 'eval-fails': | |
74 # Send an eval request that will fail. | |
75 cmd = '["eval","xxx", -2]' | |
76 print("sending: {}".format(cmd)) | |
77 thesocket.sendall(cmd.encode('utf-8')) | |
78 response = "ok" | |
79 elif decoded[1] == 'eval-result': | |
80 # Send back the last received eval result. | |
81 response = last_eval | |
68 elif decoded[1] == '!quit!': | 82 elif decoded[1] == '!quit!': |
69 # we're done | 83 # we're done |
70 sys.exit(0) | 84 sys.exit(0) |
85 elif decoded[1] == '!crash!': | |
86 # Crash! | |
87 42 / 0 | |
71 else: | 88 else: |
72 response = "what?" | 89 response = "what?" |
73 | 90 |
74 encoded = json.dumps([decoded[0], response]) | 91 encoded = json.dumps([decoded[0], response]) |
75 print("sending: {}".format(encoded)) | 92 print("sending: {}".format(encoded)) |
76 thesocket.sendall(encoded.encode('utf-8')) | 93 thesocket.sendall(encoded.encode('utf-8')) |
94 | |
95 # Negative numbers are used for "eval" responses. | |
96 elif decoded[0] < 0: | |
97 last_eval = decoded | |
77 | 98 |
78 thesocket = None | 99 thesocket = None |
79 | 100 |
80 class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer): | 101 class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer): |
81 pass | 102 pass |