Exception testing with clojure.test

2011-07-19 Thread Jonathan Cardoso
Hi guys,

I want to test some code that throws exceptions, but I don't want exceptions 
to be thrown in the console. 

Is there a way to do that with *is* function?
What is the best way to test my code with try-catch blocks?

-- 
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

Re: Exception testing with clojure.test

2011-07-19 Thread Sam Ritchie
Yup, this should do the trick:

(defn only-odds
  [x]
  {:pre [(odd? x)]}
  x)

(deftest only-odds-test
(is (thrown? AssertionError (only-odds 2)))
(is (= 1 (only-odds 1

On Tue, Jul 19, 2011 at 4:48 PM, Jonathan Cardoso
jonathancar...@gmail.comwrote:

 Hi guys,

 I want to test some code that throws exceptions, but I don't want
 exceptions to be thrown in the console.

 Is there a way to do that with *is* function?
 What is the best way to test my code with try-catch blocks?

 --
 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 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

Re: Exception testing with clojure.test

2011-07-19 Thread Brian Marick
On Jul 19, 2011, at 3:48 PM, Jonathan Cardoso wrote:

 Hi guys,
 
 I want to test some code that throws exceptions, but I don't want exceptions 
 to be thrown in the console. 

jcrit.server= (use 'midje.sweet)
jcrit.server= (fact
(f) = (throws NullPointerException))
true

-
Brian Marick, Artisanal Labrador
Contract programming in Ruby and Clojure
Occasional consulting on Agile
www.exampler.com, www.twitter.com/marick

-- 
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


Re: Exception testing with clojure.test

2011-07-19 Thread Jonathan Cardoso
Thank's a lot. That's exactly what I was looking for and didn't realize 
there was a thrown? function in the API =S

Thanks.

-- 
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