malli

https://github.com/metosin/malli :malli:
aaron51 2021-02-15T03:23:37.098300Z

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.

ikitommi 2021-02-15T08:40:16.099500Z

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?

aaron51 2021-02-15T22:38:45.102800Z

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

borkdude 2021-02-15T22:40:42.103200Z

I also have this one: https://github.com/borkdude/respeced This was written to test fdef specs.

ikitommi 2021-02-16T20:04:05.104200Z

wrote an issue out of this: https://github.com/metosin/malli/issues/369.

aaron51 2021-02-15T04:27:34.098400Z

(is (validate schema data) (humanize (explain schema data))) — anything like this built in? Or just validate! that throws on failure?

borkdude 2021-02-15T07:55:47.099Z

Write a function?

ikitommi 2021-02-15T08:34:24.099400Z

@caumond PR welcome

ikitommi 2021-02-15T08:42:06.100900Z

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?]]}

borkdude 2021-02-15T08:44:26.101200Z

is this in a branch somewhere?

ikitommi 2021-02-15T08:45:52.101400Z

not yet, needs a new -min-count protocol method to regex-schma to resolve the arities from :=> schemas. few hours away from a branch.

borkdude 2021-02-15T08:49:46.101600Z

cool. how are you generating the fn per arity?

ikitommi 2021-02-15T08:53:40.101800Z

pushed the current: https://github.com/metosin/malli/blob/fn_new/src/malli/generator.cljc#L104-L129

ikitommi 2021-02-15T08:54:34.102100Z

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?]]]))

borkdude 2021-02-15T08:59:54.102300Z

:thumbsup: