Skip to content

Commit

Permalink
update l-e to work with lein 2
Browse files Browse the repository at this point in the history
  • Loading branch information
jaycfields committed Jun 20, 2012
1 parent afbcbec commit a1b02b8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject lein-expectations "0.0.4-SNAPSHOT"
(defproject lein-expectations "0.0.5"
:description "Leiningen plugin to run tests written using the expectations library."
:dependencies [[org.clojure/clojure "1.2.1"]]
:eval-in-leiningen true)
35 changes: 29 additions & 6 deletions src/leiningen/expectations.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
(ns leiningen.expectations
(:use [leiningen.compile :only [eval-in-project]]
[leiningen.util.ns :only [namespaces-in-dir]])
(:import (java.io File)))

(defn eval-in-project
"Support eval-in-project in both Leiningen 1.x and 2.x."
[project form init]
(let [[eip two?] (or (try (require 'leiningen.core.eval)
[(resolve 'leiningen.core.eval/eval-in-project)
true]
(catch java.io.FileNotFoundException _))
(try (require 'leiningen.compile)
[(resolve 'leiningen.compile/eval-in-project)]
(catch java.io.FileNotFoundException _)))]
(if two?
(eip project form init)
(eip project form nil nil init))))

(defn namespaces-in-dir
"Support namespaces-in-dir in both Leiningen 1.x and 2.x."
[dir]
(let [nid (or (try (require 'leiningen.util.ns)
(resolve 'leiningen.util.ns/namespaces-in-dir)
(catch java.io.FileNotFoundException _))
(try (require 'bultitude.core)
(resolve 'bultitude.core/namespaces-in-dir)
(catch java.io.FileNotFoundException _)))]
(nid dir)))

(defn matching-ns?
[to-match]
(let [to-match (map re-pattern to-match)]
Expand All @@ -18,7 +41,10 @@
By default all test namespaces will be run, or you can specify
which namespaces to run using regex syntax to filter."
[project & args]
(let [ns (->> (namespaces-in-dir (:test-path project))
(let [paths (if (:test-path project)
[(:test-path project)]
(:test-paths project))
ns (->> (mapcat namespaces-in-dir paths)
(filter (matching-ns? args)))
results (doto (File/createTempFile "lein" "result") .deleteOnExit)
path (.getAbsolutePath results)]
Expand All @@ -34,12 +60,9 @@
(java.io.OutputStreamWriter.))]
(.write w# (pr-str summary#))))
(shutdown-agents))
nil
nil
'(require ['expectations]))
(if (and (.exists results) (pos? (.length results)))
(let [summary (read-string (slurp path))
success? (zero? (+ (:fail summary) (:error summary)))]
(if success? 0 1))
1)))

0 comments on commit a1b02b8

Please sign in to comment.