Permalink
Browse files

Allow use of junit-report with Midje

  • Loading branch information...
1 parent 5b4469d commit af847b36fb92f0f6e9f6faee83a034bc71763ab1 @pmoriarty pmoriarty committed Jul 19, 2012
View
@@ -8,7 +8,7 @@
[org.clojure/core.incubator "0.1.0"]
[swiss-arrows "0.1.0"]])
-(defproject midje "1.5.0-SNAPSHOT"
+(defproject midje "1.4.0"
:description "A TDD library for Clojure that supports top-down ('mockish') TDD, encourages readable tests, provides a smooth migration path from clojure.test, balances abstraction and concreteness, and strives for graciousness."
:url "https://github.com/marick/Midje"
:dependencies ~(cons '[org.clojure/clojure "1.4.0"]
@@ -18,12 +18,13 @@
"1.2.1" [[org.clojure/clojure "1.2.1"]]
"1.3.0" [[org.clojure/clojure "1.3.0"]]
"1.4.0" [[org.clojure/clojure "1.4.0"]]
-; "1.5.0" [[org.clojure/clojure "1.5.0-SNAPSHOT"]]
+ "1.5.0" [[org.clojure/clojure "1.5.0-SNAPSHOT"]]
:all ~common-deps }
:dev-dependencies [[slamhound "1.2.0"]
[jonase/kibit "0.0.3"]
[jonase/eastwood "0.0.2"]
[com.stuartsierra/lazytest "1.2.3"]]
+ :resource-paths ["test-resources"]
;; automatically detects when your :dependencies key changes and runs
;; lein deps behind the scenes when necessary.
@@ -1,6 +1,7 @@
(ns ^{:doc "Renders the various reported fact evaluation results."}
midje.ideas.reporting.report
(:use clojure.test
+ clojure.test.junit
[midje.ideas.reporting.string-format :only [report-strings-format-config]]
[midje.ideas.reporting.junit-xml-format :only [junit-xml-format-config]]))
@@ -23,11 +24,8 @@
;;; Reporting
-(intern (the-ns 'clojure.test) 'old-report clojure.test/report)
-
(def #^:dynamic #^:private *renderer* println)
-
;;; This mechanism is only used to make `fact` return appropriate values of
;;; true or false. It doesn't piggyback off clojure.test/*report-counters*
;;; partly because that's not normally initialized and partly to reduce
@@ -59,10 +57,30 @@
(map *renderer*)
doall))]
- (defmethod clojure.test/old-report :default [m]
- (inc-report-counter :fail )
+ (defmethod clojure.test/report :default [m]
+ (inc-report-counter :fail)
+ (note-failure-in-fact)
+ (render m))
+
+ (defmethod clojure.test/report :future-fact [m]
+ (render m))
+
+ (defmethod clojure.test.junit/junit-report :default [m]
+ (inc-report-counter :fail)
(note-failure-in-fact)
+ (try
+ (with-test-out
+ (failure-el (:description m)
+ (:expected m)
+ (:actual m)))
+ (catch Exception e
+ (.printStackTrace e)
+ (throw e)))
+ (render m))
+
+
+ (defmethod clojure.test.junit/junit-report :future-fact [m]
(render m))
- (defmethod clojure.test/old-report :future-fact [m]
- (render m)))
+ (defmethod clojure.test.junit/junit-report :summary [m])
+ )
@@ -1,16 +1,53 @@
(ns midje.ideas.reporting.t-report
(:use midje.ideas.reporting.report
- [midje sweet test-util]))
+ midje.ideas.reporting.string-format
+ [midje sweet test-util])
+ (:require [clojure.test :as t]
+ [clojure.test.junit :as junit]))
;; These tests generate failures to examine. We don't want them to be
;; added to the total failure count, which should always be zero.
(without-counting-failures
-(fact "report formatter is dynamically rebindindable"
- (binding [*report-format-config* {:single-fact-fn (fn [_] "successfully rebound")
- :summary-fn :irrelevant}]
- (let [raw-report (with-identity-renderer (clojure.test/old-report :irrelevant))]
- (nth raw-report 0) => #"FAIL.*some description.*foo.clj:3"
- (nth raw-report 1) => "successfully rebound")))
+(fact "report formatter is dynamically rebindable"
+ (let [message {:type :mock-expected-result-failure :description "FAILURE" :expected 1 :actual 2}]
+ (binding [*report-format-config* {:single-fact-fn (fn [m]
+ (if (= m message)
+ ["successfully rebound"]
+ (report-strings m)))}]
+ (with-identity-renderer (t/report message)) => ["successfully rebound"]
+ )))
+
+(fact "junit-report default is treated as failure"
+ (let [message {:type :mock-expected-result-failure :description "FAILURE" :expected 1 :actual 2}]
+ (dosync (ref-set t/*report-counters* t/*initial-report-counters*))
+ (binding [*report-format-config* {:single-fact-fn
+ (fn [m]
+ (if (= m message)
+ [(:description m)]
+ (report-strings m)))}]
+ (with-identity-renderer (junit/junit-report message)) => (chatty-checker [a]
+ (and (= a ["FAILURE"])
+ (= {:pass 0, :test 0, :error 0, :fail 1}
+ @t/*report-counters*)))
+ (provided
+ (note-failure-in-fact) => nil
+ (junit/failure-el "FAILURE" 1 2) => nil
+ )
+ )))
+
+(fact "junit-report future-fact is rendered"
+ (let [message {:type :future-fact :description "FUTURE FACT"}]
+ (binding [*report-format-config* {:single-fact-fn
+ (fn [m]
+ (if (= m message)
+ [(:description m)]
+ (report-strings m)))}]
+ (with-identity-renderer (junit/junit-report message)) => ["FUTURE FACT"]
+ )))
+
+(fact "junit-report summary is ignored"
+ (let [message {:type :summary :description "FUTURE FACT"}]
+ (junit/junit-report message)) => nil)
) ; end without-counting-failures
@@ -29,7 +29,7 @@
:intermediate-results [ ['(f 1) 33] ]
:position ["foo.clj" 3]
:expected '(test-checker 33)}
- raw-report (with-identity-renderer (clojure.test/old-report failure-map))]
+ raw-report (with-identity-renderer (clojure.test/report failure-map))]
(nth raw-report 0) => #"FAIL.*some description.*foo.clj:3"
(nth raw-report 1) => #"Actual.*did not agree"
@@ -43,7 +43,7 @@
:actual 2
:position ["foo.clj" 3]
:expected 'odd?}
- raw-report (with-identity-renderer (clojure.test/old-report failure-map))]
+ raw-report (with-identity-renderer (clojure.test/report failure-map))]
(nth raw-report 0) => #"FAIL.*some description.*foo.clj:3"
(nth raw-report 1) => #"Actual.*did not agree"
(nth raw-report 2) => #"Actual.*2"
@@ -56,7 +56,7 @@
:expected '(sloobom "forp")
:intermediate-results [['(+ 1 "ate") nil]]
:position ["foo" 23]}
- raw-report (with-identity-renderer (clojure.test/old-report failure-map))]
+ raw-report (with-identity-renderer (clojure.test/report failure-map))]
(nth raw-report 2) => #"result: nil"
(nth raw-report 3) => #"function: \(sloobom \"forp\""
(nth raw-report 5) => #"\(\+ 1 \"ate\"\) => nil")
@@ -67,7 +67,7 @@
:notes ["NOTE ME!" "ME TOO"]
:position ["foo.clj" 3]
:expected '(test-checker 33)}
- raw-report (with-identity-renderer (clojure.test/old-report failure-map))]
+ raw-report (with-identity-renderer (clojure.test/report failure-map))]
(nth raw-report 0) => #"FAIL.*some description.*foo.clj:3"
(nth raw-report 1) => #"Actual.*did not agree"
(nth raw-report 2) => #"Actual.*2"
@@ -83,7 +83,7 @@
:actual 2
:position ["foo.clj" 3]
:expected '(test-checker 33)}
- raw-report (with-identity-renderer (clojure.test/old-report failure-map))]
+ raw-report (with-identity-renderer (clojure.test/report failure-map))]
(nth raw-report 0) => #"FAIL.*some description.*foo.clj:3"
(nth raw-report 1) => #"Actual.*was NOT supposed to agree"
@@ -97,7 +97,7 @@
:actual '(nil)
:position ["foo.clj" 3]
:var odd?}
- raw-report (with-identity-renderer (clojure.test/old-report failure-map))]
+ raw-report (with-identity-renderer (clojure.test/report failure-map))]
(nth raw-report 0) => #"FAIL.*some description.* at .*foo.clj:3"
(nth raw-report 1) => #"never said .*odd.* would be needed"
(nth raw-report 1) =future=> #"never said odd\? would be needed"
@@ -110,7 +110,7 @@
:expected-count nil
:position ["foo.clj" 3]
:expected "(f a)"}] }
- raw-report (with-identity-renderer (clojure.test/old-report failure-map))]
+ raw-report (with-identity-renderer (clojure.test/report failure-map))]
(nth raw-report 0) => #"FAIL.*some description.* at .*foo.clj:3"
(nth raw-report 1) => #"These calls were not made the right number of times"
(nth raw-report 2) => #"\(f a\)"
@@ -123,7 +123,7 @@
:expected-count 1
:position ["foo.clj" 3]
:expected "(f a)" }] }
- raw-report (with-identity-renderer (clojure.test/old-report failure-map))]
+ raw-report (with-identity-renderer (clojure.test/report failure-map))]
(nth raw-report 0) => #"FAIL.*some description.* at .*foo.clj:3"
(nth raw-report 1) => #"These calls were not made the right number of times"
(nth raw-report 2) => #"\(f a\)"
@@ -138,7 +138,7 @@
:position ["foo.clj" 3]
:actual nil
:expected "s"}
- raw-report (with-identity-renderer (clojure.test/old-report failure-map))]
+ raw-report (with-identity-renderer (clojure.test/report failure-map))]
(nth raw-report 0) => #"FAIL.*some description.* at .*foo.clj:3"
(nth raw-report 1) => #"Expected: \"s\""
(nth raw-report 2) => #"Actual: nil"))
@@ -149,7 +149,7 @@
:position ["foo.clj" 3]
:actual "s"
:expected "s"}
- raw-report (with-identity-renderer (clojure.test/old-report failure-map))]
+ raw-report (with-identity-renderer (clojure.test/report failure-map))]
(nth raw-report 0) => #"FAIL.*some description.* at .*foo.clj:3"
(nth raw-report 1) => #"Expected: Anything BUT \"s\""
(nth raw-report 2) => #"Actual: \"s\""))
@@ -160,7 +160,7 @@
:position ["foo.clj" 3]
:actual (captured-throwable (Error. "message"))
:expected "hi"}
- raw-report (with-identity-renderer (clojure.test/old-report failure-map))]
+ raw-report (with-identity-renderer (clojure.test/report failure-map))]
;; Because midje stack traces are filtered out, there's not much more to check.
(nth raw-report 2) => #"Error.*message")
@@ -172,7 +172,7 @@
:description ["some description"]
:notes ["message"]
:position ["foo.clj" 3]}
- raw-report (with-identity-renderer (clojure.test/old-report failure-map))]
+ raw-report (with-identity-renderer (clojure.test/report failure-map))]
(nth raw-report 0) => #"FAIL.*some description.* at .*foo.clj:3"
(nth raw-report 2) => #"message"))
@@ -182,7 +182,7 @@
:macro-form '(foo bar)
:stacktrace ["one" "two"]
:position ["foo.clj" 3]}
- raw-report (with-identity-renderer (clojure.test/old-report failure-map))]
+ raw-report (with-identity-renderer (clojure.test/report failure-map))]
(nth raw-report 0) => #"FAIL.*some description.* at .*foo.clj:3"
(nth raw-report 2) => (contains "(foo bar)")
(nth raw-report 4) => (contains "one")
@@ -195,7 +195,7 @@
:position ["foo.clj" 3]
:actual nil
:expected "s"}
- raw-report (with-identity-renderer (clojure.test/old-report failure-map))]
+ raw-report (with-identity-renderer (clojure.test/report failure-map))]
(nth raw-report 0) => #"FAIL.*some description.* at .*foo.clj:3"
(nth raw-report 1) => #"a note"))

0 comments on commit af847b3

Please sign in to comment.