blob: 1475052fe3c24caa8f096f1882c70bd7b2b9de04 [file] [log] [blame]
Christian Brabandtcc979b42024-01-23 21:13:58 +01001" Test for the --remote functionality
2
3source check.vim
4CheckFeature clientserver
5CheckFeature terminal
6
7source shared.vim
8source screendump.vim
9source mouse.vim
10source term_util.vim
11
12let s:remote_works = 0
13let s:skip = 'Skipped: --remote feature is not possible'
14
15" nees to be run as first test to verify, that vim --servername works
16func 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
35endfunc
36
37call Verify_remote_feature_works()
38
39if !s:remote
40 finish
41endif
42
43func 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
77endfunc
78
Christian Brabandt349f5cd2024-04-19 15:22:33 +020079func 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
122endfunc
123
Christian Brabandtcc979b42024-01-23 21:13:58 +0100124" vim: shiftwidth=2 sts=2 expandtab