Permalink
Browse files

play nicer with symbols in test names, fix tally bug

  • Loading branch information...
stuarthalloway committed Feb 27, 2010
1 parent 7c34a88 commit 50a1c4e768c7a292e0ec4a6037b1f03944e470ee
View
@@ -1,4 +1,4 @@
-(defproject circumspec "0.0.8"
+(defproject circumspec "0.0.9"
:dependencies [[org.clojure/clojure
"1.2.0-master-SNAPSHOT"]
[org.clojure/clojure-contrib
@@ -14,7 +14,7 @@
(defn test-function-metadata
[desc forms]
(merge {:circumspec/test true
- :circumspec/name desc
+ :circumspec/name (str desc)
:circumspec/context '(concat [(.name *ns*)] circumspec.context/*context*)}
(if (empty? forms)
{:circumspec/pending true}
View
@@ -73,20 +73,20 @@
#(apply merge-with + %&)
(map #(select-keys % [:success :failure :error :pending]) result-seq)))
-(defn report-tally
- [tally]
- (let [{:keys [success failure error pending nsec]} tally]
- (println
- (apply format "%d success, %d failure, %d error, %d pending [%d msec]"
- (map #(or % 0) [success failure error pending (quot nsec 1000000)])))))
-
(defn exit-code
[tally]
(cond
(:error tally) 2
(:failure tally) 1
:default 0))
+(defn report-tally
+ [tally]
+ (let [{:keys [success failure error pending nsec]} tally]
+ (println
+ (apply format "%d success, %d failure, %d error, %d pending [%d msec]"
+ (map #(or % 0) [success failure error pending (quot nsec 1000000)])))))
+
(defn run-tests
"Runs all tests for current configuration, or as
passed in via tests."
@@ -99,13 +99,13 @@
(report results)
(raw/dump-results results)
(let [tally (assoc (tally results) :nsec (- (System/nanoTime) start))]
- (report-tally tally))
- tally))
+ (report-tally tally)
+ tally)))
(defn run-tests-and-exit
"Run tests and exit the process"
[& args]
- (let [tally (apply run-tests args)]
+ (let [tally (run-tests)]
(shutdown-agents)
(System/exit (exit-code tally))))
@@ -92,7 +92,7 @@
(let [actual (.getMessage throwable)]
(if ((match-fn expected-message) expected-message actual)
true
- (fail (merge (message-map ~message) {:expected expected-message :actual actual}))))
+ (fail (merge (message-map message) {:expected expected-message :actual actual}))))
true))
(defmethod should-body :throws
View
@@ -36,7 +36,7 @@
[fn form]
(let [c (count form)]
`(should
- (= (apply ~fn ~(apply vector (take (- c 2) form)))
+ (= (~fn ~@(apply vector (take (- c 2) form)))
~(last form)))))
(defmacro testing-fn
@@ -0,0 +1,15 @@
+(ns circumspec.for-test
+ (:use circumspec)
+ (:require [circumspec.should :as s]))
+
+(testing for-these
+ (for-these [x y] (should (= (+ x 10) y))
+ 5 15
+ 0 10
+ 3 13
+ 325342342 325342352)
+ (for-these [x y z] (should (= (+ x y) z))
+ 5 5 10
+ 0 0 0
+ 0 1 1
+ -4 10 6))
@@ -2,14 +2,14 @@
(:use circumspec)
(:require [circumspec.runner :as r]))
-(describe "with-timing"
+(describe r/with-timing
(it "adds nsec timings"
(let [x (r/with-timing {:success 1})]
(should (= 2 (count x)))
(should (= 1 (:success x)))
(should (instance? Long (:nsec x))))))
-(describe "tally"
+(describe r/tally
(it "sums the success, failure, error, and pending keys in sequence of results"
(for-these [tallied result-seq] (should (= tallied (r/tally result-seq)))
nil []
@@ -21,4 +21,4 @@
{:success 1 :error 2 :failure 3 :pending 4}
[{:success 1} {:error 2 :pending 2} {:failure 3 :pending 2}]
- )))
+ )))
@@ -2,7 +2,7 @@
(:use circumspec)
(:require [circumspec.should :as s]))
-(testing "match-fn"
+(testing s/match-fn
(for-these [fn type] (should (= fn (s/match-fn type)))
re-find #"foo"
= "foo"))
@@ -14,20 +14,9 @@
(should (throws? ArithmeticException "Divide by zero" (/ 1 f)))
(should (throws? ArithmeticException #"by" (/ 1 f)))))
-(testing "should-exception-matches"
+(testing s/should-exception-matches
(should (s/should-exception-matches nil "boom" (Throwable. "boom"))))
-(testing "for-these test"
- (for-these [x y] (should (= (+ x 10) y))
- 5 15
- 0 10
- 3 13
- 325342342 325342352)
- (for-these [x y z] (should (= (+ x y) z))
- 5 5 10
- 0 0 0
- 0 1 1
- -4 10 6))
@@ -2,13 +2,13 @@
(:use circumspec circumspec.for-all)
(:require [circumspec.test :as t]))
-(it t/make-test-name
+(testing t/make-test-name
(let [whitespacey-string (string-of alpha-ascii famous-whitespace (constantly \/))]
(for-all [s (whitespacey-string)]
(when-not (empty? s)
(should (not (re-find #" |\t|\n|/|\." (t/make-test-name s))))))))
-(it "=>-assertion?"
+(testing t/=>-assertion?
(should (false? (t/=>-assertion? nil)))
(should (false? (t/=>-assertion? [])))
(should (false? (t/=>-assertion? '[a])))
@@ -18,20 +18,20 @@
(should (true? (t/=>-assertion? '[a => b])))
(should (true? (t/=>-assertion? '[a b => c]))))
-(it "rewrite-=>"
+(testing t/rewrite-=>
(should (= (t/rewrite-=> '+ '[1 2 => 3])
- '(circumspec.should/should (clojure.core/= (clojure.core/apply + [1 2]) 3)))))
+ '(circumspec.should/should (clojure.core/= (+ 1 2) 3)))))
-(it "testing-fn"
+(testing t/testing-fn
(should (= '(circumspec.utils/defn! add-test
"Generated test from the testing-fn macro."
[]
- (circumspec.should/should (clojure.core/= (clojure.core/apply add [1 2]) 3))
- (circumspec.should/should (clojure.core/= (clojure.core/apply add [4 5]) 9)))
+ (circumspec.should/should (clojure.core/= (add 1 2) 3))
+ (circumspec.should/should (clojure.core/= (add 4 5) 9)))
(macroexpand-1
'(circumspec.test/testing-fn add (1 2 => 3) (4 5 => 9))))))
-(testing "test-function-name"
+(testing t/test-function-name
(should (= 'foo-test (t/test-function-name 'foo)) "symbol that does not resolve")
(should (= 'last-test (t/test-function-name 'last)) "symbol that resolves")
(should (= 'spec-vars-test (t/test-function-name 't/spec-vars)) "namespace-abbrev prefixed symbol")
@@ -2,7 +2,7 @@
(:use circumspec circumspec.utils circumspec.for-all
clojure.contrib.with-ns))
-(describe "class-symbol?"
+(describe class-symbol?
(testing "always returns a boolean"
(let [ascii-symbol (symbol-of alpha-ascii)]
(for-all [s (ascii-symbol)]
@@ -12,7 +12,7 @@
("src/circumspec/runner.clj" => 'circumspec.runner-test)
("test/circumspec/runner_test.clj" => 'circumspec.runner-test))
-(testing "mark-watched"
+(testing w/mark-watched
(binding [w/last-watched-atom (atom {})]
(w/mark-watched 111 ['circumspec.runner-test])
(should (= {'circumspec.runner-test 111}
@@ -22,4 +22,4 @@
(testing "finding changed namespaces"
(binding [w/last-watched-atom (atom {})]
- (should (seq (w/find-recent-namespaces-in-dir "src")))))
+ (should (seq (w/find-recent-namespaces-in-dir "src")))))

0 comments on commit 50a1c4e

Please sign in to comment.