how to unit-test vim scripts?

45 views
Skip to first unread message

Javier Rojas

unread,
Dec 4, 2010, 11:43:50 AM12/4/10
to v...@vim.org
Hi all,

Do you vim script authors write tests for your code? how do you do unit
testing for your VimL code?

I ask because I'd like to do it for some of my scripts, but I don't
usually see anything similar being done in other people's scripts.

--
Javier Rojas

GPG Key ID: 0x24E00D68

signature.asc

Tom Link

unread,
Dec 4, 2010, 12:28:32 PM12/4/10
to vim_use
> Do you vim script authors write tests for your code? how do you do unit
> testing for your VimL code?

There are a few plugins around for that. Here are a few links
(incomplete list):

http://groups.google.com/group/vim_dev/browse_frm/thread/2d9463e7b167ce23/ca5ae493f061a8af
http://code.google.com/p/lh-vim/wiki/UT
https://github.com/dsummersl/vimunit
http://www.vim.org/scripts/script.php?script_id=2565
http://www.vim.org/scripts/script.php?script_id=2213
My own: https://github.com/tomtom/spec_vim

My own experience is though that most problems when writing vim
scripts arise from unusual option values. Campbell wrote pluginkiller
that tries to deal with this issue (http://www.vim.org/scripts/
script.php?script_id=1489) but this approach IMHO gets you only so
far.

Regard,
Tom

Steve Losh

unread,
Dec 4, 2010, 12:29:08 PM12/4/10
to vim...@googlegroups.com
On 12/04/10 at 11:43P, Javier Rojas wrote:
> Hi all,
>
> Do you vim script authors write tests for your code? how do you do unit
> testing for your VimL code?

I've added a few tests to my Gundo plugin. I still need to add a lot more, but
looking at Gundo's tests/ directory and tests/README should give you a good
overview of how I'm doing it.

http://bitbucket.org/sjl/gundo.vim/src/tip/tests/

>
> I ask because I'd like to do it for some of my scripts, but I don't
> usually see anything similar being done in other people's scripts.
>
> --
> Javier Rojas
>
> GPG Key ID: 0x24E00D68

--
Steve Losh

Ben Fritz

unread,
Dec 6, 2010, 12:29:02 AM12/6/10
to vim_use


On Dec 4, 10:43 am, Javier Rojas <jeroja...@devnull.li> wrote:
> Hi all,
>
> Do you vim script authors write tests for your code? how do you do unit
> testing for your VimL code?
>
> I ask because I'd like to do it for some of my scripts, but I don't
> usually see anything similar being done in other people's scripts.
>

I wrote a fairly comprehensive test script for the 2html plugin, but
it's not very fancy. Basically I generate script output for almost all
the script option combinations. I have the output files in version
control with Mercurial, so I just look through the changes for each
file to ensure all changes were expected after making script updates.
It's brute-force, but it helps prevent regression, especially due to
weird option combinations.

I had envisioned something better, but it's good enough for the time
being and was quick to implement.

http://code.google.com/p/vim-2html-test/
Reply all
Reply to author
Forward
0 new messages