diff options
Diffstat (limited to 'src/clojure/contrib/test_contrib')
18 files changed, 61 insertions, 182 deletions
diff --git a/src/clojure/contrib/test_contrib/complex_numbers.clj b/src/clojure/contrib/test_contrib/complex_numbers.clj index 2ac2ff86..7498e897 100644 --- a/src/clojure/contrib/test_contrib/complex_numbers.clj +++ b/src/clojure/contrib/test_contrib/complex_numbers.clj @@ -13,7 +13,7 @@ (ns clojure.contrib.test-contrib.complex-numbers (:refer-clojure :exclude [+ - * / = < > <= >=]) - (:use [clojure.contrib.test-is + (:use [clojure.test :only (deftest is are run-tests)] [clojure.contrib.generic.arithmetic :only (+ - * /)] diff --git a/src/clojure/contrib/test_contrib/fnmap.clj b/src/clojure/contrib/test_contrib/fnmap.clj index ccd7a54a..7fe87cc3 100644 --- a/src/clojure/contrib/test_contrib/fnmap.clj +++ b/src/clojure/contrib/test_contrib/fnmap.clj @@ -1,19 +1,19 @@ (ns clojure.contrib.test-contrib.fnmap (:use clojure.contrib.fnmap - clojure.contrib.test-is)) + clojure.test)) (deftest acts-like-map (let [m1 (fnmap get assoc :key1 1 :key2 2)] - (are (= _2 (get m1 _1)) + (are [k v] (= v (get m1 k)) :key1 1 :key2 2 :nonexistent-key nil) - (are (= _2 (_1 m1)) + (are [k v] (= v (k m1)) :key1 1 :key2 2 :nonexistent-key nil) (let [m2 (assoc m1 :key3 3 :key4 4)] - (are (= _2 (get m2 _1)) + (are [k v] (= v (get m2 k)) :key1 1 :key2 2 :key3 3 diff --git a/src/clojure/contrib/test_contrib/greatest_least.clj b/src/clojure/contrib/test_contrib/greatest_least.clj index 557c0a3c..f273aaf2 100644 --- a/src/clojure/contrib/test_contrib/greatest_least.clj +++ b/src/clojure/contrib/test_contrib/greatest_least.clj @@ -1,6 +1,6 @@ (ns clojure.contrib.test-contrib.greatest-least (:use clojure.contrib.greatest-least - [clojure.contrib.test-is :only (is deftest run-tests)])) + [clojure.test :only (is deftest run-tests)])) (deftest test-greatest (is (nil? (greatest)) "greatest with no arguments is nil") diff --git a/src/clojure/contrib/test_contrib/macro_utils.clj b/src/clojure/contrib/test_contrib/macro_utils.clj index 01c64678..ac1ced06 100644 --- a/src/clojure/contrib/test_contrib/macro_utils.clj +++ b/src/clojure/contrib/test_contrib/macro_utils.clj @@ -12,7 +12,7 @@ ;; remove this notice, or any other, from this software. (ns clojure.contrib.test-contrib.macro-utils - (:use [clojure.contrib.test-is :only (deftest is are run-tests use-fixtures)] + (:use [clojure.test :only (deftest is are run-tests use-fixtures)] [clojure.contrib.macro-utils :only (macrolet symbol-macrolet defsymbolmacro with-symbol-macros mexpand-1 mexpand mexpand-all)] diff --git a/src/clojure/contrib/test_contrib/monads.clj b/src/clojure/contrib/test_contrib/monads.clj index 5d38b544..f523f0ec 100644 --- a/src/clojure/contrib/test_contrib/monads.clj +++ b/src/clojure/contrib/test_contrib/monads.clj @@ -12,14 +12,14 @@ ;; remove this notice, or any other, from this software. (ns clojure.contrib.test-contrib.monads - (:use [clojure.contrib.test-is :only (deftest is are run-tests)] + (:use [clojure.test :only (deftest is are run-tests)] [clojure.contrib.monads :only (with-monad domonad m-lift m-seq m-chain sequence-m maybe-m state-m maybe-t sequence-t)])) (deftest sequence-monad (with-monad sequence-m - (are (= _1 _2) + (are [a b] (= a b) (domonad [x (range 3) y (range 2)] (+ x y)) '(0 1 1 2 2 3) (domonad [x (range 5) y (range (+ 1 x)) :when (= (+ x y) 2)] (list x y)) @@ -37,7 +37,7 @@ (with-monad maybe-m (let [m+ (m-lift 2 +) mdiv (fn [x y] (domonad [a x b y :when (not (zero? b))] (/ a b)))] - (are (= _1 _2) + (are [a b] (= a b) (m+ (m-result 1) (m-result 3)) (m-result 4) (mdiv (m-result 1) (m-result 3)) @@ -50,7 +50,7 @@ (deftest seq-maybe-monad (with-monad (maybe-t sequence-m) (letfn [(pairs [xs] ((m-lift 2 #(list %1 %2)) xs xs))] - (are (= _1 _2) + (are [a b] (= a b) ((m-lift 1 inc) (for [n (range 10)] (when (odd? n) n))) '(nil 2 nil 4 nil 6 nil 8 nil 10) (pairs (for [n (range 5)] (when (odd? n) n))) diff --git a/src/clojure/contrib/test_contrib/pprint/cl_format.clj b/src/clojure/contrib/test_contrib/pprint/cl_format.clj index 3de10959..b101b92b 100644 --- a/src/clojure/contrib/test_contrib/pprint/cl_format.clj +++ b/src/clojure/contrib/test_contrib/pprint/cl_format.clj @@ -15,7 +15,7 @@ (ns clojure.contrib.test-contrib.pprint.cl-format (:refer-clojure :exclude [format]) - (:use [clojure.contrib.test-is :only (deftest are run-tests)] + (:use [clojure.test :only (deftest are run-tests)] clojure.contrib.test-contrib.pprint.helper clojure.contrib.pprint)) diff --git a/src/clojure/contrib/test_contrib/pprint/helper.clj b/src/clojure/contrib/test_contrib/pprint/helper.clj index c7112e68..bf25ca61 100644 --- a/src/clojure/contrib/test_contrib/pprint/helper.clj +++ b/src/clojure/contrib/test_contrib/pprint/helper.clj @@ -14,8 +14,8 @@ ;; This is just a macro to make my tests a little cleaner (ns clojure.contrib.test-contrib.pprint.helper - (:use [clojure.contrib.test-is :only (deftest are run-tests)])) + (:use [clojure.test :only (deftest are run-tests)])) (defmacro simple-tests [name & test-pairs] - `(deftest ~name (are (= _1 _2) ~@test-pairs))) + `(deftest ~name (are [x y] (= x y) ~@test-pairs))) diff --git a/src/clojure/contrib/test_contrib/pprint/pretty.clj b/src/clojure/contrib/test_contrib/pprint/pretty.clj index c0cbb615..f51b172f 100644 --- a/src/clojure/contrib/test_contrib/pprint/pretty.clj +++ b/src/clojure/contrib/test_contrib/pprint/pretty.clj @@ -12,7 +12,7 @@ ; You must not remove this notice, or any other, from this software. (ns clojure.contrib.test-contrib.pprint.pretty - (:use [clojure.contrib.test-is :only (deftest are run-tests)] + (:use [clojure.test :only (deftest are run-tests)] clojure.contrib.test-contrib.pprint.helper clojure.contrib.pprint)) diff --git a/src/clojure/contrib/test_contrib/shell_out.clj b/src/clojure/contrib/test_contrib/shell_out.clj index 0bd1afbe..c5447099 100644 --- a/src/clojure/contrib/test_contrib/shell_out.clj +++ b/src/clojure/contrib/test_contrib/shell_out.clj @@ -1,5 +1,5 @@ (ns clojure.contrib.test-contrib.shell-out - (:use clojure.contrib.test-is + (:use clojure.test clojure.contrib.shell-out) (:import (java.io File))) @@ -9,7 +9,7 @@ (def as-env-string ((ns-interns 'clojure.contrib.shell-out) 'as-env-string)) (deftest test-parse-args - (are (= _1 _2) + (are [x y] (= x y) {:cmd [nil] :out "UTF-8" :dir nil :env nil} (parse-args []) {:cmd ["ls"] :out "UTF-8" :dir nil :env nil} (parse-args ["ls"]) {:cmd ["ls" "-l"] :out "UTF-8" :dir nil :env nil} (parse-args ["ls" "-l"]) @@ -17,17 +17,17 @@ )) (deftest test-with-sh-dir - (are (= _1 _2) + (are [x y] (= x y) nil *sh-dir* "foo" (with-sh-dir "foo" *sh-dir*))) (deftest test-with-sh-env - (are (= _1 _2) + (are [x y] (= x y) nil *sh-env* {:KEY "VAL"} (with-sh-env {:KEY "VAL"} *sh-env*))) (deftest test-as-env-string - (are (= _1 _2) + (are [x y] (= x y) nil (as-env-string nil) ["FOO=BAR"] (seq (as-env-string {"FOO" "BAR"})) ["FOO_SYMBOL=BAR"] (seq (as-env-string {'FOO_SYMBOL "BAR"})) @@ -35,7 +35,7 @@ (deftest test-as-file - (are (= _1 _2) + (are [x y] (= x y) (File. "foo") (as-file "foo") nil (as-file nil) (File. "bar") (as-file (File. "bar"))))
\ No newline at end of file diff --git a/src/clojure/contrib/test_contrib/str_utils.clj b/src/clojure/contrib/test_contrib/str_utils.clj index 812821dc..815525bb 100644 --- a/src/clojure/contrib/test_contrib/str_utils.clj +++ b/src/clojure/contrib/test_contrib/str_utils.clj @@ -1,5 +1,5 @@ (ns clojure.contrib.test-contrib.str-utils - (:use clojure.contrib.test-is + (:use clojure.test clojure.contrib.str-utils)) diff --git a/src/clojure/contrib/test_contrib/str_utils2.clj b/src/clojure/contrib/test_contrib/str_utils2.clj index d7d9b131..dac0893a 100644 --- a/src/clojure/contrib/test_contrib/str_utils2.clj +++ b/src/clojure/contrib/test_contrib/str_utils2.clj @@ -1,6 +1,6 @@ (ns clojure.contrib.test-contrib.str-utils2 (:require [clojure.contrib.str-utils2 :as s]) - (:use clojure.contrib.test-is)) + (:use clojure.test)) (deftest t-blank (is (s/blank? nil)) diff --git a/src/clojure/contrib/test_contrib/test_dataflow.clj b/src/clojure/contrib/test_contrib/test_dataflow.clj index 9ad327eb..991e7f2e 100644 --- a/src/clojure/contrib/test_contrib/test_dataflow.clj +++ b/src/clojure/contrib/test_contrib/test_dataflow.clj @@ -15,7 +15,7 @@ (ns clojure.contrib.test-contrib.test-dataflow - (:use clojure.contrib.test-is) + (:use clojure.test) (:use clojure.contrib.dataflow)) (def df-1 diff --git a/src/clojure/contrib/test_contrib/test_graph.clj b/src/clojure/contrib/test_contrib/test_graph.clj index 425966bf..ed03b9ae 100644 --- a/src/clojure/contrib/test_contrib/test_graph.clj +++ b/src/clojure/contrib/test_contrib/test_graph.clj @@ -14,7 +14,7 @@ ;; Created 23 June 2009 (ns clojure.contrib.test-contrib.test-graph - (use clojure.contrib.test-is + (use clojure.test clojure.contrib.graph)) diff --git a/src/clojure/contrib/test_contrib/test_is.clj b/src/clojure/contrib/test_contrib/test_is.clj deleted file mode 100644 index f9e77d76..00000000 --- a/src/clojure/contrib/test_contrib/test_is.clj +++ /dev/null @@ -1,113 +0,0 @@ -;;; test_contrib/test_is.clj: unit tests for test_is.clj - -;; by Stuart Sierra, http://stuartsierra.com/ -;; January 16, 2009 - -;; Thanks to Chas Emerick, Allen Rohner, and Stuart Halloway for -;; contributions and suggestions. - -;; Copyright (c) Stuart Sierra, 2008. All rights reserved. The use -;; and distribution terms for this software are covered by the Eclipse -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) -;; which can be found in the file epl-v10.html at the root of this -;; distribution. By using this software in any fashion, you are -;; agreeing to be bound by the terms of this license. You must not -;; remove this notice, or any other, from this software. - - -(ns clojure.contrib.test-contrib.test-is - (:use clojure.contrib.test-is)) - -(deftest can-test-symbol - (let [x true] - (is x "Should pass")) - (let [x false] - (is x "Should fail"))) - -(deftest can-test-boolean - (is true "Should pass") - (is false "Should fail")) - -(deftest can-test-nil - (is nil "Should fail")) - -(deftest can-test-= - (is (= 2 (+ 1 1)) "Should pass") - (is (= 3 (+ 2 2)) "Should fail")) - -(deftest can-test-instance - (is (instance? Integer (+ 2 2)) "Should pass") - (is (instance? Float (+ 1 1)) "Should fail")) - -(deftest can-test-thrown - (is (thrown? ArithmeticException (/ 1 0)) "Should pass") - ;; No exception is thrown: - (is (thrown? Exception (+ 1 1)) "Should fail") - ;; Wrong class of exception is thrown: - (is (thrown? ArithmeticException (throw (RuntimeException.))) "Should error")) - -(deftest can-test-thrown-with-msg - (is (thrown-with-msg? ArithmeticException #"Divide by zero" (/ 1 0)) "Should pass") - ;; Wrong message string: - (is (thrown-with-msg? ArithmeticException #"Something else" (/ 1 0)) "Should fail") - ;; No exception is thrown: - (is (thrown? Exception (+ 1 1)) "Should fail") - ;; Wrong class of exception is thrown: - (is (thrown-with-msg? IllegalArgumentException #"Divide by zero" (/ 1 0)) "Should error")) - -(deftest can-catch-unexpected-exceptions - (is (= 1 (throw (Exception.))) "Should error")) - -(deftest can-test-method-call - (is (.startsWith "abc" "a") "Should pass") - (is (.startsWith "abc" "d") "Should fail")) - -(deftest can-test-anonymous-fn - (is (#(.startsWith % "a") "abc") "Should pass") - (is (#(.startsWith % "d") "abc") "Should fail")) - -(deftest can-test-regexps - (is (re-matches #"^ab.*$" "abbabba") "Should pass") - (is (re-matches #"^cd.*$" "abbabba") "Should fail") - (is (re-find #"ab" "abbabba") "Should pass") - (is (re-find #"cd" "abbabba") "Should fail")) - - -;; still have to declare the symbol before testing unbound symbols -(declare does-not-exist) - -(deftest can-test-unbound-symbol - (is (= nil does-not-exist) "Should error")) - -(deftest can-test-unbound-function - (is (does-not-exist) "Should error")) - - -;; Here, we create an alternate version of test-is/report, that -;; compares the event with the message, then calls the original -;; 'report' with modified arguments. - -(declare original-report) - -(defn custom-report [data] - (let [event (:type data) - msg (:message data) - expected (:expected data) - actual (:actual data) - passed (cond - (= event :fail) (= msg "Should fail") - (= event :pass) (= msg "Should pass") - (= event :error) (= msg "Should error") - :else true)] - (if passed - (original-report {:type :pass, :message msg, - :expected expected, :actual actual}) - (original-report {:type :fail, :message (str msg " but got " event) - :expected expected, :actual actual})))) - -;; test-ns-hook will be used by test-is/test-ns to run tests in this -;; namespace. -(defn test-ns-hook [] - (binding [original-report report - report custom-report] - (test-all-vars (find-ns 'clojure.contrib.test-contrib.test-is)))) diff --git a/src/clojure/contrib/test_contrib/test_is_fixtures.clj b/src/clojure/contrib/test_contrib/test_is_fixtures.clj deleted file mode 100644 index 218c45d5..00000000 --- a/src/clojure/contrib/test_contrib/test_is_fixtures.clj +++ /dev/null @@ -1,42 +0,0 @@ -;;; test_is_fixtures.clj: unit tests for fixtures in test_is.clj - -;; by Stuart Sierra, http://stuartsierra.com/ -;; March 28, 2009 - -;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use -;; and distribution terms for this software are covered by the Eclipse -;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) -;; which can be found in the file epl-v10.html at the root of this -;; distribution. By using this software in any fashion, you are -;; agreeing to be bound by the terms of this license. You must not -;; remove this notice, or any other, from this software. - - -(ns clojure.contrib.test-contrib.test-is-fixtures - (:use clojure.contrib.test-is)) - -(declare *a* *b* *c* *d*) - -(defn fixture-a [f] - (binding [*a* 3] (f))) - -(defn fixture-b [f] - (binding [*b* 5] (f))) - -(defn fixture-c [f] - (binding [*c* 7] (f))) - -(defn fixture-d [f] - (binding [*d* 11] (f))) - -(use-fixtures :once fixture-a fixture-b) - -(use-fixtures :each fixture-c fixture-d) - -(deftest can-use-once-fixtures - (is (= 3 *a*)) - (is (= 5 *b*))) - -(deftest can-use-each-fixtures - (is (= 7 *c*)) - (is (= 11 *d*))) diff --git a/src/clojure/contrib/test_contrib/test_java_utils.clj b/src/clojure/contrib/test_contrib/test_java_utils.clj index 409f07b2..8a56b197 100644 --- a/src/clojure/contrib/test_contrib/test_java_utils.clj +++ b/src/clojure/contrib/test_contrib/test_java_utils.clj @@ -1,5 +1,5 @@ (ns clojure.contrib.test-contrib.test-java-utils - (:use clojure.contrib.test-is + (:use clojure.test [clojure.contrib.duck-streams :only (spit)] clojure.contrib.java-utils) (:import [java.io File] diff --git a/src/clojure/contrib/test_contrib/test_lazy_seqs.clj b/src/clojure/contrib/test_contrib/test_lazy_seqs.clj index 3bf4ba78..33bbcae1 100644 --- a/src/clojure/contrib/test_contrib/test_lazy_seqs.clj +++ b/src/clojure/contrib/test_contrib/test_lazy_seqs.clj @@ -1,5 +1,5 @@ (ns clojure.contrib.test-contrib.test-lazy-seqs - (:use clojure.contrib.test-is + (:use clojure.test clojure.contrib.lazy-seqs)) (deftest test-fibs diff --git a/src/clojure/contrib/test_contrib/walk.clj b/src/clojure/contrib/test_contrib/walk.clj new file mode 100644 index 00000000..9e79f8d6 --- /dev/null +++ b/src/clojure/contrib/test_contrib/walk.clj @@ -0,0 +1,34 @@ +(ns clojure.contrib.test-contrib.walk + (:require [clojure.contrib.walk :as w]) + (:use clojure.test)) + +(deftest t-prewalk-replace + (is (= (w/prewalk-replace {:a :b} [:a {:a :a} (list 3 :c :a)]) + [:b {:b :b} (list 3 :c :b)]))) + +(deftest t-postwalk-replace + (is (= (w/postwalk-replace {:a :b} [:a {:a :a} (list 3 :c :a)]) + [:b {:b :b} (list 3 :c :b)]))) + +(deftest t-stringify-keys + (is (= (w/stringify-keys {:a 1, nil {:b 2 :c 3}, :d 4}) + {"a" 1, nil {"b" 2 "c" 3}, "d" 4}))) + +(deftest t-prewalk-order + (is (= (let [a (atom [])] + (w/prewalk (fn [form] (swap! a conj form) form) + [1 2 {:a 3} (list 4 [5])]) + @a) + [[1 2 {:a 3} (list 4 [5])] + 1 2 {:a 3} [:a 3] :a 3 (list 4 [5]) + 4 [5] 5]))) + +(deftest t-postwalk-order + (is (= (let [a (atom [])] + (w/postwalk (fn [form] (swap! a conj form) form) + [1 2 {:a 3} (list 4 [5])]) + @a) + [1 2 + :a 3 [:a 3] {:a 3} + 4 5 [5] (list 4 [5]) + [1 2 {:a 3} (list 4 [5])]])))
\ No newline at end of file |