dilvan
dilvan

Reputation: 2239

How do I set up a clojureScript project to use specs and test the clojure.core functions at runtime?

Clojure 1.9 introduced specs. Functions in the clojure.core library now have specs. How do I set up a clojurescript project to use specs and test the clojure.core functions at runtime?

I used the libraries [org.clojure/test.check "0.10.0-alpha2"] and [org.clojure/spec.alpha "0.1.123"] to install specs and the command instrument. It worked to detect problems in functions that I wrote specs. But it didn't detect problems with clojure.core (for instance, map).

Maybe specs do not work with clojurescript yet.

Upvotes: 3

Views: 272

Answers (1)

Juraj Martinka
Juraj Martinka

Reputation: 4368

This is because there are no specs for clojure.core functions, only specs for a couple of macros - look here: https://github.com/clojure/core.specs.alpha/blob/master/src/main/clojure/clojure/core/specs/alpha.clj#L53

Note, that:

macros are always checked during macro expansion, you do not need to call instrument for macro specs

(https://clojure.org/guides/spec#_macros)

You can write your own specs for core functions and register them as shown here: https://clojure.github.io/clojure/branch-master/clojure.spec-api.html#clojure.spec/fdef

(s/fdef clojure.core/symbol
  :args (s/alt :separate (s/cat :ns string? :n string?)
               :str string?
               :sym symbol?)
  :ret symbol?)

However, be careful with this since you might get into nasty issues if you don't get it right.

Upvotes: 2

Related Questions