diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2018-07-12 00:22:55 -0400 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2018-07-12 06:22:55 +0200 |
commit | 798f05876c114436851d98232739b4ba28318d79 (patch) | |
tree | 0231e0d63dd32af1db4bce9809ed29cb9f070676 | |
parent | 671b244e6ced960a7c39471cefa758e0d6e47146 (diff) | |
download | rneovim-798f05876c114436851d98232739b4ba28318d79.tar.gz rneovim-798f05876c114436851d98232739b4ba28318d79.tar.bz2 rneovim-798f05876c114436851d98232739b4ba28318d79.zip |
vim-patch:8.0.0{474,475,492,633,1251} (#8725)
* vim-patch:8.0.0474: the client-server feature is not tested
Problem: The client-server feature is not tested.
Solution: Add a test.
https://github.com/vim/vim/commit/15bf76d40be1f1622ff5cc16596c308e76e2ca94
* vim-patch:8.0.0475: not enough testing for the client-server feature
Problem: Not enough testing for the client-server feature.
Solution: Add more tests. Add the remote_startserver() function. Fix that
a locally evaluated expression uses function-local variables.
https://github.com/vim/vim/commit/7416f3e73ab2c4e7ae3adc2ff6e70234f7d40d2e
* vim-patch:8.0.0492: a failing client-server request can make Vim hang
Problem: A failing client-server request can make Vim hang.
Solution: Add a timeout argument to functions that wait.
https://github.com/vim/vim/commit/81b9d0bd5c705815e903e671e81b0b05828efd9c
Include src/nvim/testdir/test_clientserver.vim changes from
patches 8.0.0477, 8.0.0479.
* vim-patch:8.0.0633: the client-server test is still a bit flaky
Problem: The client-server test is still a bit flaky.
Solution: Wait a bit for the GUI to start. Check that the version number
can be obtained.
https://github.com/vim/vim/commit/60964f68740b8abcbb2d3f0f3aeade21d1bacb22
Include src/nvim/testdir/test_clientserver.vim changes
from patches 8.0.0507, 8.0.0511.
* vim-patch:8.0.1251: invalid expressin passed to WaitFor()
Problem: Invalid expressin passed to WaitFor().
Solution: Check if the variable exists.
https://github.com/vim/vim/commit/d97fbf171ec0e63117813da045d2a1c51a9b6f62
-rw-r--r-- | runtime/doc/eval.txt | 22 | ||||
-rw-r--r-- | src/nvim/testdir/Makefile | 1 | ||||
-rw-r--r-- | src/nvim/testdir/test_clientserver.vim | 107 |
3 files changed, 125 insertions, 5 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 635c08556b..d71bbf2528 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2222,6 +2222,8 @@ remote_read({serverid} [, {timeout}]) String read reply string remote_send({server}, {string} [, {idvar}]) String send key sequence +remote_startserver({name}) none become server {name} + String send key sequence remove({list}, {idx} [, {end}]) any remove items {idx}-{end} from {list} remove({dict}, {key}) any remove entry {key} from {dict} rename({from}, {to}) Number rename (move) file from {from} to {to} @@ -6196,15 +6198,17 @@ reltimestr({time}) *reltimestr()* < Also see |profiling|. *remote_expr()* *E449* -remote_expr({server}, {string} [, {idvar}]) +remote_expr({server}, {string} [, {idvar} [, {timeout}]]) Send the {string} to {server}. The string is sent as an expression and the result is returned after evaluation. The result must be a String or a |List|. A |List| is turned into a String by joining the items with a line break in between (not at the end), like with join(expr, "\n"). - If {idvar} is present, it is taken as the name of a - variable and a {serverid} for later use with + If {idvar} is present and not empty, it is taken as the name + of a variable and a {serverid} for later use with remote_read() is stored there. + If {timeout} is given the read times out after this many + seconds. Otherwise a timeout of 600 seconds is used. See also |clientserver| |RemoteReply|. This function is not available in the |sandbox|. {only available when compiled with the |+clientserver| feature} @@ -6248,9 +6252,10 @@ remote_peek({serverid} [, {retvar}]) *remote_peek()* :let repl = "" :echo "PEEK: ".remote_peek(id, "repl").": ".repl -remote_read({serverid}) *remote_read()* +remote_read({serverid}, [{timeout}]) *remote_read()* Return the oldest available reply from {serverid} and consume - it. It blocks until a reply is available. + it. Unless a {timeout} in seconds is given, it blocks until a + reply is available. See also |clientserver|. This function is not available in the |sandbox|. {only available when compiled with the |+clientserver| feature} @@ -6268,6 +6273,7 @@ remote_send({server}, {string} [, {idvar}]) See also |clientserver| |RemoteReply|. This function is not available in the |sandbox|. {only available when compiled with the |+clientserver| feature} + Note: Any errors will be reported in the server and may mess up the display. Examples: > @@ -6279,6 +6285,12 @@ remote_send({server}, {string} [, {idvar}]) :echo remote_send("gvim", ":sleep 10 | echo ". \ 'server2client(expand("<client>"), "HELLO")<CR>') < + *remote_startserver()* *E941* *E942* +remote_startserver({name}) + Become the server {name}. This fails if already running as a + server, when |v:servername| is not empty. + {only available when compiled with the |+clientserver| feature} + remove({list}, {idx} [, {end}]) *remove()* Without {end}: Remove the item at {idx} from |List| {list} and return the item. diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index 651ab3db2b..e3b717989e 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -40,6 +40,7 @@ NEW_TESTS ?= \ test_changedtick.res \ test_charsearch.res \ test_cindent.res \ + test_clientserver.res \ test_close_count.res \ test_cmdline.res \ test_command_count.res \ diff --git a/src/nvim/testdir/test_clientserver.vim b/src/nvim/testdir/test_clientserver.vim new file mode 100644 index 0000000000..60ef20e0b2 --- /dev/null +++ b/src/nvim/testdir/test_clientserver.vim @@ -0,0 +1,107 @@ +" Tests for the +clientserver feature. + +if !has('job') || !has('clientserver') + finish +endif + +source shared.vim + +func Test_client_server() + let cmd = GetVimCommand() + if cmd == '' + return + endif + if has('x11') + if empty($DISPLAY) + throw 'Skipped: $DISPLAY is not set' + endif + try + call remote_send('xxx', '') + catch + if v:exception =~ 'E240:' + throw 'Skipped: no connection to the X server' + endif + " ignore other errors + endtry + endif + + let name = 'XVIMTEST' + let cmd .= ' --servername ' . name + let g:job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'}) + call WaitFor('job_status(g:job) == "run"') + if job_status(g:job) != 'run' + call assert_report('Cannot run the Vim server') + return + endif + + " Takes a short while for the server to be active. + call WaitFor('serverlist() =~ "' . name . '"') + call assert_match(name, serverlist()) + + call remote_foreground(name) + + call remote_send(name, ":let testvar = 'yes'\<CR>") + call WaitFor('remote_expr("' . name . '", "exists(\"testvar\") ? testvar : \"\"", "", 1) == "yes"') + call assert_equal('yes', remote_expr(name, "testvar", "", 2)) + + if has('unix') && has('gui') && !has('gui_running') + " Running in a terminal and the GUI is available: Tell the server to open + " the GUI and check that the remote command still works. + " Need to wait for the GUI to start up, otherwise the send hangs in trying + " to send to the terminal window. + if has('gui_athena') || has('gui_motif') + " For those GUIs, ignore the 'failed to create input context' error. + call remote_send(name, ":call test_ignore_error('E285') | gui -f\<CR>") + else + call remote_send(name, ":gui -f\<CR>") + endif + " Wait for the server to be up and answering requests. + sleep 100m + call WaitFor('remote_expr("' . name . '", "v:version", "", 1) != ""') + call assert_true(remote_expr(name, "v:version", "", 1) != "") + + call remote_send(name, ":let testvar = 'maybe'\<CR>") + call WaitFor('remote_expr("' . name . '", "testvar", "", 1) == "maybe"') + call assert_equal('maybe', remote_expr(name, "testvar", "", 2)) + endif + + call assert_fails('call remote_send("XXX", ":let testvar = ''yes''\<CR>")', 'E241') + + " Expression evaluated locally. + if v:servername == '' + call remote_startserver('MYSELF') + " May get MYSELF1 when running the test again. + call assert_match('MYSELF', v:servername) + endif + let g:testvar = 'myself' + call assert_equal('myself', remote_expr(v:servername, 'testvar')) + + call remote_send(name, ":call server2client(expand('<client>'), 'got it')\<CR>", 'g:myserverid') + call assert_equal('got it', remote_read(g:myserverid, 2)) + + call remote_send(name, ":call server2client(expand('<client>'), 'another')\<CR>", 'g:myserverid') + let peek_result = 'nothing' + let r = remote_peek(g:myserverid, 'peek_result') + " unpredictable whether the result is already avaialble. + if r > 0 + call assert_equal('another', peek_result) + elseif r == 0 + call assert_equal('nothing', peek_result) + else + call assert_report('remote_peek() failed') + endif + let g:peek_result = 'empty' + call WaitFor('remote_peek(g:myserverid, "g:peek_result") > 0') + call assert_equal('another', g:peek_result) + call assert_equal('another', remote_read(g:myserverid, 2)) + + call remote_send(name, ":qa!\<CR>") + call WaitFor('job_status(g:job) == "dead"') + if job_status(g:job) != 'dead' + call assert_report('Server did not exit') + call job_stop(g:job, 'kill') + endif +endfunc + +" Uncomment this line to get a debugging log +" call ch_logfile('channellog', 'w') |