Closed sandhu closed 8 years ago
I'm confused about the use case here -- why wouldn't your example just be written without test.check at all?
(deftest foo
(testing "checking for nil"
(is (nil? (identity nil)))))
I could certainly do it the way you've shown and the consistency argument wouldn't be strong enough on it's own.
I'd structured my tests the way I've described above (using checking
) and it did work until I tried to upgrade.
At this point the strongest case I could make would be for backwards compatibility. Fixing this regression would save me from having to go through my code base and "fix" the tests written this way.
It's worth pointing out that this is a great library and has worked flawlessly up until this point for me.
I'm not opposed to a change that supports this. I think the difference was caused by switching from test.check's prop/for-all to test.chuck's prop/for-all as the underlying expansion, so the root cause is that chuck.prop/for-all doesn't support empty bindings. At a glance it seems not trivial to fix this, but it might be easy after five minutes of thinking or so.
I can get to this before too long, if nobody else is interested in trying. Would probably be a fun exercise for anybody looking for that sort of thing.
Took some time to dig into it this morning and the issue appears to be with gen'/for
where it is using destructing to take apart the bindings
(let [[k1 v1 & [k2 v2 & even-more :as more]] bindings] ...)
One quick "fix" is to guard against that as follows:
(defmacro for-all
"Alternative version of clojure.test.check.properties/for-all where
the binding forms are interpreted as per
com.gfredericks.test.chuck.generators/for."
[bindings expr]
`(prop/for-all ~(if (empty? bindings)
`[{:syms []} []]
(let [bound-names (for-bindings bindings)
quoted-names (map #(list 'quote %) bound-names)]
`[{:syms [~@bound-names]}
(gen'/for ~bindings
(with-meta
~(zipmap quoted-names bound-names)
{::for-all-bindings-map true}))]))
~expr))
The proper solution would be to change for
so that it does not use destructing or add a nil check.
Thank you. Very much appreciated.
Released in 0.2.3
.
I've been using v0.2.0 and was able to integrate specific unit test cases into the generative tests by doing something like
In the master branch I am unable to do that and get the following error on compile.