This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-05
Channels
- # beginners (229)
- # cider (54)
- # cljs-dev (187)
- # cljsrn (1)
- # clojure (187)
- # clojure-dev (5)
- # clojure-italy (31)
- # clojure-losangeles (1)
- # clojure-russia (3)
- # clojure-spec (76)
- # clojure-uk (29)
- # clojurescript (94)
- # cursive (18)
- # datascript (8)
- # datomic (26)
- # docker (6)
- # emacs (19)
- # figwheel (6)
- # fulcro (41)
- # garden (1)
- # graphql (1)
- # hoplon (33)
- # jobs (1)
- # jobs-discuss (1)
- # lein-figwheel (14)
- # leiningen (7)
- # nrepl (10)
- # nyc (1)
- # off-topic (2)
- # onyx (2)
- # parinfer (25)
- # portkey (6)
- # powderkeg (1)
- # protorepl (1)
- # re-frame (14)
- # reagent (14)
- # shadow-cljs (31)
- # spacemacs (3)
- # test-check (33)
- # uncomplicate (1)
- # unrepl (40)
- # vim (5)
- # yada (16)
@mpcarolin You can use back tick you expand a symbol's name:
(-> (test/check `my-index-of) (test/summarize-results))
will probably work.@seancorfield Hey, thanks! I did not know that existed. It will save me a lot of redundant typing.
I want to use spec to constraint the schema of edn which used as a configuration file. I want useless keys are not allowed.
@doglooksgood there is no official way, you use s/and
with s/keys
and another predicate that constrains the keys to be in a specified set, but then you are listing the keys twice. Some people have written macros for this sort of thing
but spec is like that by design, probably the decision that has caused the most controversy about it
here’s an example https://github.com/gfredericks/schpec/blob/b2d80cff29861925e7e3407ef3e5de25a90fa7cc/src/com/gfredericks/schpec.clj#L13
is https://github.com/clojure/spec.alpha the main repository for spec?
Asking because it is like 3 months since the last commit
ok, thanks. Looking to fix a bug
Now I just have to figure out how it is built, I expected a .deps.edn,project.clj, build.boot, makefile....
It’s maven - you can test with mvn clean test
etc
got it to run with mvn clojure:compile
going with mvn clean test
since I want to fix a problem
Is there a way to make a function return an error if parameters don't conform to their given spec?
I think what you’re looking for is spec.test/instrument. Once you execute it, it will tell you if any :args specs are violated for a given function.
But if you want it at runtime without instrument, you can also use :pre condition for a function with s/valid?
The function's given spec, anyways
does clojure 1.9 come with specs for clojure core functions somehow?
there must be some coverage in there, here’s a spec error for invalid let
:
CompilerException clojure.lang.ExceptionInfo: Call to clojure.core/let did not conform to spec:
In: [0] val: () fails spec: :clojure.core.specs.alpha/bindings at: [:args :bindings :init-expr] predicate: any?, Insufficient input
#:clojure.spec.alpha{:problems [{:path [:args :bindings :init-expr], :reason "Insufficient input", :pred clojure.core/any?, :val (), :via [:clojure.core.specs.alpha/bindings :clojure.core.specs.alpha/bindings], :in [0]}], :spec #object[clojure.spec.alpha$regex_spec_impl$reify__2436 0x482c71e3 "clojure.spec.alpha$regex_spec_impl$reify__2436@482c71e3"], :value ([x] (prn x)), :args ([x] (prn x))}, compiling:
well that's a macro, which is a pretty different use case (in particular, it's checked at compilation; function specs would only get involved if a user intentionally instrumented them)
(or are there official specs somewhere else?)
I guess they'd probably be in core.specs.alpha if anywhere, and I see those are basically just a handful of macros
surely somebody somewhere is assembling a non-official collection of such things?
The two I know of are https://github.com/leifp/spec-play and https://github.com/tirkarthi/respec . I have used neither but @alexmiller has pointed out errors in those specs
👍 thanks
They’re not good
If we had a large enough test suite across enough projects, could we infer “good enough” specs for core functions with https://github.com/stathissideris/spec-provider ? :thinking_face:
I understand that for general usage, “good enough” is not really a concept, or we’ll get confusing false positives and false negatives 🙂
But in my case, “good enough” specs are useful so I can see if error messages can be improved
@U08EKSQMS spec inference for functions is still work in progress in spec-provider (but not too far off). I suspect it wouldn’t be able to give you anything very useful if you ran it on map
though (which I think is very tricky to write a spec for anyway)
I wonder how much it would slow down a test to instrument all of clojure.core 😄
do you think some aspect of this will be useful for some things at some point?
I hope so
I have worked with portions of core speced and it’s really useful at the repl
do you think there's a reasonable place to draw the line that maximizes utility and speed?
I think it’s mostly not useful in a test suite (if the suite already runs)
I don’t feel ready to answer that yet
I have a utility fn that can operate on any map, so its :args
spec is just (s/cat :v (s/keys))
. But when I do generative testing with that, I get a bunch of empty maps (which makes some sense I suppose). What's a good way to make that generate a bunch of random maps instead (ideally w/ an emphasis on namespaced keyword keys)?
Should I just use map?
instead of s/keys
?
sounds plausible
I'm of the opinion that virtually all uses of maps fall into two nonoverlapping categories, roughly corresponding to s/keys
and s/map-of
map?
seems to not commit to either
yeah, map?
seems better
The two I know of are https://github.com/leifp/spec-play and https://github.com/tirkarthi/respec . I have used neither but @alexmiller has pointed out errors in those specs
@alexmiller Are specs for the core library something that contributors could help with? In other words, are they blocked on dev/reviewer time, or are they more fundamentally blocked on any upcoming changes in spec?
They are really blocked on Rich review time. have written some of them but don’t have them public anywhere
They tend to raise many questions with issues of taste and judgement
Eric Normand actually was working on some of this at one point and I gave him some ideas of things to do with it
I understand the issues of taste will take time to resolve, but to the extent that the official specs need testing, I’m sure the community could provide feedback there
He wanted to help and so I told him what would be helpful
Perhaps correctness is much easier than making idiomatic specs that conform/generate cleanly 🙂
I doubt correctness is easy either
And there's also the issue that some functions are extremely hard to spec correctly...
Correct, although that’s one place where the community could help - install specs, run tests, see what breaks
I don’t remember now what that was but I think I asked Eric to help in categorizing what was out there. I think he did but it was a while ago
My experience in testing core specs is that it’s extremely difficult to test more than one at a time
Hm, that’s a good point. Since we can see the list of isntrumentable symbols, a project could loop over them, instrument each one in isolation, and run tests
again, if it was useful to get broader validation of specs by running across a large variety of project
Hi, is there a good way to spec anonymous functions? I am trying to use fspec
, but I keep getting Cannot read property for_all_STAR_ of undefined
@scot-brown Do you have org.clojure/test.check as a dependency?
In order to check whether the function conforms to the spec, it is tested used a generative approach, so you need test.check in your project for that (`clojure.spec` will try to load it dynamically and you'll get some odd-looking failures if it isn't available)