Permalink
Browse files

Merge pull request #2 from xeqi/get-all-output

allow using test directory; lein2 support; wait for all output before exiting
  • Loading branch information...
2 parents a635146 + a32f302 commit c8096a93b6239fff60acfee3004729b1797d125b @fogus fogus committed Jun 22, 2012
Showing with 42 additions and 41 deletions.
  1. +1 −1 README.markdown
  2. +41 −40 src/leiningen/generative.clj
View
2 README.markdown
@@ -18,7 +18,7 @@ To run tests defined with test.generative you can simply run:
$ lein generative
-This will, by default run all tests in the project's `test` directory. If you prefer to run tests in a different directory then you can add something like the following to your `project.clj` properties:
+This will, by default run all tests in the project's test directory. If you prefer to use a seperate directory you can add something like the following to your `project.clj`:
:generative-path "/path/to/your/tests"
View
81 src/leiningen/generative.clj
@@ -1,36 +1,24 @@
-(ns leiningen.generative
- (:refer-clojure :exclude [test])
- (:require leiningen.core)
- (:use [leiningen.compile :only [eval-in-project]]
- [leiningen.classpath :only [classpath]]))
+(ns leiningen.generative)
-(defn- run-generative-tests [project]
+(defn- run-generative-tests [paths keep-alive?]
`(do
- (let [path# ~(or (:generative-path project) "test/")]
- (println "Testing generative tests in" path#
- "on" gen/*cores* "cores for"
- gen/*msec* "msec.")
- (let [futures# (gen/test-dirs ~(:generative-path project))]
- (doseq [f# futures#]
- (try
- @f#
- (catch Throwable t#
- (.printStackTrace t#)
- (System/exit -1))
- (finally
- (when-not ~leiningen.core/*interactive?*
- (shutdown-agents)))))))))
+ (println "Testing generative tests in" [~@paths]
+ "on" gen/*cores* "cores for"
+ gen/*msec* "msec.")
+ (let [futures# (gen/test-dirs ~@paths)
+ results# (doall (map (fn [f#] (try @f# (catch Throwable t# -1)))
+ futures#))
+ code# (or (first (filter identity results#)) 0)]
+ (await gen/last-report)
+ (when-not (and ~keep-alive?
+ (= code# 0))
+ (shutdown-agents)
+ (System/exit code#)))))
-(defn- set-generative-path-to-project [project]
- (let [generative-path (str (:root project)
- java.io.File/separatorChar
- "generative")]
- (merge {:generative-path generative-path} project)))
-
-(defn- add-generative-path-to-classpath [project]
- (update-in project
- [:extra-classpath-dirs]
- #(conj % (:generative-path project))))
+(defn- add-generative-path-to-classpath [project classpath-id]
+ (if-let [path (:generative-path project)]
+ (update-in project classpath-id #(conj % path))
+ project))
(defn add-generative-dependency [project]
(if (some #(= 'org.clojure/test.generative (first %)) (:dependencies project))
@@ -41,13 +29,26 @@
(defn generative
"Run test.generative tests"
[project & _]
- (let [new-project (-> project
- add-generative-dependency
- set-generative-path-to-project
- add-generative-path-to-classpath)]
- (eval-in-project
- new-project
- (run-generative-tests new-project)
- nil
- nil
- '(require '[clojure.test.generative :as gen]))))
+ (let [[eip keep-alive? classpath-id paths]
+ (or (try (require 'leiningen.core.eval)
+ [(resolve 'leiningen.core.eval/eval-in-project)
+ (not @(resolve 'leiningen.core.main/*exit-process?*))
+ [:test-paths]
+ (if-let [path (:generative-path project)]
+ [path]
+ (:test-paths project))]
+ (catch java.io.FileNotFoundException _))
+ (try (require 'leiningen.compile)
+ [(fn [p f g]
+ ((resolve 'leiningen.compile/eval-in-project) p f nil nil g))
+ @(resolve 'leiningen.core/*interactive?*)
+ [:extra-classpath-dirs]
+ [(or (:generative-path project)
+ (:test-path project))]]
+ (catch java.io.FileNotFoundException _)))]
+ (let [new-project (-> project
+ add-generative-dependency
+ (add-generative-path-to-classpath classpath-id))]
+ (eip new-project
+ (run-generative-tests paths keep-alive?)
+ '(require '[clojure.test.generative :as gen])))))

0 comments on commit c8096a9

Please sign in to comment.