Testament is a testing library for Janet. It takes inspiration Clojure's clojure.test library.
Add the dependency to your info.jdn file:
:dependencies ["https://github.com/pyrmont/testament"]Testament can be used like this:
(use testament)
(deftest one-plus-one
(is (= 2 (+ 1 1)) "1 + 1 = 2"))
(deftest two-plus-two
{:skip-when (= :windows (os/which))
:tags [:arithmetic]}
(is (= 5 (+ 2 2)) "2 + 2 = 5"))
(run-tests!)deftest accepts an optional metadata struct immediately after the test name.
Metadata is retained for tooling, and a :skip-when form is evaluated when
run-tests! considers the test. A truthy result omits the test from the run;
false or nil allows it to run. Skipped tests are recorded in the returned
reports with :skipped? true, but are excluded from test and assertion totals.
When at least one test is skipped, the default summary appends the number of
skipped tests to its second line. The form captures lexical bindings from
where the test is declared. Calling the named test function directly always
runs its body.
A leading struct is metadata only when another form follows it. Consequently,
(deftest response {:status 200}) still has a struct as its sole test body. If
a multi-expression body needs to begin with a struct, wrap the body in do.
Put your tests in the test/ directory within your project and then use a
bundle manager like Jeep:
$ jeep test -ROr if you walk to school through the snow uphill both ways:
$ for f in test/*.janet; do janet "$f" || { rc=$?; break; }; done; (exit ${rc:-0})If you use Jeep, with a file saved to test/example.janet, you should see:
running ./test/example.janet...
-----------------------------------
> Failed: two-plus-two
Assertion: 2 + 2 = 5
Expect (L): 5
Actual (R): 4
===================================
2 tests run containing 2 assertions
1 tests passed, 1 tests failed
===================================
1 of 1 scripts failed:
./test/example.janet
To use Testament in a REPL, set the dynamic variable :testament/repl? to
true:
(setdyn :testament/repl? true)This will (a) stop Testament from exiting your REPL if a test fails, (b) reset
the reports between runs and (c) empty the module/cache to prevent old code
from running.
Documentation for Testament's API is in api.md.
Found a bug? I'd love to know about it. The best way is to report your bug in the Issues section on GitHub.
Testament is licensed under the MIT Licence. See LICENSE for more details.