Permalink
Browse files

combo runner for c.t. / c.t.g.

  • Loading branch information...
1 parent 4d488b9 commit be0c54be648dab677ffe06f0ca3f8adc51a9f504 @stuarthalloway stuarthalloway committed Aug 17, 2012
View
@@ -1 +0,0 @@
-script/maven-classpath
View
@@ -38,13 +38,40 @@ and a validator:
[^long a ^long b] ;; input spec
(assert (integer? %))) ;; 0 or more validator forms
-To generate test data, see the fns in the generators namespace.
-
-To integrate with clojure.test:
-
- ;; somewhere in your test suite
- (:require '[clojure.test.generative.clojure-test :as clojure-test])
- (clojure-test/run-generative-tests)
+To generate test data, see the fns in the generators namespace. Note
+that these functions shadow a bunch of clojure.core names.
+
+You can run clojure.test and clojure.test.generative tests together
+from the c.t.g. runner:
+
+ (require '[clojure.test.generative.runner :as runner])
+ (runner/-main "src/test/clojure" "src/examples/clojure")
+
+Assertion support is currently minimal. There is an `is` macro,
+similar to clojure.test's, that provides rudimentaty contextual
+reporting. You can also use plain assertions, or clojure.test
+validation forms such as `is` and `are`, or any other forms that throw
+exception on failure. No contextual reporting for these yet.
+
+You can configure the runner with Java system properties:
+
+<table>
+ <tr>
+ <th>Java Property</th><th>Interpretation</th>
+ </tr>
+ <tr>
+ <td>clojure.test.generative.threads</td><td>Number of concurrent threads</td>
+ </tr>
+ <tr>
+ <td>clojure.test.generative.msec</td><td>Desired test run duration</td>
+ </tr>
+ <tr>
+ <td>clojure.test.generative.handlers</td><td>Comma-delimited list of handlers</td>
+ </tr>
+</table>
+
+The default handler prints test run to stdout, but others could
+e.g. put test events in a database.
Developer Information
========================================
@@ -57,8 +84,6 @@ Developer Information
* [Compatibility Test Matrix](http://build.clojure.org/job/test.generative-test-matrix/)
-
-
Change Log
====================
View
@@ -0,0 +1,3 @@
+(require '[clojure.test.generative.runner :as runner])
+(runner/-main "src/test/clojure" "src/examples/clojure")
+
View
@@ -0,0 +1,58 @@
+* Common Event Keys
+| name | type | notes |
+|-------------+--------------------+----------------------------------------|
+| tstamp | long | msec since epoch |
+| thread | long | thread id |
+| pid | long | process id |
+| level | keyword enum | severiry level |
+| type | namespaced keyword | drive extended interpretation |
+| locals | map | local bindings |
+| file | string | file path |
+| ns | symbol | namespace |
+| line | long | line number |
+| bindings | map | dynamic bindings |
+| thread/name | string | name of a thread |
+| msec | long | a duration |
+| nsec | long | a duration |
+| count | long | a count |
+| tag | set of keyword | |
+| args | list of any | args to a fn |
+| return | any | return value of a fun |
+| exception | exception | an exception |
+| name | symbol | a name |
+| description | string | a non-name characterization of a thing |
+| uuid | uuid | a unique name |
+| message | string | a message |
+* Comment Event Types
+| type | notes |
+|-------+------------|
+| error | runtime error |
+* Test Event Keys
+| name | type | notes |
+|---------------+--------+----------------------|
+| test/count | long | number of tests |
+| test/threads | long | number of threads |
+| test/seed | long | numeric seed |
+| text/expected | any | |
+| test/actual | any | |
+| test/library | symbol | name of test library |
+* Test Events in c.t.g
+| name | begin/end tags? | count | args | test/threads | msec | context | level |
+|--------------+-----------------+-------+------+--------------+------+---------+-------|
+| :test/group | x | x | | | | | info |
+| :test/iter | | | x | | | | info |
+| :test/test | x | x | | | x | | info |
+| :test/seed | | | | | | | info |
+| :test/fail | | | | | | x | warn |
+| :test/pass | | | | | | | info |
+| :assert/pass | | | | | | | debug |
+| :assert/fail | | | | | | | debug |
+* Test Events in c.t
+| name | becomes | other keys |
+|---------------------+-------------------------+--------------------------------------------------|
+| :pass | :assert/pass | |
+| :fail | :assert/fail | :expected, :actual, :message, *testing-contexts* |
+| :error | :error | :expected, :actual, :message, *testing-contexts* |
+| :summary | (ignore, do own calc) | |
+| :begin/end-test-ns | :test/group :begin/:end | :ns -> name |
+| :begin/end-test-var | :test/test :begin/:end | :var -> name |
View
@@ -96,7 +96,10 @@
<version>1.3.7</version>
<configuration>
<vmargs>-Dclojure.test.generative.runner=clojure.test</vmargs>
- <!-- <testScript>bin/test_runner.clj</testScript> -->
+ <testScript>bin/test.clj</testScript>
+ <testSourceDirectories>
+ <testSourceDirectory>src/examples/clojure</testSourceDirectory>
+ </testSourceDirectories>
<copiedNamespaces>
<namespace>!.*</namespace>
</copiedNamespaces>
@@ -9,10 +9,7 @@
(ns clojure.test.array-test
(:use clojure.test.generative)
- (:require [clojure.test.generative.generators :as gen]
- [clojure.test.generative.clojure-test :as clojure-test]))
-
-(clojure-test/run-generative-tests)
+ (:require [clojure.test.generative.generators :as gen]))
(defn nan-or-=
[a b]
@@ -49,7 +49,7 @@
[& args]
`(do
(runner/failed!)
- ~(with-meta `(event/report-context :type ::fail
+ ~(with-meta `(event/report-context :assert/fail
:level :warn
~@args)
(meta &form))))
@@ -60,7 +60,7 @@
`(let [~'actual ~v ~'expected '~v]
(if ~'actual
(do
- (event/report :level :debug :type ::pass)
+ (event/report :assert/pass :level :debug)
~'actual)
~(with-meta
`(fail ~@(when msg `[:message ~msg]))
@@ -1,78 +0,0 @@
-; Copyright (c) Rich Hickey, Stuart Halloway, and contributors.
-; All rights reserved.
-; The use and distribution terms for this software are covered by the
-; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
-; which can be found in the file epl-v10.html at the root of this distribution.
-; By using this software in any fashion, you are agreeing to be bound by
-; the terms of this license.
-; You must not remove this notice, or any other, from this software.
-
-(ns clojure.test.generative.clojure-test
- (:require [clojure.test.generative.event :as event]
- [clojure.test.generative.config :as config]
- [clojure.test.generative.runner :as runner]
- [clojure.tools.namespace :as ns]
- [clojure.test :as ctest]))
-
-(defmulti event->ctevent
- "Returns an event for a Clojure test reporter, or nil"
- :type)
-
-(defmethod event->ctevent :default [_] nil)
-(defmethod event->ctevent :clojure.test.generative/pass [_] {:type :pass})
-(defmethod event->ctevent :clojure.test.generative/iter [e] e)
-(defmethod event->ctevent :clojure.test.generative/fail [e] e)
-(defmethod event->ctevent :clojure.test.generative/error [e] e)
-
-(defmethod ctest/report :clojure.test.generative/iter
- [e]
- (when (contains? (:tags e) :begin)
- (ctest/inc-report-counter :test)))
-
-(defmethod ctest/report :clojure.test.generative/fail
- [e]
- (ctest/inc-report-counter :fail)
- (println "\nFAIL\n")
- (event/pprint e))
-
-(defmethod ctest/report :clojure.test.generative/error
- [e]
- (ctest/inc-report-counter :error)
- (println "\nERROR\n")
- (event/pprint e))
-
-(defn handler
- "Event handler that delegates c.t.g events to clojure.test/report"
- [e]
- (event/dot-progress e)
- (when-let [cte (event->ctevent e)]
- (clojure.test/report cte)))
-
-(defmacro run-generative-tests
- "Add this macro somewhere in your clojure.test suite to create
- a clojure.test entry point that will run your generative tests"
- []
- (event/add-handler handler)
- `(ctest/deftest ~'generative-test-adapter
- []
- (runner/run-all)))
-
-(defn -main
- "Command line entry point, runs all tests in dirs using clojure.test"
- [& dirs]
- (if (seq dirs)
- (let [nses (mapcat #(ns/find-namespaces-in-dir (java.io.File. ^String %)) dirs)]
- (doseq [ns nses] (require ns))
- (let [{:keys [threads msec]} (config/config)]
- (try
- (println "Testing on" threads "threads for" msec "msec.")
- (apply ctest/run-tests nses)
- (catch Throwable t
- (.printStackTrace t)
- (System/exit -1))
- (finally
- (shutdown-agents)))))
- (do
- (println "Specify at least one directory with tests")
- (System/exit -1))))
-
@@ -0,0 +1,81 @@
+; Copyright (c) Rich Hickey, Stuart Halloway, and contributors.
+; All rights reserved.
+; The use and distribution terms for this software are covered by the
+; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
+; which can be found in the file epl-v10.html at the root of this distribution.
+; By using this software in any fashion, you are agreeing to be bound by
+; the terms of this license.
+; You must not remove this notice, or any other, from this software.
+
+(ns clojure.test.generative.clojure-test-adapter
+ (:require [clojure.test.generative.event :as event]
+ [clojure.test.generative.config :as config]
+ [clojure.test.generative.io :as testio]
+ [clojure.tools.namespace :as ns]
+ [clojure.test :as ctest]))
+
+(defmulti ctevent->event
+ "Convert a clojure.test reporting event to an event."
+ :type)
+
+(defmethod ctevent->event :default
+ [e]
+ (event/create :clojure.test/unknown e))
+
+(defmethod ctevent->event :pass
+ [e]
+ (event/create :type :assert/pass))
+
+(defmethod ctevent->event :fail
+ [e]
+ (event/create :type :assert/fail
+ ::ctest/testing-contexts (seq ctest/*testing-contexts*)))
+
+(defmethod ctevent->event :error
+ [e]
+ (event/create :level :error
+ :type :error
+ ::ctest/testing-contexts (seq ctest/*testing-contexts*)
+ :message (:message e)
+ :test/expected (:expected e)
+ :test/actual (:actual e)
+ :file (:file e)
+ :line (:line e)
+ ::ctest/testing-vars (reverse (map #(:name (meta %)) ctest/*testing-vars*))))
+
+(defmethod ctevent->event :summary
+ [e]
+ nil)
+
+(defmethod ctevent->event :begin-test-ns
+ [e]
+ (event/create :type :test/group
+ :tags #{:begin}
+ :name (ns-name (:ns e))))
+
+(defmethod ctevent->event :end-test-ns
+ [e]
+ (event/create :type :test/group
+ :tags #{:end}
+ :name (ns-name (:ns e))))
+
+(defmethod ctevent->event :begin-test-var
+ [e]
+ (event/create :type :test/test
+ :tags #{:begin}
+ :name (event/fqname (:var e))))
+
+(defmethod ctevent->event :end-test-var
+ [e]
+ (event/create :type :test/test
+ :tags #{:end}
+ :name (event/fqname (:var e))))
+
+(defn report-adapter
+ "Adapt clojure.test event model to fire c.t.g events."
+ [m]
+ (when-let [e (ctevent->event m)]
+ (event/report-fn e)))
+
+
+
@@ -7,12 +7,13 @@
; the terms of this license.
; You must not remove this notice, or any other, from this software.
-(ns clojure.test.generative.config)
+(ns clojure.test.generative.config
+ (:require [clojure.string :as str]))
(def config-mapping
[["clojure.test.generative.threads" [:threads] read-string (.availableProcessors (Runtime/getRuntime))]
["clojure.test.generative.msec" [:msec] read-string 10000]
- ["clojure.test.generative.runner" [:runner] identity nil]])
+ ["clojure.test.generative.handlers" [:handlers] #(str/split % #",") ["clojure.test.generative.io/console-reporter"]]])
(defn config
[]
Oops, something went wrong.

0 comments on commit be0c54b

Please sign in to comment.