clojure-spec

Dave Russell 2022-04-26T14:55:11.060559Z

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. Hill 2022-04-26T15:08:08.829679Z

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) 2022-04-26T15:09:13.403769Z

isn't there a function for this in stest?

Colin P. Hill 2022-04-26T15:09:54.617349Z

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

Alex Miller (Clojure team) 2022-04-26T15:10:40.794669Z

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

Dave Russell 2022-04-26T15:11:02.392499Z

Yep 🙂 instrumented-syms would have been perfect

Dave Russell 2022-04-26T15:11:38.877859Z

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. Hill 2022-04-26T15:12:25.911069Z

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.

Alex Miller (Clojure team) 2022-04-26T15:30:50.113299Z

feel free to file requests at https://ask.clojure.org ...

Dave Russell 2022-04-26T15:39:26.154539Z

Will do -- thanks!