1个不稳定版本
0.1.0-rc | 2024年3月4日 |
---|
#280 在 测试
51 每月下载次数
19KB
460 代码行
jqunit
在libjq之上的JQ测试框架,用Rust编写。
什么是测试?
jqunit
将测试视为以 should_
开头的函数,位于以 _test.jq
结尾的文件中。如果测试函数返回错误,则失败,否则通过。
def should_pass_test: 1;
def should_fail_test: error("Fails test");
你可以在 jq
标准构建中实现自己的 assert
,直到有现成的。
def assert($description; $assertion):
if $assertion then . else error("\($description)") end;
示例
在advent-of-code-2021 仓库的第11天运行。
$ jqunit --libraries ../advent-of-code-2021 ../advent-of-code-2021/* --module day_11_test
test day_11_test::should_parse_input ... ok (5ms)
test day_11_test::should_test_if_any_octopodes_ready_to_flash ... ok (5ms)
test day_11_test::should_get_neighbouring_octopodes ... ok (5ms)
test day_11_test::should_tick ... ok (7ms)
test day_11_test::should_tick_test_input ... ok (5ms)
test day_11_test::should_count_flashes_after_1_tick ... ok (5ms)
test day_11_test::should_count_flashes_after_2_ticks ... ok (12ms)
test day_11_test::should_count_flashes_after_10_ticks ... ok (38ms)
test day_11_test::should_count_flashes_after_100_ticks ... ok (301ms)
test day_11_test::should_find_first_simultaneous_flash ... ok (537ms)
用法
--libraries
:运行测试时导入的目录列表。类似于jq的-L
--module
:要执行的测试模块。如果不存在,jqunit
将遍历目录树并搜索与*_test
匹配的文件名。
依赖
~1.3–9MB
~71K SLoC