Re: Bug? with-redefs fails on functions with primitive type hints

2014-11-28 Thread Sean Corfield
On Nov 28, 2014, at 12:59 PM, Brian Marick mar...@exampler.com wrote:
 A Midje user reports a bug that is actually a Clojure behavior. Does it count 
 as a bug?

If you're mocking a function that is specifically declared to take a long 
(primitive), shouldn't the mocked call also be declared to take a long?

(defn test-fn [^long x] x); Note hint
#'user/test-fn
(defn do-something [x] (test-fn x))
#'user/do-something
(with-redefs [test-fn (fn [^long x] (prn :x x) x)] ; Note hint here too!
  (do-something non-int))

And this fails (as expected):

ClassCastException java.lang.String cannot be cast to java.lang.Number  
user/do-something (form-init1785865955014487522.clj:1)

Sean Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

Perfection is the enemy of the good.
-- Gustave Flaubert, French realist novelist (1821-1880)



-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Bug? with-redefs fails on functions with primitive type hints

2014-11-28 Thread Brian Marick



Sean Corfield wrote:

If you're mocking a function that is specifically declared to take a long 
(primitive), shouldn't the mocked call also be declared to take a long?


Midje has an idea called a metaconstant 
https://github.com/marick/Midje/wiki/Metaconstants. Metaconstants are used to document that nothing 
about a test value matters except what you explicitly mention (by declaring what values particular 
functions have when applied to the test value). It's useful at making tests more abstract, closer 
to for all statements.

So the actual (still example) code looked something like:

   (fact convert any integer into a map thing
 (function-under-test ..any-integer..) = {..any-integer [..any-integer..]}
 (provided
   (intlister ..any-integer..) = [..any-integer..]))


If this isn't a bug, I wouldn't expect Clojure to change. Once one chooses 
static types, one has many crosses to bear, and this would be another. But the 
way it works for non-primitives but not primitives could conceivably be a 
symptom of an important bug.

--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups Clojure group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.