Hegel integration with clojure.test.
Hegel integration with clojure.test.
(capture-reports & body)Evaluates body for clojure.test reports as a side effect. Returns a vector of those reports. In the final test phase, also sends those final reports to the normal clojure.test reporter.
Evaluates body for clojure.test reports as a side effect. Returns a vector of those reports. In the final test phase, also sends those final reports to the normal clojure.test reporter.
(origin reports)Produces an origin string for a set of reports. Hegel is... vague about what the origin should be; you don't want to be too specific or else it will explode the state space. I think just the file and line, perhaps?
Produces an origin string for a set of reports. Hegel is... vague about what the origin should be; you don't want to be *too* specific or else it will explode the state space. I think just the file and line, perhaps?
(pass? reports)Did every clojure.test report pass?
Did every clojure.test report pass?
(with opts bindings & body)Can be embedded within a clojure.test deftest to generate some series of
values and test whether they produce correct results. Takes an options map
for hegel-clj.test/test!*, a binding vector, then a body. Evaluates
body roughly test-cases times, with bindings provided by
hegel-clj.core/let. You can generate more values using hegel-clj.core/draw! or
hegel-clj.core/let, if needed. Make test assertions using clojure.test/is, as
usual. Failing tests will be automatically shrunk and re-run with minimal
examples. Log these examples using note.
For example:
(deftest reverse-test
; Generate roughly a hundred integers of vectors
(with {:test-cases 100, :seed 5}
[xs (gen/vector (g/integer))]
; Print out only the smallest vectors that make this fail
(fprn :xs xs)
; Is sorting the same as reversing? Clearly not, so this will fail,
; likely with a two-element vector of different numbers.
(is (= (sort xs)
(reverse xs)))))
with suppresses clojure.test reporting until the final phase, where it
reports as normal. You can broadly pretend that this is a clojure.test case
where you just happened to guess the right small inputs to reproduce a
failing bug.
Can be embedded within a clojure.test deftest to generate some series of
values and test whether they produce correct results. Takes an options map
for `hegel-clj.test/test!*`, a binding vector, then a body. Evaluates
body roughly `test-cases` times, with bindings provided by
`hegel-clj.core/let`. You can generate more values using `hegel-clj.core/draw!` or
`hegel-clj.core/let`, if needed. Make test assertions using `clojure.test/is`, as
usual. Failing tests will be automatically shrunk and re-run with minimal
examples. Log these examples using `note`.
For example:
(deftest reverse-test
; Generate roughly a hundred integers of vectors
(with {:test-cases 100, :seed 5}
[xs (gen/vector (g/integer))]
; Print out only the smallest vectors that make this fail
(fprn :xs xs)
; Is sorting the same as reversing? Clearly not, so this will fail,
; likely with a two-element vector of different numbers.
(is (= (sort xs)
(reverse xs)))))
`with` suppresses clojure.test reporting until the final phase, where it
reports as normal. You can broadly pretend that this is a clojure.test case
where you just happened to guess the right small inputs to reproduce a
failing bug.cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |