Christian Brabandt | cc979b4 | 2024-01-23 21:13:58 +0100 | [diff] [blame] | 1 | " Test for the --remote functionality |
| 2 | |
| 3 | source check.vim |
| 4 | CheckFeature clientserver |
| 5 | CheckFeature terminal |
| 6 | |
| 7 | source shared.vim |
| 8 | source screendump.vim |
| 9 | source mouse.vim |
| 10 | source term_util.vim |
| 11 | |
| 12 | let s:remote_works = 0 |
| 13 | let s:skip = 'Skipped: --remote feature is not possible' |
| 14 | |
| 15 | " nees to be run as first test to verify, that vim --servername works |
| 16 | func Verify_remote_feature_works() |
| 17 | CheckRunVimInTerminal |
| 18 | enew |
| 19 | let buf = RunVimInTerminal('--servername XVIMTEST', {'rows': 8}) |
| 20 | call TermWait(buf) |
| 21 | let cmd = GetVimCommandCleanTerm() .. '--serverlist' |
| 22 | call term_sendkeys(buf, ":r! " .. cmd .. "\<CR>") |
| 23 | call TermWait(buf) |
| 24 | call term_sendkeys(buf, ":w! XVimRemoteTest.txt\<CR>") |
| 25 | call TermWait(buf) |
| 26 | call term_sendkeys(buf, ":q\<CR>") |
| 27 | call StopVimInTerminal(buf) |
| 28 | bw! |
| 29 | let result = readfile('XVimRemoteTest.txt') |
| 30 | call delete('XVimRemoteTest.txt') |
| 31 | if empty(result) |
| 32 | throw s:skip |
| 33 | endif |
| 34 | let s:remote = 1 |
| 35 | endfunc |
| 36 | |
| 37 | call Verify_remote_feature_works() |
| 38 | |
| 39 | if !s:remote |
| 40 | finish |
| 41 | endif |
| 42 | |
| 43 | func Test_remote_servername() |
| 44 | CheckRunVimInTerminal |
| 45 | |
| 46 | " That is the file we want the server to open, |
| 47 | " despite the wildignore setting |
| 48 | call writefile(range(1, 20), 'XTEST.txt', 'D') |
| 49 | " just a dummy file, so that the ':wq' further down is successful |
| 50 | call writefile(range(1, 20), 'Xdummy.log', 'D') |
| 51 | |
| 52 | " Run Vim in a terminal and open a terminal window to run Vim in. |
| 53 | let lines =<< trim END |
| 54 | set wildignore=*.txt |
| 55 | END |
| 56 | call writefile(lines, 'XRemoteEditing.vim', 'D') |
| 57 | let buf = RunVimInTerminal('--servername XVIMTEST -S XRemoteEditing.vim Xdummy.log', {'rows': 8}) |
| 58 | call TermWait(buf) |
| 59 | botright new |
| 60 | " wildignore setting should be ignored and the XVIMTEST server should now |
| 61 | " open XTEST.txt, if wildignore setting is not ignored, the server |
| 62 | " will continue with the Xdummy.log file |
| 63 | let buf2 = RunVimInTerminal('--servername XVIMTEST --remote-silent XTEST.txt', {'rows': 5, 'wait_for_ruler': 0}) |
| 64 | " job should be no-longer running, so we can just close it |
| 65 | exe buf2 .. 'bw!' |
| 66 | call term_sendkeys(buf, ":sil :3,$d\<CR>") |
| 67 | call TermWait(buf) |
| 68 | call term_sendkeys(buf, ":wq!\<CR>") |
| 69 | call TermWait(buf) |
| 70 | if term_getstatus(buf) == 'running' |
| 71 | call StopVimInTerminal(buf) |
| 72 | endif |
| 73 | let buf_contents = readfile('XTEST.txt') |
| 74 | call assert_equal(2, len(buf_contents)) |
| 75 | bw! |
| 76 | close |
| 77 | endfunc |
| 78 | |
Christian Brabandt | 349f5cd | 2024-04-19 15:22:33 +0200 | [diff] [blame] | 79 | func Test_remote_servername_shellslash() |
| 80 | " Note this test does not currently run on Windows |
| 81 | " because: |
| 82 | " 1) we cannot run the gui version of Vim inside a terminal |
| 83 | " 2) Running Windows vim.exe inside a terminal would work, but is |
| 84 | " disabled because of the limited colors inside the default Windows |
| 85 | " console (see CanRunVimInTerminal in term_util.vim) |
| 86 | CheckRunVimInTerminal |
| 87 | CheckMSWindows |
| 88 | |
| 89 | " That is the file we want the server to open, |
| 90 | " despite the wildignore setting |
| 91 | call mkdir(expand('~/remote/'), 'pD') |
| 92 | call writefile(range(1, 20), expand('~/remote/XTEST.txt'), 'D') |
| 93 | " just a dummy file, so that the ':wq' further down is successful |
| 94 | call writefile(range(1, 20), 'Xdummy.log', 'D') |
| 95 | |
| 96 | " Run Vim in a terminal and open a terminal window to run Vim in. |
| 97 | let lines =<< trim END |
| 98 | set shellslash |
| 99 | cd ~/remote |
| 100 | END |
| 101 | call writefile(lines, 'XRemoteEditing1.vim', 'D') |
| 102 | let buf = RunVimInTerminal('--servername XVIMTEST -S XRemoteEditing1.vim Xdummy.log', {'rows': 10}) |
| 103 | call TermWait(buf) |
| 104 | |
| 105 | " wildignore setting should be ignored and the XVIMTEST server should now |
| 106 | " open XTEST.txt, if wildignore setting is not ignored, the server |
| 107 | " will continue with the Xdummy.log file |
| 108 | let buf2 = RunVimInTerminal('--servername XVIMTEST --remote-silent ~/remote/XTEST.txt', {'rows': 5, 'wait_for_ruler': 0}) |
| 109 | " job should be no-longer running, so we can just close it |
| 110 | exe buf2 .. 'bw!' |
| 111 | |
| 112 | call term_sendkeys(buf, ":pwd\<CR>") |
| 113 | call WaitForAssert({-> assert_match('remote/$', term_getline(buf, 10))}, 1000) |
| 114 | call TermWait(buf) |
| 115 | call term_sendkeys(buf, ":q!\<CR>") |
| 116 | call TermWait(buf) |
| 117 | if term_getstatus(buf) == 'running' |
| 118 | call StopVimInTerminal(buf) |
| 119 | endif |
| 120 | bw! |
| 121 | close |
| 122 | endfunc |
| 123 | |
Christian Brabandt | cc979b4 | 2024-01-23 21:13:58 +0100 | [diff] [blame] | 124 | " vim: shiftwidth=2 sts=2 expandtab |