myfreeweb avatar myfreeweb committed 90a9ae3

midje support

Comments (0)

Files changed (4)

 subprojects {
-    group = 'clojuresque'
+    group = 'org.clojars.myfreeweb.clojuresque'
     version = '1.5.0-SNAPSHOT'
 }
 

clojuresque/src/main/groovy/clojuresque/ClojureBasePlugin.groovy

             }
         }
         project.dependencies {
-            clojuresque group: "clojuresque", name: "runtime",
+            clojuresque group: "org.clojars.myfreeweb.clojuresque", name: "runtime",
                 version: this.properties.getProperty("clojuresque.version")
         }
     }

clojuresque/src/main/groovy/clojuresque/ClojureTestTask.groovy

         project.clojureexec {
             this.jvmOptions()
             classpath = project.files(
+                this.resRoots.srcDirs,
                 this.testRoots.srcDirs,
                 this.classesDir,
                 this.classpath
             )
-            if (tests.size() == 0) {
-                main = "clojuresque.tasks.test/test-namespaces"
-                args = this.source.files
-            } else {
-                main = "clojuresque.tasks.test/test-vars"
-                args = tests
-            }
+            main = "clojuresque.tasks.test/midje"
+            args = this.source.files
         }
     }
 }

runtime/src/main/resources/clojuresque/tasks/test.clj

 (ns clojuresque.tasks.test
+  (:require [clojure test string])
   (:use
-    [clojure.test :only (run-tests) :as t]
     [clojuresque.cli :only (deftask)]
     [clojuresque.util :only (namespaces)]))
 
-(defn check-result
-  [result]
-  (when (or (pos? (:fail result)) (pos? (:error result)))
-    (System/exit 1)))
+; https://raw.github.com/marick/Midje/master/examples/cake-midje/tasks.clj
 
-(deftask test-namespaces
-  "Run all tests in the namespaces of the given files by virtue of clojure.test."
+(deftask midje
+  "Run midje and clojure.test tests"
   [files]
   (let [namespaces (namespaces files)]
-    (apply require namespaces)
-    (check-result (apply run-tests namespaces))))
+    ;; This turns off "Testing ...." lines, which I hate, especially
+    ;; when there's no failure output.
+    (defmethod clojure.test/report :begin-test-ns [m])
+    (alter-var-root (var clojure.test/*report-counters*)
+                    (fn [_] (ref clojure.test/*initial-report-counters*)))
+    (doseq [n namespaces] (require n :reload))
+    (let [midje-passes    (:pass @clojure.test/*report-counters*)
+          midje-fails     (:fail @clojure.test/*report-counters*)
+          midje-failure-message
+            (condp = midje-fails
+              0 (format "All claimed facts (%d) have been confirmed." midje-passes)
+              1 (format "FAILURE: %d fact was not confirmed." midje-fails)
+              (format "FAILURE: %d facts were not confirmed." midje-fails))
+          potential-consolation
+            (condp = midje-passes
+              0 ""
+              1 "(But 1 was.)"
+              (format "(But %d were.)" midje-passes))
+          midje-consolation
+            (if (> midje-fails 0) potential-consolation "")
+          ; Stashed clojure.test output
+          clojure-test-output-catcher (java.io.StringWriter.)
+          clojure-test-result
+            (binding [clojure.test/*test-out* clojure-test-output-catcher]
+              (apply clojure.test/run-tests namespaces))
+          clojure-test-output
+            (-> clojure-test-output-catcher .toString clojure.string/split-lines)]
 
-; For now: do stuff manually for explicitly named tests.
-(deftask test-vars
-  "Run only the named tests by virtue of clojure.test."
-  [tests]
-  (let [tests (group-by (comp symbol namespace) (map read-string tests))]
-    (apply require (keys tests))
-    (binding [t/*report-counters* (ref t/*initial-report-counters*)]
-      (doseq [[nspace test-vars] tests]
-        (let [ns-obj          (the-ns nspace)
-              once-fixture-fn (t/join-fixtures
-                                (::t/once-fixtures (meta ns-obj)))
-              each-fixture-fn (t/join-fixtures
-                                (::t/each-fixtures (meta ns-obj)))]
-          (t/do-report {:type :begin-test-ns :ns ns-obj})
-          (once-fixture-fn
-            (fn []
-              (doseq [v (map resolve test-vars)]
-                (when (:test (meta v))
-                  (each-fixture-fn (fn [] (t/test-var v)))))))
-          (t/do-report {:type :end-test-ns :ns ns-obj})))
-      (let [summary (assoc @t/*report-counters* :type :summary)]
-        (t/do-report summary)
-        (check-result summary)))))
+      (when (> (+ (:fail clojure-test-result) (:error clojure-test-result))
+               0)
+        (println ">>> Output from clojure.test tests:")
+        (dorun (map println (drop-last 2 clojure-test-output))))
+
+      (when (> (:test clojure-test-result) 0)
+        (println ">>> clojure.test summary:")
+        (dorun (map println (take-last 2 clojure-test-output)))
+        (println ">>> Midje summary:"))
+      (println midje-failure-message midje-consolation)
+      (System/exit (+ midje-fails
+                      (:fail clojure-test-result)
+                      (:error clojure-test-result))))))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.