@matti.uusitalo117 has joined the channel
Hello! Trying to use this and ran into some trouble. How would one write a multi line assertion, the kind that is useful for bigger data structures? For example:
(m/ast non-empty-string)
;; => {:type :string
;; :properties {:min 1}}
This ends up throwing. Same happens with
(m/ast non-empty-string)
;; => {:type :string
; :properties {:min 1}}
I was also looking at the sample from https://github.com/lread/test-doc-blocks/blob/main/doc/example.md#indented-blocks which made me try
(m/ast non-empty-string)
;; =>
; {:type :string
; :properties {:min 1}}
but that emits
(m/ast non-empty-string)
=>
; {:type :string
; :properties {:min 1}}
which doesn't workHi @matti.uusitalo117! I wrote and use test-doc-blocks, but am rusty on the details of what it supports here. I'll take a peek.
Huh! Yes, I see your point:
# README
clojure
;; this works
(map inc [1 2 3 4 5 6])
=> [2 3
4 5
6 7]
clojure
;; this works...
(map inc [1 2 3 4 5 6])
;; => [2 3
4 5
6 7]
clojure
;; this fails at test generation time with Unexpected EOF
(map inc [1 2 3 4 5 6])
;; => [2 3
;; 4 5
;; 6 7]
Raised an issue: https://github.com/lread/test-doc-blocks/issues/33
I didn't fully understand why the single semicolon was needed. Hopefully this latest change doesn't break existing use cases.
At least I don't see any difference between these examples
(=
(prep-block-for-conversion-to-test ";; =stdout=> line1
; line2")
(prep-block-for-conversion-to-test ";; =stdout=> line1
;; line2"))
;; => trueiirc, I think the single semicolon for stdout and stderr allowed us to know when those blocks ended.
(somefn)
;; =sdtout=>
; out1
; out2
; =sdtderr=> out3
;; =stderr=>
; err1
; err2
; => err3
;; => eval-result
That make sense? Eval out is more structured so might not need this distinction. I see, so the difference wouldn't be noticeable in my little example
This seems to work fine
clojure
(def multi-arity-pow
(m/-instrument
{:schema [:function
[:=> [:cat :int] [:int {:max 6}]]
[:=> [:cat :int :int] [:int {:max 6}]]]
:scope #{:input :output}
:report println}
(fn
([x] (* x x))
([x y] (* x y)))))
(multi-arity-pow 4)
;; =stdout=> :malli.core/invalid-output {:output [:int {:max 6}], :value 16, :args [4], :schema [:=> [:cat :int] [:int {:max 6}]]}
;; => 16
(multi-arity-pow 5 0.1)
;; =stdout=> :malli.core/invalid-input {:input [:cat :int :int], :args [5 0.1], :schema [:=> [:cat :int :int] [:int {:max 6}]]}
;; :malli.core/invalid-output {:output [:int {:max 6}], :value 0.5, :args [5 0.1], :schema [:=> [:cat :int :int] [:int {:max 6}]]}
;; => 0.5
It yields sensible tests too!I've been able to use this to test the majority of examples in metosin/malli's markdown documentation
The limitations are not due to test-doc-blocks
still traveling… happy to take a deeper peek when I get back
Thanks for showing a working example. I can work with this. Great library!
This seems to work: https://github.com/lread/test-doc-blocks/pull/35
It would allow both the old style without leading comments and the one that is consistent with =stdout=> style
Oh thanks, @matti.uusitalo117! I'm travelling today and tomorrow, and will take a look as soon as I can.
All good. 🫡
In the meantime I'll try to test this further to see if there's hiccups
Cool. One thing I was wondering was if we actually technically needed the subsequent lines to start with a single ; or would it also be ok for it to start with ;;. I think the latter should be ok too (and more user-friendly), but haven't thought it through yet.
Yeah. I had a homegrown stub of a tool like this that worked like that, but since learning about this tool I'd much prefer to use this. The solutions how to add metadata to the blocks and support for different engines is great
Glad you are enjoying it.
Now that you mention it, it would be way less error prone if the leading comments can be one-or-more semicolons
Yeah there was a good reason for =stdout=> continuation to use the single semicolon... but this continuation... might be ok with multiple semicolons... unless we realize it's not ok. simple_smile
Added some unit tests. Also the latest commit has support for using multiple semicolons. Appears to be just a small adjustment to the regex in body_prep
I added some tests for md and adoc for this feature as well