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.
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.
(is (validate schema data) (humanize (explain schema data)))
— anything like this built in? Or just validate!
that throws on failure?
Write a function?
@caumond PR welcome
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?]]}
is this in a branch somewhere?
not yet, needs a new -min-count
protocol method to regex-schma to resolve the arities from :=>
schemas. few hours away from a branch.
cool. how are you generating the fn per arity?
pushed the current: https://github.com/metosin/malli/blob/fn_new/src/malli/generator.cljc#L104-L129
but that code doesn’t infer the arity, needs to set manually:
(def f
(mg/generate
[:function
[0 [:=> :cat int?]]
[1 [:=> [:cat int?] nat-int?]]]))
:thumbsup: