All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
2 let g:can_run_socket_tests = !has('win32')
3 \ && (exists('*ch_close') || exists('*chanclose'))
5 if g:can_run_socket_tests
6 call ale#test#SetDirectory('/testplugin/test')
8 let g:channel_id_received = 0
9 let g:data_received = ''
11 function! WaitForData(expected_data, timeout) abort
14 while l:ticks < a:timeout
15 " Sleep first, so we can switch to the callback.
19 if g:data_received is# a:expected_data
25 function! TestCallback(channel_id, data) abort
26 let g:channel_id_received = a:channel_id
27 let g:data_received .= a:data
31 let g:pid_tcp = str2nr(system(
33 \ . ' ' . ale#Escape(g:dir . '/script/dumb_tcp_server.py')
36 let g:pipe_path = tempname()
37 let g:pid_pipe = str2nr(system(
39 \ . ' ' . ale#Escape(g:dir . '/script/dumb_named_pipe_server.py')
45 if g:can_run_socket_tests
46 call ale#test#RestoreDirectory()
48 unlet! g:channel_id_received
49 unlet! g:data_received
52 delfunction WaitForData
53 delfunction TestCallback
55 if has_key(g:, 'pid_tcp')
56 call system('kill ' . g:pid_tcp)
59 if has_key(g:, 'pid_pipe')
60 call system('kill ' . g:pid_pipe)
69 unlet! g:can_run_socket_tests
71 Execute(Sending and receiving connections to tcp sockets should work):
72 if g:can_run_socket_tests
73 let g:channel_id = ale#socket#Open(
74 \ '127.0.0.1:' . g:port,
75 \ {'callback': function('TestCallback')}
78 Assert g:channel_id >= 0, 'The socket was not opened!'
80 call ale#socket#Send(g:channel_id, 'hello')
81 call ale#socket#Send(g:channel_id, ' world')
83 AssertEqual 1, ale#socket#IsOpen(g:channel_id)
85 " Wait up to 1 second for the expected data to arrive.
86 call WaitForData('hello world', 1000)
88 AssertEqual g:channel_id, g:channel_id_received
89 AssertEqual 'hello world', g:data_received
90 AssertEqual '127.0.0.1:' . g:port, ale#socket#GetAddress(g:channel_id)
92 call ale#socket#Close(g:channel_id)
94 AssertEqual 0, ale#socket#IsOpen(g:channel_id)
95 AssertEqual '', ale#socket#GetAddress(g:channel_id)
98 " NeoVim versions which can't connect to sockets should just fail.
99 if has('nvim') && !exists('*chanclose')
100 AssertEqual -1, ale#socket#Open(
102 \ {'callback': function('function')}
106 Execute(Sending and receiving connections to named pipe sockets should work):
107 if g:can_run_socket_tests && has('nvim-0.4')
108 let g:channel_id = ale#socket#Open(
110 \ {'callback': function('TestCallback')}
113 Assert g:channel_id >= 0, 'The socket was not opened!'
115 call ale#socket#Send(g:channel_id, 'hello')
116 call ale#socket#Send(g:channel_id, ' world')
118 AssertEqual 1, ale#socket#IsOpen(g:channel_id)
120 " Wait up to 1 second for the expected data to arrive.
121 call WaitForData('hello world', 1000)
123 AssertEqual g:channel_id, g:channel_id_received
124 AssertEqual 'hello world', g:data_received
125 AssertEqual g:pipe_path, ale#socket#GetAddress(g:channel_id)
127 call ale#socket#Close(g:channel_id)
129 AssertEqual 0, ale#socket#IsOpen(g:channel_id)
130 AssertEqual '', ale#socket#GetAddress(g:channel_id)
133 " NeoVim versions which can't connect to sockets should just fail.
134 if has('nvim-0.4') && !exists('*chanclose')
135 AssertEqual -1, ale#socket#Open(
137 \ {'callback': function('function')}