This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-24
Channels
- # adventofcode (13)
- # beginners (163)
- # boot (8)
- # cider (1)
- # clojure (86)
- # clojure-germany (1)
- # clojure-italy (2)
- # clojure-spec (66)
- # clojure-switzerland (1)
- # clojure-uk (25)
- # clojured (1)
- # clojurescript (58)
- # core-async (1)
- # cursive (4)
- # datomic (11)
- # events (1)
- # funcool (3)
- # hoplon (86)
- # off-topic (8)
- # om (11)
- # onyx (1)
- # protorepl (7)
- # re-frame (15)
- # ring-swagger (4)
i still can't figure out how to specify a list of possible s/def
s to pass to :args
and :ret
π i keep getting a "No value supplied for key" error
@hlship see http://dev.clojure.org/jira/browse/CLJ-1941 -- known places where instrument
doesn't work (includes primitive returning fn and protocols)
Protocols are mentioned in the comments.
Can you share the problematic code re: :args
:ret
?
remove the [a b]
s-exp
Then it should work.
As for ::sym
-- it can't be all those things at once -- shouldn't that be s/or
?
and int?
to make it a predicate
wow. i can't believe i even had the guide open and misread speccing functions as taking an argument list
Heh, I've read that thing over and over and I still write nonsense for specs at times π
If your specs are generatable... which yours won't be since you can't generate from instance?
I believe...
Hmm, actually I'd have to try s/exercise
to check whether it only uses the :args
spec
for functions defined in protocols, but dispatched on defrecords not primitives so hopefully it should work
Ah, yes, it must generate data to even pass stuff into :args
...
You'll need to write generators for your rational and complex types I suspect...
What happens if you try (s/exercise ::rational)
?
Right... you need something like this:
(defrecord Foo [a])
(require '[clojure.spec :as s] '[clojure.spec.gen :as gen])
(s/def ::foo (s/with-gen #(instance? Foo %)
(fn [] (gen/fmap ->Foo (s/gen int?)))))
(s/exercise ::foo)
Basically you need to specify a generator that maps your record constructor over a generator for the values it accepts
Yeah, that was my first thought... a very ambitious spec! https://clojurians.slack.com/archives/clojure-spec/p1482548398003597
Making specs generative can be quite the process... we try to do that with all of ours but sometimes it takes... ingenuity...
well i was trying to get it to somehow enumerate tests on the correct output types automatically...
Gary Fredericks has created a good companion library for spec that helps generate all sorts of things BTW (we use it, specifically, for regex generation)
i actually thought since it's so systematic it would be good to learn how to spec a whole project so i could apply it to code where i really can't figure out what's going on
FYI, s/exercise-fn
doesn't check :ret
-- only :args
(defn foo [a b] (+ a b))
(s/fdef foo :args (s/cat :a int? :b int?) :ret string?)
(s/exercise-fn `foo)
doesn't complain that foo
is supposed to return string?
valuesbut it will tell me if any subtyping combinations are throwing errors, which i believe was the case before
I get this error: RuntimeException Var clojure.test.check.generators/keyword-ns is not on the classpath clojure.spec.gen/dynaload (gen.clj:21)
when running this code: (gen/generate (s/gen number?))
in the REPL. Any ideas what I am missing here?
@sveri do you have a test.check dependency declared?
@gfredericks No, I dont think so
you need one to use generators
[org.clojure/test.check "0.9.0"]
what is clojure.spec/Specize
? i'm getting the following error: IllegalArgumentException No implementation of method: :specize* of protocol: #'clojure.spec/Specize found for class: nil
IIRC itβs the protocol by which values are coerced into specs, notably by which keywords resolve themselves in the spec registry
ah, so it does have to do with trying to exercise protocol functions? because i think i may be experiencing this issue, but am having trouble isolating it to be sure: http://dev.clojure.org/jira/browse/CLJ-1941
my case is complicated because the protocol functions i'd like to test all dispatch on records so theoretically should be unaffected. however, i went so granular as to define arguments to their type constructors using s/with-gen
and gen/fmap
. so i can't tell if some of the errors are actually what i'm looking for, known subtyping bugs, because i'm not sure if the generators that don't do that are affected and am currently getting three different error codes dependent on whether the arguments to the type constuctors are primitives or other records and also (the really odd part) the function itself, which shouldn't make a difference as far as i can tell