我正在探索测试 vim 脚本的选项。我想知道我是否需要像 Vader 这样的工具,或者我是否可以从命令行使用 vim 来滚动我自己的工具。
我正在使用 Perl(但它可以是任何语言),我可以这样做:
`$path_to_vi -c "normal iLink" -c "normal \r" -c wq ~/vimwiki/output.md`;
然后我可以通过适当的测试检查 output.md
的内容。
感谢任何提示和建议。
最佳答案
您可以使用内置函数,例如 :h assert_true()
来测试脚本。每次调用 assert 函数时,都会在 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
一个个运行case,测试失败立即停止
if(assert_true(...)) | throw v:errors[-1] | endif
if(assert_equal(...)) | throw v:errors[-1] | endif
if(assert_match(...)) | throw v:errors[-1] | endif
关于测试 vim 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56052213/