testing - 测试 vim 脚本
问题描述
我正在探索测试 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
. 请注意,如果测试失败,断言函数返回 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
推荐阅读
- flutter - 如何在 Flutter 中默认使用不可为空?
- javascript - Javascript Promise 方法中的 resolve 和 reject 是还是一些变量?
- mpi - 在 OpenMPI 中是否可以像 Intel-MPI 一样进行进程固定?
- r - 您如何使用 randomForestSRC 预测生存时间?
- asp.net - Microsoft.AspNet.Web.Optimization - 无需捆绑即可缩小文件
- javascript - Web Scraper 返回 Null 值
- flutter - 如何在颤动中将页面添加到浮动操作按钮
- node.js - 来自 process.env 的测试中的所有自定义变量 mssing
- image - 将 multipart.File 放入 image.Decode 作为参数
- javascript - AVJ 不验证枚举类型