Fork me on GitHub

Would it be considered ok to promote s/assert* to good for "public" use (atm the docstring says : "Do not call this directly, use 'assert'.")


in cases where you want the check to always happen no matter the value of check-assert/compile-asserts


or is there a better way? ping @alexmiller


I guess if it would be used that way it could warrant a rename maybe

Andreas Liljeqvist10:01:52

I seem to remember that I could generate with a provided example. Something like (gen/fill-in ::spec {::id "all generated will have this id, other values are generated"})

Andreas Liljeqvist10:01:12

Can't remember what it was called though... anyone?



(s/def ::id string?)
(s/def ::foo (s/keys :req [::id]))
(s/exercise ::foo 2 {::id #(s/gen #{"a" "b"})})
;([{::id "a"} {::id "a"}]
; [{::id "b"} {::id "b"}])


(defn gen
  "... Optionally an overrides map can be provided which
  should map spec names or paths (vectors of keywords) to no-arg
  generator-creating fns. These will be used instead of the generators at those
  names/paths. Note that parent generator (in the spec or overrides
  map) will supersede those of any subtrees. 
parent generator will supersede those of any subtrees part just bit me in the ass harold


but it forces me to keep generators and specs separate, which ends up to be cleaner


I have some function

(defn foo
  {:pre [(s/valid? ::bar a)]}
That asserts if the input conforms to a spec. It works well, but I’m having trouble to debug when it fails, I want to know what input I’m passing that doesnt conform and why.


I just get an AssertionError


@pablore I use s/explain-data instead of s/valid. it returns nil if everything is ok, and a datastructure, if there are any errors.


So you can use it in if or when.


read through this too, may be it'll give you some ideas afaik, specs are replacement of :pre/`:post`-conditions


s/explain works better than I expected! I know of s/fdef but I’m writing a really complex reducing function with lot of if-cases.


(s/check-asserts true)
(s/assert string? :a)
;; clojure.lang.ExceptionInfo: Spec assertion failed
;;    val: :a fails predicate: :clojure.spec.alpha/unknown
note string? and predicate: :clojure.spec.alpha/unknown