This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-05-28
Channels
- # admin-announcements (1)
- # beginners (33)
- # boot (35)
- # braveandtrue (1)
- # cider (6)
- # cljs-dev (59)
- # cljsrn (24)
- # clojure (44)
- # clojure-austin (3)
- # clojure-china (1)
- # clojure-russia (13)
- # clojure-spec (63)
- # clojurescript (71)
- # community-development (1)
- # core-async (2)
- # cursive (6)
- # datomic (1)
- # editors-rus (2)
- # emacs (3)
- # hoplon (47)
- # jobs-discuss (3)
- # keechma (1)
- # lein-figwheel (2)
- # om (38)
- # om-next (4)
- # onyx (2)
- # other-languages (63)
- # parinfer (3)
- # planck (4)
- # re-frame (3)
- # reagent (2)
- # slack-help (4)
- # specter (26)
- # tmp-json-parsing (7)
- # uncomplicate (66)
- # yada (7)
@alexmiller: You mentioned you have a spec for spec. Any interest in showing that? It would help with adding support in Cursive.
It's almost certainly pretty buggy so it's not something I really want to publish yet
I have turned on instrumentation with it and had it actually find bugs while I was working though :)
Yeah, I’m planning to merge in the validation code I demoed at the conj, having real-time validation in Cursive for specs would be nice.
I can send it to you privately if you want
And using specs to help with completion is probably nice too, although I need to work with it more to see what’s possible.
@sekao: yep although you don't even need the s/cat there just '(s/* string?)' would be sufficient
how could I write a spec for, say, clojure.core/conj
that enforces that in (conj coll x)
x
satisfies the same spec as the elements of coll
? Is this kind of reasoning within the intended scope of clojure.spec
?
That's not a true constraint of conj :)
But you could spec something like that with the :fn spec in fdef which relates the args and ret
It's passed a map with the conformed value of both
A bit more feedback. I constantly run into errors like this:
In: [0] val: ([{:name "age", :type :int, :null false}]) fails at: [:args] predicate: (cat :cols :de.sveri.clospcrud.schema/columns), Extra input
:clojure.spec/args ([{:name "age", :type :int, :null false}])
clojure.core/ex-info (core.clj:4617)
Most of the times the problem was that I was missing a (s/spec ::columns)
expression around the spec definition. Still, everytime I see this error it is so far away from what the problem actually is, that I need time to remember this.
Worse is, that at first I look and search if I did something wrong while transforming my schema to spec.
Maybe a somewhat better error message is possible?Not sure what a generically better error would be
Interesting - file a jira if you want so we don't lose it over the weekend
@alexmiller: For me it would be something like: "Maybe you forgot a spec around a regex? Try (s/spec ...)" But, I dont know how generic that error is and if it would fit everytime?
is there a way to exclude certain vars from being tested by run-all-tests
? i have some side-effecting functions that will cause some havoc if run in generative tests 😃
I’m not entirely clear on when generative testing happens. In some cases (side-effects), I’d like the ability to check conform but not do generative testing
for now i copied the code into my project and added an if
statement that checks for :no-check
in the var’s metadata
@arohner: My understanding is that generative testing only happens if you invoke run-all-tests
. If you just wanted to test specific functions in your test suite, you could do something like:
(deftest test-my-function
(is (= true (:result (t/check-var #’my-function)))))
repl> (defn foo [fnn] (fnn 42))
#'repl/foo
repl> (s/fdef foo :args (s/cat :f (s/fspec :args (s/cat :i integer?)
:ret integer?)))
repl/foo
repl> (s/instrument 'foo)
#'repl/foo
repl> (foo #(when (even? %) 42))
ExceptionInfo Call to #'repl/foo did not conform to spec:
In: [0] val: nil fails at: [:args :f :ret] predicate: integer?
:clojure.spec/args (#object[repl$eval66335$fn__66336 0x55f2e735 "repl$eval66335$fn__66336@55f2e735"])
clojure.core/ex-info (core.clj:4617)
I may be misunderstanding, but I don't think it did. I think it just checked that the spec matched the invocation: (foo #(when (even? %) 42))
(s/unstrument 'foo)
#'repl/foo
repl> (foo #(do (println %) (when (even? %) 42)))
42
42
Hm, yeah, you're right, I was reading that wrong. I still don't think (from playing with other examples) that the generative testing occurs unless you do one of the testing calls. I think this example might just have a bug. I could be misunderstanding though.
(I'm trying to try it myself, but on my version of clojure, the fdef
is not working for some reason)
@arohner: Yep, you're correct - there was no testing call, but it's doing some generation for the args for the inner function.
@arohner: interestingly, that does not seem to occur in all cases:
(s/fdef double
:args (s/cat :x integer?)
:ret integer?)
(defn double [x]
(if (zero? x)
"zero"
(* 2 x)))
(s/instrument 'double)
(double 1)
ah, yes, the docs do mention that now that I read them a little more carefully 😄 . Well, TIL
Also, FWIW, that example won't quite work on 1.9.0-alpha3. fspec
seems to require a ret
now
nvm, i realized it was a copy/paste fail on my part (didn't grab the full fspec above)
Hi, did anyone try to generate a boolean spec? Like this: (s/def ::required #(instance? Boolean %))
. Calling (gen/sample (s/gen ::required))
fails for me with: Exception Unable to construct gen...
.
This becomes problematic if ::required is part of a nested spec, how would I provide a generator for that?
That specific case is covered in the (updated) documentation @sveri
@seancorfield: Ah, thats nice, I just solved it by defining boolean as true / false: (s/def ::boolean #{true false})
for which the generator works too
"There are some common cases that currently don’t have standard predicates, but good generators exist. It’s likely there will be changes in this area in the future but for now you might find these useful: (defn boolean? [x] (instance? Boolean x)) (s/def ::boolean (s/with-gen boolean? #(gen/boolean))) (defn uuid? [x] (instance? java.util.UUID x)) (s/def ::uuid (s/with-gen uuid? #(gen/uuid)))"
(That didn't paste well -- sorry, on my phone)
Why is (doc subs)
printing Spec
on the last line. Bug?
user=> (doc subs)
-------------------------
clojure.core/subs
([s start] [s start end])
Returns the substring of s beginning at start inclusive, and ending
at end (defaults to length of string), exclusive.
Spec
nil