Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

allow using test directory; lein2 support; wait for all output before exiting
  • Loading branch information...
commit c8096a93b6239fff60acfee3004729b1797d125b 2 parents a635146 + a32f302
Fogus fogus authored

Showing 2 changed files with 42 additions and 41 deletions. Show diff stats Hide diff stats

  1. +1 1  README.markdown
  2. +41 40 src/leiningen/generative.clj
2  README.markdown
Source Rendered
@@ -18,7 +18,7 @@ To run tests defined with test.generative you can simply run:
18 18
19 19 $ lein generative
20 20
21   -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:
  21 +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`:
22 22
23 23 :generative-path "/path/to/your/tests"
24 24
81 src/leiningen/generative.clj
... ... @@ -1,36 +1,24 @@
1   -(ns leiningen.generative
2   - (:refer-clojure :exclude [test])
3   - (:require leiningen.core)
4   - (:use [leiningen.compile :only [eval-in-project]]
5   - [leiningen.classpath :only [classpath]]))
  1 +(ns leiningen.generative)
6 2
7   -(defn- run-generative-tests [project]
  3 +(defn- run-generative-tests [paths keep-alive?]
8 4 `(do
9   - (let [path# ~(or (:generative-path project) "test/")]
10   - (println "Testing generative tests in" path#
11   - "on" gen/*cores* "cores for"
12   - gen/*msec* "msec.")
13   - (let [futures# (gen/test-dirs ~(:generative-path project))]
14   - (doseq [f# futures#]
15   - (try
16   - @f#
17   - (catch Throwable t#
18   - (.printStackTrace t#)
19   - (System/exit -1))
20   - (finally
21   - (when-not ~leiningen.core/*interactive?*
22   - (shutdown-agents)))))))))
  5 + (println "Testing generative tests in" [~@paths]
  6 + "on" gen/*cores* "cores for"
  7 + gen/*msec* "msec.")
  8 + (let [futures# (gen/test-dirs ~@paths)
  9 + results# (doall (map (fn [f#] (try @f# (catch Throwable t# -1)))
  10 + futures#))
  11 + code# (or (first (filter identity results#)) 0)]
  12 + (await gen/last-report)
  13 + (when-not (and ~keep-alive?
  14 + (= code# 0))
  15 + (shutdown-agents)
  16 + (System/exit code#)))))
23 17
24   -(defn- set-generative-path-to-project [project]
25   - (let [generative-path (str (:root project)
26   - java.io.File/separatorChar
27   - "generative")]
28   - (merge {:generative-path generative-path} project)))
29   -
30   -(defn- add-generative-path-to-classpath [project]
31   - (update-in project
32   - [:extra-classpath-dirs]
33   - #(conj % (:generative-path project))))
  18 +(defn- add-generative-path-to-classpath [project classpath-id]
  19 + (if-let [path (:generative-path project)]
  20 + (update-in project classpath-id #(conj % path))
  21 + project))
34 22
35 23 (defn add-generative-dependency [project]
36 24 (if (some #(= 'org.clojure/test.generative (first %)) (:dependencies project))
@@ -41,13 +29,26 @@
41 29 (defn generative
42 30 "Run test.generative tests"
43 31 [project & _]
44   - (let [new-project (-> project
45   - add-generative-dependency
46   - set-generative-path-to-project
47   - add-generative-path-to-classpath)]
48   - (eval-in-project
49   - new-project
50   - (run-generative-tests new-project)
51   - nil
52   - nil
53   - '(require '[clojure.test.generative :as gen]))))
  32 + (let [[eip keep-alive? classpath-id paths]
  33 + (or (try (require 'leiningen.core.eval)
  34 + [(resolve 'leiningen.core.eval/eval-in-project)
  35 + (not @(resolve 'leiningen.core.main/*exit-process?*))
  36 + [:test-paths]
  37 + (if-let [path (:generative-path project)]
  38 + [path]
  39 + (:test-paths project))]
  40 + (catch java.io.FileNotFoundException _))
  41 + (try (require 'leiningen.compile)
  42 + [(fn [p f g]
  43 + ((resolve 'leiningen.compile/eval-in-project) p f nil nil g))
  44 + @(resolve 'leiningen.core/*interactive?*)
  45 + [:extra-classpath-dirs]
  46 + [(or (:generative-path project)
  47 + (:test-path project))]]
  48 + (catch java.io.FileNotFoundException _)))]
  49 + (let [new-project (-> project
  50 + add-generative-dependency
  51 + (add-generative-path-to-classpath classpath-id))]
  52 + (eip new-project
  53 + (run-generative-tests paths keep-alive?)
  54 + '(require '[clojure.test.generative :as gen])))))

0 comments on commit c8096a9

Please sign in to comment.
Something went wrong with that request. Please try again.