Ответ на сообщение «Re: [BUG] getchar inside normal always returns an escape», 
присланное в 00:06:20 23 сентября 2010, Четверг,
отправитель Benjamin R. Haskell:

> Wrapping your file with:
> 
> redir > TESTmessages
> " contents of test-normalesc.vim
> redir END
> 
> the following seems to do what you want:
> 
> find ./ -maxdepth 1 -name 'TEST*' -delete
> vi -u NONE -N +'so test-normalesc.vim' +'qa!' > TESTstdout 2> TESTstderr
> head -n -0 TEST*

Actually no, since I want to check for contents of a buffer. Better solution is 
to use something like this (better because vim will be opened in a tty):

    #!/usr/bin/python
    # vim: set fileencoding=utf-8
    import pexpect
    vim=pexpect.spawn("vim", ["-c", "Tr3Command tof start"])
    vim.send("A$iii\x1B:call writefile(getline(1, line('$')), 'test', 'b')")
    f=open('test', 'r')
    result=f.read()
    f.close()
    if result!="∭":
        # Test failed

But strace shows lots of EIO errors returned when vim tries to write something 
and I do not want to examine it now. I also failed to quickly write it using 
zsh/zpty module: zpty crashed for unknown reason. Maybe someone knows how to 
write it so that it will work.


Текст сообщения:
> On Wed, 22 Sep 2010, ZyX wrote:
> > Ответ на сообщение «Re: [BUG] getchar inside normal always returns an
> > escape», присланное в 23:09:18 22 сентября 2010, Среда,
> > 
> > отправитель Bram Moolenaar:
> >> I'm not sure this is supposed to work.  ":normal" feeds characters
> >> into Vim, using getchar() is problematic there.
> > 
> > According to the `:help :normal' ``{commands} is executed like it is
> > typed.'' (here is probably a typo: should be ``{commands} are executed
> > like if they were typed'').
> 
> The syntax is okay.  '{commands}' is being treated as a mass noun.
> Something like "The string represented in the summary as {commands}".
> 
> > If this does not work with `getchar()' then it should be mentioned in
> > documentation.
> 
> (no real input -- just commenting that I agree it's an omission.)
> 
> >> The script you give can also be sourced interactively.
> > 
> > What do you mean? I have a List with Lists with two items: user input
> > 
> > and my script output. I want to do something like this:
> >    for [input, output] in tests
> >    
> >        execute 'normal '.input
> >        let result=getline(1, line('$'))
> >        if result!=#output
> >        
> >            throw "test failed"
> >        
> >        endif
> >    
> >    endfor
> > 
> > then tests can be done with `so %' just after they are written and
> > without opening another vim. Without normal command I will have to
> > write some annoying IPC stuff, the most simple suggestion is to write
> > result into file and check its content. If I continue finding such
> > bugs, I will have to write a framework for functional test of vim
> > plugins using something like pexpect, but now it is simpler to omit
> > those tests that cannot be easily written in Vimscript.
> 
> See the thread asking for a testing coördinator ("Looking for test
> coordinator" from Bram starting on July 28)
> 
> http://groups.google.com/group/vim_dev/browse_thread/thread/e5245b45d87a74f
> 0
> 
> Wasn't really resolved.  But the point is that, no, there's no nice way
> to test interactive things at the moment.
> 
> In this particular case, can't you script it by redirecting the messages
> (via :h :redir) and writing them out to a file, and/or capturing
> stdout/stderr?
> 
> Wrapping your file with:
> 
> redir > TESTmessages
> " contents of test-normalesc.vim
> redir END
> 
> the following seems to do what you want:
> 
> find ./ -maxdepth 1 -name 'TEST*' -delete
> vi -u NONE -N +'so test-normalesc.vim' +'qa!' > TESTstdout 2> TESTstderr
> head -n -0 TEST*
> ==> TESTmessages <==
> 
> 27
> 27
> 27
> 27
> 27
> 27
> 27
> 27
> 27
> 27
> 10
> 
> ==> TESTstderr <==
> Vim: Warning: Output is not to a terminal
> 
> ==> TESTstdout <==
> 
> > Текст сообщения:
> >> ZyX wrote:
> >>> In the attached script vim prints sequence of ten `27' (that is
> >>> character number of escape) and a `10', while it is supposed to print
> >>> 
> >>> 99
> >>> 104
> >>> 97
> >>> 114
> >>> 115
> >>> 5
> >>> 
> >>> (this is ASCII values of characters in string `chars' and a number of
> >>> symbols).
> >>> 
> >>> Test command:
> >>>     vim -u NONE -c 'so test-normalesc.vim' -c 'messages' -c 'qa!'
> >> 
> >> I'm not sure this is supposed to work.  ":normal" feeds characters into
> >> Vim, using getchar() is problematic there.
> >> 
> >>> PS: It looks like it is impossible to write tests for vim plugins
> >>> using vimscript, so I will now have to switch to something like
> >>> pexpect or just stop writing them.
> >> 
> >> The script you give can also be sourced interactively.

Attachment: signature.asc
Description: This is a digitally signed message part.

Raspunde prin e-mail lui