Clojure tests not executed correctly

0 views
Skip to first unread message

Frantisek Sodomka

unread,
Jul 2, 2009, 8:05:23 AM7/2/09
to Clojure Dev
Hello!
I found a bug caused by the recent transition from old test-is and
template. Old 'are' used to have a syntax for testing if things are
logically true:

(are _
true false nil)

This syntax is used in numbers.clj, see old version (search for "are
_"):
http://code.google.com/p/clojure-contrib/source/browse/trunk/src/clojure/contrib/test_clojure/numbers.clj
and functions
Coerced-Byte, Coerced-Short, ...
and test-even?, test-odd?.

If I change (even? 8) to (even? 1) in test-even? new tests will not
fail.

The reason is that new 'are' needs one more parameter:
OLD:
user=> (macroexpand-1 '(are _ true false nil))
(clojure.contrib.template/do-template (clojure.contrib.test-is/is _)
true false nil)
NEW:
user=> (macroexpand-1 '(are [x] true false nil))
(clojure.template/do-template [x] (clojure.test/is true) false nil)

Fix is to rewrite these tests by adding (true? x) or (if x true
false):

(deftest test-even?
(are [x] (true? x)
(even? -4)
(not (even? -3))
(even? 0)
(not (even? 5))
(even? 1))
(is (thrown? ArithmeticException (even? 1/2)))
(is (thrown? ArithmeticException (even? (double 10)))))

=>
[java] FAIL in (test-even?) (numbers.clj:373)
[java] expected: (true? (even? 1))
[java] actual: (not (true? false))

Thank you for your attention, Frantisek

Frantisek Sodomka

unread,
Jul 6, 2009, 5:11:26 PM7/6/09
to Clojure Dev
I created a ticket #144
https://www.assembla.com/spaces/clojure/tickets/144-test-clojure--change-(are-_----)-to-(are-%5Bx%5D-(true--x)----)

and added a patch to it. Hopefully everything is ok. Feel free to
check it in.

Frantisek


On Jul 2, 2:05 pm, Frantisek Sodomka <fsodo...@gmail.com> wrote:
> Hello!
> I found a bug caused by the recent transition from old test-is and
> template. Old 'are' used to have a syntax for testing if things are
> logically true:
>
> (are _
>   true false nil)
>
> This syntax is used in numbers.clj, see old version (search for "are
> _"):http://code.google.com/p/clojure-contrib/source/browse/trunk/src/cloj...
Reply all
Reply to author
Forward
0 new messages