Adapts Expectations v2 (https://github.com/clojure-expectations/clojure-test) to Lazytest.
Adapts Expectations v2 (https://github.com/clojure-expectations/clojure-test) to Lazytest.
(=? e a msg)(=? e a form' msg)Internal fuzzy-equality test (clojure.test/assert-expr).
Internal fuzzy-equality test (clojure.test/assert-expr).
(expect a)(expect e a)(expect e a msg)(expect e a msg ex? e')Translate Expectations DSL to lazytest language.
These are approximate translations for the most basic forms:
(expect actual) => (is actual)
(expect expected actual) => (is (= expected actual))
(expect predicate actual) => (is (predicate actual))
(expect regex actual) => (is (re-find regex actual))
(expect ClassName actual) => (is (instance? ClassName actual))
(expect ExceptionType actual) => (is (thrown? ExceptionType actual))
(expect spec actual) => (is (s/valid? spec actual))
An optional third argument can be provided: a message to be included in the output if the test fails.
In addition, actual can be (from-each [x coll] (computation-of x))
or (in set-of-results) or (in larger-hash-map).
Also, expect can be one of (more predicate1 .. predicateN),
(more-> exp1 expr1 .. expN exprN) where actual is threaded through
each expression exprX and checked with the expected value expX,
or (more-of binding exp1 val1 .. expN valN) where actual is
destructured using the binding and then each expected value expX
is used to check each valX -- expressions based on symbols in the
binding.
Translate Expectations DSL to `lazytest` language. These are approximate translations for the most basic forms: `(expect actual)` => `(is actual)` `(expect expected actual)` => `(is (= expected actual))` `(expect predicate actual)` => `(is (predicate actual))` `(expect regex actual)` => `(is (re-find regex actual))` `(expect ClassName actual)` => `(is (instance? ClassName actual))` `(expect ExceptionType actual)` => `(is (thrown? ExceptionType actual))` `(expect spec actual)` => `(is (s/valid? spec actual))` An optional third argument can be provided: a message to be included in the output if the test fails. In addition, `actual` can be `(from-each [x coll] (computation-of x))` or `(in set-of-results)` or `(in larger-hash-map)`. Also, `expect` can be one of `(more predicate1 .. predicateN)`, `(more-> exp1 expr1 .. expN exprN)` where `actual` is threaded through each expression `exprX` and checked with the expected value `expX`, or `(more-of binding exp1 val1 .. expN valN)` where `actual` is destructured using the `binding` and then each expected value `expX` is used to check each `valX` -- expressions based on symbols in the `binding`.
(from-each bindings & body)(expect expected (from-each [v coll] (f v))) -- expect this to be true
for each element of collection. (f v) is the actual result.
Equivalent to: (doseq [v coll] (expect expected (f v)))
(expect even? (from-each [v (range 10)] (* 2 v)))
from-each may only be used inside expect and is a purely syntactic construct.
This macro can be refer'd to satisfy tooling like clj-kondo.
`(expect expected (from-each [v coll] (f v)))` -- expect this to be true for each element of collection. `(f v)` is the actual result. Equivalent to: `(doseq [v coll] (expect expected (f v)))` `(expect even? (from-each [v (range 10)] (* 2 v)))` `from-each` may only be used inside `expect` and is a purely syntactic construct. This macro can be `refer`'d to satisfy tooling like `clj-kondo`.
If Humane Test Output is available, activate it, and enable compatibility
of our =? with it.
This Var will be true if Humane Test Output is available and activated,
otherwise it will be nil.
If Humane Test Output is available, activate it, and enable compatibility of our `=?` with it. This Var will be `true` if Humane Test Output is available and activated, otherwise it will be `nil`.
(in coll)(expect expected (in actual)) -- expect a subset of a collection.
If actual is a hash map, expected can be a hash map of key/value pairs
that you expect to be in the actual result (there may be other key/value
pairs, which are ignored).
If actual is a set, vector, or list, expected can be any value that
you expect to be a member of the actual data.
(expect {:b 2} (in {:a 1 :b 2 :c 3}))
(expect 2 (in #{1 2 3}))
(expect 2 (in [1 2 3]))
in may only be used inside expect and is a purely syntactic construct.
This macro can be refer'd to satisfy tooling like clj-kondo.
`(expect expected (in actual))` -- expect a subset of a collection.
If `actual` is a hash map, `expected` can be a hash map of key/value pairs
that you expect to be in the `actual` result (there may be other key/value
pairs, which are ignored).
If `actual` is a set, vector, or list, `expected` can be any value that
you expect to be a member of the `actual` data.
`(expect {:b 2} (in {:a 1 :b 2 :c 3}))`
`(expect 2 (in #{1 2 3}))`
`(expect 2 (in [1 2 3]))`
`in` may only be used inside `expect` and is a purely syntactic construct.
This macro can be `refer`'d to satisfy tooling like `clj-kondo`.(more & expecteds)(expect (more expected1 ...) actual) -- provide multiple expectations
on actual as a series of expected results.
Equivalent to: (do (expect expected1 actual) ...)
(expect (more int? even?) 42)
more may only be used inside expect and is a purely syntactic construct.
This macro can be refer'd to satisfy tooling like clj-kondo.
`(expect (more expected1 ...) actual)` -- provide multiple expectations on `actual` as a series of expected results. Equivalent to: `(do (expect expected1 actual) ...)` `(expect (more int? even?) 42)` `more` may only be used inside `expect` and is a purely syntactic construct. This macro can be `refer`'d to satisfy tooling like `clj-kondo`.
(more-> & expected-threaded-pairs)(expect (more-> expected1 (threaded1) ...) actual) -- provide multiple
expectations on actual based on threading it into various expressions.
Equivalent to: (do (expect expected1 (-> actual (threaded1))) ...)
(expect (more-> string? (first) int? (second)) ["test" 42])
more-> may only be used inside expect and is a purely syntactic construct.
This macro can be refer'd to satisfy tooling like clj-kondo.
`(expect (more-> expected1 (threaded1) ...) actual)` -- provide multiple expectations on `actual` based on threading it into various expressions. Equivalent to: `(do (expect expected1 (-> actual (threaded1))) ...)` `(expect (more-> string? (first) int? (second)) ["test" 42])` `more->` may only be used inside `expect` and is a purely syntactic construct. This macro can be `refer`'d to satisfy tooling like `clj-kondo`.
(more-of destructuring & expected-actual-pairs)(expect (more-of destructuring expected1 actual1 ...) actual) -- provide
multiple expectations on actual based on binding it against the
destructuring expression (like in a let) and then expecting things about
its subcomponents.
Equivalent to: (let [destructuring actual] (expect expected1 actual1) ...)
(expect (more-of [a b] string? a int? b) ["test" 42])
more-of may only be used inside expect and is a purely syntactic construct.
This macro can be refer'd to satisfy tooling like clj-kondo.
`(expect (more-of destructuring expected1 actual1 ...) actual)` -- provide multiple expectations on `actual` based on binding it against the `destructuring` expression (like in a `let`) and then expecting things about its subcomponents. Equivalent to: `(let [destructuring actual] (expect expected1 actual1) ...)` `(expect (more-of [a b] string? a int? b) ["test" 42])` `more-of` may only be used inside `expect` and is a purely syntactic construct. This macro can be `refer`'d to satisfy tooling like `clj-kondo`.
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 |