测试Vim脚本

时间:2019-05-09 04:28:19

标签: testing vim

我正在探索测试vim脚本的选项。我想知道是否需要像Vader这样的工具,或者是否可以在命令行中使用vim滚动自己的工具。

我正在使用Perl(但可以是任何语言),我可以这样做:

`$path_to_vi -c "normal iLink" -c "normal \r" -c wq ~/vimwiki/output.md`;

然后我可以通过适当的测试来检查output.md的内容。

感谢任何提示和建议。

1 个答案:

答案 0 :(得分:2)

您可以使用内置功能(例如:h assert_true())来测试脚本。每次调用断言函数时,如果失败,则会将新的错误消息添加到v:error,请检查:h assert-return。请注意,如果测试失败,则assert函数将返回1,而不是0。

断言家庭

assert_beeps
assert_equal
assert_equalfile
assert_exception
assert_fails
assert_false
assert_inrange
assert_match
assert_notequal
assert_notmatch
assert_report
assert_true

我使用两种样式的测试:

运行所有测试用例,然后逐个报告错误

" clear errors
let v:errors = []

call assert_true(...)
call assert_equal(...)
call assert_match(...)
...
echohl WarningMsg
for err in v:errors
  echo err
endfor
echohl None

逐个运行案例,如果测试失败,立即停止

if(assert_true(...)) | throw v:errors[-1] | endif
if(assert_equal(...)) | throw v:errors[-1] | endif
if(assert_match(...)) | throw v:errors[-1] | endif