views:

66

answers:

2

I'm looking for some tools for testing vim scripts. Either vim scripts that

  • do unit/functional testing, or
  • classes for some other library (eg Python's unittest module) that make it convenient to
    • run vim with parameters that cause it to do some tests on its environment, and
    • determine from the output whether or not a given test passed.

I'm aware of a couple of vim scripts that do unit testing, but they're sort of vaguely documented and may or may not actually be useful:

vim-unit:

  • purports "To provide vim scripts with a simple unit testing framework and tools"
  • first and only version (v0.1) was released in 2004
  • documentation doesn't mention whether or not it works reliably, other than to state that it is "fare [sic] from finished".

unit-test.vim:

  • This one also seems pretty experimental, and may not be particularly reliable.
  • May have been abandoned or back-shelved: last commit was in 2009-11 (> 6 months ago)
  • No tagged revisions have been created (ie no releases)

So information from people who are using one of those two existent modules, and/or links to other, more clearly usable, options, are very welcome.

+1  A: 

I've used vim-unit before. At the very least it means you don't have to write your own AssertEquals and AssertTrue functions. It also has a nice feature that lets you run the current function, if it begins with "Test", by placing the cursor within the function body and typing :call VUAutoRun().

The documentation is a bit iffy and unfinished, but if you have experience with other XUnit testing libraries it won't be unfamiliar to you.

Neither of the script mentioned have ways to check for vim specific features - you can't change buffers and then check expectations on the result - so you will have to write your vimscript in a testable way. For example, pass strings into functions rather than pulling them out of buffers with getline() inside the function itself, return strings instead of using setline(), that sort of thing.

rq
Any support for configuring vim startup? For example, can I specify that only a specific plugin should be loaded?
intuited
Nope, but you can always fake that with --noplugin and -u if it's an issue.
rq
+3  A: 

There is another UT plugin that I'm maintaining.

It is documented, it comes with several examples, and it is also used by my other plugins.

Luc Hermitte
yay documentation! Thanks, I'll check this out. Also noticed that there are a couple of other similar tools listed in the links section there.
intuited