Using private functions in prerequisites
Clone this wiki locally
Earlier, you saw three ways of using private functions in checkables: referring to them via their var,
expose-testables. Only the first way works when you want use a private function as a prerequisite:
(fact (counter 4) => 8 (provided (#'scratch.core/super-secret-function 4) => 4))
Why don't the other ways work?
expose-testables create new vars in the current namespace. They have the same names as the private vars, and they point at the same function, but they're different objects.
Prerequisites work by temporarily pointing vars at new functions. Therefore, in this code:
(ns scratch.core-tests) (testable-privates scratch.core super-secret-function) (fact (counter 4) => 8 (provided (super-secret-function 4) => 4))
... the prerequisite overrides the test namespace's var (
#'scratch.core-tests/super-secret-function) while leaving the original var pointing to the original function. Since the code for
counter is in the source namespace, its call to
super-secret-function uses the un-overridden var (