summaryrefslogtreecommitdiff
path: root/mnv/src/testdir/test_remote.mnv
blob: 2dae5e2869dfb8e558b5edc4521c990a84d3823f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
" Test for the --remote functionality

CheckFeature clientserver
CheckFeature terminal

source util/screendump.mnv
source util/mouse.mnv

let s:remote_works = 0
let s:skip = 'Skipped: --remote feature is not possible'

" needs to be run as first test to verify, that mnv --servername works
func Verify_remote_feature_works()
  CheckRunMNVInTerminal
  enew
  let buf = RunMNVInTerminal('--servername XMNVTEST', {'rows': 8})
  call TermWait(buf)

  " For some reason when the socket server is being used, the terminal MNV never
  " receives the `:w! XMNVRemoteTest.txt` command from term_sendkeys.
  if has('socketserver') && !has('X11')
    if match(serverlist(), "XMNVTEST") == -1
      call StopMNVInTerminal(buf)
      throw s:skip
    endif

    let s:remote = 1
    return
  endif

  let cmd = GetMNVCommandCleanTerm() .. '--serverlist'
  call term_sendkeys(buf, ":r! " .. cmd .. "\<CR>")
  call TermWait(buf)
  call term_sendkeys(buf, ":w! XMNVRemoteTest.txt\<CR>")
  call TermWait(buf)
  call term_sendkeys(buf, ":q\<CR>")
  call StopMNVInTerminal(buf)
  bw!
  let result = readfile('XMNVRemoteTest.txt')
  call delete('XMNVRemoteTest.txt')
  if empty(result)
    throw s:skip
  endif
  let s:remote = 1
endfunc

call Verify_remote_feature_works()

if !s:remote
  finish
endif

func Test_remote_servername()
  CheckRunMNVInTerminal

  " That is the file we want the server to open,
  " despite the wildignore setting
  call writefile(range(1, 20), 'XTEST.txt', 'D')
  " just a dummy file, so that the ':wq' further down is successful
  call writefile(range(1, 20), 'Xdummy.log', 'D')

  " Run MNV in a terminal and open a terminal window to run MNV in.
  let lines =<< trim END
    set wildignore=*.txt
  END
  call writefile(lines, 'XRemoteEditing.mnv', 'D')
  let buf = RunMNVInTerminal('--servername XMNVTEST -S XRemoteEditing.mnv  Xdummy.log', {'rows': 8})
  call TermWait(buf)
  botright new
  " wildignore setting should be ignored and the XMNVTEST server should now
  " open XTEST.txt, if wildignore setting is not ignored, the server
  " will continue with the Xdummy.log file
  let buf2 = RunMNVInTerminal('--servername XMNVTEST --remote-silent XTEST.txt', {'rows': 5, 'wait_for_ruler': 0})
  " job should be no-longer running, so we can just close it
  exe buf2 .. 'bw!'
  call term_sendkeys(buf, ":sil :3,$d\<CR>")
  call TermWait(buf)
  call term_sendkeys(buf, ":wq!\<CR>")
  call TermWait(buf)
  if term_getstatus(buf) == 'running'
    call StopMNVInTerminal(buf)
  endif
  let buf_contents = readfile('XTEST.txt')
  call assert_equal(2, len(buf_contents))
  bw!
  close
endfunc

func Test_remote_servername_shellslash()
  " Note this test does not currently run on Windows
  " because:
  " 1) we cannot run the gui version of MNV inside a terminal
  " 2) Running Windows mnv.exe inside a terminal would work, but is
  "    disabled because of the limited colors inside the default Windows
  "    console (see CanRunMNVInTerminal in term_util.mnv)
  CheckRunMNVInTerminal
  CheckMSWindows

  " That is the file we want the server to open,
  " despite the wildignore setting
  call mkdir(expand('~/remote/'), 'pD')
  call writefile(range(1, 20), expand('~/remote/XTEST.txt'), 'D')
  " just a dummy file, so that the ':wq' further down is successful
  call writefile(range(1, 20), 'Xdummy.log', 'D')

  " Run MNV in a terminal and open a terminal window to run MNV in.
  let lines =<< trim END
    set shellslash
    cd ~/remote
  END
  call writefile(lines, 'XRemoteEditing1.mnv', 'D')
  let buf = RunMNVInTerminal('--servername XMNVTEST -S XRemoteEditing1.mnv  Xdummy.log', {'rows': 10})
  call TermWait(buf)

  " wildignore setting should be ignored and the XMNVTEST server should now
  " open XTEST.txt, if wildignore setting is not ignored, the server
  " will continue with the Xdummy.log file
  let buf2 = RunMNVInTerminal('--servername XMNVTEST --remote-silent ~/remote/XTEST.txt', {'rows': 5, 'wait_for_ruler': 0})
  " job should be no-longer running, so we can just close it
  exe buf2 .. 'bw!'

  call term_sendkeys(buf, ":pwd\<CR>")
  call WaitForAssert({-> assert_match('remote/$', term_getline(buf, 10))}, 1000)
  call TermWait(buf)
  call term_sendkeys(buf, ":q!\<CR>")
  call TermWait(buf)
  if term_getstatus(buf) == 'running'
    call StopMNVInTerminal(buf)
  endif
  bw!
  close
endfunc

" Test if serverlist() lists itself.
func Test_remote_servername_itself()
  let lines =<< trim END
    call writefile([serverlist()], "XTest")
  END
  defer delete("XTest")
  call writefile(lines, 'XRemote.mnv', 'D')
  let buf = RunMNVInTerminal('--servername XMNVTEST -S XRemote.mnv', {'rows': 8})
  call TermWait(buf)

  call WaitForAssert({-> assert_match("XMNVTEST", readfile("XTest")[0])})

  call StopMNVInTerminal(buf)
endfunc

" mnv: shiftwidth=2 sts=2 expandtab