用于测试 vim 插件的工具
我正在寻找一些用于测试 vim 脚本的工具。 的 vim 脚本
- 执行单元/功能测试
- ,或其他库的类(例如 Python 的 unittest 模块),方便
- 使用参数运行 vim,使其对其环境进行一些测试,并且
- 根据输出确定给定测试是否通过。
我知道有几个进行单元测试的 vim 脚本,但它们的记录有点模糊,实际上可能有用,也可能没有用:
- 旨在“为 vim 脚本提供简单的单元测试框架和工具”,
- 第一个也是唯一的版本 (v0.1) 于 2004 年发布
- 文档没有提及它是否可靠地工作,只是说它是“从完成开始的票价[原文如此]”。
- 这个看起来也相当实验性,可能不是特别可靠。
- 可能已被放弃或后搁置:最后一次提交是在 2009-11(> 6 个月前)
- 没有创建标记的修订(即没有发布)
因此来自使用这两个现有模块之一的人员的信息,和/或链接到其他更清晰可用的选项,非常受欢迎。
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:
- 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".
- 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
vader.vim 非常简单,而且令人惊叹。它没有外部依赖(不需要 ruby/rake),它是一个纯粹的 vimscript 插件。这是一个完全指定的测试:
如果您打开了测试文件,则可以像这样运行它:
或者您可以指向文件路径:
vader.vim is easy, and amazing. It has no external dependencies (doesn't require ruby/rake), it's a pure vimscript plugin. Here's a fully specified test:
If you have the test file open, you can run it like this:
Or you can point to the file path:
我已经成功地将 Andrew Radev 的 Vimrunner 与 RSpec 用于测试 Vim 插件并将其设置在持续集成服务器上。
简而言之,Vimrunner 使用 Vim 的客户端-服务器功能来启动 Vim 服务器,然后发送远程命令,以便您可以检查(并验证)结果。它是 Ruby gem,因此您至少需要熟悉 Ruby,但如果您投入时间,那么您将获得 RSpec 的全部功能来编写测试。
例如,一个名为
spec/runspec.vim_spec.rb
的文件:我在 “使用 RSpec 和 Vimrunner 在 Travis CI 上测试 Vim 插件” 如果您想了解更多详细信息。
I've had success using Andrew Radev's Vimrunner in conjunction with RSpec to both test Vim plugins and set them up on a continuous integration server.
In brief, Vimrunner uses Vim's client-server functionality to fire up a Vim server and then send remote commands so that you can inspect (and verify) the outcome. It's a Ruby gem so you'll need at least some familiarity with Ruby but if you put the time in then you get the full power of RSpec in order to write your tests.
For example, a file called
spec/runspec.vim_spec.rb
:I've written about it at length in "Testing Vim Plugins on Travis CI with RSpec and Vimrunner" if you want more detail.
我正在维护另一个(纯 Vimscript)UT 插件。
它有文档记录,附带几个示例,并且我的其他插件也使用它。
它的目的是测试函数结果和缓冲区内容,并在快速修复窗口中显示故障。异常调用堆栈也被解码。 AFAIK,这是迄今为止唯一一个(或至少是第一个)旨在填充快速修复窗口的插件。从那时起,我添加了帮助程序脚本来使用 rspec (+Vimrunner) 生成测试结果。
自 v2.0(2020 年 5 月)以来,该插件还可以测试缓冲区内容 - 在使用映射/片段/...进行更改后。直到那时我一直在使用其他插件。例如,我曾经使用 VimRunner+RSpec 在 travis 上测试我的 C++ 片段(来自 lh-cpp)。
关于语法,例如,
将产生以下内容:
或者,如果我们想要测试缓冲区内容
,其结果为
(在快速修复窗口中点击
D
将在 diff 模式下打开生成的结果以及预期结果)一个新标签)There is another (pure Vimscript) UT plugin that I'm maintaining.
It is documented, it comes with several examples, and it is also used by my other plugins.
It aims at testing function results and buffer contents, and displaying the failures in the quickfix window. Exception callstacks are also decoded. AFAIK, it's the only plugin so far (or at least the first) that's meant to fill the quickfix window. Since then, I've added helper scripts to produce test results with rspec (+Vimrunner)
Since v2.0 (May 2020), the plugin can also test buffer content -- after it has been altered with mappings/snippets/.... Up until then I've been using other plugins. For instance, I used to test my C++ snippets (from lh-cpp) on travis with VimRunner+RSpec.
Regarding the syntax, for instance the following
would produce:
Or, if we want to test buffer contents
which results into
(hitting
D
in the quickfix window will open the produced result alongside the expected result in diff mode in a new tab)我以前用过
vim-unit
。至少,这意味着您不必编写自己的AssertEquals
和AssertTrue
函数。它还有一个很好的功能,可以让您运行当前函数(如果该函数以“Test”开头),方法是将光标放在函数体内并键入:call VUAutoRun()
。该文档有点不确定且未完成,但如果您有使用其他 XUnit 测试库的经验,它对您来说不会陌生。
提到的两个脚本都没有方法来检查 vim 特定功能 - 您无法更改缓冲区,然后检查结果的预期 - 因此您必须以可测试的方式编写 vim 脚本。例如,将字符串传递到函数中,而不是使用函数本身内的 getline() 来将它们从缓冲区中取出,返回字符串而不是使用 setline() 之类的事情。
I've used
vim-unit
before. At the very least it means you don't have to write your ownAssertEquals
andAssertTrue
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 usingsetline()
, that sort of thing.有 vim-vspec。
您的测试是用 vimscript 编写的,您可以使用 BDD 风格编写它们(描述、它、期望……)
。GitHub 提供了视频和文章的链接,可帮助您入门:
There is vim-vspec.
Your tests are written in vimscript and you can write them using a BDD-style (describe, it, expect, ...)
The GitHub has links to a video and an article to get you started:
对于功能测试,有一个名为 vroom 的工具。它有一些限制,可能需要几秒到几分钟的时间才能完成对大型项目的彻底测试,但它具有很好的文字测试/文档格式,并具有 vim 语法突出显示支持。
它用于测试 codefmt 插件和一些类似的项目。您可以查看 vroom/ dir 那里的示例。
For functional testing, there's a tool called vroom. It has some limitations and can take seconds-to-minutes to get through thorough tests for a good size project, but it has a nice literate testing / documentation format with vim syntax highlighting support.
It's used to test the codefmt plugin and a few similar projects. You can check out the vroom/ dir there for examples.
另外几个候选者:
VimBot - 与 VimRunner 类似,它是用 Ruby 编写的,允许您控制 vim 实例远程。旨在与单元测试框架 RSpec 一起使用。
VimDriver - 与 VimBot 相同,只是使用 Python 而不是 Ruby 完成(作为 VimBot 的直接端口启动),因此您如果您更熟悉Python的单元测试框架,可以使用它。
Another few candidates:
VimBot - Similar to VimRunner in that it's written in Ruby and allows you to control a vim instance remotely. Is built to be used with the unit testing framework RSpec.
VimDriver - Same as VimBot except done in Python instead of Ruby (started as a direct port from VimBot) so you can use Python's unit testing framework if you're more familiar with that.