简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM