Skip to content

Commit

Permalink
minimal port of tests to match SVN 283 version of test-is
Browse files Browse the repository at this point in the history
  • Loading branch information
stuarthalloway committed Dec 8, 2008
1 parent 640173f commit d6f85a6
Show file tree
Hide file tree
Showing 28 changed files with 65 additions and 67 deletions.
8 changes: 4 additions & 4 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ All rights reserved.

This version of the sample code has been tested with:

Clojure SVN revision 1132
svn co -r 1132 https://clojure.svn.sourceforge.net/svnroot/clojure/trunk clojure
Clojure SVN revision 1146
svn co -r 1146 https://clojure.svn.sourceforge.net/svnroot/clojure/trunk clojure

Clojure-Contrib SVN revision 259:
svn co -r 259 https://clojure-contrib.svn.sourceforge.net/svnroot/clojure-contrib/trunk clojure-contrib
Clojure-Contrib SVN revision 285:
svn co -r 285 https://clojure-contrib.svn.sourceforge.net/svnroot/clojure-contrib/trunk clojure-contrib
7 changes: 3 additions & 4 deletions examples/test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
(doseq [test tests]
(require (test-name test)))

(binding [*test-out* (java.io.PrintWriter. *out*)]
(doseq [test tests]
(println "\n\n=====>" test)
(run-tests (test-name test))))
(doseq [test tests]
(println "\n\n=====>" test)
(run-tests (test-name test)))

; TODO: document in book
(shutdown-agents)
2 changes: 1 addition & 1 deletion examples/test/chat.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
(deftest validate-message-list
(is (nil? (c/validate-message-list ())))
(is (nil? (c/validate-message-list '({:sender "X" :text "Y"}))))
(throws IllegalStateException (c/validate-message-list '({})))
(is (thrown? IllegalStateException (c/validate-message-list '({}))))
)


2 changes: 1 addition & 1 deletion examples/test/exploring.clj
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
(square-corners 0 0 2))))

(deftest test-busted
(throws Exception (test #'busted)))
(is (thrown? Exception (test #'busted))))

(deftest test-greet-author-1
(is (= "Hello, John\n" (with-out-str (greet-author-1 {:first-name "John"}))))
Expand Down
8 changes: 4 additions & 4 deletions examples/test/interop.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
;; to write this test you would need a cross-thread with-out-str

(deftest test-try-finally
(is (= (with-out-str (throws Exception (demo-try-finally)))
(is (= (with-out-str (is (thrown? Exception (demo-try-finally))))
"we get to clean up\n"))
)

(deftest test-class-available
(throws ClassNotFoundException (poor-class-available? "java.lang.MicrosoftRocks"))
(is (thrown? ClassNotFoundException (poor-class-available? "java.lang.MicrosoftRocks")))
(is (= String (poor-class-available? "java.lang.String")))
(is (false? (class-available? "java.lang.MicrosoftRocks")))
(is (class-available? "java.lang.String"))
Expand All @@ -36,8 +36,8 @@
(deftest test-describe-class
(is (= {:name "java.lang.String", :final true} (untyped-describe-class String)))
(is (= {:name "java.lang.String", :final true} (typed-describe-class String)))
(throws IllegalArgumentException (untyped-describe-class "foo"))
(throws ClassCastException (typed-describe-class "foo"))
(is (thrown? IllegalArgumentException (untyped-describe-class "foo")))
(is (thrown? ClassCastException (typed-describe-class "foo")))
)


Expand Down
4 changes: 2 additions & 2 deletions examples/test/life_without_multi.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
)

(deftest test-my-print
(throws NullPointerException (my-print-1 nil))
(each=
(is (thrown? NullPointerException (my-print-1 nil)))
(are =
(with-out-str (my-print-1 "foo")) "foo"

(with-out-str (my-print-2 "foo")) "foo"
Expand Down
14 changes: 7 additions & 7 deletions examples/test/macros.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@

; unless-1 evals args before test
(deftest test-unless-1
(throws Exception (unless-1 false (throw (Exception.))))
(throws Exception (unless-1 true (throw (Exception.))))
(is (thrown? Exception (unless-1 false (throw (Exception.)))))
(is (thrown? Exception (unless-1 true (throw (Exception.)))))
)

; unless-2 evals args before test
(deftest test-unless-2
(each=
(are =
(with-out-str (unless-2 false :foo)) "About to test...\n"
(with-out-str (unless-2 true :foo)) "About to test...\n"))

; unless-3 is a macro and does the right thing
(deftest test-unless
(throws Exception (unless false (throw (Exception.))))
(is (thrown? Exception (unless false (throw (Exception.)))))
(unless true (throw (Exception.)))
)

; bad-unless captures a symbol
(deftest test-expansions
(each=
(are =
(macroexpand-1 '(examples.macros/unless false :foo)) '(if false nil :foo)
(macroexpand-1 '(examples.macros/bad-unless false :foo)) '(if expr nil :foo)
)
)

(deftest test-bench-2
(each=
(are =
(:result (examples.macros/bench (+ 1 2)))
3))

(deftest test-bench-fn
(each=
(are =
(:result (examples.macros/bench-fn (fn [] (+ 2 2))))
4))

Expand Down
2 changes: 1 addition & 1 deletion examples/test/macros/bench_1.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:use clojure.contrib.test-is examples.macros.bench-1))

(deftest test-bench-1
(each=
(are =
(macroexpand-1 '(examples.macros.bench-1/bench :foo))
'(clojure.core/let [examples.macros.bench-1/start (System/nanoTime)
examples.macros.bench-1/result :foo]
Expand Down
4 changes: 2 additions & 2 deletions examples/test/macros/chain_1.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:use clojure.contrib.test-is examples.macros.chain-1))

(deftest test-chain-1
(each=
(are =
(macroexpand-1 '(examples.macros.chain-1/chain a b)) '(. a b))
(throws IllegalArgumentException (macroexpand-1 '(examples.macros.chain-1/chain a b c)))
(is (thrown? IllegalArgumentException (macroexpand-1 '(examples.macros.chain-1/chain a b c))))
)
2 changes: 1 addition & 1 deletion examples/test/macros/chain_2.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:use clojure.contrib.test-is examples.macros.chain-2))

(deftest test-chain-2
(each=
(are =
(macroexpand-1 '(examples.macros.chain-2/chain a b)) '(. a b)
(macroexpand-1 '(examples.macros.chain-2/chain a b c)) '(chain (. a b) c)
))
4 changes: 2 additions & 2 deletions examples/test/macros/chain_3.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:use clojure.contrib.test-is examples.macros.chain-3))

(deftest test-chain-3
(each=
(are =
(macroexpand-1 '(examples.macros.chain-3/chain a b)) '(. a b))
(throws IllegalArgumentException (macroexpand-1 '(examples.macros.chain-3/chain a b c)))
(is (thrown? IllegalArgumentException (macroexpand-1 '(examples.macros.chain-3/chain a b c))))
)
2 changes: 1 addition & 1 deletion examples/test/macros/chain_4.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:use clojure.contrib.test-is examples.macros.chain-4))

(deftest test-chain-4
(each=
(are =
(macroexpand-1 '(examples.macros.chain-4/chain a b)) '(. a b)
(macroexpand-1 '(examples.macros.chain-4/chain a b c)) '(examples.macros.chain-4/chain (. a b) (c))
))
2 changes: 1 addition & 1 deletion examples/test/macros/chain_5.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:use clojure.contrib.test-is examples.macros.chain-5))

(deftest test-chain-5
(each=
(are =
(macroexpand-1 '(examples.macros.chain-5/chain a b)) '(. a b)
(macroexpand-1 '(examples.macros.chain-5/chain a b c)) '(examples.macros.chain-5/chain (. a b) c)
))
4 changes: 2 additions & 2 deletions examples/test/multimethods.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

(deftest test-my-print
(let [my-print-str (fn [& args] (with-out-str (apply my-print args)))]
(each=
(are =
(my-print-str "strval") "strval"
(my-print-str nil) "nil"
(my-print-str 42) "42"
Expand All @@ -18,7 +18,7 @@
)))

(deftest test-my-class
(each=
(are =
String (my-class "foo")
nil (my-class nil)
))
Expand Down
4 changes: 2 additions & 2 deletions examples/test/multimethods/account.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
(alias 'acc 'examples.multimethods.account)

(deftest test-interest-rate
(each=
(are =
(interest-rate {:tag ::acc/Checking}) 0M
(interest-rate {:tag ::acc/Savings}) 0.05M
))

(deftest test-account-level
(each=
(are =
(account-level {:tag ::acc/Checking, :balance 4999}) ::acc/Basic
(account-level {:tag ::acc/Checking, :balance 5000}) ::acc/Premium
(account-level {:tag ::acc/Savings, :balance 999}) ::acc/Basic
Expand Down
2 changes: 1 addition & 1 deletion examples/test/multimethods/default.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(:use examples.multimethods.default))

(deftest test-my-print
(each=
(are =
(with-out-str (my-print "foo")) "foo"
(with-out-str (my-print 42)) "Not implemented yet..."
))
Expand Down
2 changes: 1 addition & 1 deletion examples/test/multimethods/service_charge_1.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
(alias 'acc 'examples.multimethods.account)

(deftest test-service-charge
(each=
(are =
(service-charge {:tag ::acc/Checking, :balance 4999}) 25
(service-charge {:tag ::acc/Checking, :balance 5000}) 0
(service-charge {:tag ::acc/Savings, :balance 999}) 10
Expand Down
2 changes: 1 addition & 1 deletion examples/test/multimethods/service_charge_2.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
(alias 'acc 'examples.multimethods.account)

(deftest test-service-charge
(each=
(are =
(service-charge {:tag ::acc/Checking, :balance 4999}) 25
(service-charge {:tag ::acc/Checking, :balance 5000}) 0
(service-charge {:tag ::acc/Savings, :balance 999}) 10
Expand Down
2 changes: 1 addition & 1 deletion examples/test/multimethods/service_charge_3.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
(alias 'acc 'examples.multimethods.account)

(deftest test-service-charge
(each=
(are =
(service-charge {:tag ::acc/Checking, :balance 4999}) 25
(service-charge {:tag ::acc/Checking, :balance 5000}) 0
(service-charge {:tag ::acc/Savings, :balance 999}) 10
Expand Down
6 changes: 3 additions & 3 deletions examples/test/sequences.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
)

(deftest test-clojure-loc
(each=
(are =
(non-svn? ".svn") false
(non-svn? "foo") true
(clojure-source? "foo.clj") true
Expand All @@ -21,13 +21,13 @@
(let [now #(System/currentTimeMillis)
recent (proxy [File] ["recent"] (lastModified [] (now)))
older (proxy [File] ["older"] (lastModified [] (- (now) (minutes 1000))))]
(each=
(are =
(recently-modified? recent) true
(recently-modified? older) false
)))

(deftest test-sets
(each=
(are =
(union languages beverages) #{"java" "c" "d" "clojure" "chai" "pop"}
(difference languages beverages) #{"c" "d" "clojure"}
(intersection languages beverages) #{"java"}
Expand Down
7 changes: 3 additions & 4 deletions lancet/test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
(doseq [test tests]
(require (test-name test)))

(binding [*test-out* (java.io.PrintWriter. *out*)]
(doseq [test tests]
(println "\n\n=====>" test)
(run-tests (test-name test))))
(doseq [test tests]
(println "\n\n=====>" test)
(run-tests (test-name test)))

(shutdown-agents)
4 changes: 2 additions & 2 deletions lancet/test/defrunonce_1.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
; this test depends on a proposed enhancement to test-is...
; and is broken anyway
;; (deftest test-defrunonce-1-refers-to-nonexistent-vars
;; (each=
;; (are =
;; (.getMessage (throws Exception (use :reload 'lancet.defrunonce-1)))
;; "java.lang.Exception: Unable to resolve symbol: reset-fn in this context (defrunonce_1.clj:6)"))

(deftest test-defrunonce-1-refers-to-nonexistent-vars
(throws Exception (use :reload 'lancet.defrunonce-1)))
(is (thrown? Exception (use :reload 'lancet.defrunonce-1))))

4 changes: 2 additions & 2 deletions lancet/test/step_1_complete.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

(deftest test-ant-project
(let [listeners (.getBuildListeners ant-project)]
(each=
(are =
(count (filter #(= (class %) org.apache.tools.ant.NoBannerLogger) listeners))
1
)))
Expand All @@ -13,5 +13,5 @@
(is (=
(class (instantiate-task ant-project "echo"))
org.apache.tools.ant.taskdefs.Echo))
(throws IllegalArgumentException (instantiate-task ant-project "not-a-task-name"))
(is (thrown? IllegalArgumentException (instantiate-task ant-project "not-a-task-name")))
)
6 changes: 3 additions & 3 deletions lancet/test/step_1_repl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

(deftest test-ant-project
(let [listeners (.getBuildListeners ant-project)]
(each=
(are =
(count (filter #(= (class %) org.apache.tools.ant.NoBannerLogger) listeners))
1
)))
Expand All @@ -13,14 +13,14 @@
(is (=
(class (instantiate-task ant-project "echo"))
org.apache.tools.ant.taskdefs.Echo))
(throws NullPointerException (instantiate-task ant-project "not-a-task-name"))
(is (thrown? NullPointerException (instantiate-task ant-project "not-a-task-name")))
)

(deftest test-safe-instantiate-task
(is (=
(class (safe-instantiate-task ant-project "echo"))
org.apache.tools.ant.taskdefs.Echo))
(throws IllegalArgumentException (safe-instantiate-task ant-project "not-a-task-name"))
(is (thrown? IllegalArgumentException (safe-instantiate-task ant-project "not-a-task-name")))
)


Expand Down
4 changes: 2 additions & 2 deletions lancet/test/step_2_complete.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

(deftest test-ant-project
(let [listeners (.getBuildListeners ant-project)]
(each=
(are =
(count (filter #(= (class %) org.apache.tools.ant.NoBannerLogger) listeners))
1
)))

(deftest test-instantiate-task
(let [echo-task (instantiate-task ant-project "echo" {:message "foo"})]
(is (= (get-field echo-task "message") "foo")))
(throws IllegalArgumentException (instantiate-task ant-project "not-a-task-name"))
(is (thrown? IllegalArgumentException (instantiate-task ant-project "not-a-task-name")))
)

; using Logger as an example bean. Amazing how few built-in Java
Expand Down
4 changes: 2 additions & 2 deletions lancet/test/step_2_repl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

(deftest test-ant-project
(let [listeners (.getBuildListeners ant-project)]
(each=
(are =
(count (filter #(= (class %) org.apache.tools.ant.NoBannerLogger) listeners))
1
)))

(deftest test-instantiate-task
(let [echo-task (instantiate-task ant-project "echo" {:message "foo"})]
(is (= (get-field echo-task "message") "foo")))
(throws IllegalArgumentException (instantiate-task ant-project "not-a-task-name"))
(is (thrown? IllegalArgumentException (instantiate-task ant-project "not-a-task-name")))
)

; using Logger as an example bean. Amazing how few built-in Java
Expand Down

0 comments on commit d6f85a6

Please sign in to comment.