Fork me on GitHub
#clojure-spec
<
2022-04-26
>
Dave Russell14:04:11

Hello! Is there a good way to find all currently instrumented vars? It looks like (st/unstrument) will return anything that has been unstrumented, so that's a way to tell (sort-of), but for our use-case we'd like to: • Preserve current instrumentation state • Instrument all vars • Do something • Restore previous instrumentation state Which allows us to enable instrumentation when, e.g., running tests but keeping any instrumentation state in the REPL

Colin P. Hill15:04:08

Looks like no, unless you want to access a private var and risk breakage later. The instrumented vars are kept in a global atom. https://github.com/clojure/spec.alpha/blob/f23ea614b3cb658cff0044a027cacdd76831edcf/src/main/clojure/clojure/spec/test/alpha.clj#L150

Alex Miller (Clojure team)15:04:13

isn't there a function for this in stest?

Colin P. Hill15:04:54

Doesn't appear to be. There's one that does the opposite though, turning off instrumentation within a dynamic scope.

Alex Miller (Clojure team)15:04:40

There's instrumentable-syms and checkable-syms but I guess not instrumented-syms

Dave Russell15:04:02

Yep 🙂 instrumented-syms would have been perfect

Dave Russell15:04:38

Right now we basically have:

(let [currently-instrumented-vars (st/unstrument)]
   (set/difference (set (st/instrument)) (set currently-instrumented-vars)))
As a way to figure out what syms we should restore

Colin P. Hill15:04:25

A with-instrument-enabled macro parallel to the with-instrument-disabled would have been pretty slick, to let this be done in a call scope rather than with global state changes.

Dave Russell15:04:26

Will do -- thanks!