This namespace provides compatibility with clojure.test
and related tooling.
This namespace should be used standalone, without requiring the 'expectations'
namespace -- this provides a translation layer from Expectations syntax down
to clojure.test
functionality.
This namespace provides compatibility with `clojure.test` and related tooling. This namespace should be used standalone, without requiring the 'expectations' namespace -- this provides a translation layer from Expectations syntax down to `clojure.test` functionality.
(=? expected actual & [form])
Internal fuzzy-equality test (clojure.test/assert-expr).
Internal fuzzy-equality test (clojure.test/assert-expr).
(approximately v)
(approximately v d)
Given a value and an optional delta (default 0.001), return a predicate that expects its argument to be within that delta of the given value.
Given a value and an optional delta (default 0.001), return a predicate that expects its argument to be within that delta of the given value.
(between a b)
Given a pair of (numeric) values, return a predicate that expects its argument to be be those values or between them -- inclusively.
Given a pair of (numeric) values, return a predicate that expects its argument to be be those values or between them -- inclusively.
(between' a b)
Given a pair of (numeric) values, return a predicate that expects its argument to be (strictly) between those values -- exclusively.
Given a pair of (numeric) values, return a predicate that expects its argument to be (strictly) between those values -- exclusively.
(defexpect n & body)
Given a name (a symbol that may include metadata) and a test body,
produce a standard clojure.test
test var (using deftest
).
Given a name (a symbol that may include metadata) and a test body, produce a standard `clojure.test` test var (using `deftest`).
(expect a)
(expect e a)
(expect e a msg)
(expect e a msg ex? e')
Translate Expectations DSL to clojure.test
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 `clojure.test` 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`.
(expecting string & body)
The Expectations version of clojure.test/testing
.
The Expectations version of `clojure.test/testing`.
(from-clojure-test f)
Intern the specified symbol from clojure.test
as a symbol in
expectations.clojure.test
with the same value and metadata.
Intern the specified symbol from `clojure.test` as a symbol in `expectations.clojure.test` with the same value and metadata.
(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`.
(functionally expected-fn actual-fn)
(functionally expected-fn actual-fn difference-fn)
Given a pair of functions, return a custom predicate that checks that they return the same result when applied to a value. May optionally accept a 'difference' function that should accept the result of each function and return a string explaininhg how they actually differ. For explaining strings, you could use expectations/strings-difference. (only when I port it across!)
Right now this produces pretty awful failure messages. FIXME!
Given a pair of functions, return a custom predicate that checks that they return the same result when applied to a value. May optionally accept a 'difference' function that should accept the result of each function and return a string explaininhg how they actually differ. For explaining strings, you could use expectations/strings-difference. (only when I port it across!) Right now this produces pretty awful failure messages. FIXME!
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`.
(run-all-tests)
(run-all-tests re)
Runs all tests in all namespaces; prints results. Optional argument is a regular expression; only namespaces with names matching the regular expression (with re-matches) will be tested.
Imported from clojure.test.
Runs all tests in all namespaces; prints results. Optional argument is a regular expression; only namespaces with names matching the regular expression (with re-matches) will be tested. Imported from clojure.test.
(run-tests)
(run-tests & namespaces)
Runs all tests in the given namespaces; prints results. Defaults to current namespace if none given. Returns a map summarizing test results.
Imported from clojure.test.
Runs all tests in the given namespaces; prints results. Defaults to current namespace if none given. Returns a map summarizing test results. Imported from clojure.test.
(side-effects fn-vec & forms)
Given a vector of functions to track calls to, execute the body.
Returns a vector of each set of arguments used in calls to those
functions. The specified functions will not actually be called:
only their arguments will be tracked. If you need the call to return
a specific value, the function can be given as a pair of its name
and the value you want its call(s) to return. Functions given just
by name will return nil
.
Given a vector of functions to track calls to, execute the body. Returns a vector of each set of arguments used in calls to those functions. The specified functions will not actually be called: only their arguments will be tracked. If you need the call to return a specific value, the function can be given as a pair of its name and the value you want its call(s) to return. Functions given just by name will return `nil`.
(test-all-vars ns)
Calls test-vars on every var interned in the namespace, with fixtures.
Imported from clojure.test.
Calls test-vars on every var interned in the namespace, with fixtures. Imported from clojure.test.
(test-ns ns)
If the namespace defines a function named test-ns-hook, calls that. Otherwise, calls test-all-vars on the namespace. 'ns' is a namespace object or a symbol.
Internally binds report-counters to a ref initialized to initial-report-counters. Returns the final, dereferenced state of report-counters.
Imported from clojure.test.
If the namespace defines a function named test-ns-hook, calls that. Otherwise, calls test-all-vars on the namespace. 'ns' is a namespace object or a symbol. Internally binds *report-counters* to a ref initialized to *initial-report-counters*. Returns the final, dereferenced state of *report-counters*. Imported from clojure.test.
(test-var v)
If v has a function in its :test metadata, calls that function, with testing-vars bound to (conj testing-vars v).
Imported from clojure.test.
If v has a function in its :test metadata, calls that function, with *testing-vars* bound to (conj *testing-vars* v). Imported from clojure.test.
(test-vars vars)
Groups vars by their namespace and runs test-vars on them with appropriate fixtures applied.
Imported from clojure.test.
Groups vars by their namespace and runs test-vars on them with appropriate fixtures applied. Imported from clojure.test.
(use-fixtures fixture-type & fs)
Wrap test runs in a fixture function to perform setup and
teardown. Using a fixture-type of :each
wraps every test
individually, while :once
wraps the whole run in a single function.
Like cljs.test/use-fixtures
, also accepts hash maps with :before
and/or :after
keys that specify 0-arity functions to invoke
before/after the test/run.
Wrap test runs in a fixture function to perform setup and teardown. Using a fixture-type of `:each` wraps every test individually, while `:once` wraps the whole run in a single function. Like `cljs.test/use-fixtures`, also accepts hash maps with `:before` and/or `:after` keys that specify 0-arity functions to invoke before/after the test/run.
(with-test definition & body)
Takes any definition form (that returns a Var) as the first argument. Remaining body goes in the :test metadata function for that Var.
When load-tests is false, only evaluates the definition, ignoring the tests.
Imported from clojure.test.
Takes any definition form (that returns a Var) as the first argument. Remaining body goes in the :test metadata function for that Var. When *load-tests* is false, only evaluates the definition, ignoring the tests. Imported from clojure.test.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close