Skip to content

Commit

Permalink
Merge pull request #1 from fogus/master
Browse files Browse the repository at this point in the history
Updated
  • Loading branch information
fogus committed Sep 27, 2012
2 parents 9c68483 + c8096a9 commit 3a84d0c
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 52 deletions.
13 changes: 0 additions & 13 deletions README

This file was deleted.

36 changes: 36 additions & 0 deletions README.markdown
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.
5 changes: 2 additions & 3 deletions project.clj
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)

82 changes: 46 additions & 36 deletions src/leiningen/generative.clj
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])))))

0 comments on commit 3a84d0c

Please sign in to comment.