wedge.core

Function call verification for use with clojure.test

call-count

macro

(call-count fn-counter search-args)
Counts the number of times a fn has been called within a with-wedge binding for a certain set of arguments to the fn.

Example:

;; assume the fn (defn foo [a b] ...) and the following code is inside a (with-wedge [foo foo-counter] ...) binding

(call-count foo-counter [1 2]) ;; counts the number of times (foo 1 2) was called
(call-count foo-counter [? 2]) ;; counts the number of times foo was called with 2 for the 'b' parameter. (foo 1 2) and (foo 2 2) would both match
(call-count foo-counter [? ?]) ;; counts the number of times foo was called
(call-count foo-counter [1 [? #(< 1 %)]]) ;; counts the number of times foo was called with the 'b' parameter value greater than 1. (foo 1 2) would match but
                                             (foo 1 1) would not

fn-counter  - the counter which tracks the number of times a specific fn is called while within a with-wedge binding
search-args - a vector of arguments matching the fn calls which should be counted. The parameters to the vector can either be the literal values used to call the fn,
              the special form '?' to mean 'all argument values', or the special form '[? predicate]', where predicate is a fn which takes one argument and returns
              a true or false value indicating if that argument should be included in the fn calls counted.

called?

(called? fn-counter)
Tests that a fn is called at all, for any set of parameters. Returns true if the fn is called inside the with-wedge binding, and false otherwise

fn-counter - the counter which tracks the number of times a specific fn is called while within a with-wedge binding

total-calls

(total-calls fn-counter)
Counts all calls to the fn, regardless of the arguments passed to it

fn-counter - the counter which tracks the number of times a specific fn is called while within a with-wedge binding

with-wedge

macro

(with-wedge bindings & body)
Defines a set of bindings to track the number of times a fn is called within the body of with-wedge. Redefs the fns to a shim fn which calls the original fn, counts
the call to the fn, and records with what arguments the fn was called. More than one fn can be tracked at a time within the body of with-wedge. Use wedge.core/call-count
or one of its derrivative fns/macros to count the number of times a fn was called within the body of with-wedge.

Example:

;; assume the fn (defn foo [a b] ...) and (bar [c d] ...)

(deftest foo-tests
  (with-wedge [foo foo-counter bar bar-counter]
    (is (zero? (count-call foo-counter [? ?])))
    ;; etc
  ))

bindings - a vector defining a relationship between a fn which should be tracked and an object which will track the calls to the fn. There must be an even number of symbols in
           the binding vector. The first symbol in the binding vector must be the name of a fn to track calls to, the second symbol in the vector must be a name for the object
           to track the calls to the fn.
body     - the body of the test