-
-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create and run tests for clojure.spec.alpha-2 #124
Comments
Our tests are running in this branch, except those that use Repro:
cc @puredanger |
@puredanger With update to SHA 50ff9ba32cca0ddc87df2d01d4ff424a747c6270:
no longer works, it now gives:
This spec broke:
with:
I tried something here but didn't get very far: speculative/src/speculative/specs.cljc Line 87 in 1bf0b3d
|
With SHA a5ed7684fd87e75f5c2f99e186c7163b6bf48696 I get: Caused by: java.lang.IllegalArgumentException: No method in multimethod 'create-spec' for dispatch value: clojure.spec-alpha2/spec* on
@puredanger Any clues how to port this spec? |
With SHA a5ed7684fd87e75f5c2f99e186c7163b6bf48696 I get: Caused by: clojure.lang.ArityException: Wrong number of args (3) passed to: clojure.spec-alpha2.impl/or-spec-impl on
cc @puredanger |
few updates on latest master:
seqable-of is interesting, still looking at where we're going with that |
I think for something like seqable-of, you are making specs from specs and really in the realm of making your own custom spec op now. As in https://github.com/clojure/spec-alpha2/wiki/Differences-from-spec.alpha#implementing-custom-specs - implementing the op macro and the create-spec defmethod that reifies Spec. |
SHA: 0d98d147a12cc63ce0179d3cb525cd287a51a2b3 This also seems to work: (defn seqable-of
[spec]
(s/spec*
`(s/with-gen (s/and seqable?
(s/or :empty empty?
:seq (s/and (s/conformer seq)
(s/every ~spec))))
#(s/gen (s/nilable (s/every ~spec :kind coll?)))))) $ clj -A:test
Clojure 1.10.0
user=> (require '[clojure.spec-alpha2 :as s])
nil
user=> (require '[speculative.specs :as ss])
nil
user=> (s/valid? ::ss/seqable-of-map-entry {:a 1})
true Some specs that don't work: (s/def :atom/validator ifn?)
(s/def :atom/meta map?)
(s/fdef clojure.core/atom
:args (s/cat :x any? :options (s/keys* :opt-un [:atom/validator :atom/meta]))
:ret #(instance? clojure.lang.IAtom %))
Syntax error (IllegalArgumentException) compiling at (core.cljc:220:1).
No method in multimethod 'create-spec' for dispatch value: clojure.spec-alpha2/spec* (s/fdef clojure.core/map
:args (s/alt :transducer (s/cat :f ifn?)
:seqable (s/cat :f ifn? :colls (s/+ seqable?)))
:ret (s/or :transducer ifn? :seqable? ifn?)
:fn (fn [{:keys [args ret]}]
(= (key args) (key ret))))
Syntax error (IllegalArgumentException) compiling fn* at (core.cljc:271:1).
fn params must be Symbols |
Both fixed in latest sha. Bugs! |
@puredanger The For the
TODO:
|
Sorry! I made another change after I fixed and broke it in a different way. Fixed that in latest sha. |
Well, maybe not. |
ok, try again with latest. I reverted my last changes around keys*. |
@puredanger spec1:
spec2:
Not sure if that's important, but there may be tools like expound which rely on this. |
@puredanger Next issue:
This however works:
This also works:
Solution: this is expected. Use |
@puredanger New bug:
This seems to be specific for the combination of |
I assume that should be |
Still doesn't work with |
@puredanger Possibly another bug:
|
complement is not a symbolic spec op so you’ll need |
This works in spec1 and 2: |
Apart from these issues, the speculative tests pass with spec-alpha2! TODO:
|
NOTE: It just occurred to me that libs can maintain compatibility with spec1 and spec2 by doing this: |
|
@puredanger Yeah, the |
@puredanger I started playing with (s/defop spec2-seqable-of
[spec]
:gen #(s/gen (s/nilable (s/every spec :kind coll?)))
(s/and seqable?
(s/or :empty empty?
:seq (s/and (s/conformer seq)
(s/every spec)))))
#'user/spec2-seqable-of
user=> (s/def ::seqable-of-maps (spec2-seqable-of ::map))
:user/seqable-of-maps
user=> (s/valid? ::seqable-of-maps ["foo"])
false
user=> (s/valid? ::seqable-of-maps [{:a 1}])
true
user=> (require '[clojure.spec-alpha2.gen :as gen])
nil
user=> (gen/sample (s/gen ::seqable-of-maps))
(#{{}} ({} {-1 -1.0} {} {-1 U*/tV} {} {}) #{{1.0 -1/3} {true 1, :h? x/pf} {0 -2} {0 1, -3/2 :*E/v} {} {true \I, ?? :c, :?/-* ??} {#uuid "8d01f9a8-6dab-42e3-b8c4-5a76e14141ba" \-} {1 2, d/H -3/2, \< ""} {\z #uuid "e7b7fa13-10b8-415f-b559-66bec2508763"} {-1 \M, \r _/xh, :hx/t -3/4} {-1 0.5, -3 -3} {1.0 m/c8, "Jz" -2} {:?/R. _6/?v, Y true, :j #uuid "b68f2e13-1756-40db-b101-350d674dd748"} {+ -0.6875, -3 :*E/Ct}} #{{:?/y? -2, :. "~"} {\6 0.5} {#uuid "74a68951-7051-4a3b-b61a-3b12ec3e8cb0" \L, true "M!#", \r \9}} ({} {"AD<" -3/2, 1.875 :fd/MP} {h2 -1.0} {1 0, -5 -1.0} {I/RX "uuSr", true -3} {"b]" ?A/e, true -3.75, -3 #uuid "f5fa7648-cd01-4f93-9463-2864c944f10f", V- "8l'1\\u"} {-5 :+/!V, "_\"" 4/3, \u -2/5, #uuid "b7c783e0-2544-45a0-9de7-051ba4e0de07" "}+", +v/. .} {:/ -2, :m+/U8? 0, 5/3 -2/3, l/n 2.0, "" false} {4 :?_, g.! #uuid "ea557c10-50aa-4294-92c2-f45dcbdbe5b1"} {i1+/O+! true, true false, 1/2 3, false true} {} {:rr 5, *A+/qV! C, 3.5 Mg, -0.71875 1.9375} {true #uuid "90ca2f6c-70b5-4f00-bd9b-b927612928b1", 0 3/4, WB/p._ :R*?, :!R -4} {} {*b./bH mv/_, :Iy? 1, 1 -3.0, "j<R(K" :Y/cV} {\7 0, #uuid "97c715b7-83fa-4e49-9382-e4c9a503beef" -5/4, -2.375 j!./+} {#uuid "b44068c2-d811-4895-92a1-7325655c6adc" 1, 0 -1, "" false} {false :Ok, U2S 4}) #{{:x/- "'!Vs]", \K -4/5, 0 "t|W", \i false} {-1 true, -4 :u3T, T+./y5V \8, -2 \|, \! false} {0 3, Y/?h -5, \& :ru/Z, -5 -1} {true !/+, \_ \H} {} #:Ob{p #uuid "796ea6e7-d58b-483b-8df1-9ce6d9665c4c"} {:s/E?u 1/4, \Z #uuid "63f2b5da-5379-4448-a2a7-92d5a335c55f", s false, -2 G/_, \E #uuid "24b3e398-311f-487d-b7cf-1a4aeb25eba3"} {:. \H, false "", 1/2 :-gO, 3 -3} {3 :h, :u :H/ou, #uuid "83c14998-1d59-4f72-8d97-6cfbafc62f70" "WHAi", J #uuid "1df28979-32c0-411c-8272-c323bb28515c"} {"Pd" false} {#uuid "a3081adf-12df-4366-81ca-c9967f95c2ac" _/q+, #uuid "cac544d2-cab6-4802-b24e-35d5f8b9115e" 4, :c27 V/A3, -2.75 -16}} {} nil [{:z :h, #uuid "cd09387d-91d1-44bc-a79c-75287651f494" 6.5, 3/4 -7.28125, -4/7 :__H/E, #uuid "cfdd2ff9-fe03-4b4f-bf89-f0463dd91f32" *2*9, :pBI2 i:d/yKX, "/U:`TexDt" wOg/?, #uuid "d13a42de-b6c9-4f00-825a-8594486d56e4" :!} {0 -5/7, 0.5 3.30078125, 1/3 true, 31 X, _w3 :Y/_, "To" :_8!/l8, :s #uuid "6f72736b-987b-48b5-b010-21d5b9530752", true 0.625, -9/8 -7} {:xF*/zL+ 5, "y{qLz" false, 7 true, :nd1 :.VVd, :cr7/yr6 -5.0} {:Y \A, -10 -3/2, #uuid "abd0ccfc-bca4-401e-8d4b-c30a07b647a1" *Y-./d, 219 "*"} {?6P/! 9, :e?- kl/!3_, 9/5 tN, :_/XR:. -7, -0.875 :p, ??-/c:7? 4.0} {}] []) It seems I can only use this "higher order spec" when I use a defined spec, not with an "anonymous" spec:
Will this be supported? This macro does support it: (defmacro spec2-seqable-of [spec]
`(s/with-gen (s/and seqable?
(s/or :empty empty?
:seq (s/and (s/conformer seq)
(s/every ~spec))))
#(s/gen (s/nilable (s/every ~spec :kind coll?))))) |
No, this will not be supported by defop. |
To expand, defop is designed for cases where you need to parameterize a fixed spec. It cannot be used to create specs of arbitrary specs. Doing that is really creating a full spec op and requires reifying the Spec protocol. Or, you can macro at the front as you're doing to construct the desired symbolic spec. A consequence of the macro approach is that the |
Thanks! Yeah, I really just wanted to avoid writing some boilerplate for this one and don't see this macro as something other users would call, so I guess that's fine then. |
I may have found another bug in spec (that was already there since the last time I tested spec, but I only discovered it now):
|
I encountered the above bug in this spec which I used for generating random regexes. I replaced the sets of chars with sets of strings to work around the above issue:
Now I'm seeing a new bug:
It seems like spec2 has trouble dealing with recursive specs. Also spec2 doesn't deal with out of order specs (first define |
The forward references for regex specs is a known issue - Sean ran into that too and I will get it eventually but it's tedious. Until that's fixed, this example won't work. |
And I fixed the char thing. |
clojure.core has started work on https://github.com/clojure/spec-alpha2
It would be nice to run our tests against this version as well.
The text was updated successfully, but these errors were encountered: