This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-02-15
Channels
- # announcements (27)
- # architecture (15)
- # aws (2)
- # babashka (5)
- # beginners (77)
- # calva (42)
- # cider (22)
- # clj-kondo (47)
- # cljfx (7)
- # clojure (66)
- # clojure-australia (1)
- # clojure-europe (32)
- # clojure-france (10)
- # clojure-israel (2)
- # clojure-italy (1)
- # clojure-nl (8)
- # clojure-uk (53)
- # clojurescript (29)
- # conjure (28)
- # core-async (2)
- # cursive (26)
- # data-science (1)
- # datascript (11)
- # datomic (33)
- # emacs (4)
- # fulcro (5)
- # girouette (3)
- # helix (1)
- # jobs (2)
- # leiningen (17)
- # luminus (2)
- # malli (15)
- # music (2)
- # off-topic (51)
- # pathom (3)
- # rdf (91)
- # remote-jobs (1)
- # reveal (7)
- # sci (6)
- # shadow-cljs (10)
- # spacemacs (3)
- # sql (23)
- # tools-deps (52)
- # uncomplicate (2)
- # vim (3)
- # xtdb (9)
Is there an easy way to use Malli in clojure.test/is
?
I’d like to assert that m/validate
returns true, and show m/explain
output when it fails.
(is (validate schema data) (humanize (explain schema data)))
— anything like this built in? Or just validate!
that throws on failure?
there are no test helpers atm, but should be easy to do in user space as borkdude suggests, Are there good helpers / utilities for this (testing) in spec? in schema?
Yes, it is straightforward enough to write it in user space. But I thought it would be a common case… Found a few similar things: • schema: https://github.com/plumatic/schema/blob/master/test/clj/schema/test_macros.clj • schema: https://github.com/plumatic/schema/blob/master/test/cljx/schema/core_test.cljx • clojure-expectations has “spec expectations” https://github.com/clojure-expectations/clojure-test
I also have this one: https://github.com/borkdude/respeced This was written to test fdef specs.
wrote an issue out of this: https://github.com/metosin/malli/issues/369.
wip: function generators generate correctly function with different arities
(def f
(mg/generate
[:function
[:=> :cat int?]
[:=> [:cat int?] nat-int?]]))
(f)
;=> 132816
;=> -7823115
;=> -36
;=> -97
;=> 13412759
;=> 1444
(f 1)
;=> 1038018
;=> 11009747
;=> 8
;=> 59186626
;=> 10
;=> 5373734
(f "1")
; =throws=> :malli.generator/invalid-input {:schema [:cat int?], :args ["1"]}
(f 1 2)
; =throws=> :malli.generator/invalid-arity {:arity 2, :arities #{0 1}, :args (1 2), :schema [:function [:=> :cat int?] [:=> [:cat int?] nat-int?]]}
not yet, needs a new -min-count
protocol method to regex-schma to resolve the arities from :=>
schemas. few hours away from a branch.
pushed the current: https://github.com/metosin/malli/blob/fn_new/src/malli/generator.cljc#L104-L129