Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
29 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,30 @@ | ||
(ns leiningen.midje | ||
(:require [leiningen.test :as lein])) | ||
(:use [leiningen.util.ns :only [namespaces-in-dir]] | ||
[leiningen.compile :only [eval-in-project]])) | ||
|
||
(defn midje [project] | ||
(lein/test project)) | ||
(defn require-namespaces-form [namespaces] | ||
`(do | ||
(require 'clojure.test) | ||
(alter-var-root (var clojure.test/*report-counters*) | ||
(fn [_#] (ref clojure.test/*initial-report-counters*))) | ||
(doseq [n# '~namespaces] (require n#)) | ||
(let [passes# (:pass @clojure.test/*report-counters*) | ||
fails# (:fail @clojure.test/*report-counters*) | ||
failure-message# (condp = fails# | ||
0 (format "All claimed facts (%d) have been confirmed." passes#) | ||
1 (format "FAILURE: %d fact was not confirmed." fails#) | ||
(format "FAILURE: %d facts were not confirmed." fails#)) | ||
potential-consolation# (condp = passes# | ||
0 "" | ||
1 "(But 1 was.)" | ||
(format "(But %d were.)" passes#)) | ||
consolation# (if (> fails# 0) potential-consolation# "")] | ||
(println failure-message# consolation#)))) | ||
|
||
(defn midje [project & namespaces] | ||
(let [desired-namespaces (if (empty? namespaces) | ||
(concat (namespaces-in-dir (:test-path project)) | ||
(namespaces-in-dir (:source-path project))) | ||
(map symbol namespaces))] | ||
(eval-in-project project | ||
(require-namespaces-form desired-namespaces)))) |