jqunit

Crates.iojqunit
lib.rsjqunit
version0.1.0-rc
sourcesrc
created_at2024-03-04 21:53:17.954694
updated_at2024-03-04 21:53:17.954694
descriptionA test framework for jq, built on top of libjq.
homepagehttps://github.com/mrwilson/jqunit
repositoryhttps://github.com/mrwilson/jqunit
max_upload_size
id1162305
size26,106
Alex Wilson (mrwilson)

documentation

README

jqunit

Build and Test

A test framework for JQ, written in Rust, on top of libjq.

What is a test?

jqunit views a test as a function starting with should_ in a file ending with _test.jq. The test function fails if it returns an error, and passes if it returns anything else.

def should_pass_test: 1; 

def should_fail_test: error("Fails test");

You can implement your own assert until there is one in the jq standard build.

def assert($description; $assertion):
    if $assertion then . else error("\($description)") end;

Example

Running against Day 11 of my advent-of-code-2021 repository.

$ 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)

Usage

  • --libraries: Space separated list of directories to import when running tests. Analogous to jq's -L
  • --module: Test module to execute. If not present, jqunit will traverse the directory tree and search for files with names matching *_test
Commit count: 0

cargo fmt