ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/AnyEvent-MCP/t/e12_vim_startup.t
Revision: 1.4
Committed: Mon Nov 16 22:31:53 2026 UTC (2 weeks, 3 days ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-0_92, HEAD
Changes since 1.3: +42 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 use common::sense;
2     use Test::More;
3     BEGIN {
4     plan skip_all => "extended vim_startup test (PERL_ANYEVENT_MCP_TESTS=1)"
5     unless ($ENV{PERL_ANYEVENT_MCP_TESTS} || 0) >= 1;
6     }
7    
8     use File::Temp ();
9     use File::Path ();
10     use AnyEvent::MCP::Config ();
11     use IPC::Open3 ();
12     use Symbol ();
13    
14     my $dir = File::Temp::tempdir (CLEANUP => 1);
15     File::Path::mkpath (["$dir/home", "$dir/config"], 0, 0700);
16     local $ENV{HOME} = "$dir/home";
17     local $ENV{XDG_CONFIG_HOME} = "$dir/config";
18    
19     sub run_vim {
20     my @argv = @_;
21     my $error = Symbol::gensym;
22     my $pid = IPC::Open3::open3 (my $input, my $output, $error,
23     $^X, "-Ilib", "bin/mcp-vim", @argv);
24     close $input;
25     local $/;
26     my $out = <$output> // "";
27     my $err = <$error> // "";
28     waitpid $pid, 0;
29     ($? >> 8, $out, $err)
30     }
31    
32     my ($status, $url, $err) = run_vim ("--print-url");
33     is $status, 0, "print-url exits successfully";
34     like $url, qr{\Ahttp://127\.0\.0\.1:[0-9]+/[A-Za-z0-9_-]{43}/ \# user global:default \(connect\)\n\z},
35     "print-url emits a cookie-bearing URL prefix";
36     is $err, "", "print-url has no diagnostics on success";
37    
38     my $file = "$dir/config/anyevent-mcp/global.ini";
39     ok -f $file && !((stat $file)[2] & 077), "global master secret saved privately";
40 root 1.2 my $config = AnyEvent::MCP::Config->new (file => $file)->load;
41 root 1.1 my ($default_port, $cookie);
42     {
43     local $0 = "mcp-vim";
44     $default_port = $config->server_port ("default");
45     $cookie = $config->user_credentials ("default")->[0][2];
46     }
47     like $url, qr{\Ahttp://127\.0\.0\.1:$default_port/},
48     "default port is derived from the service name";
49     # token is derived in the broker program domain above.
50     like $url, qr{\Q/$cookie/\E \# user global:default \(connect\)\n\z}, "cookie derives from global master secret";
51    
52     my ($again_status, $again_url) = run_vim ("--print-url");
53     is $again_status, 0, "second invocation exits successfully";
54     is $again_url, $url, "cookie and URL are stable across processes";
55     ($status, $url) = run_vim ("--print-url", "--token", "cli-first", "--token", "cli-second");
56     is $status, 0, "repeated --token options accepted";
57     like $url, qr{/cli-first/\n\z}, "first CLI token is advertised";
58     ok !-e "$dir/home/.xpcse-broker", "startup no longer generates old cookie config";
59    
60     open my $legacy, ">>", $file or die $!;
61     print {$legacy} "\n[instance default]\nbind = 127.0.0.1:31749\n";
62     close $legacy or die $!;
63     ($status, $url, $err) = run_vim ("--print-url");
64     is $status, 0, "named bind setting accepted";
65     is $url, "http://127.0.0.1:31749/$cookie/ # user global:default (connect)\n",
66     "named bind overrides derived port";
67    
68     open my $fh, ">>", $file or die $!;
69     print {$fh} "tokens = explicit-cookie,secondary-token\n";
70     close $fh or die $!;
71     ($status, $url) = run_vim ("--print-url");
72     is $status, 0, "explicit configured tokens accepted";
73     like $url, qr{\Ahttp://[^:/\s]+:31749/explicit-cookie/\n\z},
74     "first configured token overrides derived default";
75    
76     ($status, $url) = run_vim ("--print-url", "--bind", "127.0.0.1:41859");
77     is $status, 0, "bind switch accepted";
78     is $url, "http://127.0.0.1:41859/explicit-cookie/\n",
79     "explicit bind overrides named setting";
80    
81     ($status, $url) = run_vim ("--print-url", "--bind", "[::1]:41859");
82     is $status, 0, "IPv6 bind accepted";
83     is $url, "http://[::1]:41859/explicit-cookie/\n",
84     "IPv6 URL host is bracketed";
85    
86     ($status, $url) = run_vim ("--print-url", "--bind", "[::]");
87     is $status, 0, "IPv6 wildcard accepted";
88     like $url, qr{\Ahttp://[^:/\s]+:31749/explicit-cookie/\n\z},
89     "wildcard bind advertises concrete hostname";
90    
91     ($status, undef, $err) = run_vim ("--print-url", "--bind", ":0");
92     ok $status != 0 && $err =~ /port is not known/,
93     "zero port rejected because a printable fixed URL is required";
94     ($status, undef, $err) = run_vim ("--print-url", "--bind", ":65536");
95     ok $status != 0 && $err =~ /Invalid MCP bind/,
96     "out-of-range port rejected";
97     ($status, undef, $err) = run_vim ("--print-url", "--bind", "");
98     ok $status != 0 && $err =~ /Invalid MCP bind/,
99     "empty host rejected";
100    
101     {
102     local $ENV{XDG_CONFIG_HOME} = "/proc/self/mcp-vim-no-persistent-secret-$$";
103     ($status, $url, $err) = run_vim ("--print-url");
104     ok $status != 0 && !length $url,
105     "cannot print a URL backed only by unsaved, process-local entropy";
106 root 1.3 like $err, qr/(?:mkdir|cannot create).*mcp-vim-no-persistent-secret/,
107     "secret persistence failure is diagnosed before advertising a URL";
108 root 1.1 }
109    
110     ($status, my $help) = run_vim ("--help");
111     is $status, 0, "help exits successfully";
112     like $help, qr/print-url/, "help explains URL switch";
113     ($status, undef, $err) = run_vim ("--not-a-switch");
114     ok $status != 0, "unknown option rejected";
115     # exercise message capture and error propagation in Vim itself, when available.
116     SKIP: {
117     skip "extended real Vim tests (PERL_ANYEVENT_MCP_TESTS=1)", 2
118     unless ($ENV{PERL_ANYEVENT_MCP_TESTS} || 0) >= 1;
119     my ($vim) = grep -x $_ && !-d _, map "$_/vim", split /:/, $ENV{PATH};
120     skip "vim not available", 2 unless $vim;
121    
122     my $script = "$dir/ex-test.vim";
123     open my $fh, ">", $script or die "$script: $!";
124     print {$fh} <<'VIM';
125     if !exists ('*getscriptinfo') || !exists ('*assert_equal') || !exists ('*bufadd') || !exists ('*bufload') || !exists ('*execute')
126     call writefile (['SKIP: Vim lacks required scripting functions'], argv (0))
127     qa!
128     endif
129     source vim/plugin/mcp-vim.vim
130     let sid = filter (getscriptinfo (), 'v:val.name =~# "mcp-vim\\.vim$"')[0].sid
131     let Rpc = function ('<SNR>' . sid . '_rpc_call_ex')
132     call assert_equal ("\nhello\nworld", Rpc ("echo 'hello' | echo 'world'").output)
133     call assert_equal ('', Rpc ("let g:mcp_ex_test = 42").output)
134     call assert_equal (42, g:mcp_ex_test)
135     call Rpc ("call setline (1, 'changed')\nlet g:mcp_ex_second = 1")
136     call assert_equal ('changed', getline (1))
137     call assert_equal (1, g:mcp_ex_second)
138     let error = ''
139     try
140     call Rpc ("let g:mcp_ex_partial = 1 | throw 'deliberate failure'")
141     catch
142     let error = v:exception
143     endtry
144     call assert_equal ('deliberate failure', error)
145     call assert_equal (1, g:mcp_ex_partial)
146     let error = ''
147     try
148     call Rpc ('NoSuchExCommand')
149     catch
150     let error = v:exception
151     endtry
152     call assert_match ('E492:', error)
153     call assert_equal ("\nafter error", Rpc ("echo 'after error'").output)
154    
155     let original = bufnr ('%')
156     let file = tempname ()
157     call writefile (['original'], file)
158     let target = bufadd (file)
159     call bufload (target)
160     call setbufline (target, 1, 'saved by update')
161     let tick = getbufvar (target, 'changedtick')
162     call Rpc ('update', target, tick)
163     call assert_equal (target, bufnr ('%'))
164     call assert_equal (['saved by update'], readfile (file))
165     call assert_equal (0, &modified)
166     call Rpc ("call setline (1, 'newer contents')", target)
167     let error = ''
168     try
169     call Rpc ('let g:mcp_stale_ex_ran = 1', target, tick)
170     catch
171     let error = v:exception
172     endtry
173     call assert_match ('rpc/stale_buffer:', error)
174     call assert_equal (0, exists ('g:mcp_stale_ex_ran'))
175     call assert_equal (['saved by update'], readfile (file))
176     let error = ''
177     try
178     call Rpc ('let g:mcp_stale_ex_ran = 1', v:null, b:changedtick)
179     catch
180     let error = v:exception
181     endtry
182     call assert_match ('requires_buffer', error)
183     call assert_equal (0, exists ('g:mcp_stale_ex_ran'))
184    
185     " Entering a buffer can run autocommands; check the tick afterwards.
186     execute 'hide buffer ' . original
187     execute 'autocmd BufEnter <buffer=' . target . '> call setline (1, "changed on entry")'
188     let tick = getbufvar (target, 'changedtick')
189     let error = ''
190     try
191     call Rpc ('let g:mcp_stale_ex_ran = 1', target, tick)
192     catch
193     let error = v:exception
194     endtry
195     call assert_match ('rpc/stale_buffer:', error)
196     call assert_equal (0, exists ('g:mcp_stale_ex_ran'))
197    
198     " A hidden buffer has its own history; undo must not affect the current one.
199     let Undo = function ('<SNR>' . sid . '_rpc_call_undo')
200     let Redo = function ('<SNR>' . sid . '_rpc_call_redo')
201     let Substitute = function ('<SNR>' . sid . '_rpc_call_substitute')
202     let caller = bufnr ('%')
203     let caller_lines = getline (1, '$')
204     let caller_view = winsaveview ()
205     let undo_file = tempname ()
206     call writefile (['base'], undo_file)
207     let undo_buf = bufadd (undo_file)
208     call bufload (undo_buf)
209     call Substitute (undo_buf, '%', 'base', 'one', '', getbufvar (undo_buf, 'changedtick'))
210     let one = getbufvar (undo_buf, 'changedtick')
211     call Substitute (undo_buf, '%', 'one', 'two', '', one)
212     let two = getbufvar (undo_buf, 'changedtick')
213     let result = Undo (undo_buf, two)
214     call assert_equal (['one'], getbufline (undo_buf, 1, '$'))
215     call assert_equal (undo_buf, result.buffer)
216     call assert_equal (1, result.changed)
217     call assert_equal (1, result.modified)
218     call assert_equal (1, result.seq_cur)
219     call assert_equal (2, result.seq_last)
220     call assert_equal (getbufvar (undo_buf, 'changedtick'), result.changedtick)
221     call assert_equal (caller, bufnr ('%'))
222     call assert_equal (caller_lines, getline (1, '$'))
223     call assert_equal (caller_view, winsaveview ())
224     call assert_equal (['base'], readfile (undo_file))
225    
226     let error = ''
227     try
228     call Redo (undo_buf, two)
229     catch
230     let error = v:exception
231     endtry
232     call assert_match ('rpc/stale_buffer:', error)
233     call assert_equal (['one'], getbufline (undo_buf, 1, '$'))
234     let result = Redo (undo_buf, result.changedtick)
235     call assert_equal (['two'], getbufline (undo_buf, 1, '$'))
236     call assert_equal (2, result.seq_cur)
237     call assert_equal (1, result.changed)
238     let result = Redo (undo_buf, result.changedtick)
239     call assert_equal (0, result.changed)
240     call assert_equal (2, result.seq_cur)
241    
242     let result = Undo (undo_buf, result.changedtick)
243     let result = Undo (undo_buf, result.changedtick)
244     call assert_equal (['base'], getbufline (undo_buf, 1, '$'))
245     call assert_equal (0, result.seq_cur)
246     call assert_equal (0, result.modified)
247     let result = Undo (undo_buf, result.changedtick)
248     call assert_equal (0, result.changed)
249     call assert_equal (0, result.seq_cur)
250    
251     " A new edit after undo selects a new branch; redo cannot resurrect the old one.
252     let result = Redo (undo_buf, result.changedtick)
253     call Substitute (undo_buf, '%', 'one', 'branch', '', result.changedtick)
254     let tick = getbufvar (undo_buf, 'changedtick')
255     let result = Redo (undo_buf, tick)
256     call assert_equal (['branch'], getbufline (undo_buf, 1, '$'))
257     call assert_equal (0, result.changed)
258     call assert_equal (3, result.seq_cur)
259     call assert_equal (3, result.seq_last)
260    
261     call setbufvar (undo_buf, '&modifiable', 0)
262     let error = ''
263     try
264     call Undo (undo_buf, result.changedtick)
265     catch
266     let error = v:exception
267     endtry
268     call assert_match ('rpc/not_modifiable', error)
269     call setbufvar (undo_buf, '&modifiable', 1)
270     call assert_equal (['base'], readfile (undo_file))
271     call assert_equal (caller, bufnr ('%'))
272    
273     " The current-buffer case keeps Vim's normal cursor adjustment and history.
274     execute 'noautocmd hide buffer ' . undo_buf
275     let result = Undo (undo_buf, getbufvar (undo_buf, 'changedtick'))
276     call assert_equal (undo_buf, bufnr ('%'))
277     call assert_equal (['one'], getline (1, '$'))
278     call assert_equal (1, result.seq_cur)
279     let result = Redo (undo_buf, result.changedtick)
280     call assert_equal (['branch'], getline (1, '$'))
281     call assert_equal (3, result.seq_cur)
282    
283     let Update = function ('<SNR>' . sid . '_rpc_call_update')
284     let caller = bufnr ('%')
285     let caller_lines = getline (1, '$')
286     let caller_view = winsaveview ()
287     let update_file = tempname ()
288     call writefile (['saved'], update_file)
289     let update_buf = bufadd (update_file)
290     call bufload (update_buf)
291     call setbufline (update_buf, 1, 'edited')
292     let old_tick = getbufvar (update_buf, 'changedtick')
293     let result = Update (update_buf, old_tick)
294     call assert_equal (['edited'], readfile (update_file))
295     call assert_equal (0, result.modified)
296     call assert_equal (update_buf, result.buffer)
297     call assert_equal (update_file, result.filename)
298     call assert_equal (getbufvar (update_buf, 'changedtick'), result.changedtick)
299     call assert_equal (caller, bufnr ('%'))
300     call assert_equal (caller_lines, getline (1, '$'))
301     call assert_equal (caller_view, winsaveview ())
302    
303     let g:update_writes = 0
304     execute 'autocmd BufWritePre <buffer=' . update_buf . '> let g:update_writes += 1'
305     let result = Update (update_buf, result.changedtick)
306     call assert_equal (0, g:update_writes)
307     call assert_equal (0, result.modified)
308     call setbufline (update_buf, 1, 'newer')
309     let error = ''
310     try
311     call Update (update_buf, old_tick)
312     catch
313     let error = v:exception
314     endtry
315     call assert_match ('rpc/stale_buffer:', error)
316     call assert_equal (['edited'], readfile (update_file))
317     call assert_equal (0, g:update_writes)
318    
319     " Write autocommands run normally; the result describes the buffer afterwards.
320     execute 'autocmd BufWritePre <buffer=' . update_buf . '> call setline (1, "prewrite")'
321     execute 'autocmd BufWritePost <buffer=' . update_buf . '> call setline (1, "postwrite")'
322     let result = Update (update_buf, getbufvar (update_buf, 'changedtick'))
323     call assert_equal (1, g:update_writes)
324     call assert_equal (['prewrite'], readfile (update_file))
325     call assert_equal (['postwrite'], getbufline (update_buf, 1, '$'))
326     call assert_equal (getbufvar (update_buf, '&modified'), result.modified)
327     call assert_equal (getbufvar (update_buf, 'changedtick'), result.changedtick)
328     execute 'autocmd! BufWritePre <buffer=' . update_buf . '>'
329     execute 'autocmd! BufWritePost <buffer=' . update_buf . '>'
330    
331     call setbufvar (update_buf, '&modified', 1)
332     execute 'autocmd BufWritePre <buffer=' . update_buf . '> throw "deliberate write failure"'
333     let error = ''
334     try
335     call Update (update_buf, result.changedtick)
336     catch
337     let error = v:exception
338     endtry
339     call assert_equal ('deliberate write failure', error)
340     call assert_equal (['prewrite'], readfile (update_file))
341     call assert_equal (1, getbufvar (update_buf, '&modified'))
342     call assert_equal (caller, bufnr ('%'))
343     execute 'autocmd! BufWritePre <buffer=' . update_buf . '>'
344    
345     call setbufvar (update_buf, '&readonly', 1)
346     let error = ''
347     try
348     call Update (update_buf, getbufvar (update_buf, 'changedtick'))
349     catch
350     let error = v:exception
351     endtry
352     call assert_match ('E45:', error)
353     call assert_equal (['prewrite'], readfile (update_file))
354     call setbufvar (update_buf, '&readonly', 0)
355     let result = Update (update_buf, getbufvar (update_buf, 'changedtick'))
356     call assert_equal (['postwrite'], readfile (update_file))
357     call assert_equal (0, result.modified)
358    
359     " A write autocommand may change the current buffer; report the saved target.
360     execute 'autocmd BufWritePost <buffer=' . update_buf . '> execute "noautocmd hide buffer " . ' . caller
361     call setbufline (update_buf, 1, 'switched')
362     let result = Update (update_buf, getbufvar (update_buf, 'changedtick'))
363     call assert_equal (update_buf, result.buffer)
364     call assert_equal (update_file, result.filename)
365     call assert_equal (getbufvar (update_buf, 'changedtick'), result.changedtick)
366     call assert_equal (['switched'], readfile (update_file))
367     call assert_equal (caller, bufnr ('%'))
368     execute 'autocmd! BufWritePost <buffer=' . update_buf . '>'
369    
370     let unnamed = bufadd ('')
371     call bufload (unnamed)
372     call setbufline (unnamed, 1, 'unsaved')
373     let error = ''
374     try
375     call Update (unnamed, getbufvar (unnamed, 'changedtick'))
376     catch
377     let error = v:exception
378     endtry
379     call assert_match ('E32:', error)
380     call assert_equal (1, getbufvar (unnamed, '&modified'))
381     call assert_equal (caller, bufnr ('%'))
382     " Opening files loads a listed buffer without changing the current view.
383     let Open = function ('<SNR>' . sid . '_rpc_call_open')
384     let open_dir = tempname ()
385     call mkdir (open_dir)
386     let old_cwd = getcwd ()
387     execute 'lcd ' . fnameescape (open_dir)
388     let caller = bufnr ('%')
389     let caller_lines = getline (1, '$')
390     let caller_view = winsaveview ()
391     let literal_name = "literal # % | [*] $HOME 'quote'.txt"
392     call writefile (['disk one', 'disk two'], literal_name)
393     let opened = Open (literal_name)
394     call assert_equal (open_dir . '/' . literal_name, opened.filename)
395     call assert_equal (['disk one', 'disk two'], getbufline (opened.buffer, 1, '$'))
396     call assert_equal (1, buflisted (opened.buffer))
397     call assert_equal (2, opened.line_count)
398     call assert_equal (0, opened.modified)
399     call assert_equal (getbufvar (opened.buffer, 'changedtick'), opened.changedtick)
400     call assert_equal (caller, bufnr ('%'))
401     call assert_equal (caller_lines, getline (1, '$'))
402     call assert_equal (caller_view, winsaveview ())
403    
404     call setbufline (opened.buffer, 1, 'unsaved edit')
405     call writefile (['external disk edit'], literal_name)
406     let reopened = Open (open_dir . '/' . literal_name)
407     call assert_equal (opened.buffer, reopened.buffer)
408     call assert_equal (['unsaved edit', 'disk two'], getbufline (reopened.buffer, 1, '$'))
409     call assert_equal (1, reopened.modified)
410     call assert_equal (getbufvar (reopened.buffer, 'changedtick'), reopened.changedtick)
411    
412     call writefile (['unloaded'], 'unloaded.txt')
413     let unloaded = bufadd ('unloaded.txt')
414     call assert_equal (0, bufloaded (unloaded))
415     let loaded = Open ('unloaded.txt')
416     call assert_equal (unloaded, loaded.buffer)
417     call assert_equal (1, bufloaded (loaded.buffer))
418     call assert_equal (1, buflisted (loaded.buffer))
419     call assert_equal (['unloaded'], getbufline (loaded.buffer, 1, '$'))
420    
421     let missing = Open ('missing.txt')
422     call assert_equal ([''], getbufline (missing.buffer, 1, '$'))
423     call assert_equal (1, missing.line_count)
424     call assert_equal (0, missing.modified)
425     call assert_equal (0, filereadable ('missing.txt'))
426    
427     let g:open_event_file = open_dir . '/events.txt'
428     call writefile (['disk'], g:open_event_file)
429     augroup MCP_TEST_OPEN
430     autocmd!
431     autocmd BufReadPost * if expand ('<afile>:p') ==# g:open_event_file | call setline (1, 'autocommand edit') | endif
432     augroup END
433     let event_buffer = Open (g:open_event_file)
434     call assert_equal (['autocommand edit'], getbufline (event_buffer.buffer, 1, '$'))
435     call assert_equal (getbufvar (event_buffer.buffer, 'changedtick'), event_buffer.changedtick)
436     call assert_equal (getbufvar (event_buffer.buffer, '&modified'), event_buffer.modified)
437     call assert_equal (caller, bufnr ('%'))
438    
439     set modeline modelines=5
440     call writefile (['text', 'vim: set ts=7:'], 'modeline.txt')
441     let modeline_buffer = Open ('modeline.txt')
442     call assert_equal (7, getbufvar (modeline_buffer.buffer, '&tabstop'))
443    
444     let g:open_event_file = open_dir . '/failure.txt'
445     call writefile (['disk'], g:open_event_file)
446     augroup MCP_TEST_OPEN
447     autocmd!
448     autocmd BufReadPost * if expand ('<afile>:p') ==# g:open_event_file | throw 'deliberate open failure' | endif
449     augroup END
450     let error = ''
451     try
452     call Open (g:open_event_file)
453     catch
454     let error = v:exception
455     endtry
456     call assert_match ('deliberate open failure', error)
457     call assert_equal (caller, bufnr ('%'))
458     augroup MCP_TEST_OPEN
459     autocmd!
460     augroup END
461 root 1.4
462     " The temporary patch files and stdin are UTF-8 even with a Latin-1 Vim.
463     let Patch = function ('<SNR>' . sid . '_rpc_call_apply_patch')
464     let old_encoding = &encoding
465     set encoding=latin1
466     enew!
467     let old = 'h' . nr2char (0xe4) . 'llo'
468     let new = 'h' . nr2char (0xf6) . 'llo'
469     call setline (1, [old, 'keep' . "\n" . 'NUL'])
470     let tick = b:changedtick
471     let result = Patch (bufnr ('%'), "@@ -1 +1 @@\n-" . old . "\n+" . new . "\n", [0], tick)
472     call assert_equal ([new, 'keep' . "\n" . 'NUL'], getline (1, '$'))
473     call assert_equal (1, result.hunks)
474     call assert_equal (1, &modified)
475    
476     " Simulate an external patch returning a UTF-8 character outside Latin-1.
477     " The conversion must fail without modifying the live buffer.
478     let fake_dir = tempname ()
479     call mkdir (fake_dir)
480     call writefile ([
481     \ '#!/bin/sh',
482     \ 'while [ "$1" != "-o" ]; do shift; done',
483     \ 'printf "\360\237\230\200\n" > "$2"',
484     \ ], fake_dir . '/patch')
485     call setfperm (fake_dir . '/patch', 'rwx------')
486     let old_path = $PATH
487     let $PATH = fake_dir . ':' . old_path
488     let tick = b:changedtick
489     let error = ''
490     try
491     call Patch (bufnr ('%'), "@@ -1 +1 @@\n-" . new . "\n+changed\n", [0], tick)
492     catch
493     let error = v:exception
494     finally
495     let $PATH = old_path
496     call delete (fake_dir, 'rf')
497     endtry
498     call assert_match ('rpc/patch_encoding_failed', error)
499     call assert_equal ([new, 'keep' . "\n" . 'NUL'], getline (1, '$'))
500     call assert_equal (tick, b:changedtick)
501     let &encoding = old_encoding
502    
503 root 1.1 execute 'lcd ' . fnameescape (old_cwd)
504     call delete (open_dir, 'rf')
505     call delete (update_file)
506     call delete (undo_file)
507     call delete (file)
508     call writefile (v:errors, argv (0))
509     qa!
510     VIM
511     close $fh or die "$script: $!";
512     my $errors = "$dir/vim-errors";
513     my $error = Symbol::gensym;
514     my $pid = IPC::Open3::open3 (my $input, my $output, $error,
515     $vim, "-Nu", "NONE", "-i", "NONE", "-n", "-es", "-S", $script, "--", $errors);
516     close $input;
517     local $/;
518     my $stdout = <$output>;
519     my $stderr = <$error>;
520     waitpid $pid, 0;
521     my $status = $?;
522     open $fh, "<", $errors or die "$errors: $!";
523     my $messages = <$fh> // "";
524     close $fh;
525    
526     skip $messages, 2 if !$status && $messages =~ /\ASKIP:/;
527     is $status, 0, "real Vim loads the plugin and exercises unrestricted Ex RPC";
528     diag $stdout, $stderr if $status;
529     is $messages, "", "real Vim captures messages, changes state, propagates errors and retains partial effects";
530     }
531    
532     done_testing;