-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from fogus/master
Updated
- Loading branch information
Showing
4 changed files
with
84 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# lein-generative | ||
|
||
A [Leiningen](https://github.com/technomancy/leiningen) plugin used to run generative tests defined using the [test.generative](https://github.com/clojure/test.generative) Clojure contrib library. | ||
|
||
## Getting | ||
|
||
*This is currently only proven to work in Leiningen versions earlier than 2.0* | ||
|
||
Add the following to your Leiningen `project.clj` file in the `:plugins` section: | ||
|
||
[lein-generative "0.1.4.0"] | ||
|
||
The version number of lein-generative will track the latest released version of test.generative. The end of the version number will be the specific sub-version of this plugin. | ||
|
||
## Using | ||
|
||
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 use a seperate directory you can add something like the following to your `project.clj`: | ||
|
||
:generative-path "/path/to/your/tests" | ||
|
||
## Resources | ||
|
||
* [Source code](http://github.com/fogus/lein-generative) | ||
* [The Generative Generation](https://github.com/abedra/the-generative-generation) by Aaron Bedra | ||
* [Programming Clojure](http://pragprog.com/book/shcloj/programming-clojure) (2nd edition) by Stuart Halloway and Aaron Bedra | ||
* [Haskell Quickcheck](http://www.haskell.org/haskellwiki/Introduction_to_QuickCheck) (a library similar in intent to test.generative) | ||
|
||
## License | ||
|
||
Copyright (C) 2011-2012 Roman Gonzalez and Fogus | ||
|
||
Distributed under the Eclipse Public License, the same as Clojure. |
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,4 @@ | ||
(defproject lein-generative "1.0.0-SNAPSHOT" | ||
:description "FIXME: write description" | ||
:dev-dependencies [[org.clojure/test.generative "0.1.3"]] | ||
(defproject lein-generative "0.1.4.1-SNAPSHOT" | ||
:description "test.generative runner for Clojure contrib's test.generative." | ||
:eval-in-leiningen true) | ||
|
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,44 +1,54 @@ | ||
(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 | ||
(println "Testing 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)) | ||
(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#))))) | ||
|
||
(finally | ||
(when-not ~leiningen.core/*interactive?* | ||
(shutdown-agents)))))))) | ||
(defn- add-generative-path-to-classpath [project classpath-id] | ||
(if-let [path (:generative-path project)] | ||
(update-in project classpath-id #(conj % path)) | ||
project)) | ||
|
||
(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-dependency [project] | ||
(if (some #(= 'org.clojure/test.generative (first %)) (:dependencies project)) | ||
project | ||
(update-in project [:dependencies] | ||
conj '[org.clojure/test.generative "0.1.4"]))) | ||
|
||
(defn generative | ||
"Run test.generative tests" | ||
[project & _] | ||
(let [new-project (-> project | ||
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]))))) |